Source Code Cross Referenced for ColumnMetaData.java in  » Database-ORM » JPOX » org » jpox » metadata » 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 ORM » JPOX » org.jpox.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************
002:        Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003:        Licensed under the Apache License, Version 2.0 (the "License");
004:        you may not use this file except in compliance with the License.
005:        You may obtain a copy of the License at
006:
007:            http://www.apache.org/licenses/LICENSE-2.0
008:
009:        Unless required by applicable law or agreed to in writing, software
010:        distributed under the License is distributed on an "AS IS" BASIS,
011:        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        See the License for the specific language governing permissions and
013:        limitations under the License.
014:         
015:
016:        Contributors:
017:            ...
018:         **********************************************************************/package org.jpox.metadata;
019:
020:        import org.jpox.util.StringUtils;
021:
022:        /**
023:         * Representation of the Meta-Data for a column mapping of a field.
024:         * JDO metadata represented is :-
025:         * <PRE>
026:         * &lt;!ELEMENT column (extension*)?&gt;
027:         * &lt;!ATTLIST column name CDATA #IMPLIED&gt;
028:         * &lt;!ATTLIST column target CDATA #IMPLIED&gt;
029:         * &lt;!ATTLIST column target-field CDATA #IMPLIED&gt;
030:         * &lt;!ATTLIST column jdbc-type CDATA #IMPLIED&gt;
031:         * &lt;!ATTLIST column sql-type CDATA #IMPLIED&gt;
032:         * &lt;!ATTLIST column length CDATA #IMPLIED&gt;
033:         * &lt;!ATTLIST column scale CDATA #IMPLIED&gt;
034:         * &lt;!ATTLIST column allows-null CDATA #IMPLIED&gt;
035:         * &lt;!ATTLIST column default-value CDATA #IMPLIED&gt;
036:         * &lt;!ATTLIST column insert-value CDATA #IMPLIED&gt;
037:         * </PRE>
038:         *
039:         * @since 1.1
040:         * @version $Revision: 1.20 $
041:         */
042:        public class ColumnMetaData extends MetaData {
043:            /** column name. */
044:            protected String name;
045:
046:            /** target column name. */
047:            protected String target;
048:
049:            /** target field/property name. */
050:            protected String targetMember;
051:
052:            /** jdbc-type to use (if any). */
053:            protected String jdbcType;
054:
055:            /** sql-type to use (if any). */
056:            protected String sqlType;
057:
058:            /** length to use (if any). Also known as precision */
059:            protected Integer length;
060:
061:            /** scale to use (if any). */
062:            protected Integer scale;
063:
064:            /** allows-null tag value. */
065:            protected Boolean allowsNull;
066:
067:            /** column default value (when constructing the table with this column). */
068:            protected String defaultValue;
069:
070:            /** value to use when inserting this column in the datastore (the column is not mapped to a field/property) */
071:            protected String insertValue;
072:
073:            /** Whether this column is to be inserted when the owning object is inserted. JPA 1.0 attribute. */
074:            protected boolean insertable = true;
075:
076:            /** Whether this column can be updated when the owning object is updated. JPA 1.0 attribute. */
077:            protected boolean updateable = true;
078:
079:            /** unique tag value. JPA 1.0 attribute. */
080:            protected boolean unique;
081:
082:            /**
083:             * Creates a ColumnMetaData by copying contents from <code>colmd</code>.
084:             * @param parent Parent MetaData component
085:             * @param colmd MetaData for the column
086:             */
087:            public ColumnMetaData(final MetaData parent,
088:                    final ColumnMetaData colmd) {
089:                super (parent);
090:
091:                name = colmd.getName();
092:                target = colmd.getTarget();
093:                targetMember = colmd.getTargetMember();
094:                jdbcType = colmd.getJdbcType();
095:                sqlType = colmd.getSqlType();
096:                length = colmd.getLength();
097:                scale = colmd.getScale();
098:                allowsNull = colmd.allowsNull;
099:                defaultValue = colmd.getDefaultValue();
100:                insertValue = colmd.getInsertValue();
101:                insertable = colmd.getInsertable();
102:                updateable = colmd.getUpdateable();
103:                unique = colmd.getUnique();
104:            }
105:
106:            /**
107:             * Convenience constructor specifying just the column name, and the parent metadata component.
108:             * Assigns nulls to other parameters.
109:             * @param parent Parent MetaData component
110:             * @param name Name of the column
111:             */
112:            public ColumnMetaData(final MetaData parent, final String name) {
113:                this (parent, name, null, null, null, null, null, null, null,
114:                        null, null, null, null, null);
115:            }
116:
117:            /**
118:             * Constructor.
119:             * @param parent parent MetaData instance
120:             * @param name field name 
121:             * @param target target
122:             * @param targetMember target field/property
123:             * @param jdbcType JDBC Type to use
124:             * @param sqlType SQL Type to use
125:             * @param length length of field
126:             * @param scale scale of field
127:             * @param allowsNull Whether nulls are allowed
128:             * @param defaultValue The default value for the column
129:             * @param insertValue The insert value for the column
130:             * @param insertable Whether this column is insertable
131:             * @param updateable Whether this column is updateable
132:             * @param unique Whether this column is unique
133:             */
134:            public ColumnMetaData(MetaData parent, final String name,
135:                    final String target, final String targetMember,
136:                    final String jdbcType, final String sqlType,
137:                    final String length, final String scale,
138:                    final String allowsNull, final String defaultValue,
139:                    final String insertValue, final String insertable,
140:                    final String updateable, final String unique) {
141:                super (parent);
142:
143:                this .name = (StringUtils.isWhitespace(name) ? null : name);
144:
145:                this .target = (StringUtils.isWhitespace(target) ? null : target);
146:                this .targetMember = (StringUtils.isWhitespace(targetMember) ? null
147:                        : targetMember);
148:
149:                this .jdbcType = (StringUtils.isWhitespace(jdbcType) ? null
150:                        : jdbcType);
151:                /*if (this.jdbcType != null && !JDBCUtils.isValidJDBCType(this.jdbcType))
152:                {
153:                    // Invalid "jdbc-type" (maybe not supported by JPOX?)
154:                    // TODO This uses RDBMS-specific code so is commented out
155:                    throw new InvalidMetaDataException(LOCALISER, "044118", this.jdbcType);
156:                }*/
157:
158:                this .sqlType = (StringUtils.isWhitespace(sqlType) ? null
159:                        : sqlType);
160:
161:                if (length != null && length.length() > 0) {
162:                    this .length = Integer.valueOf(length);
163:                }
164:
165:                if (scale != null && scale.length() > 0) {
166:                    this .scale = Integer.valueOf(scale);
167:                }
168:
169:                if (allowsNull != null) {
170:                    if (allowsNull.equalsIgnoreCase("true")) {
171:                        this .allowsNull = Boolean.TRUE;
172:                    } else if (allowsNull.equalsIgnoreCase("false")) {
173:                        this .allowsNull = Boolean.FALSE;
174:                    }
175:                }
176:
177:                this .defaultValue = (StringUtils.isWhitespace(defaultValue) ? null
178:                        : defaultValue);
179:                this .insertValue = (StringUtils.isWhitespace(insertValue) ? null
180:                        : insertValue);
181:
182:                if (insertable != null && insertable.equalsIgnoreCase("false")) {
183:                    this .insertable = false;
184:                } else {
185:                    // Insertable unless specified otherwise
186:                    this .insertable = true;
187:                }
188:                if (updateable != null && updateable.equalsIgnoreCase("false")) {
189:                    this .updateable = false;
190:                } else {
191:                    // Updateable unless specified otherwise
192:                    this .updateable = true;
193:                }
194:                if (unique != null && unique.equalsIgnoreCase("true")) {
195:                    this .unique = true;
196:                } else {
197:                    // Non-unique unless specified otherwise
198:                    this .unique = false;
199:                }
200:            }
201:
202:            /**
203:             * Accessor for the name
204:             * @return name
205:             */
206:            public String getName() {
207:                return name;
208:            }
209:
210:            /**
211:             * Accessor for the column that is the target of this column in the referenced table.
212:             * @return target tag value
213:             */
214:            public String getTarget() {
215:                return target;
216:            }
217:
218:            /**
219:             * Accessor for the field/property that is the target of this column in the referenced class.
220:             * @return field/property that is the target
221:             */
222:            public String getTargetMember() {
223:                return targetMember;
224:            }
225:
226:            /**
227:             * Accessor for the jdbc-type tag value
228:             * @return jdbc-type tag value
229:             */
230:            public String getJdbcType() {
231:                return jdbcType;
232:            }
233:
234:            /**
235:             * Accessor for the sql-type tag value
236:             * @return sql-type tag value
237:             */
238:            public String getSqlType() {
239:                return sqlType;
240:            }
241:
242:            /**
243:             * Accessor for the length tag value. Also known as precision
244:             * @return length tag value
245:             */
246:            public Integer getLength() {
247:                return length;
248:            }
249:
250:            /**
251:             * Accessor for the scale tag value
252:             * @return scale tag value
253:             */
254:            public Integer getScale() {
255:                return scale;
256:            }
257:
258:            /**
259:             * Accessor for whether the nulls allowed flag has been set.
260:             * @return Whether it was set.
261:             */
262:            public boolean isAllowsNullSet() {
263:                return (allowsNull != null);
264:            }
265:
266:            /**
267:             * Accessor for the nulls-allowed tag value
268:             * @return nulls-allowed tag value
269:             */
270:            public boolean isAllowsNull() {
271:                if (allowsNull == null) {
272:                    return false;
273:                } else {
274:                    return allowsNull.booleanValue();
275:                }
276:            }
277:
278:            /**
279:             * Accessor for the default value
280:             * @return default value
281:             */
282:            public String getDefaultValue() {
283:                return defaultValue;
284:            }
285:
286:            /**
287:             * Accessor for the insert value
288:             * @return insert value
289:             */
290:            public String getInsertValue() {
291:                return insertValue;
292:            }
293:
294:            /**
295:             * Accessor for whether this column can be inserted when the owning object is inserted.
296:             * @return Whether it can be inserted.
297:             */
298:            public boolean getInsertable() {
299:                return insertable;
300:            }
301:
302:            /**
303:             * Accessor for whether this column can be update when the owning object is updated.
304:             * @return Whether it can be updated.
305:             */
306:            public boolean getUpdateable() {
307:                return updateable;
308:            }
309:
310:            /**
311:             * Accessor for the unique tag value
312:             * @return unique tag value
313:             */
314:            public boolean getUnique() {
315:                return unique;
316:            }
317:
318:            // ------------------------------- Mutators --------------------------------
319:
320:            /**
321:             * Mutator for the scale 
322:             * @param scale The scale to set.
323:             */
324:            public final void setScale(Integer scale) {
325:                this .scale = scale;
326:            }
327:
328:            /**
329:             * Mutator for the scale
330:             * @param scale The scale to set.
331:             */
332:            public final void setScale(int scale) {
333:                this .scale = new Integer(scale);
334:            }
335:
336:            /**
337:             * Mutator for the JDBC type
338:             * @param jdbcType The jdbcType to set.
339:             */
340:            public final void setJdbcType(String jdbcType) {
341:                this .jdbcType = jdbcType;
342:            }
343:
344:            /**
345:             * Mutator for the length. Also known as precision 
346:             * @param length The length to set.
347:             */
348:            public final void setLength(Integer length) {
349:                this .length = length;
350:            }
351:
352:            /**
353:             * Mutator for the length. Also known as precision 
354:             * @param length The length to set.
355:             */
356:            public final void setLength(int length) {
357:                this .length = new Integer(length);
358:            }
359:
360:            /**
361:             * Mutator for the name 
362:             * @param name The name to set.
363:             */
364:            public final void setName(String name) {
365:                this .name = name;
366:            }
367:
368:            /**
369:             * Mutator for whether nulls are allowed.
370:             * @param allowsNull The allowsNull to set.
371:             */
372:            public final void setAllowsNull(Boolean allowsNull) {
373:                this .allowsNull = allowsNull;
374:            }
375:
376:            /**
377:             * Mutator for the SQL type
378:             * @param sqlType The sqlType to set.
379:             */
380:            public final void setSqlType(String sqlType) {
381:                this .sqlType = sqlType;
382:            }
383:
384:            // ------------------------------- Utilities -------------------------------
385:
386:            /**
387:             * Returns a string representation of the object using a prefix
388:             * @param prefix prefix string
389:             * @param indent indent string
390:             * @return a string representation of the object.
391:             */
392:            public String toString(String prefix, String indent) {
393:                StringBuffer sb = new StringBuffer();
394:                sb.append(prefix).append("<column");
395:                if (name != null) {
396:                    sb.append(" name=\"" + name + "\"");
397:                }
398:                if (target != null) {
399:                    sb.append(" target=\"" + target + "\"");
400:                }
401:                if (targetMember != null) {
402:                    sb.append(" target-field=\"" + targetMember + "\"");
403:                }
404:                if (jdbcType != null) {
405:                    sb.append(" jdbc-type=\"" + jdbcType + "\"");
406:                }
407:                if (sqlType != null) {
408:                    sb.append(" sql-type=\"" + sqlType + "\"");
409:                }
410:                if (allowsNull != null) {
411:                    sb.append(" allows-null=\"" + allowsNull + "\"");
412:                }
413:                if (length != null) {
414:                    sb.append(" length=\"" + length + "\"");
415:                }
416:                if (scale != null) {
417:                    sb.append(" scale=\"" + scale + "\"");
418:                }
419:                if (defaultValue != null) {
420:                    sb.append(" default-value=\"" + defaultValue + "\"");
421:                }
422:                if (insertValue != null) {
423:                    sb.append(" insert-value=\"" + insertValue + "\"");
424:                }
425:
426:                if (extensions != null && extensions.size() > 0) {
427:                    sb.append(">\n");
428:
429:                    // Add extensions
430:                    sb.append(super .toString(prefix + indent, indent));
431:
432:                    sb.append(prefix).append("</column>\n");
433:                } else {
434:                    sb.append("/>\n");
435:                }
436:
437:                return sb.toString();
438:            }
439:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.