Source Code Cross Referenced for Schema.java in  » Database-ORM » openjpa » org » apache » openjpa » jdbc » schema » 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 » openjpa » org.apache.openjpa.jdbc.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:        package org.apache.openjpa.jdbc.schema;
020:
021:        import java.io.Serializable;
022:        import java.util.Map;
023:        import java.util.TreeMap;
024:
025:        import org.apache.commons.lang.StringUtils;
026:
027:        /**
028:         * Represents a database schema.
029:         *
030:         * @author Abe White
031:         */
032:        public class Schema implements  Comparable, Serializable {
033:
034:            private String _name = null;
035:            private SchemaGroup _group = null;
036:            private Map _tableMap = null;
037:            private Map _seqMap = null;
038:
039:            // cache
040:            private Table[] _tables = null;
041:            private Sequence[] _seqs = null;
042:
043:            /**
044:             * Default constructor.
045:             */
046:            public Schema() {
047:            }
048:
049:            /**
050:             * Constructor.
051:             *
052:             * @param name the schema name, if any
053:             * @param group the schema's owning group
054:             */
055:            public Schema(String name, SchemaGroup group) {
056:                setName(name);
057:                _group = group;
058:            }
059:
060:            /**
061:             * Called when the schema is removed from its group. Invalidates the
062:             * schema and removes all its member tables.
063:             */
064:            void remove() {
065:                Table[] tabs = getTables();
066:                for (int i = 0; i < tabs.length; i++)
067:                    removeTable(tabs[i]);
068:                Sequence[] seqs = getSequences();
069:                for (int i = 0; i < seqs.length; i++)
070:                    removeSequence(seqs[i]);
071:                _group = null;
072:            }
073:
074:            /**
075:             * Return the schema's group.
076:             */
077:            public SchemaGroup getSchemaGroup() {
078:                return _group;
079:            }
080:
081:            /**
082:             * Return the name of the schema, or null if none.
083:             */
084:            public String getName() {
085:                return _name;
086:            }
087:
088:            /**
089:             * Set the name of the schema. This method can only be used for schemas
090:             * not attached to a group.
091:             */
092:            public void setName(String name) {
093:                if (getSchemaGroup() != null)
094:                    throw new IllegalStateException();
095:                _name = StringUtils.trimToNull(name);
096:            }
097:
098:            /**
099:             * Return the schema's tables.
100:             */
101:            public Table[] getTables() {
102:                if (_tables == null)
103:                    _tables = (_tableMap == null) ? new Table[0]
104:                            : (Table[]) _tableMap.values().toArray(
105:                                    new Table[_tableMap.size()]);
106:                return _tables;
107:            }
108:
109:            /**
110:             * Return the table with the given name, or null if none.
111:             */
112:            public Table getTable(String name) {
113:                if (name == null || _tableMap == null)
114:                    return null;
115:                return (Table) _tableMap.get(name.toUpperCase());
116:            }
117:
118:            /**
119:             * Add a table to the schema.
120:             */
121:            public Table addTable(String name) {
122:                SchemaGroup group = getSchemaGroup();
123:                Table tab;
124:                if (group != null) {
125:                    group.addName(name, true);
126:                    tab = group.newTable(name, this );
127:                } else
128:                    tab = new Table(name, this );
129:                if (_tableMap == null)
130:                    _tableMap = new TreeMap();
131:                _tableMap.put(name.toUpperCase(), tab);
132:                _tables = null;
133:                return tab;
134:            }
135:
136:            /**
137:             * Remove the given table from the schema.
138:             *
139:             * @return true if the table was removed, false if not in the schema
140:             */
141:            public boolean removeTable(Table tab) {
142:                if (tab == null || _tableMap == null)
143:                    return false;
144:
145:                Table cur = (Table) _tableMap.get(tab.getName().toUpperCase());
146:                if (!cur.equals(tab))
147:                    return false;
148:
149:                _tableMap.remove(tab.getName().toUpperCase());
150:                _tables = null;
151:                SchemaGroup group = getSchemaGroup();
152:                if (group != null)
153:                    group.removeName(tab.getName());
154:                tab.remove();
155:                return true;
156:            }
157:
158:            /**
159:             * Import a table from another schema.	 Note that this method does
160:             * <strong>not</strong> import foreign keys, indexes, or unique constraints.
161:             */
162:            public Table importTable(Table table) {
163:                if (table == null)
164:                    return null;
165:
166:                Table copy = addTable(table.getName());
167:                Column[] cols = table.getColumns();
168:                for (int i = 0; i < cols.length; i++)
169:                    copy.importColumn(cols[i]);
170:
171:                copy.importPrimaryKey(table.getPrimaryKey());
172:                return copy;
173:            }
174:
175:            /**
176:             * Return the schema's sequences.
177:             */
178:            public Sequence[] getSequences() {
179:                if (_seqs == null)
180:                    _seqs = (_seqMap == null) ? new Sequence[0]
181:                            : (Sequence[]) _seqMap.values().toArray(
182:                                    new Sequence[_seqMap.size()]);
183:                return _seqs;
184:            }
185:
186:            /**
187:             * Return the sequence with the given name, or null if none.
188:             */
189:            public Sequence getSequence(String name) {
190:                if (name == null || _seqMap == null)
191:                    return null;
192:                return (Sequence) _seqMap.get(name.toUpperCase());
193:            }
194:
195:            /**
196:             * Add a sequence to the schema.
197:             */
198:            public Sequence addSequence(String name) {
199:                SchemaGroup group = getSchemaGroup();
200:                Sequence seq;
201:                if (group != null) {
202:                    group.addName(name, true);
203:                    seq = group.newSequence(name, this );
204:                } else
205:                    seq = new Sequence(name, this );
206:                if (_seqMap == null)
207:                    _seqMap = new TreeMap();
208:                _seqMap.put(name.toUpperCase(), seq);
209:                _seqs = null;
210:                return seq;
211:            }
212:
213:            /**
214:             * Remove the given sequence from the schema.
215:             *
216:             * @return true if the sequence was removed, false if not in the schema
217:             */
218:            public boolean removeSequence(Sequence seq) {
219:                if (seq == null || _seqMap == null)
220:                    return false;
221:
222:                Sequence cur = (Sequence) _seqMap.get(seq.getName()
223:                        .toUpperCase());
224:                if (!cur.equals(seq))
225:                    return false;
226:
227:                _seqMap.remove(seq.getName().toUpperCase());
228:                _seqs = null;
229:                SchemaGroup group = getSchemaGroup();
230:                if (group != null)
231:                    group.removeName(seq.getName());
232:                seq.remove();
233:                return true;
234:            }
235:
236:            /**
237:             * Import a sequence from another schema.
238:             */
239:            public Sequence importSequence(Sequence seq) {
240:                if (seq == null)
241:                    return null;
242:
243:                Sequence copy = addSequence(seq.getName());
244:                copy.setInitialValue(seq.getInitialValue());
245:                copy.setIncrement(seq.getIncrement());
246:                copy.setAllocate(seq.getAllocate());
247:                return copy;
248:            }
249:
250:            public int compareTo(Object other) {
251:                String name = getName();
252:                String otherName = ((Schema) other).getName();
253:                if (name == null && otherName == null)
254:                    return 0;
255:                if (name == null)
256:                    return 1;
257:                if (otherName == null)
258:                    return -1;
259:                return name.compareTo(otherName);
260:            }
261:
262:            public String toString() {
263:                return getName();
264:            }
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.