Source Code Cross Referenced for ScriptFunctionCommand.java in  » Database-Client » squirrel-sql-2.6.5a » de » ixdb » squirrel_sql » plugins » cache » 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 » de.ixdb.squirrel_sql.plugins.cache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.ixdb.squirrel_sql.plugins.cache;
002:
003:        import net.sourceforge.squirrel_sql.client.session.ISession;
004:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
005:        import net.sourceforge.squirrel_sql.fw.sql.IProcedureInfo;
006:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
007:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
008:        import org.w3c.dom.Document;
009:        import org.w3c.dom.Element;
010:        import org.w3c.dom.NodeList;
011:
012:        import java.util.Vector;
013:
014:        public class ScriptFunctionCommand {
015:            private ISession _session;
016:            private CachePlugin _plugin;
017:
018:            private static ILogger s_log;
019:
020:            public ScriptFunctionCommand(ISession session, CachePlugin plugin) {
021:                _session = session;
022:                _plugin = plugin;
023:                if (s_log == null) {
024:                    s_log = LoggerController.createLogger(getClass());
025:                }
026:            }
027:
028:            public void execute() {
029:                String[] funcNames = getSelectedFunctions();
030:
031:                if (0 == funcNames.length) {
032:                    return;
033:                }
034:
035:                String list = null;
036:                for (int i = 0; i < funcNames.length; i++) {
037:
038:                    if (null == list) {
039:                        list = "User.func" + funcNames[i];
040:                    } else {
041:                        list += ",User.func" + funcNames[i];
042:                    }
043:
044:                }
045:
046:                CdlAccessor.getSearchStringForCdlAccess(_session
047:                        .getSessionInternalFrame().getObjectTreeAPI()
048:                        .getSelectedDatabaseObjects());
049:
050:                Document doc = CdlAccessor.getDefinitionAsXmlDoc(list, _session
051:                        .getSQLConnection().getConnection());
052:
053:                StringBuffer script = new StringBuffer();
054:                for (int i = 0; i < funcNames.length; i++) {
055:                    String ddl = getDDL(doc, funcNames[i]);
056:                    script.append(ddl).append(getStatementSeparator()).append(
057:                            "\n");
058:                }
059:
060:                if (0 < script.length()) {
061:                    _session.getSessionInternalFrame().getSQLPanelAPI()
062:                            .appendSQLScript(script.toString());
063:                    _session
064:                            .selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
065:                }
066:
067:            }
068:
069:            private String getDDL(Document doc, String funcName) {
070:                Element documentElement = doc.getDocumentElement();
071:
072:                NodeList elementsByTagName = documentElement
073:                        .getElementsByTagName("Class");
074:
075:                StringBuffer ret = new StringBuffer("");
076:                for (int i = 0; i < elementsByTagName.getLength(); i++) {
077:                    Element elem = (Element) elementsByTagName.item(i);
078:
079:                    if (elem.getAttribute("name").trim().endsWith(funcName)) {
080:
081:                        ret.append("CREATE FUNCTION ").append(funcName);
082:
083:                        Element methElem = (Element) elem.getElementsByTagName(
084:                                "Method").item(0);
085:
086:                        Element elemParams = (Element) methElem
087:                                .getElementsByTagName("FormalSpec").item(0);
088:                        String cdlParamString = elemParams.getFirstChild()
089:                                .getNodeValue();
090:
091:                        ret.append(getParams(cdlParamString));
092:
093:                        Element retElem = (Element) methElem
094:                                .getElementsByTagName("ReturnType").item(0);
095:                        String cdlRetString = retElem.getFirstChild()
096:                                .getNodeValue();
097:                        String retString = getType(cdlRetString);
098:                        ret.append("\nRETURNS ").append(retString).append(
099:                                "\nLANGUAGE COS\n{");
100:
101:                        Element implElem = (Element) methElem
102:                                .getElementsByTagName("Implementation").item(0);
103:                        String impl = implElem.getFirstChild().getNodeValue();
104:                        ret.append(impl);
105:                        ret.append("\n}");
106:                    }
107:                }
108:
109:                return ret.toString();
110:            }
111:
112:            private String getParams(String cdlParamString) {
113:                String clean = removeBrackets(cdlParamString);
114:
115:                String[] params = clean.split(",");
116:
117:                String ret = "(";
118:                for (int i = 0; i < params.length; i++) {
119:                    String[] pieces = params[i].split(":");
120:
121:                    String paramDef = pieces[0] + " " + getType(pieces[1]);
122:                    if (0 == i) {
123:                        ret += paramDef;
124:                    } else {
125:                        ret += ", " + paramDef;
126:                    }
127:                }
128:
129:                ret += ")";
130:
131:                return ret;
132:            }
133:
134:            private String removeBrackets(String inParams) {
135:                StringBuffer ret = new StringBuffer();
136:                int openIndex = inParams.indexOf('(');
137:                if (-1 == openIndex) {
138:                    return inParams;
139:                }
140:                while (-1 != openIndex) {
141:                    ret.append(inParams.substring(0, openIndex));
142:                    inParams = inParams.substring(inParams.indexOf(')') + 1,
143:                            inParams.length());
144:                    openIndex = inParams.indexOf('(');
145:                }
146:                return ret.toString();
147:            }
148:
149:            private String getType(String cacheType) {
150:                if (cacheType.equals("%Library.TimeStamp")
151:                        || cacheType.equals("%TimeStamp")) {
152:                    return "DATETIME";
153:                } else if (cacheType.startsWith("%Library.String")
154:                        || cacheType.startsWith("%String")) {
155:                    // Die 200 braucht nur SQL Server 7.0,
156:                    // SQL Server 2000 nicht mehr sagt SAN
157:                    return "VARCHAR(200)";
158:                } else if (cacheType.startsWith("%Library.Integer")
159:                        || cacheType.startsWith("%Integer")) {
160:                    return "INTEGER";
161:                } else if (cacheType.equals("%Library.Numeric")
162:                        || cacheType.equals("%Numeric")) {
163:                    return "NUMERIC(18,2)";
164:                } else {
165:                    return "Unbekannter Parametertyp:>" + cacheType + "<";
166:                }
167:            }
168:
169:            private String getStatementSeparator() {
170:                String statementSeparator = _session.getProperties()
171:                        .getSQLStatementSeparator();
172:
173:                if (1 < statementSeparator.length()) {
174:                    statementSeparator = "\n" + statementSeparator + "\n";
175:                }
176:
177:                return statementSeparator;
178:            }
179:
180:            private String[] getSelectedFunctions() {
181:                IDatabaseObjectInfo[] dbObjs = _session
182:                        .getSessionInternalFrame().getObjectTreeAPI()
183:                        .getSelectedDatabaseObjects();
184:
185:                Vector ret = new Vector();
186:                for (int i = 0; i < dbObjs.length; i++) {
187:                    if (dbObjs[i] instanceof  IProcedureInfo) {
188:                        IProcedureInfo pi = (IProcedureInfo) dbObjs[i];
189:                        String sFunc = pi.getSimpleName();
190:                        ret.add(sFunc);
191:                    }
192:                }
193:                return (String[]) ret.toArray(new String[0]);
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.