Source Code Cross Referenced for ColumnConfig.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.ComputedDateValue;
005:        import liquibase.database.sql.ComputedNumericValue;
006:        import liquibase.util.ISODateFormat;
007:        import liquibase.util.StringUtils;
008:        import org.w3c.dom.Document;
009:        import org.w3c.dom.Element;
010:
011:        import java.text.NumberFormat;
012:        import java.text.ParseException;
013:        import java.util.Date;
014:
015:        /**
016:         * This class is the representation of the column tag in the XMl file
017:         * It has a reference to the Constraints object for getting information
018:         * about the columns constraints.
019:         */
020:        public class ColumnConfig {
021:            private String name;
022:            private String type;
023:            private String value;
024:            private Number valueNumeric;
025:            private Date valueDate;
026:            private Boolean valueBoolean;
027:
028:            private String defaultValue;
029:            private Number defaultValueNumeric;
030:            private Date defaultValueDate;
031:            private Boolean defaultValueBoolean;
032:
033:            private ConstraintsConfig constraints;
034:            private Boolean autoIncrement;
035:
036:            public String getName() {
037:                return name;
038:            }
039:
040:            public void setName(String name) {
041:                this .name = name;
042:            }
043:
044:            public String getType() {
045:                return type;
046:            }
047:
048:            public void setType(String type) {
049:                this .type = type;
050:            }
051:
052:            public String getValue() {
053:                return value;
054:            }
055:
056:            public void setValue(String value) {
057:                // Since we have two rules for the value it can either be specifed as an attribute
058:                // or as the tag body in case of long values then the check is necessary so that it
059:                // should not override the value specifed as an attribute.
060:                if (StringUtils.trimToNull(value) != null) {
061:                    this .value = value;
062:                }
063:            }
064:
065:            public Number getValueNumeric() {
066:                return valueNumeric;
067:            }
068:
069:            public void setValueNumeric(String valueNumeric)
070:                    throws ParseException {
071:                if (valueNumeric == null) {
072:                    this .valueNumeric = null;
073:                } else {
074:                    if (valueNumeric.matches("\\d+\\.?\\d*")) {
075:                        this .valueNumeric = NumberFormat.getInstance().parse(
076:                                valueNumeric);
077:                    } else {
078:                        this .valueNumeric = new ComputedNumericValue(
079:                                valueNumeric);
080:                    }
081:                }
082:            }
083:
084:            public void setValueNumeric(Number valueNumeric) {
085:                this .valueNumeric = valueNumeric;
086:            }
087:
088:            public Boolean getValueBoolean() {
089:                return valueBoolean;
090:            }
091:
092:            public void setValueBoolean(Boolean valueBoolean) {
093:                this .valueBoolean = valueBoolean;
094:            }
095:
096:            public Date getValueDate() {
097:                return valueDate;
098:            }
099:
100:            public void setValueDate(Date valueDate) {
101:                this .valueDate = valueDate;
102:            }
103:
104:            public void setValueDate(String valueDate) {
105:                try {
106:                    this .valueDate = new ISODateFormat().parse(valueDate);
107:                } catch (ParseException e) {
108:                    //probably a function
109:                    this .valueDate = new ComputedDateValue(valueDate);
110:                }
111:            }
112:
113:            public Object getValueObject() {
114:                if (getValue() != null) {
115:                    return getValue();
116:                } else if (getValueBoolean() != null) {
117:                    return getValueBoolean();
118:                } else if (getValueNumeric() != null) {
119:                    return getValueNumeric();
120:                } else if (getValueDate() != null) {
121:                    return getValueDate();
122:                }
123:                return null;
124:            }
125:
126:            public String getDefaultValue() {
127:                return defaultValue;
128:            }
129:
130:            public void setDefaultValue(String defaultValue) {
131:                this .defaultValue = defaultValue;
132:            }
133:
134:            public Number getDefaultValueNumeric() {
135:                return defaultValueNumeric;
136:            }
137:
138:            public void setDefaultValueNumeric(Number defaultValueNumeric) {
139:                this .defaultValueNumeric = defaultValueNumeric;
140:            }
141:
142:            public void setDefaultValueNumeric(String defaultValueNumeric)
143:                    throws ParseException {
144:                if (defaultValueNumeric == null) {
145:                    this .defaultValueNumeric = null;
146:                } else {
147:                    if ("GENERATED_BY_DEFAULT".equals(defaultValueNumeric)) {
148:                        setAutoIncrement(true);
149:                    } else {
150:                        this .defaultValueNumeric = NumberFormat.getInstance()
151:                                .parse(defaultValueNumeric);
152:                    }
153:                }
154:            }
155:
156:            public Date getDefaultValueDate() {
157:                return defaultValueDate;
158:            }
159:
160:            public void setDefaultValueDate(String defaultValueDate) {
161:                try {
162:                    this .defaultValueDate = new ISODateFormat()
163:                            .parse(defaultValueDate);
164:                } catch (ParseException e) {
165:                    //probably a computed date
166:                    this .defaultValueDate = new ComputedDateValue(
167:                            defaultValueDate);
168:                }
169:            }
170:
171:            public void setDefaultValueDate(Date defaultValueDate) {
172:                this .defaultValueDate = defaultValueDate;
173:            }
174:
175:            public Boolean getDefaultValueBoolean() {
176:                return defaultValueBoolean;
177:            }
178:
179:            public void setDefaultValueBoolean(Boolean defaultValueBoolean) {
180:                this .defaultValueBoolean = defaultValueBoolean;
181:            }
182:
183:            public Object getDefaultValueObject() {
184:                if (getDefaultValue() != null) {
185:                    return getDefaultValue();
186:                } else if (getDefaultValueBoolean() != null) {
187:                    return getDefaultValueBoolean();
188:                } else if (getDefaultValueNumeric() != null) {
189:                    return getDefaultValueNumeric();
190:                } else if (getDefaultValueDate() != null) {
191:                    return getDefaultValueDate();
192:                }
193:                return null;
194:            }
195:
196:            public ConstraintsConfig getConstraints() {
197:                return constraints;
198:            }
199:
200:            public void setConstraints(ConstraintsConfig constraints) {
201:                this .constraints = constraints;
202:            }
203:
204:            public Boolean isAutoIncrement() {
205:                return autoIncrement;
206:            }
207:
208:            public void setAutoIncrement(Boolean autoIncrement) {
209:                this .autoIncrement = autoIncrement;
210:            }
211:
212:            public Element createNode(Document document) {
213:                Element element = document.createElement("column");
214:                element.setAttribute("name", getName());
215:                if (getType() != null) {
216:                    element.setAttribute("type", getType());
217:                }
218:
219:                if (getDefaultValue() != null) {
220:                    element.setAttribute("defaultValue", getDefaultValue());
221:                }
222:                if (getDefaultValueNumeric() != null) {
223:                    element.setAttribute("defaultValueNumeric",
224:                            getDefaultValueNumeric().toString());
225:                }
226:                if (getDefaultValueDate() != null) {
227:                    element.setAttribute("defaultValueDate",
228:                            new ISODateFormat().format(getDefaultValueDate()));
229:                }
230:                if (getDefaultValueBoolean() != null) {
231:                    element.setAttribute("defaultValueBoolean",
232:                            getDefaultValueBoolean().toString());
233:                }
234:
235:                if (getValue() != null) {
236:                    element.setAttribute("value", getValue());
237:                }
238:                if (getValueNumeric() != null) {
239:                    element.setAttribute("valueNumeric", getValueNumeric()
240:                            .toString());
241:                }
242:                if (getValueBoolean() != null) {
243:                    element.setAttribute("valueBoolean", getValueBoolean()
244:                            .toString());
245:                }
246:                if (getValueDate() != null) {
247:                    element.setAttribute("valueDate", new ISODateFormat()
248:                            .format(getValueDate()));
249:                }
250:
251:                if (isAutoIncrement() != null && isAutoIncrement()) {
252:                    element.setAttribute("autoIncrement", "true");
253:                }
254:
255:                ConstraintsConfig constraints = getConstraints();
256:                if (constraints != null) {
257:                    Element constraintsElement = document
258:                            .createElement("constraints");
259:                    if (constraints.getCheck() != null) {
260:                        constraintsElement.setAttribute("check", constraints
261:                                .getCheck());
262:                    }
263:                    if (constraints.getForeignKeyName() != null) {
264:                        constraintsElement.setAttribute("foreignKeyName",
265:                                constraints.getForeignKeyName());
266:                    }
267:                    if (constraints.getReferences() != null) {
268:                        constraintsElement.setAttribute("references",
269:                                constraints.getReferences());
270:                    }
271:                    if (constraints.isDeferrable() != null) {
272:                        constraintsElement.setAttribute("deferrable",
273:                                constraints.isDeferrable().toString());
274:                    }
275:                    if (constraints.isDeleteCascade() != null) {
276:                        constraintsElement.setAttribute("deleteCascade",
277:                                constraints.isDeleteCascade().toString());
278:                    }
279:                    if (constraints.isInitiallyDeferred() != null) {
280:                        constraintsElement.setAttribute("initiallyDeferred",
281:                                constraints.isInitiallyDeferred().toString());
282:                    }
283:                    if (constraints.isNullable() != null) {
284:                        constraintsElement.setAttribute("nullable", constraints
285:                                .isNullable().toString());
286:                    }
287:                    if (constraints.isPrimaryKey() != null) {
288:                        constraintsElement.setAttribute("primaryKey",
289:                                constraints.isPrimaryKey().toString());
290:                    }
291:                    if (constraints.isUnique() != null) {
292:                        constraintsElement.setAttribute("unique", constraints
293:                                .isUnique().toString());
294:                    }
295:
296:                    if (constraints.getUniqueConstraintName() != null) {
297:                        constraintsElement.setAttribute("uniqueConstraintName",
298:                                constraints.getUniqueConstraintName());
299:                    }
300:                    element.appendChild(constraintsElement);
301:                }
302:
303:                return element;
304:            }
305:
306:            public String getDefaultColumnValue(Database database) {
307:                if (this .getDefaultValue() != null) {
308:                    if ("null".equalsIgnoreCase(this .getDefaultValue())) {
309:                        return "NULL";
310:                    }
311:                    if (!database.shouldQuoteValue(this .getDefaultValue())) {
312:                        return this .getDefaultValue();
313:                    } else {
314:                        return "'"
315:                                + this .getDefaultValue().replaceAll("'", "''")
316:                                + "'";
317:                    }
318:                } else if (this .getDefaultValueNumeric() != null) {
319:                    return this .getDefaultValueNumeric().toString();
320:                } else if (this .getDefaultValueBoolean() != null) {
321:                    String returnValue;
322:                    if (this .getDefaultValueBoolean()) {
323:                        returnValue = database.getTrueBooleanValue();
324:                    } else {
325:                        returnValue = database.getFalseBooleanValue();
326:                    }
327:
328:                    if (returnValue.matches("\\d+")) {
329:                        return returnValue;
330:                    } else {
331:                        return "'" + returnValue + "'";
332:                    }
333:                } else if (this .getDefaultValueDate() != null) {
334:                    Date defaultDateValue = this .getDefaultValueDate();
335:                    return database.getDateLiteral(defaultDateValue);
336:                } else {
337:                    return "NULL";
338:                }
339:            }
340:
341:            public boolean hasDefaultValue() {
342:                return this.getDefaultValue() != null
343:                        || this.getDefaultValueBoolean() != null
344:                        || this.getDefaultValueDate() != null
345:                        || this.getDefaultValueNumeric() != null;
346:            }
347:
348:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.