~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to totemporary.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
3
 
* TOra - An Oracle Toolkit for DBA's and developers
4
 
* Copyright (C) 2003-2005 Quest Software, Inc
5
 
* Portions Copyright (C) 2005 Other Contributors
6
 
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation;  only version 2 of
10
 
* the License is valid for this program.
11
 
12
 
* This program is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License
18
 
* along with this program; if not, write to the Free Software
19
 
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*
21
 
*      As a special exception, you have permission to link this program
22
 
*      with the Oracle Client libraries and distribute executables, as long
23
 
*      as you follow the requirements of the GNU GPL in regard to all of the
24
 
*      software in the executable aside from Oracle client libraries.
25
 
*
26
 
*      Specifically you are not permitted to link this program with the
27
 
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
 
*      And you are not permitted to distribute binaries compiled against
29
 
*      these libraries without written consent from Quest Software, Inc.
30
 
*      Observe that this does not disallow linking to the Qt Free Edition.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "tochangeconnection.h"
41
 
#include "toconf.h"
42
 
#include "toconnection.h"
43
 
#include "toextract.h"
44
 
#include "tohighlightedtext.h"
45
 
#include "totemporary.h"
46
 
#include "tomain.h"
47
 
#include "toresultextract.h"
48
 
#include "toresultlong.h"
49
 
#include "toresultview.h"
50
 
#include "tosgastatement.h"
51
 
#include "tosql.h"
52
 
#include "totool.h"
53
 
 
54
 
#ifdef TO_KDE
55
 
#  include <kmenubar.h>
56
 
#endif
57
 
 
58
 
#include <qlabel.h>
59
 
#include <qlineedit.h>
60
 
#include <qmenubar.h>
61
 
#include <qheader.h>
62
 
#include <qpopupmenu.h>
63
 
#include <qprogressdialog.h>
64
 
#include <qsplitter.h>
65
 
#include <qtoolbar.h>
66
 
#include <qtoolbutton.h>
67
 
#include <qworkspace.h>
68
 
 
69
 
#include "totemporary.moc"
70
 
 
71
 
#include "icons/refresh.xpm"
72
 
#include "icons/totemporary.xpm"
73
 
 
74
 
static toSQL SQLListTemporaryObjects("toTemporary:ListTemporaryObjects",
75
 
                                     "SELECT s.sid || ',' || s.serial# \"Session\",\n"
76
 
                                     "       s.username \"User\",\n"
77
 
                                     "       u.TABLESPACE \"Tablespace\",\n"
78
 
                                     "       segtype \"Type\",\n"
79
 
                                     "       substr ( a.sql_text,1,50 ) \"SQL\",\n"
80
 
                                     "       round ( u.blocks * p.value / :siz<int>,2 )||:sizstr<char[50]> \"Size\",\n"
81
 
                                     "       s.sql_address || ':' || s.sql_hash_value \" \"\n"
82
 
                                     "  FROM v$sort_usage u,\n"
83
 
                                     "       v$session s,\n"
84
 
                                     "       v$sqlarea a,\n"
85
 
                                     "       v$parameter p\n"
86
 
                                     " WHERE s.saddr = u.session_addr\n"
87
 
                                     "   AND a.address ( + ) = s.sql_address\n"
88
 
                                     "   AND a.hash_value ( + ) = s.sql_hash_value\n"
89
 
                                     "   AND p.name = 'db_block_size'",
90
 
                                     "Get temporary usage.", "0800");
91
 
 
92
 
static toSQL SQLListTemporaryObjects9("toTemporary:ListTemporaryObjects",
93
 
                                      "SELECT s.sid || ',' || s.serial# \"Session\",\n"
94
 
                                      "       s.username \"User\",\n"
95
 
                                      "       u.TABLESPACE \"Tablespace\",\n"
96
 
                                      "       u.segtype \"Type\",\n"
97
 
                                      "       substr ( a.sql_text,1,50 ) \"SQL\",\n"
98
 
                                      "       round ( u.blocks * p.value / :siz<int>,2 )||:sizstr<char[50]> \"Size\",\n"
99
 
                                      "       s.sql_address || ':' || s.sql_hash_value \" \"\n"
100
 
                                      "  FROM v$tempseg_usage u,\n"
101
 
                                      "       v$session s,\n"
102
 
                                      "       v$sqlarea a,\n"
103
 
                                      "       v$parameter p\n"
104
 
                                      " WHERE s.saddr = u.session_addr\n"
105
 
                                      "   AND a.address ( + ) = s.sql_address\n"
106
 
                                      "   AND a.hash_value ( + ) = s.sql_hash_value\n"
107
 
                                      "   AND p.name = 'db_block_size'",
108
 
                                      QString::null,
109
 
                                      "0900");
