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


001:        package net.sourceforge.squirrel_sql.plugins.refactoring;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
007:        import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
008:
009:        import org.hibernate.HibernateException;
010:
011:        public class DBUtil {
012:
013:            /**
014:             * 
015:             * @param info
016:             * @param dialect
017:             * @return
018:             * @throws UnsupportedOperationException
019:             *            if the specified dialect doesn't support
020:             * @throws HibernateException
021:             *            if the type in the specified info isn't supported by this
022:             *            dialect.
023:             */
024:            public static String[] getAlterSQLForColumnAddition(
025:                    TableColumnInfo info, HibernateDialect dialect)
026:                    throws HibernateException, UnsupportedOperationException {
027:                ArrayList<String> result = new ArrayList<String>();
028:
029:                String[] addSQLs = dialect.getColumnAddSQL(info);
030:
031:                for (int i = 0; i < addSQLs.length; i++) {
032:                    String addSQL = addSQLs[i];
033:                    result.add(addSQL);
034:                }
035:
036:                return result.toArray(new String[result.size()]);
037:            }
038:
039:            public static String[] getAlterSQLForColumnChange(
040:                    TableColumnInfo from, TableColumnInfo to,
041:                    HibernateDialect dialect) {
042:                ArrayList<String> result = new ArrayList<String>();
043:                // It is important to process the name change first - so that we can use
044:                // the new name instead of the old in subsequent alterations
045:                String nameSQL = getColumnNameAlterSQL(from, to, dialect);
046:                if (nameSQL != null) {
047:                    result.add(nameSQL);
048:                }
049:                String nullSQL = getNullAlterSQL(from, to, dialect);
050:                if (nullSQL != null) {
051:                    result.add(nullSQL);
052:                }
053:                String commentSQL = getCommentAlterSQL(from, to, dialect);
054:                if (commentSQL != null) {
055:                    result.add(commentSQL);
056:                }
057:                List<String> typeSQL = getTypeAlterSQL(from, to, dialect);
058:                if (typeSQL != null) {
059:                    result.addAll(typeSQL);
060:                }
061:                String defaultSQL = getAlterSQLForColumnDefault(from, to,
062:                        dialect);
063:                if (defaultSQL != null) {
064:                    result.add(defaultSQL);
065:                }
066:                return result.toArray(new String[result.size()]);
067:            }
068:
069:            public static List<String> getTypeAlterSQL(TableColumnInfo from,
070:                    TableColumnInfo to, HibernateDialect dialect) {
071:                if (from.getDataType() == to.getDataType()
072:                        && from.getColumnSize() == to.getColumnSize()) {
073:                    return null;
074:                }
075:                return dialect.getColumnTypeAlterSQL(from, to);
076:            }
077:
078:            public static String getColumnNameAlterSQL(TableColumnInfo from,
079:                    TableColumnInfo to, HibernateDialect dialect) {
080:                if (from.getColumnName().equals(to.getColumnName())) {
081:                    return null;
082:                }
083:                return dialect.getColumnNameAlterSQL(from, to);
084:            }
085:
086:            public static String getNullAlterSQL(TableColumnInfo from,
087:                    TableColumnInfo to, HibernateDialect dialect) {
088:                if (from.isNullable().equalsIgnoreCase(to.isNullable())) {
089:                    return null;
090:                }
091:                return dialect.getColumnNullableAlterSQL(to);
092:            }
093:
094:            public static String getCommentAlterSQL(TableColumnInfo from,
095:                    TableColumnInfo to, HibernateDialect dialect) {
096:                String oldComment = from.getRemarks();
097:                String newComment = to.getRemarks();
098:                if (!dialect.supportsColumnComment()) {
099:                    return null;
100:                }
101:                if (oldComment == null && newComment == null) {
102:                    return null;
103:                }
104:                if (oldComment == null || !oldComment.equals(newComment)) {
105:                    return dialect.getColumnCommentAlterSQL(to);
106:                }
107:                return null;
108:            }
109:
110:            public static String getAlterSQLForColumnDefault(
111:                    TableColumnInfo from, TableColumnInfo to,
112:                    HibernateDialect dialect) {
113:                String oldDefault = from.getDefaultValue();
114:                String newDefault = to.getDefaultValue();
115:                // empty string ('') seems to be represented as null in some drivers.
116:                // Not sure if this is the best thing to do here, but it fixes an issue
117:                // where SQL returns is set default to '', when it is already null.
118:                if (oldDefault == null) {
119:                    oldDefault = "";
120:                }
121:                if (newDefault == null) {
122:                    newDefault = "";
123:                }
124:                if (!oldDefault.equals(newDefault)) {
125:                    if (!dialect.supportsAlterColumnDefault()) {
126:                        throw new UnsupportedOperationException(
127:                                dialect.getDisplayName()
128:                                        + " doesn't support column default value alterations");
129:                    }
130:                    return dialect.getColumnDefaultAlterSQL(to);
131:                }
132:                return null;
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.