Source Code Cross Referenced for GenerateSqlCommand.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » mssql » action » 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.mssql.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.mssql.action;
002:
003:        /*
004:         * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        import java.io.FileWriter;
022:        import java.io.IOException;
023:        import java.sql.SQLException;
024:        import java.util.ArrayList;
025:
026:        import javax.swing.JFileChooser;
027:
028:        import net.sourceforge.squirrel_sql.client.session.ISession;
029:        import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
030:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
031:        import net.sourceforge.squirrel_sql.fw.sql.SQLDriverProperty;
032:        import net.sourceforge.squirrel_sql.fw.sql.WrappedSQLException;
033:        import net.sourceforge.squirrel_sql.fw.util.*;
034:
035:        import net.sourceforge.squirrel_sql.plugins.mssql.MssqlPlugin;
036:        import net.sourceforge.squirrel_sql.plugins.mssql.gui.GenerateSqlDialog;
037:        import net.sourceforge.squirrel_sql.fw.util.ExtensionFilter;
038:        import net.sourceforge.squirrel_sql.plugins.mssql.util.MssqlIntrospector;
039:
040:        public class GenerateSqlCommand implements  ICommand {
041:
042:            private static final StringManager s_stringMgr = StringManagerFactory
043:                    .getStringManager(GenerateSqlCommand.class);
044:
045:            private ISession _session;
046:            private final MssqlPlugin _plugin;
047:
048:            private final IDatabaseObjectInfo[] _dbObjs;
049:
050:            public GenerateSqlCommand(ISession session, MssqlPlugin plugin,
051:                    IDatabaseObjectInfo[] dbObjs) {
052:                super ();
053:                if (session == null)
054:                    throw new IllegalArgumentException("ISession == null");
055:                if (plugin == null)
056:                    throw new IllegalArgumentException("MssqlPlugin == null");
057:                if (dbObjs == null)
058:                    throw new IllegalArgumentException(
059:                            "IDatabaseObjectInfo[] is null");
060:
061:                _session = session;
062:                _plugin = plugin;
063:                _dbObjs = dbObjs;
064:            }
065:
066:            public void execute() throws BaseException {
067:                try {
068:                    /* because of the cross-catalog problem, let's not invoke this if the current catalog isn't equal
069:                     * to the catalog specified in the URL.
070:                     */
071:
072:                    SQLDriverProperty[] props = _session.getSQLConnection()
073:                            .getConnectionProperties().getDriverProperties();
074:                    for (int i = 0; i < props.length; i++) {
075:                        if (props[i].getName().equals("DBNAME")) {
076:                            // there's a DBNAME specified, so make sure it matches the current catalog.
077:                            if (!props[i].getValue().equals(
078:                                    _session.getSQLConnection().getCatalog())) {
079:
080:                                String[] params = {
081:                                        props[i].getValue(),
082:                                        _session.getSQLConnection()
083:                                                .getCatalog() };
084:                                // i18n[mmsql.catalogErr=The DBNAME of the session's URL is set to '{0}', but the session's current catalog is set to '{1}'.\n\nSQL Server doesn't support this in most cases.  This is a current issue.]
085:                                _session.getApplication().showErrorDialog(
086:                                        s_stringMgr.getString(
087:                                                "mmsql.catalogErr", params));
088:                                return;
089:                            }
090:                        }
091:                    }
092:
093:                    GenerateSqlDialog dlog = new GenerateSqlDialog(_session,
094:                            _plugin, _dbObjs);
095:                    dlog.preselectObjects(_dbObjs);
096:                    dlog.pack();
097:                    GUIUtils.centerWithinParent(dlog);
098:                    if (!dlog.showGeneralSqlDialog())
099:                        return;
100:
101:                    JFileChooser fc = new JFileChooser();
102:                    if (dlog.getOneFile()) {
103:                        ExtensionFilter ef = new ExtensionFilter();
104:                        // i18n[mmsql.sqlScripts=SQL Scripts]
105:                        ef.addExtension(s_stringMgr
106:                                .getString("mmsql.sqlScripts"), "sql");
107:                        // i18n[mmsql.textFiles=Text Files]
108:                        ef.addExtension(s_stringMgr
109:                                .getString("mmsql.textFiles"), "txt");
110:                        fc.setFileFilter(ef);
111:                    } else
112:                        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
113:
114:                    if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
115:
116:                        FileWriter fw = null;
117:
118:                        if (dlog.getOneFile()) {
119:                            fw = new FileWriter(fc.getSelectedFile(), false);
120:
121:                            if (dlog.getScriptDatabase())
122:                                fw.write(MssqlIntrospector
123:                                        .generateCreateDatabaseScript(_session
124:                                                .getSQLConnection()
125:                                                .getCatalog(), _session
126:                                                .getSQLConnection()));
127:
128:                            if (dlog.getScriptUsersAndRoles())
129:                                fw.write(MssqlIntrospector
130:                                        .generateUsersAndRolesScript(_session
131:                                                .getSQLConnection()
132:                                                .getCatalog(), _session
133:                                                .getSQLConnection()));
134:                        }
135:
136:                        ArrayList<IDatabaseObjectInfo> objs = dlog
137:                                .getSelectedItems();
138:                        for (int i = 0; i < objs.size(); i++) {
139:                            IDatabaseObjectInfo oi = objs.get(i);
140:
141:                            if (!dlog.getOneFile())
142:                                fw = new FileWriter(fc.getSelectedFile()
143:                                        + java.io.File.separator
144:                                        + MssqlIntrospector
145:                                                .getFixedVersionedObjectName(oi
146:                                                        .getSimpleName())
147:                                        + ".txt", false);
148:
149:                            if (dlog.getGenerateDrop())
150:                                fw.write(MssqlIntrospector
151:                                        .generateDropScript(oi));
152:
153:                            if (dlog.getGenerateCreate()) {
154:                                String script = MssqlIntrospector
155:                                        .generateCreateScript(oi, _session
156:                                                .getSQLConnection(), dlog
157:                                                .getScriptConstraints());
158:                                fw.write(script);
159:                            }
160:
161:                            if (dlog.getScriptIndexes()) {
162:                                String script = MssqlIntrospector
163:                                        .generateCreateIndexesScript(oi,
164:                                                _session.getSQLConnection());
165:                                fw.write(script);
166:                            }
167:
168:                            if (dlog.getScriptTriggers()) {
169:                                String script = MssqlIntrospector
170:                                        .generateCreateTriggersScript(oi,
171:                                                _session.getSQLConnection());
172:                                fw.write(script);
173:                            }
174:
175:                            if (dlog.getScriptPermissions()) {
176:                                String script = MssqlIntrospector
177:                                        .generatePermissionsScript(oi, _session
178:                                                .getSQLConnection());
179:                                fw.write(script);
180:                            }
181:
182:                            if (!dlog.getOneFile())
183:                                fw.close();
184:                        }
185:                        if (dlog.getOneFile())
186:                            fw.close();
187:                    }
188:                } catch (SQLException ex) {
189:                    ex.printStackTrace();
190:                    throw new WrappedSQLException(ex);
191:                } catch (IOException ex) {
192:                    ex.printStackTrace();
193:                    _session.getApplication().showErrorDialog(ex.getMessage());
194:                }
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.