1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _CPPUHELPER_EXC_HLP_HXX_
#include <cppuhelper/exc_hlp.hxx>
#endif
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
#ifndef _DBAUI_ADASTAT_HXX_
#include "AdabasStat.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _COM_SUN_STAR_SDBC_XSTATEMENT_HPP_
#include <com/sun/star/sdbc/XStatement.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
#include <com/sun/star/sdbc/XResultSet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef DBAUI_ADABASSTAT_HRC
#include "AdabasStat.hrc"
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
using namespace dbaui;
DBG_NAME(OAdabasStatistics)
namespace dbaui
{
using namespace dbtools;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::lang;
OAdabasStatistics::OAdabasStatistics( Window* pParent,
const ::rtl::OUString& _rUser,
const Reference< ::com::sun::star::sdbc::XConnection >& _xCurrentConnection,
const Reference< XMultiServiceFactory >& _xFactory)
: ModalDialog( pParent, ModuleRes(DLG_ADABASSTAT) )
,m_FL_FILES( this , ModuleRes(FL_FILES))
,m_FT_SYSDEVSPACE( this , ModuleRes(FT_SYSDEVSPACE))
,m_ET_SYSDEVSPACE( this , STR_ADABAS_HELP_SYSDEVSPACE,ModuleRes(ET_SYSDEVSPACE))
,m_FT_TRANSACTIONLOG( this , ModuleRes(FT_TRANSACTIONLOG))
,m_ET_TRANSACTIONLOG( this , STR_ADABAS_HELP_TRANSACT,ModuleRes(ET_TRANSACTIONLOG))
,m_FT_DATADEVSPACE( this , ModuleRes(FT_DATADEVSPACE))
,m_LB_DATADEVS( this , STR_ADABAS_HELP_DATADEVSPACES,ModuleRes(LB_DATADEVS))
,m_FL_SIZES( this , ModuleRes(FL_SIZES))
,m_FT_SIZE( this , ModuleRes(FT_SIZE))
,m_ET_SIZE( this , STR_ADABAS_HELP_SIZE,ModuleRes(ET_SIZE))
,m_FT_FREESIZE( this , ModuleRes(FT_FREESIZE))
,m_ET_FREESIZE( this , STR_ADABAS_HELP_FREESIZE,ModuleRes(ET_FREESIZE))
,m_FT_MEMORYUSING( this , ModuleRes(FT_MEMORYUSING))
,m_ET_MEMORYUSING( this , STR_ADABAS_HELP_MEMORYUSING,ModuleRes(ET_MEMORYUSING))
,m_PB_OK( this , ModuleRes(PB_OK))
,m_xConnection(_xCurrentConnection)
,m_bErrorShown(sal_False)
{
DBG_CTOR(OAdabasStatistics,NULL);
FreeResource();
DBG_ASSERT(m_xConnection.is(),"No connection");
if(m_xConnection.is())
{
Reference<XStatement> xStmt;
Reference<XResultSet> xRes;
sal_Bool bCanSelect = sal_False;
::rtl::OUString aStmt;
::rtl::OUString sSchema = _rUser.toAsciiUpperCase();
Reference<XDatabaseMetaData> xMetaData;
// first read the sizes
try
{
xMetaData = m_xConnection->getMetaData();
bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("SERVERDBSTATISTICS"),sSchema);
if(bCanSelect)
{
aStmt = ::rtl::OUString::createFromAscii("SELECT SERVERDBSIZE, UNUSEDPAGES FROM ");
aStmt += ::dbtools::quoteTableName(xMetaData,sSchema,::dbtools::eInDataManipulation);
aStmt += ::rtl::OUString::createFromAscii(".\"SERVERDBSTATISTICS\"");
xStmt = m_xConnection->createStatement();
xRes = xStmt->executeQuery(aStmt);
Reference<XRow> xRow(xRes,UNO_QUERY);
// first the db sizes
if(xRes.is() && xRes->next())
{
double nUsedPages = xRow->getInt(1) / 256;
double nFreePages = xRow->getInt(2) / 256;
m_ET_SIZE.SetText(::rtl::OUString::valueOf((INT32)nUsedPages));
m_ET_FREESIZE.SetText(::rtl::OUString::valueOf((INT32)nFreePages));
m_ET_MEMORYUSING.SetValue(static_cast<sal_Int32>(((nUsedPages-nFreePages)/nUsedPages)*100));
}
else
showError();
xRow = NULL;
}
else
showError();
}
catch(const SQLException& )
{
::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ), pParent, _xFactory );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
try
{
::comphelper::disposeComponent(xStmt);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
// now fill the datadev spaces
if(bCanSelect)
{
try
{
bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("DATADEVSPACES"),sSchema);
if(bCanSelect)
{
// then the db files
aStmt = ::rtl::OUString::createFromAscii("SELECT DEVSPACENAME FROM ");
aStmt += ::dbtools::quoteTableName(xMetaData,sSchema,::dbtools::eInDataManipulation);
aStmt += ::rtl::OUString::createFromAscii(".\"DATADEVSPACES\"");
xStmt = m_xConnection->createStatement();
xRes = xStmt->executeQuery(aStmt);
Reference<XRow> xRow(xRes,UNO_QUERY);
while(xRes.is() && xRes->next())
{
m_LB_DATADEVS.InsertEntry(xRow->getString(1));
}
if(!m_LB_DATADEVS.GetEntryCount())
showError();
}
else
showError();
}
catch(const SQLException& e)
{
::dbaui::showError(SQLExceptionInfo(e),pParent,_xFactory);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
try
{
::comphelper::disposeComponent(xStmt);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
// now fill the sysdatadev spaces
if(bCanSelect)
{
try
{
bCanSelect = checkSystemTable(::rtl::OUString::createFromAscii("CONFIGURATION"),sSchema);
if(bCanSelect)
{
aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
aStmt += ::dbtools::quoteTableName(xMetaData,sSchema,::dbtools::eInDataManipulation);
aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION LIKE 'SYS%DEVSPACE%NAME'");
xStmt = m_xConnection->createStatement();
xRes = xStmt->executeQuery(aStmt);
if(xRes.is() && xRes->next())
{
Reference<XRow> xRow(xRes,UNO_QUERY);
m_ET_SYSDEVSPACE.SetText(xRow->getString(2));
}
else
showError();
aStmt = ::rtl::OUString::createFromAscii("SELECT * FROM ");
aStmt += ::dbtools::quoteTableName(xMetaData,sSchema,::dbtools::eInDataManipulation);
aStmt += ::rtl::OUString::createFromAscii(".CONFIGURATION WHERE DESCRIPTION = 'TRANSACTION LOG NAME'");
xRes = xStmt->executeQuery(aStmt);
if(xRes.is() && xRes->next())
{
Reference<XRow> xRow(xRes,UNO_QUERY);
m_ET_TRANSACTIONLOG.SetText(xRow->getString(2));
}
else
showError();
}
else
showError();
}
catch(const SQLException& e)
{
::dbaui::showError(SQLExceptionInfo(e),pParent,_xFactory);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
try
{
::comphelper::disposeComponent(xStmt);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
}
m_ET_SYSDEVSPACE.SetSpecialReadOnly(sal_True);
m_ET_TRANSACTIONLOG.SetSpecialReadOnly(sal_True);
m_LB_DATADEVS.SetSpecialReadOnly(sal_True);
m_ET_SIZE.SetSpecialReadOnly(sal_True);
m_ET_FREESIZE.SetSpecialReadOnly(sal_True);
m_ET_MEMORYUSING.SetSpecialReadOnly(sal_True);
}
//------------------------------------------------------------------------
OAdabasStatistics::~OAdabasStatistics()
{
DBG_DTOR(OAdabasStatistics,NULL);
}
// -----------------------------------------------------------------------------
sal_Bool OAdabasStatistics::checkSystemTable(const ::rtl::OUString& _rsSystemTable, ::rtl::OUString& _rsSchemaName )
{
sal_Bool bCanSelect = sal_False;
Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
if ( xMeta.is() )
{
Reference<XResultSet> xRes = xMeta->getTablePrivileges(Any(),::rtl::OUString::createFromAscii("%"), _rsSystemTable);
if(xRes.is())
{
Reference<XRow> xRow(xRes,UNO_QUERY);
static const ::rtl::OUString sSelect = ::rtl::OUString::createFromAscii("SELECT");
// first the db sizes
while( xRow.is() && xRes->next() )
{
_rsSchemaName = xRow->getString(2);
if(sSelect == xRow->getString(6) && !xRow->wasNull())
{
bCanSelect = sal_True;
break;
}
}
::comphelper::disposeComponent(xRes);
}
}
return bCanSelect;
}
// -----------------------------------------------------------------------------
void OAdabasStatistics::showError()
{
if(!m_bErrorShown)
{
OSQLMessageBox aMsg(GetParent(),GetText(),String(ModuleRes(STR_ADABAS_ERROR_SYSTEMTABLES)));
aMsg.Execute();
m_bErrorShown = sal_True;
}
}
// -----------------------------------------------------------------------------
}
|