Source Code Cross Referenced for SqlExtractorHyperSonicStanaloneServer.java in  » Code-Analyzer » hammurapi-3.20.0.3 » org » hammurapi » inspectors » metrics » 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 » Code Analyzer » hammurapi 3.20.0.3 » org.hammurapi.inspectors.metrics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Oct 16, 2004
003:         *
004:         * TODO To change the template for this generated file go to
005:         * Window - Preferences - Java - Code Style - Code Templates
006:         */
007:        package org.hammurapi.inspectors.metrics;
008:
009:        import java.io.FileWriter;
010:        import java.io.IOException;
011:        import java.io.Writer;
012:        import java.sql.Connection;
013:        import java.sql.DriverManager;
014:        import java.sql.PreparedStatement;
015:        import java.sql.ResultSet;
016:        import java.sql.SQLException;
017:        import java.sql.Statement;
018:
019:        import org.hammurapi.HammurapiException;
020:        import org.hammurapi.HammurapiRuntimeException;
021:        import org.hammurapi.InspectorContext;
022:        import org.hammurapi.results.AnnotationContext;
023:        import org.hammurapi.results.AnnotationContext.FileEntry;
024:
025:        import com.pavelvlasov.jsel.Parameter;
026:        import com.pavelvlasov.jsel.VariableDefinition;
027:        import com.pavelvlasov.review.SourceMarker;
028:        import com.pavelvlasov.sql.Parameterizer;
029:        import com.pavelvlasov.sql.RowProcessor;
030:        import com.pavelvlasov.sql.SQLProcessor;
031:
032:        /**
033:         * @author 111001082
034:         *
035:         * TODO To change the template for this generated type comment go to
036:         * Window - Preferences - Java - Code Style - Code Templates
037:         */
038:        public class SqlExtractorHyperSonicStanaloneServer extends
039:                SqlExtractorHyperSonicDb implements 
040:                SqlExtractorPersistencyService {
041:
042:            private static int counter = 0;
043:            private Connection c = null;
044:            /**
045:             * Unique table name
046:             */
047:            private String sqlTableName = "SQL_STRING_LITERALS";
048:            protected String varTableName = "VAR_DEF_LITERALS";
049:            protected String[] initSQL = {
050:                    "CREATE CACHED TABLE "
051:                            + sqlTableName
052:                            + " (LITERAL VARCHAR(250), SOURCE VARCHAR(250), LINE INTEGER, COL INTEGER,  CLASS_NAME VARCHAR(250), CLASS_FCN VARCHAR(250))",
053:                    "CREATE INDEX IX_" + sqlTableName + " ON " + sqlTableName
054:                            + " (LITERAL, SOURCE, LINE, COL)",
055:
056:                    "CREATE CACHED TABLE "
057:                            + varTableName
058:                            + " (VAR_NAME VARCHAR(250), VAR_VALUE  VARCHAR(250), SOURCE VARCHAR(250), LINE INTEGER, COL INTEGER, CLASS_NAME VARCHAR(250), CLASS_FCN VARCHAR(250))",
059:                    "CREATE INDEX IX_" + varTableName + " ON " + varTableName
060:                            + " (VAR_NAME, VAR_VALUE, SOURCE, LINE, COL)"
061:
062:            };
063:            protected String[] destroySQL = {
064:                    "CREATE INDEX IX_" + sqlTableName,
065:                    "DELETE * FROM " + sqlTableName,
066:
067:                    "CREATE INDEX IX_" + varTableName,
068:                    "DELETE *  FROM " + varTableName };
069:
070:            public SqlExtractorHyperSonicStanaloneServer(
071:                    InspectorContext _context) throws HammurapiException {
072:                super ();
073:                context = _context;
074:                init();
075:            }
076:
077:            public void init() throws HammurapiException {
078:                // super.init();
079:
080:                try {
081:                    Class.forName("org.hsqldb.jdbcDriver");
082:                    // Connection c =
083:                    // DriverManager.getConnection("jdbc:hsqldb:file:D:/anwend/java/hsqldb/data/myjobdb",
084:                    // "sa", "");
085:                    c = DriverManager.getConnection(
086:                            "jdbc:hsqldb:hsql://localhost/job", "sa", "");
087:                } catch (Exception e) {
088:                    // TODO Auto-generated catch block
089:                    e.printStackTrace();
090:                    throw new HammurapiException(e);
091:                }
092:            }
093:
094:            /*
095:             * (non-Javadoc)
096:             * 
097:             * @see org.hammurapi.inspectors.metrics.SqlExtractorPersistencyService#saveLanguageElement(org.hammurapi.inspectors.metrics.StringVariable)
098:             */
099:            public void saveLanguageElement(StringVariable strVar) {
100:                System.out.println("** saveLanguageElement "
101:                        + strVar.langElement.toString());
102:
103:                final boolean[] ret = { false };
104:                try {
105:                    String templangElementName = "<unresolved>";
106:                    if (strVar.langElement instanceof  VariableDefinition) {
107:                        templangElementName = ((VariableDefinition) strVar.langElement)
108:                                .getName();
109:                    } else if (strVar.langElement instanceof  Parameter) {
110:                        templangElementName = ((Parameter) strVar.langElement)
111:                                .getName();
112:                    }
113:                    final String langElementName = templangElementName;
114:                    // System.out.println(langElementName + " :- "+ currentStringValue );
115:                    // check for String Only !
116:
117:                    //-- is entry already available?
118:
119:                    SourceMarker sourceMarker = (SourceMarker) strVar.langElement;
120:
121:                    String sqlQuery = "SELECT 'variable', SOURCE, LINE, COL,  VAR_NAME, VAR_VALUE , CLASS_NAME, CLASS_FCN FROM "
122:                            + varTableName
123:                            + " WHERE VAR_NAME = '"
124:                            + langElementName
125:                            + "'"
126:                            + "AND CLASS_NAME = '"
127:                            + strVar.className
128:                            + "'"
129:                            + "AND CLASS_FCN  = '"
130:                            + strVar.classFcn + "'";
131:
132:                    Statement stmt = c.createStatement();
133:                    ResultSet rs = stmt.executeQuery(sqlQuery);
134:
135:                    try {
136:                        String tmpStr = rs.getString("VAR_NAME");
137:                        ret[0] = langElementName.equals(tmpStr);
138:                    } catch (Exception e1) {
139:                        // TODO Auto-generated catch block
140:                        // e1.printStackTrace();
141:                    }
142:
143:                    rs.close();
144:                    stmt.close();
145:                    //-- update entry
146:
147:                    stmt = c.createStatement();
148:                    if (ret[0]) {
149:                        sqlQuery = "UPDATE " + varTableName + " SET "
150:                                + " VAR_VALUE =  '"
151:                                + strVar.varValue.toString() + "'"
152:                                + " WHERE VAR_NAME = '" + langElementName + "'"
153:                                + "AND CLASS_NAME = '" + strVar.className + "'"
154:                                + "AND CLASS_FCN  = '" + strVar.classFcn + "'";
155:                        stmt.executeQuery(sqlQuery);
156:                        stmt.close();
157:
158:                    } else {
159:                        //   System.out.println (" KKKKKKK INSERT" );
160:                        //-- insert entry
161:                        sqlQuery = "INSERT INTO "
162:                                + varTableName
163:                                + " (VAR_NAME, VAR_VALUE, SOURCE, LINE, COL,  CLASS_NAME, CLASS_FCN) "
164:                                + "VALUES (" + "'" + langElementName + "',"
165:                                + "'" + strVar.varValue.toString() + "',"
166:
167:                                + "'" + sourceMarker.getSourceURL() + "',"
168:                                + "'" + sourceMarker.getLine() + "'," + "'"
169:                                + sourceMarker.getColumn() + "'," + "'"
170:                                + strVar.className + "'," + "'"
171:                                + strVar.classFcn + "')";
172:                        stmt.executeQuery(sqlQuery);
173:                        stmt.close();
174:
175:                    } //fi
176:                } catch (SQLException e) {
177:                    context.warn((SourceMarker) strVar.langElement, e);
178:                }
179:            }
180:
181:            /* (non-Javadoc)
182:             * @see org.hammurapi.inspectors.metrics.SqlExtractorPersistencyService#render(org.hammurapi.results.AnnotationContext, java.lang.String)
183:             */
184:            public void render(AnnotationContext context, String path)
185:                    throws HammurapiException {
186:                try {
187:                    FileEntry a = context.getNextFile(".html");
188:                    path = a.getPath();
189:
190:                    final Writer w = new FileWriter(a.getFile());
191:                    try {
192:                        w
193:                                .write("<HTML><BODY><TABLE border=\"1\"><TR><TH>Var Name</TH><TH>Var Value</TH><TH>File</TH><TH>Line</TH><TH>Column</TH><TH>Class</TH><TH>FCN</TH></TR>");
194:                        Statement stmt = c.createStatement();
195:                        String sqlString = "SELECT * FROM ("
196:                                + "SELECT 'variable', SOURCE, LINE, COL,  VAR_NAME, VAR_VALUE , CLASS_NAME, CLASS_FCN FROM "
197:                                + varTableName + ") ORDER BY SOURCE, LINE, COL";
198:                        ResultSet rs = stmt.executeQuery(sqlString);
199:
200:                        while (rs.next()) {
201:                            try {
202:                                w.write("<TR><TD>");
203:                                // w.write(rs.getString("LITERAL"));
204:                                w.write(rs.getString(5));
205:                                w.write("</TD><TD>");
206:
207:                                w.write(rs.getString(6)); // VAR_VALUE or LITERAL
208:                                w.write("</TD><TD>");
209:                                // w.write(rs.getString( 1 ));
210:                                // w.write("</TD><TD>");
211:
212:                                w.write(rs.getString("SOURCE"));
213:                                w.write("</TD><TD aligh=\"right\">");
214:                                w.write(rs.getString("LINE"));
215:                                w.write("</TD><TD aligh=\"right\">");
216:                                w.write(rs.getString("COL"));
217:                                w.write("</TD><TD>");
218:                                w.write(rs.getString("CLASS_NAME"));
219:                                w.write("</TD><TD>");
220:                                w.write(rs.getString("CLASS_FCN"));
221:
222:                                w.write("</TD><TR>");
223:
224:                            } catch (IOException e) {
225:                                throw new HammurapiRuntimeException(e);
226:                            }
227:                        }
228:
229:                        ;
230:                        w.write("</TABLE></BODY></HTML>");
231:                    } finally {
232:                        w.close();
233:                    }
234:                } catch (SQLException e) {
235:                    throw new HammurapiException(e);
236:                } catch (HammurapiRuntimeException e) {
237:                    throw new HammurapiException(e.getCause());
238:                } catch (IOException e) {
239:                    throw new HammurapiException(e);
240:
241:                } catch (HammurapiException e) {
242:                    throw new HammurapiException(e);
243:                }
244:
245:            }
246:
247:            public void destroy() {
248:                try {
249:                    Statement stmt = c.createStatement();
250:                    for (int i = 0; i < destroySQL.length; i++) {
251:                        try {
252:                            ResultSet rs = stmt.executeQuery(destroySQL[i]);
253:
254:                        } catch (SQLException e) {
255:                            System.err.println("Could not delete tables");
256:                            e.printStackTrace();
257:                        }
258:                    }
259:                } catch (SQLException e) {
260:                    System.err.println("Could not delete tables");
261:                    e.printStackTrace();
262:                }
263:
264:            }
265:
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.