1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AdabasStat.cxx,v $
10 * $Revision: 1.17.158.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _TOOLS_DEBUG_HXX
35 #include <tools/debug.hxx>
37 #ifndef _CPPUHELPER_EXC_HLP_HXX_
38 #include <cppuhelper/exc_hlp.hxx>
40 #ifndef TOOLS_DIAGNOSE_EX_H
41 #include <tools/diagnose_ex.h>
43 #ifndef _DBAUI_ADASTAT_HXX_
44 #include "AdabasStat.hxx"
46 #ifndef _COMPHELPER_TYPES_HXX_
47 #include <comphelper/types.hxx>
49 #ifndef _COM_SUN_STAR_SDBC_XSTATEMENT_HPP_
50 #include <com/sun/star/sdbc/XStatement.hpp>
52 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
53 #include <com/sun/star/sdbc/XRow.hpp>
55 #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
56 #include <com/sun/star/sdbc/XResultSet.hpp>
58 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
59 #include <com/sun/star/beans/XPropertySet.hpp>
61 #ifndef DBAUI_ADABASSTAT_HRC
62 #include "AdabasStat.hrc"
65 #include "dbu_dlg.hrc"
67 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
68 #include "dbustrings.hrc"
70 #ifndef DBAUI_TOOLS_HXX
71 #include "UITools.hxx"
73 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
74 #include <connectivity/dbtools.hxx>
76 #ifndef _DBAUI_SQLMESSAGE_HXX_
77 #include "sqlmessage.hxx"
80 using namespace dbaui
;
81 DBG_NAME(OAdabasStatistics
)
84 using namespace dbtools
;
85 using namespace ::com::sun::star::uno
;
86 using namespace ::com::sun::star::beans
;
87 using namespace ::com::sun::star::sdbc
;
88 using namespace ::com::sun::star::lang
;
92 OAdabasStatistics::OAdabasStatistics( Window
* pParent
,
93 const ::rtl::OUString
& _rUser
,
94 const Reference
< ::com::sun::star::sdbc::XConnection
>& _xCurrentConnection
,
95 const Reference
< XMultiServiceFactory
>& _xFactory
)
96 : ModalDialog( pParent
, ModuleRes(DLG_ADABASSTAT
) )
97 ,m_FL_FILES( this , ModuleRes(FL_FILES
))
98 ,m_FT_SYSDEVSPACE( this , ModuleRes(FT_SYSDEVSPACE
))
99 ,m_ET_SYSDEVSPACE( this , STR_ADABAS_HELP_SYSDEVSPACE
,ModuleRes(ET_SYSDEVSPACE
))
100 ,m_FT_TRANSACTIONLOG( this , ModuleRes(FT_TRANSACTIONLOG
))
101 ,m_ET_TRANSACTIONLOG( this , STR_ADABAS_HELP_TRANSACT
,ModuleRes(ET_TRANSACTIONLOG
))
102 ,m_FT_DATADEVSPACE( this , ModuleRes(FT_DATADEVSPACE
))
103 ,m_LB_DATADEVS( this , STR_ADABAS_HELP_DATADEVSPACES
,ModuleRes(LB_DATADEVS
))
104 ,m_FL_SIZES( this , ModuleRes(FL_SIZES
))
105 ,m_FT_SIZE( this , ModuleRes(FT_SIZE
))
106 ,m_ET_SIZE( this , STR_ADABAS_HELP_SIZE
,ModuleRes(ET_SIZE
))
107 ,m_FT_FREESIZE( this , ModuleRes(FT_FREESIZE
))
108 ,m_ET_FREESIZE( this , STR_ADABAS_HELP_FREESIZE
,ModuleRes(ET_FREESIZE
))
109 ,m_FT_MEMORYUSING( this , ModuleRes(FT_MEMORYUSING
))
110 ,m_ET_MEMORYUSING( this , STR_ADABAS_HELP_MEMORYUSING
,ModuleRes(ET_MEMORYUSING
))
111 ,m_PB_OK( this , ModuleRes(PB_OK
))
112 ,m_xConnection(_xCurrentConnection
)
113 ,m_bErrorShown(sal_False
)
115 DBG_CTOR(OAdabasStatistics
,NULL
);
119 DBG_ASSERT(m_xConnection
.is(),"No connection");
120 if(m_xConnection
.is())
122 Reference
<XStatement
> xStmt
;
123 Reference
<XResultSet
> xRes
;
125 sal_Bool bCanSelect
= sal_False
;
126 ::rtl::OUString aStmt
;
127 ::rtl::OUString sSchema
= _rUser
.toAsciiUpperCase();
129 Reference
<XDatabaseMetaData
> xMetaData
;
130 // first read the sizes
133 xMetaData
= m_xConnection
->getMetaData();
134 bCanSelect
= checkSystemTable(::rtl::OUString::createFromAscii("SERVERDBSTATISTICS"),sSchema
);
138 aStmt
= ::rtl::OUString::createFromAscii("SELECT SERVERDBSIZE, UNUSEDPAGES FROM ");
140 aStmt
+= ::dbtools::quoteTableName(xMetaData
,sSchema
,::dbtools::eInDataManipulation
);
141 aStmt
+= ::rtl::OUString::createFromAscii(".\"SERVERDBSTATISTICS\"");
143 xStmt
= m_xConnection
->createStatement();
144 xRes
= xStmt
->executeQuery(aStmt
);
147 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
148 // first the db sizes
149 if(xRes
.is() && xRes
->next())
151 double nUsedPages
= xRow
->getInt(1) / 256;
152 double nFreePages
= xRow
->getInt(2) / 256;
154 m_ET_SIZE
.SetText(::rtl::OUString::valueOf((INT32
)nUsedPages
));
155 m_ET_FREESIZE
.SetText(::rtl::OUString::valueOf((INT32
)nFreePages
));
156 m_ET_MEMORYUSING
.SetValue(static_cast<sal_Int32
>(((nUsedPages
-nFreePages
)/nUsedPages
)*100));
166 catch(const SQLException
& )
168 ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ), pParent
, _xFactory
);
170 catch( const Exception
& )
172 DBG_UNHANDLED_EXCEPTION();
176 ::comphelper::disposeComponent(xStmt
);
178 catch( const Exception
& )
180 DBG_UNHANDLED_EXCEPTION();
183 // now fill the datadev spaces
188 bCanSelect
= checkSystemTable(::rtl::OUString::createFromAscii("DATADEVSPACES"),sSchema
);
193 aStmt
= ::rtl::OUString::createFromAscii("SELECT DEVSPACENAME FROM ");
194 aStmt
+= ::dbtools::quoteTableName(xMetaData
,sSchema
,::dbtools::eInDataManipulation
);
195 aStmt
+= ::rtl::OUString::createFromAscii(".\"DATADEVSPACES\"");
196 xStmt
= m_xConnection
->createStatement();
197 xRes
= xStmt
->executeQuery(aStmt
);
199 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
200 while(xRes
.is() && xRes
->next())
202 m_LB_DATADEVS
.InsertEntry(xRow
->getString(1));
204 if(!m_LB_DATADEVS
.GetEntryCount())
210 catch(const SQLException
& e
)
212 ::dbaui::showError(SQLExceptionInfo(e
),pParent
,_xFactory
);
214 catch( const Exception
& )
216 DBG_UNHANDLED_EXCEPTION();
220 ::comphelper::disposeComponent(xStmt
);
222 catch( const Exception
& )
224 DBG_UNHANDLED_EXCEPTION();
227 // now fill the sysdatadev spaces
232 bCanSelect
= checkSystemTable(::rtl::OUString::createFromAscii("CONFIGURATION"),sSchema
);
236 aStmt
= ::rtl::OUString::createFromAscii("SELECT * FROM ");
237 aStmt
+= ::dbtools::quoteTableName(xMetaData
,sSchema
,::dbtools::eInDataManipulation
);
238 aStmt
+= ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION LIKE 'SYS%DEVSPACE%NAME'");
239 xStmt
= m_xConnection
->createStatement();
240 xRes
= xStmt
->executeQuery(aStmt
);
241 if(xRes
.is() && xRes
->next())
243 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
244 m_ET_SYSDEVSPACE
.SetText(xRow
->getString(2));
249 aStmt
= ::rtl::OUString::createFromAscii("SELECT * FROM ");
250 aStmt
+= ::dbtools::quoteTableName(xMetaData
,sSchema
,::dbtools::eInDataManipulation
);
251 aStmt
+= ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION = 'TRANSACTION LOG NAME'");
252 xRes
= xStmt
->executeQuery(aStmt
);
253 if(xRes
.is() && xRes
->next())
255 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
256 m_ET_TRANSACTIONLOG
.SetText(xRow
->getString(2));
264 catch(const SQLException
& e
)
266 ::dbaui::showError(SQLExceptionInfo(e
),pParent
,_xFactory
);
268 catch( const Exception
& )
270 DBG_UNHANDLED_EXCEPTION();
274 ::comphelper::disposeComponent(xStmt
);
276 catch( const Exception
& )
278 DBG_UNHANDLED_EXCEPTION();
284 m_ET_SYSDEVSPACE
.SetSpecialReadOnly(sal_True
);
285 m_ET_TRANSACTIONLOG
.SetSpecialReadOnly(sal_True
);
286 m_LB_DATADEVS
.SetSpecialReadOnly(sal_True
);
287 m_ET_SIZE
.SetSpecialReadOnly(sal_True
);
288 m_ET_FREESIZE
.SetSpecialReadOnly(sal_True
);
289 m_ET_MEMORYUSING
.SetSpecialReadOnly(sal_True
);
291 //------------------------------------------------------------------------
292 OAdabasStatistics::~OAdabasStatistics()
294 DBG_DTOR(OAdabasStatistics
,NULL
);
296 // -----------------------------------------------------------------------------
297 sal_Bool
OAdabasStatistics::checkSystemTable(const ::rtl::OUString
& _rsSystemTable
, ::rtl::OUString
& _rsSchemaName
)
299 sal_Bool bCanSelect
= sal_False
;
300 Reference
<XDatabaseMetaData
> xMeta
= m_xConnection
->getMetaData();
303 Reference
<XResultSet
> xRes
= xMeta
->getTablePrivileges(Any(),::rtl::OUString::createFromAscii("%"), _rsSystemTable
);
306 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
307 static const ::rtl::OUString sSelect
= ::rtl::OUString::createFromAscii("SELECT");
308 // first the db sizes
309 while( xRow
.is() && xRes
->next() )
311 _rsSchemaName
= xRow
->getString(2);
312 if(sSelect
== xRow
->getString(6) && !xRow
->wasNull())
314 bCanSelect
= sal_True
;
318 ::comphelper::disposeComponent(xRes
);
324 // -----------------------------------------------------------------------------
325 void OAdabasStatistics::showError()
329 OSQLMessageBox
aMsg(GetParent(),GetText(),String(ModuleRes(STR_ADABAS_ERROR_SYSTEMTABLES
)));
331 m_bErrorShown
= sal_True
;
334 // -----------------------------------------------------------------------------