Source Code Cross Referenced for GenericJdbcManager.java in  » J2EE » jag » com » finalist » jaggenerator » 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 » J2EE » jag » com.finalist.jaggenerator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.jaggenerator;
019:
020:        import javax.swing.*;
021:        import java.sql.Connection;
022:        import java.sql.Driver;
023:        import java.sql.DriverManager;
024:        import java.sql.ResultSet;
025:        import java.util.ArrayList;
026:
027:        /**
028:         *
029:         * @author  hillie
030:         */
031:        public class GenericJdbcManager {
032:
033:            private String url;
034:            private String schema;
035:            private String username;
036:            private String password;
037:            private String clazz;
038:            private String dbName = "";
039:            private String[] displayTypes = null;
040:            private static final String SCHEMA_NAME_COLUMN = "TABLE_SCHEM";
041:
042:            public GenericJdbcManager(String url, String username,
043:                    String password, String clazz, String[] displayTypes) {
044:                this .url = url;
045:                this .username = username;
046:                this .password = password;
047:                this .clazz = clazz;
048:                this .displayTypes = displayTypes;
049:
050:                int dbIndex = url.lastIndexOf("/");
051:                if (dbIndex != -1) {
052:                    dbName = url.substring(dbIndex + 1);
053:                }
054:
055:                //by default use the schema that maches the username - otherwise prompt for a schema..
056:                ArrayList allSchemas = new ArrayList();
057:                try {
058:                    Connection cx = connect();
059:                    ResultSet schemas = cx.getMetaData().getSchemas();
060:                    while (schemas.next()) {
061:                        String s = schemas.getString(SCHEMA_NAME_COLUMN);
062:                        /* Do NOT ignore case here, otherwise the schema will not be selected correctly */
063:                        if (username.equals(s)) {
064:                            schema = username;
065:                            break;
066:                        }
067:                        allSchemas.add(s);
068:                    }
069:
070:                    // Only show if there are any schema's to select.
071:                    if ((schema == null) && (allSchemas.size() != 0)) {
072:                        schema = (String) JOptionPane
073:                                .showInputDialog(
074:                                        JagGenerator.jagGenerator,
075:                                        "There is no schema called \""
076:                                                + username
077:                                                + "\" in this database!\n\n"
078:                                                + "Please choose the desired schema from this list, \n"
079:                                                + "or press 'Cancel' to access all schemas.\n",
080:                                        "Database schemas",
081:                                        JOptionPane.QUESTION_MESSAGE, null,
082:                                        allSchemas.toArray(), null);
083:                    }
084:
085:                    JagGenerator.logToConsole("Using database schema: "
086:                            + schema);
087:
088:                } catch (Exception e) {
089:                    e.printStackTrace();
090:                }
091:            }
092:
093:            public Connection connect() throws Exception {
094:                DriverManager.registerDriver((Driver) Class.forName(clazz)
095:                        .newInstance());
096:                return DriverManager.getConnection(url, username, password);
097:            }
098:
099:            /** Getter for property url.
100:             * @return Value of property url.
101:             *
102:             */
103:            public String getUrl() {
104:                return this .url;
105:            }
106:
107:            /** Setter for property url.
108:             * @param url New value of property url.
109:             *
110:             */
111:            public void setUrl(String url) {
112:                this .url = url;
113:            }
114:
115:            /** Getter for property username.
116:             * @return Value of property username.
117:             *
118:             */
119:            public String getUsername() {
120:                return this .username;
121:            }
122:
123:            /** Setter for property username.
124:             * @param username New value of property username.
125:             *
126:             */
127:            public void setUsername(String username) {
128:                this .username = username;
129:            }
130:
131:            /** Getter for property password.
132:             * @return Value of property password.
133:             *
134:             */
135:            public String getPassword() {
136:                return this .password;
137:            }
138:
139:            /** Setter for property password.
140:             * @param password New value of property password.
141:             *
142:             */
143:            public void setPassword(String password) {
144:                this .password = password;
145:            }
146:
147:            /** Getter for property Database Name.
148:             * @return Value of database name.
149:             *
150:             *
151:             */
152:            public String getDBName() {
153:                return this .dbName;
154:            }
155:
156:            /** Setter for property password.
157:             * @param dbName New value of property password.
158:             *
159:             *
160:             */
161:            public void setDBName(String dbName) {
162:                this .dbName = dbName;
163:            }
164:
165:            /**
166:             * Return an array list of types that should be displayed while connecting
167:             * to the database. For example: TABLE, VIEW, SYNONYM
168:             */
169:            public String[] getDisplayTableTypes() {
170:                return this .displayTypes;
171:            }
172:
173:            /**
174:             * Gets the currently database schema, or <code>null</code> if no schema is being used.
175:             * @return Value of database name.
176:             */
177:            public String getSchema() {
178:                return schema;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.