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


001:        package net.sourceforge.squirrel_sql.plugins.userscript.kernel;
002:
003:        public class TemplateCode {
004:            public static final String CODE = "package pack;\n"
005:                    + "\n"
006:                    + "import java.sql.Connection;\n"
007:                    + "import java.sql.DriverManager;\n"
008:                    + "import java.io.PrintStream;\n"
009:                    + "import java.lang.reflect.Method;\n"
010:                    + "\n"
011:                    + "public class TemplateUserScript\n"
012:                    + "{\n"
013:                    + "	public static final String DB_OBJECT_TYPE_TABLE = \"TABLE\";\n"
014:                    + "	public static final String DB_OBJECT_TYPE_VIEW = \"VIEW\";\n"
015:                    + "	public static final String DB_OBJECT_TYPE_PROCEDURE = \"PROCEDURE\";\n"
016:                    + "	public static final String DB_OBJECT_TYPE_CONNECTION = \"CONNECTION\";\n"
017:                    + "	public static final String DB_OBJECT_TYPE_SQL_STATEMENT = \"SQL\";\n"
018:                    + "\n"
019:                    + "	/**\n"
020:                    + "	 * Will be set from inside SQuirreL via reflection.\n"
021:                    + "	 */\n"
022:                    + "	public Object environment;\n"
023:                    + "\n"
024:                    + "	/**\n"
025:                    + "	 *\n"
026:                    + "	 * Place your script code in this method.\n"
027:                    + "	 *\n"
028:                    + "	 * @param dbObjectType one of the DB_OBJECT_TYPE_... constants\n"
029:                    + "	 * @param info\n"
030:                    + "	 *        table name if DB_OBJECT_TYPE_TABLE.equals(DB_OBJECT_TYPE_TABLE)\n"
031:                    + "	 *        view name if DB_OBJECT_TYPE_TABLE.equals(DB_OBJECT_TYPE_VIEW)\n"
032:                    + "	 *        procedure name if DB_OBJECT_TYPE_TABLE.equals(DB_OBJECT_TYPE_PROCEDURE)\n"
033:                    + "	 *        null if DB_OBJECT_TYPE_TABLE.equals(DB_OBJECT_TYPE_CONNECTION)\n"
034:                    + "	 *        SQL String if DB_OBJECT_TYPE_TABLE.equals(DB_OBJECT_TYPE_SQL_STATEMENT)\n"
035:                    + "	 * @param con The connection of the DB session. If you work with transactions your\n"
036:                    + "	 *        script will executed in the same transaction. Closing the the connection will break the session.\n"
037:                    + "	 */\n"
038:                    + "	public void execute(String dbObjectType, String info, Connection con)\n"
039:                    + "		throws Exception\n"
040:                    + "	{\n"
041:                    + "		PrintStream ps;\n"
042:                    + "		ps = createPrintStream();\n"
043:                    + "		ps.println(\"PS 1\");\n"
044:                    + "		ps.println(\"type: \" + dbObjectType);\n"
045:                    + "		ps.println(\"info: \" + info);\n"
046:                    + "		ps.println(\"URL: \" + con.getMetaData().getURL());\n"
047:                    + "\n"
048:                    + "		ps = createPrintStream(\"Bean\");\n"
049:                    + "		ps.println(\"PS 2\");\n"
050:                    + "		ps.println(\"type: \" + dbObjectType);\n"
051:                    + "		ps.println(\"info: \" + info);\n"
052:                    + "		ps.println(\"URL: \" + con.getMetaData().getURL());\n"
053:                    + "\n"
054:                    + "		ps = getSQLAreaPrintStream();\n"
055:                    + "		ps.println(\"To SQL Area: \" + dbObjectType);\n"
056:                    + "		ps.println(\"type: \" + dbObjectType);\n"
057:                    + "		ps.println(\"info: \" + info);\n"
058:                    + "		ps.println(\"URL: \" + con.getMetaData().getURL());\n"
059:                    + "\n"
060:                    + "	}\n"
061:                    + "\n"
062:                    + "\n"
063:                    + "	//////////////////////////////////////////////////////////////////////////////\n"
064:                    + "	// Service Methods\n"
065:                    + "	//////////////////////////////////////////////////////////////////////////////\n"
066:                    + "\n"
067:                    + "\n"
068:                    + "	/**\n"
069:                    + "	 * The output to these print streams will be presented in a tabbed window.\n"
070:                    + "	 */\n"
071:                    + "	PrintStream createPrintStream()\n"
072:                    + "	{\n"
073:                    + "		return createPrintStream(null);\n"
074:                    + "	}\n"
075:                    + "\n"
076:                    + "	/**\n"
077:                    + "	 * The output to these print streams will be presented in a tabbed window.\n"
078:                    + "	 */\n"
079:                    + "	PrintStream createPrintStream(String tabTitle)\n"
080:                    + "	{\n"
081:                    + "		try\n"
082:                    + "		{\n"
083:                    + "			Method m = environment.getClass().getMethod(\"createPrintStream\", new Class[]{String.class});\n"
084:                    + "			return (PrintStream) m.invoke(environment, new Object[]{tabTitle});\n"
085:                    + "		}\n"
086:                    + "		catch (Exception e)\n"
087:                    + "		{\n"
088:                    + "			throw new RuntimeException(e);\n"
089:                    + "		}\n"
090:                    + "	}\n"
091:                    + "\n"
092:                    + "	/**\n"
093:                    + "	 * The output to this print stream will be appended to the  SQL text area of the db session\n"
094:                    + "	 */\n"
095:                    + "	PrintStream getSQLAreaPrintStream()\n"
096:                    + "	{\n"
097:                    + "		try\n"
098:                    + "		{\n"
099:                    + "			Method m = environment.getClass().getMethod(\"getSQLAreaPrintStream\", new Class[0]);\n"
100:                    + "			return (PrintStream) m.invoke(environment, new Object[0]);\n"
101:                    + "		}\n"
102:                    + "		catch (Exception e)\n"
103:                    + "		{\n"
104:                    + "			throw new RuntimeException(e);\n"
105:                    + "		}\n"
106:                    + "	}\n"
107:                    + "\n"
108:                    + "\n"
109:                    + "\n"
110:                    + "\n"
111:                    + "	///////////////////////////////////////////////////////////////////////////\n"
112:                    + "	// To test the script outside SQuirreL\n"
113:                    + "	//////////////////////////////////////////////////////////////////////////\n"
114:                    + "	public static void main(String[] args)\n"
115:                    + "		throws Exception\n"
116:                    + "	{\n"
117:                    + "		Class.forName(\"COM.ibm.db2.jdbc.net.DB2Driver\");\n"
118:                    + "		Connection con = DriverManager.getConnection(\"jdbc:db2://localhost/TestDB\", \"db2inst1\", \"db2inst1\");\n"
119:                    + "\n" + "\n"
120:                    + "		TemplateUserScript s = new TemplateUserScript();\n"
121:                    + "		s.environment = new TestEnvironment();\n"
122:                    + "		s.execute(DB_OBJECT_TYPE_TABLE, \"MyTable\", con);\n"
123:                    + "	}\n" + "\n" + "}\n" + "\n" + "\n"
124:                    + "class TestEnvironment\n" + "{\n" + "\n"
125:                    + "	public PrintStream createPrintStream()\n" + "	{\n"
126:                    + "		return System.out;\n" + "	}\n" + "\n"
127:                    + "	public PrintStream getSQLAreaPrintStream()\n" + "	{\n"
128:                    + "		return System.out;\n" + "	}\n" + "} ";
129:
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.