Source Code Cross Referenced for WbSchemaReport.java in  » Database-Client » SQL-Workbench » workbench » sql » wbcommands » 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 » SQL Workbench » workbench.sql.wbcommands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * WbSchemaReport.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.sql.wbcommands;
013:
014:        import java.io.File;
015:        import java.io.IOException;
016:        import java.sql.SQLException;
017:        import java.util.List;
018:        import java.util.Properties;
019:        import workbench.db.ConnectionProfile;
020:        import workbench.db.TableIdentifier;
021:        import workbench.db.report.SchemaReporter;
022:        import workbench.db.report.Workbench2Designer;
023:        import workbench.interfaces.ScriptGenerationMonitor;
024:        import workbench.log.LogMgr;
025:        import workbench.resource.ResourceMgr;
026:        import workbench.sql.SqlCommand;
027:        import workbench.sql.StatementRunnerResult;
028:        import workbench.storage.RowActionMonitor;
029:        import workbench.util.ArgumentParser;
030:        import workbench.util.ArgumentType;
031:        import workbench.util.ExceptionUtil;
032:        import workbench.util.StringUtil;
033:        import workbench.util.StringUtil;
034:        import workbench.util.WbFile;
035:        import workbench.util.XsltTransformer;
036:
037:        /**
038:         *
039:         * @author  support@sql-workbench.net
040:         */
041:        public class WbSchemaReport extends SqlCommand implements 
042:                RowActionMonitor {
043:            public static final String PARAM_INCLUDE_TABLES = "includeTables";
044:            public static final String PARAM_INCLUDE_PROCS = "includeProcedures";
045:            public static final String PARAM_INCLUDE_GRANTS = "includeTableGrants";
046:            public static final String PARAM_INCLUDE_SEQUENCES = "includeSequences";
047:            public static final String PARAM_INCLUDE_VIEWS = "includeViews";
048:
049:            public static final String VERB = "WBREPORT";
050:            private SchemaReporter reporter;
051:            private int currentTable = 0;
052:
053:            public WbSchemaReport() {
054:                cmdLine = new ArgumentParser();
055:                cmdLine.addArgument("types");
056:                cmdLine.addArgument("file");
057:                cmdLine.addArgument("namespace");
058:                cmdLine.addArgument("tables", ArgumentType.TableArgument);
059:                cmdLine.addArgument("schemas");
060:                cmdLine.addArgument("format", StringUtil
061:                        .stringToList("wb,dbdesigner"));
062:                cmdLine.addArgument("useSchemaName", ArgumentType.BoolArgument);
063:                cmdLine.addArgument(PARAM_INCLUDE_VIEWS,
064:                        ArgumentType.BoolArgument);
065:                cmdLine.addArgument(PARAM_INCLUDE_PROCS,
066:                        ArgumentType.BoolArgument);
067:                cmdLine.addArgument(PARAM_INCLUDE_TABLES,
068:                        ArgumentType.BoolArgument);
069:                cmdLine.addArgument(PARAM_INCLUDE_GRANTS,
070:                        ArgumentType.BoolArgument);
071:                cmdLine.addArgument(PARAM_INCLUDE_SEQUENCES,
072:                        ArgumentType.BoolArgument);
073:                cmdLine.addArgument(WbXslt.ARG_STYLESHEET);
074:                cmdLine.addArgument(WbXslt.ARG_OUTPUT);
075:            }
076:
077:            public String getVerb() {
078:                return VERB;
079:            }
080:
081:            public StatementRunnerResult execute(final String sql)
082:                    throws SQLException {
083:                boolean dbDesigner = false;
084:                StatementRunnerResult result = new StatementRunnerResult();
085:
086:                cmdLine.parse(getCommandLine(sql));
087:
088:                if (cmdLine.hasUnknownArguments()) {
089:                    setUnknownMessage(result, cmdLine, ResourceMgr
090:                            .getString("ErrSchemaReportWrongParameters"));
091:                    return result;
092:                }
093:
094:                WbFile output = evaluateFileArgument(cmdLine.getValue("file"));
095:
096:                if (output == null) {
097:                    result.addMessage(ResourceMgr
098:                            .getString("ErrSchemaReportWrongParameters"));
099:                    result.setFailure();
100:                    return result;
101:                }
102:
103:                String format = cmdLine.getValue("format");
104:                if (StringUtil.isEmptyString(format))
105:                    format = "xml";
106:
107:                if ("dbdesigner".equalsIgnoreCase(format)) {
108:                    dbDesigner = true;
109:                } else if (!"xml".equalsIgnoreCase(format)
110:                        && !"wb".equalsIgnoreCase(format)
111:                        && !"wbxml".equalsIgnoreCase(format)) {
112:                    result.addMessage(ResourceMgr
113:                            .getString("ErrSchemaReportWrongParameters"));
114:                    result.setFailure();
115:                    return result;
116:                }
117:                String namespace = cmdLine.getValue("namespace");
118:                this .reporter = new SchemaReporter(currentConnection);
119:                this .reporter.setNamespace(namespace);
120:                this .reporter.setDbDesigner(dbDesigner);
121:                this .reporter.setIncludeViews(cmdLine.getBoolean(
122:                        PARAM_INCLUDE_VIEWS, true));
123:                TableIdentifier[] tables = this .parseTables();
124:                if (tables != null) {
125:                    this .reporter.setTableList(tables);
126:                } else {
127:                    String arg = cmdLine.getValue("schemas");
128:                    List<String> schemas = StringUtil.stringToList(arg, ",");
129:                    this .reporter.setSchemas(schemas);
130:                }
131:
132:                String alternateSchema = cmdLine.getValue("useschemaname");
133:                this .reporter.setSchemaNameToUse(alternateSchema);
134:
135:                this .reporter.setProgressMonitor(this );
136:
137:                if (this .rowMonitor != null) {
138:                    this .rowMonitor
139:                            .setMonitorType(RowActionMonitor.MONITOR_PROCESS);
140:                }
141:
142:                this .reporter.setIncludeTables(cmdLine.getBoolean(
143:                        PARAM_INCLUDE_TABLES, true));
144:                this .reporter.setIncludeProcedures(cmdLine.getBoolean(
145:                        PARAM_INCLUDE_PROCS, false));
146:                this .reporter.setIncludeGrants(cmdLine.getBoolean(
147:                        PARAM_INCLUDE_GRANTS, false));
148:                this .reporter.setIncludeSequences(cmdLine.getBoolean(
149:                        PARAM_INCLUDE_SEQUENCES, false));
150:
151:                if (currentConnection != null
152:                        && currentConnection.getMetadata().isOracle()) {
153:                    // check if remarksReporting is turned on for Oracle, if not issue a warning.
154:                    ConnectionProfile prof = currentConnection.getProfile();
155:                    Properties props = prof.getConnectionProperties();
156:                    String value = "false";
157:                    if (props != null) {
158:                        value = props.getProperty("remarksReporting", "false");
159:                    }
160:                    if (!"true".equals(value)) {
161:                        result
162:                                .addMessage(ResourceMgr
163:                                        .getString("MsgSchemaReporterOracleRemarksWarning"));
164:                        result.addMessage("");
165:                    }
166:                }
167:
168:                // currentTable will be incremented as we have registered
169:                // this object as the RowActionMonitor of the SchemaReporter
170:                // see setCurrentObject()
171:                this .currentTable = 0;
172:
173:                //		String wbReportFilename = output.getFullPath();
174:                //		if (dbDesigner)
175:                //		{
176:                //			WbFile f = new WbFile(wbReportFilename);
177:                //			String dir = f.getParent();
178:                //			String fname = f.getName();
179:                //			WbFile nf = new WbFile(dir, "__wb_" + fname);
180:                //			wbReportFilename = nf.getFullPath();
181:                //		}
182:                this .reporter.setOutputFilename(output.getFullPath());
183:
184:                try {
185:                    this .reporter.writeXml();
186:                } catch (IOException e) {
187:                    result.setFailure();
188:                    result.addMessage(e.getMessage());
189:                }
190:
191:                String xslt = cmdLine.getValue(WbXslt.ARG_STYLESHEET);
192:                String xsltOutput = cmdLine.getValue(WbXslt.ARG_OUTPUT);
193:
194:                //		if (dbDesigner && result.isSuccess())
195:                //		{
196:                //			try
197:                //			{
198:                //				this.setCurrentObject(ResourceMgr.getString("MsgConvertReport2Designer"), -1, -1);
199:                //				Workbench2Designer converter = new Workbench2Designer(new File(wbReportFilename));
200:                //				converter.transformWorkbench2Designer();
201:                //				converter.writeOutputFile(output);
202:                //			}
203:                //			catch (Exception e)
204:                //			{
205:                //				result.setFailure();
206:                //				LogMgr.logError("WbSchemaReport.execute()", "Error generating DBDesigner file", e);
207:                //				String msg = ResourceMgr.getString("ErrGeneratingDbDesigner");
208:                //				msg = StringUtil.replace(msg, "%wbfile%", output.getFullPath());
209:                //				msg = StringUtil.replace(msg, "%error%", ExceptionUtil.getDisplay(e));
210:                //				result.addMessage(msg);
211:                //			}
212:                //		}
213:                if (result.isSuccess()) {
214:                    String msg = ResourceMgr.getFormattedString(
215:                            "MsgSchemaReportTablesWritten", currentTable,
216:                            output.getFullPath());
217:                    result.addMessage(msg);
218:                    result.setSuccess();
219:                }
220:
221:                if (!StringUtil.isEmptyString(xslt)
222:                        && !StringUtil.isEmptyString(xsltOutput)) {
223:                    try {
224:                        XsltTransformer.transformFile(output.getFullPath(),
225:                                xsltOutput, xslt);
226:                        result.addMessage(ResourceMgr.getFormattedString(
227:                                "MsgXsltSuccessful", xsltOutput));
228:                        result.setSuccess();
229:                    } catch (Exception e) {
230:                        LogMgr.logError("WbSchemaReport.execute()",
231:                                "Error when transforming '"
232:                                        + output.getFullPath() + "' to '"
233:                                        + xsltOutput + "' using " + xslt, e);
234:                        result.addMessage(e.getMessage());
235:                    }
236:                }
237:
238:                return result;
239:            }
240:
241:            private TableIdentifier[] parseTables() {
242:                String tables = this .cmdLine.getValue("tables");
243:                if (tables == null)
244:                    return null;
245:                List l = StringUtil.stringToList(tables, ",");
246:                int count = l.size();
247:                TableIdentifier[] result = new TableIdentifier[count];
248:
249:                for (int i = 0; i < count; i++) {
250:                    String table = (String) l.get(i);
251:                    if (table == null)
252:                        continue;
253:                    if (table.trim().length() == 0)
254:                        continue;
255:                    table = this .currentConnection.getMetadata()
256:                            .adjustObjectnameCase(table);
257:                    result[i] = new TableIdentifier(table);
258:                }
259:                return result;
260:            }
261:
262:            public void cancel() throws SQLException {
263:                if (this .reporter != null) {
264:                    this .reporter.cancelExecution();
265:                }
266:            }
267:
268:            public void setCurrentObject(String anObject, long number,
269:                    long total) {
270:                if (anObject == null) {
271:                    this .currentTable = 0;
272:                    return;
273:                } else {
274:                    this .currentTable++;
275:                    if (this .rowMonitor != null) {
276:                        if (number > 0) {
277:                            this .rowMonitor.setCurrentObject(anObject, number,
278:                                    total);
279:                        } else if (rowMonitor instanceof  ScriptGenerationMonitor) {
280:                            ((ScriptGenerationMonitor) this .rowMonitor)
281:                                    .setCurrentObject(anObject);
282:                        }
283:
284:                    }
285:                }
286:            }
287:
288:            public void setCurrentRow(long number, long total) {
289:            }
290:
291:            public int getMonitorType() {
292:                return RowActionMonitor.MONITOR_PLAIN;
293:            }
294:
295:            public void setMonitorType(int aType) {
296:            }
297:
298:            public void jobFinished() {
299:            }
300:
301:            public void saveCurrentType(String type) {
302:            }
303:
304:            public void restoreType(String type) {
305:            }
306:
307:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.