Source Code Cross Referenced for CreateTableChange.java in  » Database-Client » LiquiBase » liquibase » change » 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 » LiquiBase » liquibase.change 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package liquibase.change;
002:
003:        import liquibase.database.Database;
004:        import liquibase.database.sql.*;
005:        import liquibase.database.structure.Column;
006:        import liquibase.database.structure.DatabaseObject;
007:        import liquibase.database.structure.Table;
008:        import liquibase.exception.UnsupportedChangeException;
009:        import liquibase.util.StringUtils;
010:        import org.w3c.dom.Document;
011:        import org.w3c.dom.Element;
012:
013:        import java.util.ArrayList;
014:        import java.util.HashSet;
015:        import java.util.List;
016:        import java.util.Set;
017:
018:        /**
019:         * Creates a new table.
020:         */
021:        public class CreateTableChange extends AbstractChange {
022:
023:            private List<ColumnConfig> columns;
024:            private String schemaName;
025:            private String tableName;
026:            private String tablespace;
027:            private String remarks;
028:
029:            public CreateTableChange() {
030:                super ("createTable", "Create Table");
031:                columns = new ArrayList<ColumnConfig>();
032:            }
033:
034:            public SqlStatement[] generateStatements(Database database)
035:                    throws UnsupportedChangeException {
036:
037:                String schemaName = getSchemaName() == null ? database
038:                        .getDefaultSchemaName() : getSchemaName();
039:                CreateTableStatement statement = new CreateTableStatement(
040:                        schemaName, getTableName());
041:                for (ColumnConfig column : getColumns()) {
042:                    ConstraintsConfig constraints = column.getConstraints();
043:                    boolean isAutoIncrement = column.isAutoIncrement() != null
044:                            && column.isAutoIncrement();
045:                    if (constraints != null
046:                            && constraints.isPrimaryKey() != null
047:                            && constraints.isPrimaryKey()) {
048:
049:                        statement.addPrimaryKeyColumn(column.getName(),
050:                                database.getColumnType(column.getType(),
051:                                        isAutoIncrement));
052:
053:                    } else {
054:                        String defaultValue = null;
055:                        if (column.hasDefaultValue()) {
056:                            defaultValue = StringUtils.trimToNull(column
057:                                    .getDefaultColumnValue(database));
058:                        }
059:                        statement.addColumn(column.getName(), database
060:                                .getColumnType(column.getType(), column
061:                                        .isAutoIncrement()), defaultValue);
062:                    }
063:
064:                    if (constraints != null) {
065:                        if (constraints.isNullable() != null
066:                                && !constraints.isNullable()) {
067:                            statement
068:                                    .addColumnConstraint(new NotNullConstraint(
069:                                            column.getName()));
070:                        }
071:
072:                        if (constraints.getReferences() != null) {
073:                            if (StringUtils.trimToNull(constraints
074:                                    .getForeignKeyName()) == null) {
075:                                throw new UnsupportedChangeException(
076:                                        "createTable with references requires foreignKeyName");
077:                            }
078:                            ForeignKeyConstraint fkConstraint = new ForeignKeyConstraint(
079:                                    constraints.getForeignKeyName(),
080:                                    constraints.getReferences());
081:                            fkConstraint.setColumn(column.getName());
082:                            fkConstraint.setDeleteCascade(constraints
083:                                    .isDeleteCascade() != null
084:                                    && constraints.isDeleteCascade());
085:                            fkConstraint.setInitiallyDeferred(constraints
086:                                    .isInitiallyDeferred() != null
087:                                    && constraints.isInitiallyDeferred());
088:                            fkConstraint.setDeferrable(constraints
089:                                    .isDeferrable() != null
090:                                    && constraints.isDeferrable());
091:                            statement.addColumnConstraint(fkConstraint);
092:                        }
093:
094:                        if (constraints.isUnique() != null
095:                                && constraints.isUnique()) {
096:                            statement.addColumnConstraint(new UniqueConstraint(
097:                                    constraints.getUniqueConstraintName())
098:                                    .addColumns(column.getName()));
099:                        }
100:                    }
101:
102:                    if (isAutoIncrement) {
103:                        statement
104:                                .addColumnConstraint(new AutoIncrementConstraint(
105:                                        column.getName()));
106:                    }
107:                }
108:
109:                statement
110:                        .setTablespace(StringUtils.trimToNull(getTablespace()));
111:
112:                List<SqlStatement> statements = new ArrayList<SqlStatement>();
113:                statements.add(statement);
114:
115:                return statements.toArray(new SqlStatement[statements.size()]);
116:            }
117:
118:            protected Change[] createInverses() {
119:                DropTableChange inverse = new DropTableChange();
120:                inverse.setSchemaName(getSchemaName());
121:                inverse.setTableName(getTableName());
122:
123:                return new Change[] { inverse };
124:            }
125:
126:            public List<ColumnConfig> getColumns() {
127:                return columns;
128:            }
129:
130:            public String getSchemaName() {
131:                return schemaName;
132:            }
133:
134:            public void setSchemaName(String schemaName) {
135:                this .schemaName = schemaName;
136:            }
137:
138:            public String getTableName() {
139:                return tableName;
140:            }
141:
142:            public void setTableName(String tableName) {
143:                this .tableName = tableName;
144:            }
145:
146:            public String getTablespace() {
147:                return tablespace;
148:            }
149:
150:            public void setTablespace(String tablespace) {
151:                this .tablespace = tablespace;
152:            }
153:
154:            public void addColumn(ColumnConfig column) {
155:                columns.add(column);
156:            }
157:
158:            public String getRemarks() {
159:                return remarks;
160:            }
161:
162:            public void setRemarks(String remarks) {
163:                this .remarks = remarks;
164:            }
165:
166:            public String getConfirmationMessage() {
167:                return "Table " + tableName + " created";
168:            }
169:
170:            public Element createNode(Document currentChangeLogFileDOM) {
171:                Element element = currentChangeLogFileDOM
172:                        .createElement("createTable");
173:                if (getSchemaName() != null) {
174:                    element.setAttribute("schemaName", getSchemaName());
175:                }
176:
177:                element.setAttribute("tableName", getTableName());
178:                if (StringUtils.trimToNull(tablespace) != null) {
179:                    element.setAttribute("tablespace", tablespace);
180:                }
181:                if (StringUtils.trimToNull(remarks) != null) {
182:                    element.setAttribute("remarks", remarks);
183:                }
184:                for (ColumnConfig column : getColumns()) {
185:                    element.appendChild(column
186:                            .createNode(currentChangeLogFileDOM));
187:                }
188:                return element;
189:            }
190:
191:            public Set<DatabaseObject> getAffectedDatabaseObjects() {
192:                Set<DatabaseObject> returnSet = new HashSet<DatabaseObject>();
193:
194:                Table table = new Table(getTableName());
195:                returnSet.add(table);
196:
197:                for (ColumnConfig columnConfig : getColumns()) {
198:                    Column column = new Column();
199:                    column.setTable(table);
200:                    column.setName(columnConfig.getName());
201:
202:                    returnSet.add(column);
203:                }
204:
205:                return returnSet;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.