Source Code Cross Referenced for JODB.java in  » Database-DBMS » JODB » com » mobixess » jodb » core » 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 » JODB » com.mobixess.jodb.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        Copyright (C) 2007  Mobixess Inc. http://www.java-objects-database.com
003:
004:        This file is part of the JODB (Java Objects Database) open source project.
005:
006:        JODB is free software; you can redistribute it and/or modify it under
007:        the terms of version 2 of the GNU General Public License as published
008:        by the Free Software Foundation.
009:
010:        JODB is distributed in the hope that it will be useful, but WITHOUT ANY
011:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
012:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
013:        for more details.
014:
015:        You should have received a copy of the GNU General Public License along
016:        with this program; if not, write to the Free Software Foundation, Inc.,
017:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
018:         */
019:        package com.mobixess.jodb.core;
020:
021:        import java.io.File;
022:        import java.io.IOException;
023:        import java.net.URI;
024:        import java.util.WeakHashMap;
025:        import com.mobixess.jodb.core.io.rmi.JODBIOBaseProxy;
026:        import com.mobixess.jodb.soda.api.ObjectContainer;
027:
028:        /**
029:         * @author Mobixess
030:         * Factory class to launch JODB engine.
031:         * <br>
032:         * Static methods can be used to obtain database session containers.
033:         */
034:
035:        public class JODB {
036:
037:            private static WeakHashMap<URI, JODBSessionContainer> _sessionsCache = new WeakHashMap<URI, JODBSessionContainer>();
038:
039:            public final static ObjectContainer open(String file)
040:                    throws IOException {
041:                return open(new File(file));
042:            };
043:
044:            /**
045:             * Opens an {@link ObjectContainer ObjectContainer} on the specified database file for local use.
046:             * <br><br>Subsequent calls with the same database file name will return the same
047:             * {@link ObjectContainer ObjectContainer} object.<br><br>
048:             * Every call to <code>openFile()</code> requires a corresponding
049:             * {@link ObjectContainer#close ObjectContainer.close}.<br><br>
050:             * Database files can only be accessed for readwrite access from one process 
051:             * (one Java VM) at one time.
052:             * <br><br> 
053:             * 
054:             * @param file
055:             * @return {@link ObjectContainer} session container
056:             * @throws IOException
057:             */
058:            public final static ObjectContainer open(File file)
059:                    throws IOException {
060:                synchronized (_sessionsCache) {
061:                    JODBSessionContainer result = _sessionsCache.get(file);
062:                    if (result == null) {
063:                        result = new JODBSessionContainer(file);
064:                        _sessionsCache.put(result.getDbIdentificator(), result);
065:                    }
066:                    result.incOpenCounter();
067:                    return result;
068:                }
069:            };
070:
071:            /*package*/static void removeSessionFromCache(URI id) {
072:                synchronized (_sessionsCache) {
073:                    _sessionsCache.remove(id);
074:                }
075:            }
076:
077:            /**
078:             * Opens an {@link JODBServer JODBServer} on the specified database file.
079:             * <br> 
080:             * 
081:             * @param databaseFileName the database file
082:             * @throws IOException 
083:             * 
084:             */
085:            public static final JODBServer openServer(File file)
086:                    throws IOException {
087:                return openServer(file, null);
088:            }
089:
090:            /**
091:             * Opens an {@link JODBServer JODBServer} on the specified database file.
092:             * <br> 
093:             * 
094:             * @param databaseFileName the full path to the database file
095:             * @throws IOException 
096:             * 
097:             */
098:            public static final JODBServer openServer(String databaseFileName)
099:                    throws IOException {
100:                return openServer(databaseFileName, null);
101:            }
102:
103:            /**
104:             * Opens an {@link JODBServer JODBServer} with specified name 
105:             * on the specified database file.
106:             * <br>
107:             * The serverName serves as server identity when multiple 
108:             * servers (representing different db files) run on the same host. 
109:             * <br>
110:             * 
111:             * 
112:             * @param file the database file
113:             * @param serverName  the server name 
114:             * @throws IOException 
115:             * 
116:             */
117:            public static final JODBServer openServer(File file,
118:                    String serverName) throws IOException {
119:                JODBSessionContainer sessionContainer = (JODBSessionContainer) open(file);
120:                JODBServer server;
121:                try {
122:                    server = new JODBServer(sessionContainer, serverName);
123:                } catch (Exception e) {
124:                    throw new JodbIOException(e);
125:                }
126:                return server;
127:            }
128:
129:            /**
130:             * Opens an {@link JODBServer JODBServer} with specified name 
131:             * on the specified database file.
132:             * <br>
133:             * The serverName serves as server identity when multiple 
134:             * servers (representing different db files) run on the same host. 
135:             * <br>
136:             * 
137:             * 
138:             * @param databaseFileName the full path to the database file
139:             * @param serverName  the server name 
140:             * @throws IOException 
141:             * 
142:             */
143:            public static final JODBServer openServer(String databaseFileName,
144:                    String serverName) throws IOException {
145:                return openServer(new File(databaseFileName), serverName);
146:            }
147:
148:            /**
149:             * Opens an {@link ObjectContainer ObjectContainer}
150:             * client and connects it to the specified server
151:             * <br><br>
152:             * 
153:             * The <tt>mode</tt> argument specifies the access mode
154:             * in which the container is to be opened.  The permitted values and their
155:             * meanings are:
156:             *
157:             * <blockquote><table summary="Access mode permitted values and meanings">
158:             * <tr><th><p align="left">Value</p></th><th><p align="left">Meaning</p></th></tr>
159:             * <tr><td valign="top"><tt>"r"</tt></td>
160:             *     <td> Open for reading only.  Invoking any of the <tt>set()</tt>
161:             *     methods of the resulting object will cause an {@link
162:             *     java.io.IOException} to be thrown. </td></tr>
163:             * <tr><td valign="top"><tt>"rw"</tt></td>
164:             *     <td> Open for reading and writing.</td></tr>
165:             * </table></blockquote>
166:             * 
167:             * @param hostName the host name of server (should comply with {@link URI} name specification)
168:             * @param serverName optional server name (required when multiple servers run on the same host). {@code null}
169:             *        is acceptable value 
170:             * @param mode the access mode, as described
171:             *                 <a href="#mode">above</a>
172:             * @return
173:             * @throws IOException
174:             * @exception  IllegalArgumentException  if the mode argument is not equal
175:             *               to one of <tt>"r"</tt>, <tt>"rw"</tt>, or serverName is {@code null}, or mode is {@code null}
176:             */
177:            public static ObjectContainer openClient(String hostName,
178:                    String serverName, String mode) throws IOException {
179:                if (hostName == null || mode == null) {
180:                    throw new IllegalArgumentException();
181:                }
182:                mode = mode.toLowerCase();
183:                if (!"rw".startsWith(mode)) {
184:                    throw new IllegalArgumentException();
185:                }
186:                if (serverName == null) {
187:                    serverName = "";
188:                }
189:                synchronized (_sessionsCache) {
190:                    URI serverUri = JODBIOBaseProxy.composeURI(hostName,
191:                            serverName);
192:                    JODBSessionContainer result = _sessionsCache.get(serverUri);
193:                    if (result == null) {
194:                        result = new JODBSessionContainer(serverUri);
195:                        _sessionsCache.put(result.getDbIdentificator(), result);
196:                    }
197:                    result.incOpenCounter();
198:                    return result;
199:                }
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.