110
 
 
111
 
class toTemporaryTool : public toTool
112
 
{
113
 
    virtual const char **pictureXPM(void)
114
 
    {
115
 
        return const_cast<const char**>(totemporary_xpm);
116
 
    }
117
 
public:
118
 
    toTemporaryTool()
119
 
            : toTool(130, "Temporary Objects")
120
 
    { }
121
 
    virtual const char *menuItem()
122
 
    {
123
 
        return "Temporary Objects";
124
 
    }
125
 
    virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
126
 
    {
127
 
        return new toTemporary(parent, connection);
128
 
    }
129
 
    virtual bool canHandle(toConnection &conn)
130
 
    {
131
 
        if (!toIsOracle(conn))
132
 
            return false;
133
 
        if (conn.version() < "0800")
134
 
            return false;
135
 
        return true;
136
 
    }
137
 
};
138
 
 
139
 
static toTemporaryTool TemporaryTool;
140
 
 
141
 
toTemporary::toTemporary(QWidget *main, toConnection &connection)
142
 
        : toToolWidget(TemporaryTool, "temporary.html", main, connection)
143
 
{
144
 
    QToolBar *toolbar = toAllocBar(this, tr("Temporary Objects"));
145
 
 
146
 
    new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
147
 
                    tr("Refresh list"),
148
 
                    tr("Refresh list"),
149
 
                    this, SLOT(refresh()),
150
 
                    toolbar);
151
 
 
152
 
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
153
 
    new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
154
 
 
155
 
    QSplitter *splitter = new QSplitter(Vertical, this);
156
 
 
157
 
    Objects = new toResultLong(false, false, toQuery::Background, splitter);
158
 
    QString unit = toTool::globalConfig(CONF_SIZE_UNIT, DEFAULT_SIZE_UNIT);
159
 
    toQList args;
160
 
    toPush(args, toQValue(toSizeDecode(unit)));
161
 
    toPush(args, toQValue(unit));
162
 
 
163
 
    Objects->setSelectionMode(QListView::Single);
164
 
    Objects->query(SQLListTemporaryObjects, args);
165
 
    connect(Objects, SIGNAL(selectionChanged(QListViewItem *)),
166
 
            this, SLOT(changeItem(QListViewItem *)));
167
 
 
168
 
    Statement = new toSGAStatement(splitter);
169
 
 
170
 
    ToolMenu = NULL;
171
 
    connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
172
 
            this, SLOT(windowActivated(QWidget *)));
173
 
 
174
 
    setFocusProxy(Objects);
175
 
}
176
 
 
177
 
 
178
 
void toTemporary::windowActivated(QWidget *widget)
179
 
{
180
 
    if (widget == this)
181
 
    {
182
 
        if (!ToolMenu)
183
 
        {
184
 
            ToolMenu = new QPopupMenu(this);
185
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"),
186
 
                                 this, SLOT(refresh(void)),
187
 
                                 toKeySequence(tr("F5", "Temporary|Refresh")));
188
 
 
189
 
            toMainWidget()->menuBar()->insertItem(tr("&Temporary"), ToolMenu, -1, toToolMenuIndex());
190
 
        }
191
 
    }
192
 
    else
193
 
    {
194
 
        delete ToolMenu;
195
 
        ToolMenu = NULL;
196
 
    }
197
 
}
198
 
 
199
 
void toTemporary::refresh(void)
200
 
{
201
 
    Objects->refresh();
202
 
}
203
 
 
204
 
void toTemporary::changeItem(QListViewItem *item)
205
 
{
206
 
    if (item)
207
 
        Statement->changeAddress(item->text(Objects->columns()));
208
 
}