Source Code Cross Referenced for IndexMetaData.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 Erik Bengtson 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:        2004 Andy Jefferson - toString(), "column", javadocs, initialise()
018:            ...
019:         **********************************************************************/package org.jpox.metadata;
020:
021:        /**
022:         * For schema generation, it might be useful to specify that a column or columns
023:         * be indexed, and to provide the name of the index. For this purpose, an index
024:         * element can be contained within a field, element, key, value, or join
025:         * element, and this indicates that the column(s) associated with the referenced
026:         * element should be indexed. Indexes can also be specified at the class level,
027:         * by including index elements containing column elements. In this case, the
028:         * column elements are mapped elsewhere, and the column elements contain only
029:         * the column name.
030:         *
031:         * @since 1.1
032:         * @version $Revision: 1.19 $
033:         */
034:        public class IndexMetaData extends AbstractConstraintMetaData implements 
035:                ColumnMetaDataContainer {
036:            /**
037:             * You can use UNIQUE constraints to ensure that no duplicate values are
038:             * entered in specific columns that do not participate in a primary key.
039:             * Although both a UNIQUE constraint and a PRIMARY KEY constraint enforce
040:             * uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint
041:             * when you want to enforce the uniqueness of:
042:             * <ul>
043:             * <li>
044:             * A column, or combination of columns, that is not the primary key.
045:             * Multiple UNIQUE constraints can be defined on a table, whereas only one
046:             * PRIMARY KEY constraint can be defined on a table.
047:             * </li>
048:             * <li>
049:             * A column that allows null values. UNIQUE constraints can be defined on
050:             * columns that allow null values, whereas PRIMARY KEY constraints can be
051:             * defined only on columns that do not allow null values.
052:             * </li>
053:             * </ul>
054:             * A UNIQUE constraint can also be referenced by a FOREIGN KEY constraint.
055:             */
056:            Boolean unique;
057:
058:            /**
059:             * Constructor to create a copy of the passed metadata.
060:             * @param imd The metadata to copy
061:             */
062:            public IndexMetaData(IndexMetaData imd) {
063:                super (null, imd.name, imd.table); // Ignore parent
064:
065:                this .unique = imd.unique;
066:                AbstractMemberMetaData[] apmd = null;
067:                if (imd.members != null) {
068:                    apmd = (AbstractMemberMetaData[]) imd.members
069:                            .toArray(new AbstractMemberMetaData[imd.members
070:                                    .size()]);
071:                } else {
072:                    apmd = imd.memberMetaData;
073:                }
074:                if (apmd != null) {
075:                    for (int i = 0; i < apmd.length; i++) {
076:                        if (apmd[i] instanceof  FieldMetaData) {
077:                            addMember(new FieldMetaData(this , apmd[i]));
078:                        } else {
079:                            addMember(new PropertyMetaData(this ,
080:                                    (PropertyMetaData) apmd[i]));
081:                        }
082:                    }
083:                }
084:                ColumnMetaData[] colmd = null;
085:                if (imd.columns != null) {
086:                    colmd = (ColumnMetaData[]) imd.columns
087:                            .toArray(new ColumnMetaData[imd.columns.size()]);
088:                } else {
089:                    colmd = imd.columnMetaData;
090:                }
091:                if (colmd != null) {
092:                    for (int i = 0; i < colmd.length; i++) {
093:                        addColumn(new ColumnMetaData(this , colmd[i]));
094:                    }
095:                }
096:            }
097:
098:            /**
099:             * Constructor. 
100:             * @param name Name of index
101:             * @param table Name of the table
102:             * @param unique Whether it is unique.
103:             */
104:            public IndexMetaData(final String name, String table, String unique) {
105:                super (null, name, table); // Ignore parent
106:
107:                if (unique != null) {
108:                    if (unique.equalsIgnoreCase("true")) {
109:                        this .unique = Boolean.TRUE;
110:                    } else if (unique.equalsIgnoreCase("false")) {
111:                        this .unique = Boolean.FALSE;
112:                    }
113:                }
114:            }
115:
116:            /**
117:             * Method to initialise the object, creating internal convenience arrays.
118:             * Initialise all sub-objects.
119:             */
120:            public void initialise() {
121:                if (isInitialised()) {
122:                    return;
123:                }
124:
125:                // Set up the fieldMetaData
126:                if (members.size() == 0) {
127:                    memberMetaData = null;
128:                } else {
129:                    memberMetaData = new AbstractMemberMetaData[members.size()];
130:                    for (int i = 0; i < memberMetaData.length; i++) {
131:                        memberMetaData[i] = (AbstractMemberMetaData) members
132:                                .get(i);
133:                        memberMetaData[i].initialise();
134:                    }
135:                }
136:
137:                // Set up the columnMetaData
138:                if (columns.size() == 0) {
139:                    columnMetaData = null;
140:                } else {
141:                    columnMetaData = new ColumnMetaData[columns.size()];
142:                    for (int i = 0; i < columnMetaData.length; i++) {
143:                        columnMetaData[i] = (ColumnMetaData) columns.get(i);
144:                        columnMetaData[i].initialise();
145:                    }
146:                }
147:
148:                // Clean out parsing data
149:                members.clear();
150:                members = null;
151:                columns.clear();
152:                columns = null;
153:
154:                setInitialised();
155:            }
156:
157:            // -------------------------------- Mutators -------------------------------
158:
159:            /**
160:             * Accessor for whether the index is unique
161:             * @return Returns whether the index is unique.
162:             */
163:            public final Boolean isUnique() {
164:                return unique;
165:            }
166:
167:            // -------------------------------- Utilities ------------------------------
168:
169:            /**
170:             * Returns a string representation of the object.
171:             * This can be used as part of a facility to output a MetaData file. 
172:             * @param prefix prefix string
173:             * @param indent indent string
174:             * @return a string representation of the object.
175:             */
176:            public String toString(String prefix, String indent) {
177:                StringBuffer sb = new StringBuffer();
178:                sb.append(prefix).append("<index unique=\"" + unique + "\"");
179:                if (table != null) {
180:                    sb.append(" table=\"" + table + "\"");
181:                }
182:                sb.append(name != null ? (" name=\"" + name + "\">\n") : ">\n");
183:
184:                // Add fields
185:                if (memberMetaData != null) {
186:                    for (int i = 0; i < memberMetaData.length; i++) {
187:                        sb.append(memberMetaData[i].toString(prefix + indent,
188:                                indent));
189:                    }
190:                }
191:
192:                // Add columns
193:                if (columnMetaData != null) {
194:                    for (int i = 0; i < columnMetaData.length; i++) {
195:                        sb.append(columnMetaData[i].toString(prefix + indent,
196:                                indent));
197:                    }
198:                }
199:
200:                // Add extensions
201:                sb.append(super .toString(prefix + indent, indent));
202:
203:                sb.append(prefix).append("</index>\n");
204:                return sb.toString();
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.