Source Code Cross Referenced for DerbyPlugin.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » derby » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.derby 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.derby;
002:
003:        /*
004:         * Copyright (C) 2006 Rob Manning
005:         * manningr@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        import net.sourceforge.squirrel_sql.client.IApplication;
023:        import net.sourceforge.squirrel_sql.client.gui.session.ObjectTreeInternalFrame;
024:        import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
025:        import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
026:        import net.sourceforge.squirrel_sql.client.plugin.PluginException;
027:        import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
028:        import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
029:        import net.sourceforge.squirrel_sql.client.session.ISession;
030:        import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.TableWithChildNodesExpander;
031:        import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.DatabaseObjectInfoTab;
032:        import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
033:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
034:        import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
035:        import net.sourceforge.squirrel_sql.fw.sql.IQueryTokenizer;
036:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
037:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
038:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
039:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
040:        import net.sourceforge.squirrel_sql.plugins.derby.exp.DerbyTableTriggerExtractorImpl;
041:        import net.sourceforge.squirrel_sql.plugins.derby.tab.TriggerDetailsTab;
042:        import net.sourceforge.squirrel_sql.plugins.derby.tab.TriggerSourceTab;
043:        import net.sourceforge.squirrel_sql.plugins.derby.tab.ViewSourceTab;
044:        import net.sourceforge.squirrel_sql.plugins.derby.tokenizer.DerbyQueryTokenizer;
045:
046:        import java.net.MalformedURLException;
047:        import java.sql.Driver;
048:        import java.sql.SQLException;
049:        import java.util.Properties;
050:        import net.sourceforge.squirrel_sql.client.session.event.SessionAdapter;
051:        import net.sourceforge.squirrel_sql.client.session.event.SessionEvent;
052:        import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
053:        import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
054:        import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
055:
056:        /**
057:         * The main controller class for the Derby plugin.
058:         * 
059:         * @author manningr
060:         */
061:        public class DerbyPlugin extends DefaultSessionPlugin {
062:
063:            private static final StringManager s_stringMgr = StringManagerFactory
064:                    .getStringManager(DerbyPlugin.class);
065:
066:            /** Logger for this class. */
067:            private final static ILogger s_log = LoggerController
068:                    .createLogger(DerbyPlugin.class);
069:
070:            /** API for the Obejct Tree. */
071:            private IObjectTreeAPI _treeAPI;
072:
073:            static interface i18n {
074:                //i18n[DerbyPlugin.showViewSource=Show view source]
075:                String SHOW_VIEW_SOURCE = s_stringMgr
076:                        .getString("DerbyPlugin.showViewSource");
077:
078:                //i18n[DerbyPlugin.showProcedureSource=Show procedure source]
079:                String SHOW_PROCEDURE_SOURCE = s_stringMgr
080:                        .getString("DerbyPlugin.showProcedureSource");
081:            }
082:
083:            /**
084:             * Return the internal name of this plugin.
085:             *
086:             * @return  the internal name of this plugin.
087:             */
088:            public String getInternalName() {
089:                return "derby";
090:            }
091:
092:            /**
093:             * Return the descriptive name of this plugin.
094:             *
095:             * @return  the descriptive name of this plugin.
096:             */
097:            public String getDescriptiveName() {
098:                return "Derby Plugin";
099:            }
100:
101:            /**
102:             * Returns the current version of this plugin.
103:             *
104:             * @return  the current version of this plugin.
105:             */
106:            public String getVersion() {
107:                return "0.12";
108:            }
109:
110:            /**
111:             * Returns the authors name.
112:             *
113:             * @return  the authors name.
114:             */
115:            public String getAuthor() {
116:                return "Rob Manning";
117:            }
118:
119:            /**
120:             * Returns a comma separated list of other contributors.
121:             *
122:             * @return  Contributors names.
123:             */
124:            public String getContributors() {
125:                return "Alex Pivovarov";
126:            }
127:
128:            /**
129:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getChangeLogFileName()
130:             */
131:            public String getChangeLogFileName() {
132:                return "changes.txt";
133:            }
134:
135:            /**
136:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getHelpFileName()
137:             */
138:            public String getHelpFileName() {
139:                return "readme.html";
140:            }
141:
142:            /**
143:             * @see net.sourceforge.squirrel_sql.client.plugin.IPlugin#getLicenceFileName()
144:             */
145:            public String getLicenceFileName() {
146:                return "licence.txt";
147:            }
148:
149:            /**
150:             * Load this plugin.
151:             *
152:             * @param	app	 Application API.
153:             */
154:            public synchronized void load(IApplication app)
155:                    throws PluginException {
156:                super .load(app);
157:            }
158:
159:            /**
160:             * Initialize this plugin.
161:             */
162:            public synchronized void initialize() throws PluginException {
163:                super .initialize();
164:                //Add session ended listener -- needs for Embedded Derby DB
165:                _app.getSessionManager().addSessionListener(
166:                        new SessionListener());
167:            }
168:
169:            /**
170:             * Application is shutting down so save preferences.
171:             */
172:            public void unload() {
173:                super .unload();
174:            }
175:
176:            public boolean allowsSessionStartedInBackground() {
177:                return true;
178:            }
179:
180:            /**
181:             * Session has been started. Update the tree api in using the event thread
182:             *
183:             * @param   session     Session that has started.
184:             *
185:             * @return  <TT>true</TT> if session is Oracle in which case this plugin
186:             *                          is interested in it.
187:             */
188:            public PluginSessionCallback sessionStarted(final ISession session) {
189:                if (!isPluginSession(session)) {
190:                    return null;
191:                }
192:                s_log.info("Installing Derby query tokenizer");
193:                IQueryTokenizer orig = session.getQueryTokenizer();
194:                DerbyQueryTokenizer tokenizer = new DerbyQueryTokenizer(orig
195:                        .getSQLStatementSeparator(),
196:                        orig.getLineCommentBegin(), orig
197:                                .isRemoveMultiLineComment());
198:                session.setQueryTokenizer(tokenizer);
199:                GUIUtils.processOnSwingEventThread(new Runnable() {
200:                    public void run() {
201:                        updateTreeApi(session);
202:                    }
203:                });
204:
205:                return new PluginSessionCallback() {
206:                    public void sqlInternalFrameOpened(
207:                            SQLInternalFrame sqlInternalFrame, ISession sess) {
208:                        // Supports Session main window only
209:                    }
210:
211:                    public void objectTreeInternalFrameOpened(
212:                            ObjectTreeInternalFrame objectTreeInternalFrame,
213:                            ISession sess) {
214:                        // Supports Session main window only
215:                    }
216:                };
217:
218:            }
219:
220:            @Override
221:            protected boolean isPluginSession(ISession session) {
222:                return DialectFactory.isDerby(session.getMetaData());
223:            }
224:
225:            private void updateTreeApi(ISession session) {
226:
227:                _treeAPI = session.getSessionInternalFrame().getObjectTreeAPI();
228:
229:                //_treeAPI.addDetailTab(DatabaseObjectType.PROCEDURE, 
230:                //        new ProcedureSourceTab(i18n.SHOW_PROCEDURE_SOURCE));
231:
232:                _treeAPI.addDetailTab(DatabaseObjectType.VIEW,
233:                        new ViewSourceTab(i18n.SHOW_VIEW_SOURCE));
234:
235:                //_treeAPI.addDetailTab(DatabaseObjectType.INDEX, new DatabaseObjectInfoTab());
236:                //_treeAPI.addDetailTab(DatabaseObjectType.INDEX, new IndexDetailsTab());
237:                _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
238:                        new DatabaseObjectInfoTab());
239:                _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER_TYPE_DBO,
240:                        new DatabaseObjectInfoTab());
241:                //_treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE, new DatabaseObjectInfoTab());
242:                //_treeAPI.addDetailTab(DatabaseObjectType.SEQUENCE, new SequenceDetailsTab());        
243:
244:                // Expanders - trigger and index expanders are added inside the table
245:                // expander
246:                //_treeAPI.addExpander(DatabaseObjectType.SCHEMA, new SchemaExpander());
247:                TableWithChildNodesExpander trigExp = new TableWithChildNodesExpander();
248:                trigExp
249:                        .setTableTriggerExtractor(new DerbyTableTriggerExtractorImpl());
250:                _treeAPI.addExpander(DatabaseObjectType.TABLE, trigExp);
251:
252:                _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
253:                        new TriggerDetailsTab());
254:                _treeAPI.addDetailTab(DatabaseObjectType.TRIGGER,
255:                        new TriggerSourceTab("The source of the trigger"));
256:
257:            }
258:
259:            /**
260:             * A session listener that shutdown Embedded Derby when session and
261:             * connection are already closed
262:             * 
263:             * @author Alex Pivovarov
264:             */
265:            private class SessionListener extends SessionAdapter {
266:                @Override
267:                public void sessionClosed(SessionEvent evt) {
268:                    ISession session = evt.getSession();
269:                    shutdownEmbeddedDerby(session);
270:                }
271:            }
272:
273:            /**
274:             * Shutdown Embedded Derby DB and reload JDBC Driver
275:             * 
276:             * @param session
277:             *           Current session.
278:             * 
279:             * @author Alex Pivovarov
280:             */
281:            private void shutdownEmbeddedDerby(final ISession session) {
282:                try {
283:                    ISQLDriver iSqlDr = session.getDriver();
284:                    if (!(iSqlDr.getDriverClassName()
285:                            .startsWith("org.apache.derby.jdbc.EmbeddedDriver"))) {
286:                        return;
287:                    }
288:                    //the code bellow is only for Embedded Derby Driver
289:                    IIdentifier drId = iSqlDr.getIdentifier();
290:                    SQLDriverManager sqlDrMan = _app.getSQLDriverManager();
291:                    //Getting java.sql.Driver to run shutdown command
292:                    Driver jdbcDr = sqlDrMan.getJDBCDriver(drId);
293:                    //Shutdown Embedded Derby DB
294:                    try {
295:                        jdbcDr.connect("jdbc:derby:;shutdown=true",
296:                                new Properties());
297:                    } catch (SQLException e) {
298:                        //it is always thrown as said in Embedded Derby API.
299:                        //So it is not error it is info
300:                        s_log.info(e.getMessage());
301:                    }
302:                    //Re-registering driver is necessary for Embedded Derby
303:                    sqlDrMan.registerSQLDriver(iSqlDr);
304:                } catch (RuntimeException e) {
305:                    s_log.error(e.getMessage(), e);
306:                } catch (MalformedURLException e) {
307:                    s_log.error(e.getMessage(), e);
308:                } catch (IllegalAccessException e) {
309:                    s_log.error(e.getMessage(), e);
310:                } catch (InstantiationException e) {
311:                    s_log.error(e.getMessage(), e);
312:                } catch (ClassNotFoundException e) {
313:                    s_log.error(e.getMessage(), e);
314:                }
315:            }
316:
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.