Source Code Cross Referenced for DBDialect.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » upgrade » schema » 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 » Project Management » XPlanner 0.7b7 » com.technoetic.xplanner.upgrade.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created by IntelliJ IDEA.
003:         * User: sg426575
004:         * Date: May 8, 2006
005:         * Time: 1:27:04 AM
006:         */
007:        package com.technoetic.xplanner.upgrade.schema;
008:
009:        import java.util.Map;
010:        import java.util.HashMap;
011:        import java.util.List;
012:        import java.util.ArrayList;
013:        import java.sql.SQLException;
014:        import java.sql.Connection;
015:
016:        import net.sf.hibernate.Session;
017:        import net.sf.hibernate.HibernateException;
018:        import org.apache.commons.lang.StringUtils;
019:        import org.apache.log4j.Logger;
020:        import org.springframework.orm.hibernate.HibernateTemplate;
021:        import org.springframework.orm.hibernate.HibernateCallback;
022:        import org.springframework.jdbc.core.JdbcTemplate;
023:        import org.springframework.jdbc.core.ConnectionCallback;
024:        import org.springframework.dao.DataAccessException;
025:
026:        import com.technoetic.xplanner.util.LogUtil;
027:
028:        public class DBDialect {
029:
030:            protected static final Logger LOG = LogUtil.getLogger();
031:
032:            private static final Map DIALECT_BY_DATABASE = new HashMap(10);
033:
034:            static {
035:                initDialectByDatabase();
036:            }
037:
038:            private static void initDialectByDatabase() {
039:                addDialect(new MySqlTo4_0DBDialect());
040:                addDialect(new MySqlFrom4_1DBDialect());
041:                addDialect(new HsqldbDBDialect());
042:            }
043:
044:            private static void addDialect(DBDialect dialect) {
045:                String vendor = dialect.getVendor();
046:                List versions = (List) DIALECT_BY_DATABASE.get(vendor);
047:                if (versions == null) {
048:                    versions = new ArrayList(1);
049:                    DIALECT_BY_DATABASE.put(vendor, versions);
050:                }
051:                versions.add(dialect);
052:            }
053:
054:            public static DBDialect getDialect(JdbcTemplate template) {
055:                return (DBDialect) template.execute(new ConnectionCallback() {
056:                    public Object doInConnection(Connection connection)
057:                            throws SQLException, DataAccessException {
058:                        DBDialect dialect = (DBDialect) getDialect(connection);
059:                        LOG.debug("Using " + dialect
060:                                + " to handle schema migration of "
061:                                + getDatabaseVendor(connection));
062:                        return dialect;
063:                    }
064:                });
065:            }
066:
067:            private static Object getDialect(Connection connection)
068:                    throws SQLException {
069:                List versions = (List) DIALECT_BY_DATABASE
070:                        .get(getDatabaseVendor(connection));
071:                if (versions != null) {
072:                    double version = getDatabaseVersion(connection);
073:                    for (int i = 0; i < versions.size(); i++) {
074:                        DBDialect dialect = (DBDialect) versions.get(i);
075:                        if (dialect.getFromVersion() <= version
076:                                && version <= dialect.getToVersion()) {
077:                            return dialect;
078:                        }
079:                    }
080:                }
081:                return new DBDialect();
082:            }
083:
084:            private static String getDatabaseVendor(Connection connection)
085:                    throws SQLException {
086:                return connection.getMetaData().getDatabaseProductName();
087:            }
088:
089:            private static double getDatabaseVersion(Connection connection)
090:                    throws SQLException {
091:                int major = connection.getMetaData().getDatabaseMajorVersion();
092:                int minor = connection.getMetaData().getDatabaseMinorVersion();
093:                double version = Double.parseDouble("" + major + "." + minor);
094:                return version;
095:            }
096:
097:            public String getVendor() {
098:                return "default";
099:            }
100:
101:            public double getFromVersion() {
102:                return Double.MIN_VALUE;
103:            }
104:
105:            public double getToVersion() {
106:                return Double.MAX_VALUE;
107:            }
108:
109:            public String toString() {
110:                String str = getVendor();
111:                String min = getFromVersion() == Double.MIN_VALUE ? "first"
112:                        : "" + getFromVersion();
113:                String max = getToVersion() == Double.MAX_VALUE ? "latest" : ""
114:                        + getToVersion();
115:                return "{" + str + " [" + min + "-" + max + "]}";
116:            }
117:
118:            public String getAddForeignKeyConstraintQuery(String table,
119:                    String constraintName, String foreignKey,
120:                    String referencedTable, String referencedKey) {
121:                return "alter table " + table + " add constraint "
122:                        + constraintName + " foreign key (" + foreignKey
123:                        + ") references " + referencedTable + " ("
124:                        + referencedKey + ")";
125:            }
126:
127:            public String getDropForeignKeyConstraintQuery(String table,
128:                    String constraintName) {
129:                return getDropConstraintQuery(table, constraintName);
130:            }
131:
132:            public String getAddUniqueConstraintQuery(String table,
133:                    String constraintName, String column) {
134:                return "alter table " + table + " add constraint "
135:                        + constraintName + " unique " + constraintName + " ( "
136:                        + column + " )";
137:            }
138:
139:            public String getDropUniqueConstraintQuery(String table,
140:                    String constraintName) {
141:                return getDropConstraintQuery(table, constraintName);
142:            }
143:
144:            private String getDropConstraintQuery(String table,
145:                    String constraintName) {
146:                return "alter table " + table + " drop constraint "
147:                        + constraintName;
148:            }
149:
150:            public String getCreateTableQuery(String table, String fieldSQL) {
151:                return "create table " + table + " ( " + fieldSQL + " )";
152:            }
153:
154:            public String getDropTableQuery(String table) {
155:                return "drop table " + table;
156:            }
157:
158:            public String getCreateIndexQuery(String table, String name,
159:                    String field, boolean unique) {
160:                return "create " + (unique ? "unique" : "") + " index " + name
161:                        + " " + " on " + table + " ( " + field + " ) ";
162:            }
163:
164:            public String getDropIndexQuery(String table, String name) {
165:                return "drop index " + name + " on " + table;
166:            }
167:
168:            public String getAddPrimaryKeyQuery(String table,
169:                    String[] primaryColumns) {
170:                return "alter table " + table + " add primary key ( "
171:                        + StringUtils.join(primaryColumns, ',') + " )";
172:            }
173:
174:            public String getChangePrimaryKeyQuery(String table,
175:                    String[] primaryColumns) {
176:                return "alter table " + table + " alter primary key ( "
177:                        + StringUtils.join(primaryColumns, ',') + " )";
178:            }
179:
180:            public String getDropPrimaryKeyQuery(String table) {
181:                return "alter table " + table + " drop primary key";
182:            }
183:
184:            public String getRenameColumnQuery(String table, String oldName,
185:                    String newName, String type) {
186:                return "alter table " + table + " change " + oldName + " "
187:                        + newName + " " + type;
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.