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


001:        package org.apache.torque;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import org.apache.torque.adapter.DB;
023:        import org.apache.torque.dsfactory.DataSourceFactory;
024:        import org.apache.torque.map.DatabaseMap;
025:        import org.apache.torque.oid.IDBroker;
026:        import org.apache.torque.oid.IdGenerator;
027:
028:        /**
029:         * Bundles all information about a database. This includes the database adapter,
030:         * the database Map and the Data Source Factory.
031:         */
032:        public class Database {
033:            /**
034:             * The name of the database. Must be the same as the key in Torque's
035:             * databaseMap.
036:             */
037:            private String name;
038:
039:            /**
040:             * The Database adapter which encapsulates database-specific peculiarities.
041:             */
042:            private DB adapter;
043:
044:            /**
045:             * the Map of this database.
046:             */
047:            private DatabaseMap databaseMap;
048:
049:            /**
050:             * The DataSourceFactory to optain connections to this database.
051:             */
052:            private DataSourceFactory dataSourceFactory;
053:
054:            /**
055:             * Creates a new Database with the given name.
056:             *
057:             * @param aName the name of the database, not null.
058:             */
059:            Database(String aName) {
060:                this .name = aName;
061:            }
062:
063:            /**
064:             * returns the name of the database.
065:             *
066:             * @return the name of the database. May be null.
067:             */
068:            public String getName() {
069:                return name;
070:            }
071:
072:            /**
073:             * Returns the adapther to this database.
074:             *
075:             * @return the adapter to this database, or null if no adapter is set.
076:             */
077:            public DB getAdapter() {
078:                return adapter;
079:            }
080:
081:            /**
082:             * Sets the adapter for this database.
083:             *
084:             * @param anAdapter The adapter for this database, or null to remove the
085:             *        current adapter from this database.
086:             */
087:            public void setAdapter(DB anAdapter) {
088:                this .adapter = anAdapter;
089:            }
090:
091:            /**
092:             * Returns the database map for this database.
093:             * If the database map does not exist yet, it is created by this method.
094:             */
095:            public synchronized DatabaseMap getDatabaseMap() {
096:                if (databaseMap == null) {
097:                    databaseMap = new DatabaseMap(name);
098:                }
099:                return databaseMap;
100:            }
101:
102:            /**
103:             * Returns the DataSourceFactory for this database.
104:             * The DataSourceFactory is responsible to create connections
105:             * to this database.
106:             *
107:             * @return the DataSourceFactory for this database, or null if no
108:             *         DataSourceFactory exists for this database.
109:             */
110:            public DataSourceFactory getDataSourceFactory() {
111:                return dataSourceFactory;
112:            }
113:
114:            /**
115:             * Sets the DataSourceFactory for this database.
116:             * The DataSourceFactory is responsible to create connections
117:             * to this database.
118:             *
119:             * @param aDataSourceFactory The new DataSorceFactory for this database,
120:             *        or null to remove the current DataSourceFactory.
121:             */
122:            public void setDataSourceFactory(
123:                    DataSourceFactory aDataSourceFactory) {
124:                this .dataSourceFactory = aDataSourceFactory;
125:            }
126:
127:            /**
128:             * Get the IDBroker for this database.
129:             *
130:             * @return The IDBroker for this database, or null if no IdBroker has
131:             *         been started for this database.
132:             */
133:            public IDBroker getIDBroker() {
134:                if (databaseMap == null) {
135:                    return null;
136:                }
137:                return databaseMap.getIDBroker();
138:            }
139:
140:            /**
141:             * Creates the IDBroker for this DatabaseMap and starts it for the
142:             * given database.
143:             * The information about the IdTable is stored in the databaseMap.
144:             * If an IDBroker already exists for the DatabaseMap, the method
145:             * does nothing.
146:             *
147:             * @return true if a new IDBroker was created, false otherwise.
148:             */
149:            public synchronized boolean startIDBroker() {
150:                DatabaseMap dbMap = getDatabaseMap();
151:                if (dbMap.getIDBroker() != null) {
152:                    return false;
153:                }
154:                return dbMap.startIdBroker();
155:            }
156:
157:            /**
158:             * Returns the IdGenerator of the given type for this Database.
159:             * @param type The type (i.e.name) of the IdGenerator
160:             * @return The IdGenerator of the requested type, or null if no IdGenerator
161:             *         exists for the requested type.
162:             */
163:            public IdGenerator getIdGenerator(String type) {
164:                if (databaseMap == null) {
165:                    return null;
166:                }
167:                return databaseMap.getIdGenerator(type);
168:            }
169:
170:            /**
171:             * Adds an IdGenerator to the database.
172:             * @param type The type of the IdGenerator
173:             * @param idGen The new IdGenerator for the type, or null
174:             *        to remove the IdGenerator of the given type.
175:             */
176:            public void addIdGenerator(String type, IdGenerator idGen) {
177:                getDatabaseMap().addIdGenerator(type, idGen);
178:            }
179:
180:            /**
181:             * Returns the database schema for this Database.
182:             * @return the database schema for this database, or null if no schema
183:             *         has been set.
184:             */
185:            public String getSchema() {
186:                DataSourceFactory dsf = getDataSourceFactory();
187:                if (dsf == null) {
188:                    return null;
189:                }
190:                return dsf.getSchema();
191:            }
192:
193:            /**
194:             * Sets the schema for this database.
195:             * @param schema the name of the database schema to set, or null to remove
196:             *        the current schema.
197:             * @throws NullPointerException if no DatasourceFactory exists for this
198:             *         database.
199:             */
200:            public void setSchema(String schema) {
201:                getDataSourceFactory().setSchema(schema);
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.