Source Code Cross Referenced for OzoneODMGDatabase.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » odmg » 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 DBMS » Ozone 1.1 » org.ozoneDB.odmg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: OzoneODMGDatabase.java,v 1.1 2002/05/08 15:03:21 per_nyfelt Exp $
008:
009:        package org.ozoneDB.odmg;
010:
011:        import java.util.*;
012:        import org.odmg.*;
013:        import org.ozoneDB.ExternalDatabase;
014:        import org.ozoneDB.LocalDatabase;
015:        import org.ozoneDB.RemoteDatabase;
016:        import org.ozoneDB.OzoneProxy;
017:        import org.ozoneDB.OzoneRemote;
018:        import org.ozoneDB.OzoneCompatible;
019:
020:        /**
021:         * Implementation of the ODMG {@link org.odmg.Database} interface.
022:         * 
023:         * 
024:         * @author <a href="http://www.softwarebuero.de/">SMB</a>
025:         * @version $Revision: 1.1 $Date: 2002/05/08 15:03:21 $
026:         */
027:        public class OzoneODMGDatabase implements  EnhDatabase {
028:
029:            private ExternalDatabase db;
030:
031:            private OzoneODMG factory;
032:
033:            private int accessMode = NOT_OPEN;
034:
035:            public OzoneODMGDatabase(OzoneODMG _factory) {
036:                factory = _factory;
037:            }
038:
039:            public ExternalDatabase underlying() {
040:                return db;
041:            }
042:
043:            protected int mode() {
044:                return accessMode;
045:            }
046:
047:            /**
048:             * Open this ODMG database.
049:             * @param _url URL of the database (ozonedb:remote://host:port or ozonedb:local://datadir)
050:             */
051:            public synchronized void open(String _url, int _accessMode)
052:                    throws ODMGException {
053:                if (db != null) {
054:                    throw new DatabaseOpenException("Database is already open.");
055:                }
056:
057:                switch (_accessMode) {
058:                case OPEN_READ_ONLY: {
059:                    break;
060:                }
061:                case OPEN_READ_WRITE: {
062:                    break;
063:                }
064:                case OPEN_EXCLUSIVE: {
065:                    throw new ODMGRuntimeException(
066:                            "OPEN_EXCLUSIVE not supported.");
067:                }
068:                default:
069:                    throw new ODMGRuntimeException("Illegal open mode.");
070:                }
071:
072:                try {
073:                    db = ExternalDatabase.openDatabase(_url);
074:                } catch (Exception e) {
075:                    throw new DatabaseNotFoundException(e.toString());
076:                }
077:
078:                accessMode = _accessMode;
079:                factory.databaseOpened(this );
080:            }
081:
082:            public void close() throws ODMGException {
083:                if (db == null) {
084:                    throw new DatabaseClosedException("Database not open.");
085:                }
086:
087:                try {
088:                    db.close();
089:                } catch (Exception e) {
090:                    throw new ODMGException(e.toString());
091:                } finally {
092:                    db = null;
093:                    accessMode = NOT_OPEN;
094:                    factory.databaseClosed(this );
095:                }
096:            }
097:
098:            protected void finalize() throws Throwable {
099:                if (db != null) {
100:                    close();
101:                }
102:            }
103:
104:            /**
105:             * The ozone ODMG interface does not implement this method, use
106:             * createObject() instead.
107:             * <p>
108:             * ozone uses proxies to control objects inside the database. Unfortunately
109:             * ODMG is perfectly not aware of this kind of architecture.
110:             */
111:            public void makePersistent(Object object) {
112:                if (OzoneODMGTransaction.current() == null) {
113:                    throw new TransactionNotInProgressException(
114:                            "Thread has not joined a transaction.");
115:                }
116:
117:                if (db == null) {
118:                    throw new DatabaseClosedException("Database not open.");
119:                }
120:
121:                // throw exception if someone want to use this method as intended
122:                // by ODMG
123:                if (object instanceof  OzoneCompatible) {
124:                    throw new ODMGRuntimeException(
125:                            object.getClass().getName()
126:                                    + ": create a persistent instance via createPersistent.");
127:                }
128:
129:                // do nothing if the object is an proxy already
130:                if (object instanceof  OzoneProxy) {
131:                    return;
132:                }
133:            }
134:
135:            /**
136:             * Create a new persistent instance of the given class.
137:             * <p>
138:             * THIS METHOD IS NOT IN THE ODMG 3.0 STANDARD!
139:             * <p>
140:             * It must be executed in the context of an open transaction.
141:             * If the transaction in which this method is executed commits,
142:             * then the object is made durable.
143:             * ClassNotPersistenceCapableException is thrown if the implementation cannot make
144:             * the object persistent because of the type of the object.
145:             */
146:            public Object createPersistent(Class cl) {
147:                if (OzoneODMGTransaction.current() == null) {
148:                    throw new TransactionNotInProgressException(
149:                            "Thread has not joined a transaction.");
150:                }
151:
152:                if (db == null) {
153:                    throw new DatabaseClosedException("Database not open.");
154:                }
155:
156:                if (cl.isAssignableFrom(OzoneCompatible.class)) {
157:                    throw new ClassNotPersistenceCapableException(cl.getName());
158:                }
159:
160:                try {
161:                    return db.createObject(cl.getName(),
162:                            ExternalDatabase.Public, null);
163:                } catch (Exception e) {
164:                    throw new ODMGRuntimeException(e.toString());
165:                }
166:            }
167:
168:            public void deletePersistent(Object object) {
169:                if (OzoneODMGTransaction.current() == null) {
170:                    throw new TransactionNotInProgressException(
171:                            "Thread has not joined a transaction.");
172:                }
173:
174:                if (db == null) {
175:                    throw new DatabaseClosedException("Database not open.");
176:                }
177:
178:                if (!(object instanceof  OzoneProxy)) {
179:                    throw new ObjectNotPersistentException(object.getClass()
180:                            .getName());
181:                }
182:
183:                try {
184:                    db.deleteObject((OzoneRemote) object);
185:                } catch (Exception e) {
186:                    throw new ODMGRuntimeException(e.toString());
187:                }
188:            }
189:
190:            public void bind(Object object, String name) {
191:                if (OzoneODMGTransaction.current() == null) {
192:                    throw new TransactionNotInProgressException(
193:                            "Thread has not joined a transaction.");
194:                }
195:
196:                if (db == null) {
197:                    throw new DatabaseClosedException("Database not open.");
198:                }
199:
200:                if (!(object instanceof  OzoneProxy)) {
201:                    throw new ClassNotPersistenceCapableException(object
202:                            .getClass().getName());
203:                }
204:
205:                try {
206:                    db.nameObject((OzoneRemote) object, name);
207:                } catch (Exception e) {
208:                    throw new ODMGRuntimeException(e.toString());
209:                }
210:            }
211:
212:            public void unbind(String name) throws ObjectNameNotFoundException {
213:                if (OzoneODMGTransaction.current() == null) {
214:                    throw new TransactionNotInProgressException(
215:                            "Thread has not joined a transaction.");
216:                }
217:
218:                if (db == null) {
219:                    throw new DatabaseClosedException("Database not open.");
220:                }
221:
222:                Object obj = lookup(name);
223:                try {
224:                    db.nameObject((OzoneRemote) obj, null);
225:                } catch (Exception e) {
226:                    throw new ODMGRuntimeException(e.toString());
227:                }
228:            }
229:
230:            public Object lookup(String name)
231:                    throws ObjectNameNotFoundException {
232:                if (OzoneODMGTransaction.current() == null) {
233:                    throw new TransactionNotInProgressException(
234:                            "Thread has not joined a transaction.");
235:                }
236:
237:                if (db == null) {
238:                    throw new DatabaseClosedException("Database not open.");
239:                }
240:
241:                Object result;
242:                try {
243:                    result = db.objectForName(name);
244:                } catch (Exception e) {
245:                    throw new ODMGRuntimeException(e.toString());
246:                }
247:
248:                if (result == null) {
249:                    throw new ObjectNameNotFoundException(name);
250:                }
251:
252:                return result;
253:            }
254:
255:            public boolean containsObject(Object obj) {
256:                if (OzoneODMGTransaction.current() == null) {
257:                    throw new TransactionNotInProgressException(
258:                            "Thread has not joined a transaction.");
259:                }
260:
261:                if (db == null) {
262:                    throw new DatabaseClosedException("Database not open.");
263:                }
264:
265:                if (!(obj instanceof  OzoneProxy)) {
266:                    throw new ClassNotPersistenceCapableException(obj
267:                            .getClass().getName());
268:                }
269:
270:                OzoneProxy proxy = (OzoneProxy) obj;
271:                return proxy.link == db;
272:            }
273:
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.