Source Code Cross Referenced for CacheDatabaseSchema.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » controller » cache » result » 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 JDBC Connection Pool » sequoia 2.10.9 » org.continuent.sequoia.controller.cache.result.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Sequoia: Database clustering technology.
003:         * Copyright (C) 2002-2004 French National Institute For Research In Computer
004:         * Science And Control (INRIA).
005:         * Contact: sequoia@continuent.org
006:         * 
007:         * Licensed under the Apache License, Version 2.0 (the "License");
008:         * you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at
010:         * 
011:         * http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License. 
018:         *
019:         * Initial developer(s): Emmanuel Cecchet.
020:         * Contributor(s): ______________________________________.
021:         */package org.continuent.sequoia.controller.cache.result.schema;
022:
023:        import java.sql.SQLException;
024:        import java.util.ArrayList;
025:        import java.util.Collection;
026:        import java.util.Iterator;
027:
028:        import org.continuent.sequoia.common.sql.schema.DatabaseSchema;
029:        import org.continuent.sequoia.common.sql.schema.DatabaseTable;
030:
031:        /**
032:         * A <code>CacheDatabaseSchema</code> describes all the tables and columns of
033:         * a database and its associated cache entries.
034:         * 
035:         * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
036:         * @version 1.0
037:         */
038:        public class CacheDatabaseSchema {
039:            /** Database tables. */
040:            private ArrayList tables;
041:
042:            /**
043:             * Creates a new <code>CacheDatabaseSchema</code> instance by cloning an
044:             * existing <code>DatabaseSchema</code>.
045:             * 
046:             * @param dbs the <code>DatabaseSchema</code> to clone
047:             */
048:            public CacheDatabaseSchema(DatabaseSchema dbs) {
049:                if (dbs == null) {
050:                    tables = new ArrayList();
051:                    return;
052:                }
053:
054:                // Clone the tables
055:                Collection origTables = dbs.getTables().values();
056:                int size = origTables.size();
057:                tables = new ArrayList(size);
058:                for (Iterator iter = origTables.iterator(); iter.hasNext();)
059:                    for (int i = 0; i < size; i++)
060:                        tables.add(new CacheDatabaseTable((DatabaseTable) iter
061:                                .next()));
062:            }
063:
064:            /**
065:             * Adds a <code>CacheDatabaseTable</code> describing a table of the
066:             * database.
067:             * 
068:             * @param table the table to add
069:             */
070:            public void addTable(CacheDatabaseTable table) {
071:                tables.add(table);
072:            }
073:
074:            /**
075:             * Removes a <code>CacheDatabaseTable</code> describing a table of the
076:             * database.
077:             * 
078:             * @param table the table to remove
079:             */
080:            public void removeTable(CacheDatabaseTable table) {
081:                tables.remove(table);
082:            }
083:
084:            /**
085:             * Merge the given schema with the current one. All missing tables or columns
086:             * are added if no conflict is detected. An exception is thrown if the given
087:             * schema definition conflicts with the current one.
088:             * 
089:             * @param databaseSchema the schema to merge
090:             * @throws SQLException if the schemas conflict
091:             */
092:            public void mergeSchema(CacheDatabaseSchema databaseSchema)
093:                    throws SQLException {
094:                if (databaseSchema == null)
095:                    return;
096:
097:                ArrayList otherTables = databaseSchema.getTables();
098:                if (otherTables == null)
099:                    return;
100:
101:                int size = otherTables.size();
102:                for (int i = 0; i < size; i++) {
103:                    CacheDatabaseTable t = (CacheDatabaseTable) otherTables
104:                            .get(i);
105:                    CacheDatabaseTable original = getTable(t.getName());
106:                    if (original == null)
107:                        addTable(t);
108:                    else
109:                        original.mergeColumns(t);
110:                }
111:            }
112:
113:            /**
114:             * Returns an <code>ArrayList</code> of <code>CacheDatabaseTable</code>
115:             * objects describing the database.
116:             * 
117:             * @return an <code>ArrayList</code> of <code>CacheDatabaseTable</code>
118:             */
119:            public ArrayList getTables() {
120:                return tables;
121:            }
122:
123:            /**
124:             * Returns the <code>CacheDatabaseTable</code> object matching the given
125:             * table name or <code>null</code> if not found.
126:             * 
127:             * @param tableName the table name to look for
128:             * @return a <code>CacheDatabaseTable</code> value or null
129:             */
130:            public CacheDatabaseTable getTable(String tableName) {
131:                if (tableName == null)
132:                    return null;
133:
134:                int size = tables.size();
135:                for (int i = 0; i < size; i++) {
136:                    CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
137:                    if (t.getName().compareTo(tableName) == 0)
138:                        return t;
139:                }
140:                return null;
141:            }
142:
143:            /**
144:             * Returns <code>true</code> if the given <code>TableName</code> is found
145:             * in this schema.
146:             * 
147:             * @param tableName the name of the table you are looking for
148:             * @return <code>true</code> if the table has been found
149:             */
150:            public boolean hasTable(String tableName) {
151:                int size = tables.size();
152:                for (int i = 0; i < size; i++) {
153:                    CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
154:                    if (tableName.equals(t.getName()))
155:                        return true;
156:                }
157:                return false;
158:            }
159:
160:            /**
161:             * Two <code>CacheDatabaseSchema</code> are equals if they have the same
162:             * tables.
163:             * 
164:             * @param other the object to compare with
165:             * @return true if the 2 objects are the same.
166:             */
167:            public boolean equals(Object other) {
168:                if (!(other instanceof  CacheDatabaseSchema))
169:                    return false;
170:
171:                if (tables == null)
172:                    return ((CacheDatabaseSchema) other).getTables() == null;
173:                else
174:                    return tables.equals(((CacheDatabaseSchema) other)
175:                            .getTables());
176:            }
177:
178:            /**
179:             * Returns information about the database schema.
180:             * 
181:             * @param longFormat <code>true</code> for a long format, false for a short
182:             *          summary
183:             * @return a <code>String</code> value
184:             */
185:            public String getInformation(boolean longFormat) {
186:                String result = "";
187:                int size = tables.size();
188:                for (int i = 0; i < size; i++) {
189:                    CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i);
190:                    result += t.getInformation(longFormat) + "\n";
191:                }
192:                return result;
193:            }
194:
195:        }
w__ww.j___a___v__a__2s___.c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.