Source Code Cross Referenced for DBColumn.java in  » Testing » databene-benerator » org » databene » platform » db » model » 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 » Testing » databene benerator » org.databene.platform.db.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (c) Copyright 2006 by Volker Bergmann. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, is permitted under the terms of the
006:         * GNU General Public License.
007:         *
008:         * For redistributing this software or a derivative work under a license other
009:         * than the GPL-compatible Free Software License as defined by the Free
010:         * Software Foundation or approved by OSI, you must first obtain a commercial
011:         * license to this software product from Volker Bergmann.
012:         *
013:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014:         * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015:         * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017:         * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024:         * POSSIBILITY OF SUCH DAMAGE.
025:         */
026:
027:        package org.databene.platform.db.model;
028:
029:        import org.databene.commons.ArrayFormat;
030:
031:        import java.util.List;
032:        import java.util.ArrayList;
033:
034:        /**
035:         * Represents a database column.<br/><br/>
036:         * Created: 06.01.2007 08:58:49
037:         * @author Volker Bergmann
038:         */
039:        public class DBColumn {
040:
041:            private String name;
042:            private DBColumnType type;
043:            private int[] modifiers; // TODO v0.4.2 transform to 'size' and 'scale' attributes
044:            private String doc;
045:            private String defaultValue;
046:            private DBTable table;
047:            private boolean versionColumn;
048:
049:            private List<DBConstraint> ukConstraints; // constraints may be unnamed, so a Map does not make sense
050:            private DBConstraint notNullConstraint;
051:
052:            //    private DBForeignKeyConstraint fkConstraint;
053:
054:            // constructors ----------------------------------------------------------------------------------------------------
055:
056:            public DBColumn() {
057:                this (null, null);
058:            }
059:
060:            public DBColumn(String name, DBColumnType type, int... modifiers) {
061:                this (null, name, type, modifiers);
062:            }
063:
064:            public DBColumn(DBTable table, String name, DBColumnType type,
065:                    int... modifiers) {
066:                this .table = table;
067:                this .name = name;
068:                this .type = type;
069:                this .modifiers = modifiers;
070:                this .doc = null;
071:                this .defaultValue = null;
072:                this .ukConstraints = new ArrayList<DBConstraint>();
073:                this .notNullConstraint = null;
074:                //        this.fkConstraint = null;
075:                this .versionColumn = false;
076:            }
077:
078:            // properties ------------------------------------------------------------------------------------------------------
079:
080:            public DBTable getTable() {
081:                return table;
082:            }
083:
084:            public void setTable(DBTable table) {
085:                this .table = table;
086:            }
087:
088:            public String getName() {
089:                return name;
090:            }
091:
092:            public DBColumnType getType() {
093:                return type;
094:            }
095:
096:            public int[] getModifiers() {
097:                return modifiers;
098:            }
099:
100:            public void setModifiers(int[] modifiers) {
101:                this .modifiers = modifiers;
102:            }
103:
104:            public String getDoc() {
105:                return doc;
106:            }
107:
108:            public void setDoc(String doc) {
109:                this .doc = doc;
110:            }
111:
112:            public String getDefaultValue() {
113:                return defaultValue;
114:            }
115:
116:            public void setDefaultValue(String defaultValue) {
117:                this .defaultValue = defaultValue;
118:            }
119:
120:            public List<DBConstraint> getUkConstraints() {
121:                return ukConstraints;
122:            }
123:
124:            public void addUkConstraint(DBConstraint constraint) {
125:                this .ukConstraints.add(constraint);
126:            }
127:
128:            public DBConstraint getNotNullConstraint() {
129:                return notNullConstraint;
130:            }
131:
132:            public void setNotNullConstraint(DBConstraint notNullConstraint) {
133:                this .notNullConstraint = notNullConstraint;
134:            }
135:
136:            public boolean isNullable() {
137:                return (notNullConstraint == null);
138:            }
139:
140:            public void setNullable(boolean nullable) {
141:                if (nullable) {
142:                    // if a NotNullConstraint exists then remove it
143:                    notNullConstraint = null;
144:                } else {
145:                    // if there needs to be a NotNullConstraint, check if there exists one, first
146:                    if (this .isNullable()) {
147:                        this .notNullConstraint = new DBNotNullConstraint(this );
148:                    }
149:                }
150:            }
151:
152:            /*
153:             public DBForeignKeyConstraint getFkConstraint() {
154:             return fkConstraint;
155:             }
156:             */
157:
158:            public boolean isVersionColumn() {
159:                return versionColumn;
160:            }
161:
162:            public void setVersionColumn(boolean versionColumn) {
163:                this .versionColumn = versionColumn;
164:            }
165:
166:            public int size() {
167:                if (modifiers != null && modifiers.length > 0)
168:                    return modifiers[0]; // TODO v0.4.2 evaluate if byte or char
169:                return 1;
170:            }
171:
172:            // java.lang.overrides ---------------------------------------------------------------------------------------------
173:
174:            @Override
175:            public boolean equals(Object o) {
176:                if (this  == o)
177:                    return true;
178:                if (o == null || getClass() != o.getClass())
179:                    return false;
180:                final DBColumn that = (DBColumn) o;
181:                return this .table.equals(that.table) && name.equals(that.name);
182:            }
183:
184:            @Override
185:            public int hashCode() {
186:                return table.hashCode() * 29 + name.hashCode();
187:            }
188:
189:            @Override
190:            public String toString() {
191:                StringBuilder builder = new StringBuilder(name).append(" : ")
192:                        .append(type);
193:                if (modifiers.length > 0) {
194:                    builder.append('(');
195:                    builder.append(ArrayFormat.formatInts(",", modifiers));
196:                    builder.append(')');
197:                }
198:                if (!isNullable())
199:                    builder.append(" NOT NULL");
200:                return builder.toString();
201:            }
202:
203:            // static convenience methods --------------------------------------------------------------------------------------
204:
205:            public static String formatColumnNames(DBColumn[] columns) {
206:                StringBuilder builder = new StringBuilder(columns[0].getName());
207:                for (int i = 1; i < columns.length; i++)
208:                    builder.append(", ").append(columns[i].getName());
209:                return builder.toString();
210:            }
211:
212:            public static String formatColumnNames(List<DBColumn> columns) {
213:                StringBuilder builder = new StringBuilder(columns.get(0)
214:                        .getName());
215:                for (int i = 1; i < columns.size(); i++)
216:                    builder.append(", ").append(columns.get(i).getName());
217:                return builder.toString();
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.