Source Code Cross Referenced for AbstractTable.java in  » Database-ORM » TJDO » com » triactive » jdo » store » 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 » TJDO » com.triactive.jdo.store 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002 (C) TJDO.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the TJDO License version 1.0.
006:         * See the terms of the TJDO License in the documentation provided with this software.
007:         *
008:         * $Id: AbstractTable.java,v 1.3 2003/02/25 06:55:15 jackknifebarber Exp $
009:         */
010:
011:        package com.triactive.jdo.store;
012:
013:        import java.sql.Connection;
014:        import java.sql.SQLException;
015:        import java.sql.Statement;
016:        import java.util.ArrayList;
017:        import java.util.HashMap;
018:        import java.util.Iterator;
019:        import java.util.List;
020:        import org.apache.log4j.Category;
021:
022:        abstract class AbstractTable implements  Table {
023:            private static final Category LOG = Category
024:                    .getInstance(AbstractTable.class);
025:
026:            protected static final int TABLE_STATE_NEW = 0;
027:            protected static final int TABLE_STATE_INITIALIZED = 1;
028:            protected static final int TABLE_STATE_VALIDATED = 2;
029:
030:            protected final StoreManager storeMgr;
031:            protected final DatabaseAdapter dba;
032:            protected SQLIdentifier name;
033:            protected int state = TABLE_STATE_NEW;
034:
035:            protected ArrayList columns = new ArrayList();
036:            protected HashMap columnsByName = new HashMap();
037:
038:            public AbstractTable(StoreManager storeMgr) {
039:                this (null, storeMgr);
040:            }
041:
042:            public AbstractTable(SQLIdentifier name, StoreManager storeMgr) {
043:                this .storeMgr = storeMgr;
044:                this .dba = storeMgr.getDatabaseAdapter();
045:                this .name = name;
046:            }
047:
048:            public boolean isInitialized() {
049:                return state >= TABLE_STATE_INITIALIZED;
050:            }
051:
052:            public boolean isValidated() {
053:                return state >= TABLE_STATE_VALIDATED;
054:            }
055:
056:            protected void assertIsUninitialized() {
057:                if (isInitialized())
058:                    throw new IllegalStateException(
059:                            "Table object has already been initialized: "
060:                                    + this );
061:            }
062:
063:            protected void assertIsInitialized() {
064:                if (!isInitialized())
065:                    throw new IllegalStateException(
066:                            "Table object has not been initialized: " + this );
067:            }
068:
069:            protected void assertIsValidated() {
070:                if (!isValidated())
071:                    throw new IllegalStateException(
072:                            "Table has not been validated: " + this );
073:            }
074:
075:            public SQLIdentifier getName() {
076:                return name;
077:            }
078:
079:            public StoreManager getStoreManager() {
080:                return storeMgr;
081:            }
082:
083:            public String getSchemaName() {
084:                return storeMgr.getSchemaName();
085:            }
086:
087:            public synchronized void addColumn(Column col) {
088:                assertIsUninitialized();
089:
090:                SQLIdentifier colName = col.getName();
091:
092:                if (hasColumnName(colName))
093:                    throw new DuplicateColumnNameException(this , col);
094:
095:                columns.add(col);
096:                columnsByName.put(col.getName(), col);
097:            }
098:
099:            protected boolean hasColumnName(SQLIdentifier colName) {
100:                return columnsByName.get(colName) != null;
101:            }
102:
103:            public synchronized Column newColumn(Class type, String javaName) {
104:                return newColumn(type, new ColumnIdentifier(dba, javaName),
105:                        Role.NONE);
106:            }
107:
108:            public synchronized Column newColumn(Class type,
109:                    SQLIdentifier name, Role role) {
110:                assertIsUninitialized();
111:
112:                ColumnIdentifier columnName = new ColumnIdentifier(dba, name,
113:                        type, Role.NONE);
114:
115:                if (hasColumnName(columnName))
116:                    columnName = new ColumnIdentifier(dba, name, type, role);
117:
118:                Column col = new Column(this , type, columnName);
119:
120:                addColumn(col);
121:
122:                return col;
123:            }
124:
125:            protected void executeStatementList(List stmts, Connection conn)
126:                    throws SQLException {
127:                Statement stmt = conn.createStatement();
128:
129:                try {
130:                    Iterator i = stmts.iterator();
131:
132:                    while (i.hasNext()) {
133:                        String stmtText = (String) i.next();
134:                        long startTime = System.currentTimeMillis();
135:
136:                        stmt.execute(stmtText);
137:
138:                        if (LOG.isDebugEnabled())
139:                            LOG.debug("Time = "
140:                                    + (System.currentTimeMillis() - startTime)
141:                                    + " ms: " + stmtText);
142:
143:                        storeMgr.logSQLWarnings(stmt);
144:                    }
145:
146:                } finally {
147:                    stmt.close();
148:                }
149:            }
150:
151:            protected abstract List getSQLCreateStatements();
152:
153:            protected abstract List getSQLDropStatements();
154:
155:            public void create(Connection conn) throws SQLException {
156:                assertIsInitialized();
157:
158:                executeStatementList(getSQLCreateStatements(), conn);
159:            }
160:
161:            public void drop(Connection conn) throws SQLException {
162:                assertIsInitialized();
163:
164:                executeStatementList(getSQLDropStatements(), conn);
165:            }
166:
167:            /**
168:             * Tests if the database table exists.
169:             *
170:             * @param conn      a JDBC connection to the database.
171:             *
172:             * @return  <tt>true</tt> if the table exists in the database,
173:             *          <tt>false</tt> otherwise.
174:             */
175:
176:            public boolean exists(Connection conn) throws SQLException {
177:                return storeMgr.tableExists(name, conn);
178:            }
179:
180:            public final boolean equals(Object obj) {
181:                if (obj == this )
182:                    return true;
183:
184:                if (!(obj instanceof  AbstractTable))
185:                    return false;
186:
187:                AbstractTable t = (AbstractTable) obj;
188:
189:                return getClass().equals(t.getClass()) && name.equals(t.name)
190:                        && storeMgr.equals(t.storeMgr);
191:            }
192:
193:            public final int hashCode() {
194:                return name.hashCode() ^ storeMgr.hashCode();
195:            }
196:
197:            public final String toString() {
198:                return getSchemaName() + '.' + name;
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.