001: package org.apache.ojb.jdori.sql;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import java.util.HashMap;
019: import java.util.Properties;
020:
021: import javax.jdo.JDOException;
022: import javax.jdo.PersistenceManager;
023: import javax.jdo.spi.PersistenceCapable;
024:
025: import org.apache.ojb.broker.Identity;
026:
027: import com.sun.jdori.StoreManager;
028: import com.sun.jdori.TranscriberFactory;
029: import com.sun.jdori.common.PersistenceManagerFactoryImpl;
030: import com.sun.jdori.common.PersistenceManagerImpl;
031:
032: /**
033: * PMF for OjbStore implementation
034: * @author thma
035: *
036: */
037: public class OjbStorePMF extends PersistenceManagerFactoryImpl {
038: private final HashMap storeManagers = new HashMap();
039:
040: private static HashMap trackedClassesMap = getTrackedClasses();
041:
042: private static final OjbStorePMF INSTANCE = new OjbStorePMF();
043:
044: public static OjbStorePMF getInstance() {
045: return INSTANCE;
046: }
047:
048: /**
049: * Constructor for PMF.
050: */
051: public OjbStorePMF() {
052: super ();
053: }
054:
055: /**
056: * Constructor for PMF.
057: * @param URL
058: * @param userName
059: * @param password
060: * @param driverName
061: */
062: public OjbStorePMF(String URL, String userName, String password,
063: String driverName) {
064: super (URL, userName, password, driverName);
065: }
066:
067: private static HashMap getTrackedClasses() {
068: HashMap classMap = new HashMap();
069: // java.util.Date and java.sql classes:
070: classMap.put(java.util.Date.class,
071: com.sun.jdori.common.sco.Date.class);
072: classMap.put(com.sun.jdori.common.sco.Date.class,
073: com.sun.jdori.common.sco.Date.class);
074: classMap.put(java.sql.Date.class,
075: com.sun.jdori.common.sco.SqlDate.class);
076: classMap.put(com.sun.jdori.common.sco.SqlDate.class,
077: com.sun.jdori.common.sco.SqlDate.class);
078: classMap.put(java.sql.Time.class,
079: com.sun.jdori.common.sco.SqlTime.class);
080: classMap.put(com.sun.jdori.common.sco.SqlTime.class,
081: com.sun.jdori.common.sco.SqlTime.class);
082: classMap.put(java.sql.Timestamp.class,
083: com.sun.jdori.common.sco.SqlTimestamp.class);
084: classMap.put(com.sun.jdori.common.sco.SqlTimestamp.class,
085: com.sun.jdori.common.sco.SqlTimestamp.class);
086:
087: // java.util.Set
088: classMap.put(java.util.HashSet.class,
089: com.sun.jdori.common.sco.HashSet.class);
090: classMap.put(java.util.AbstractSet.class,
091: com.sun.jdori.common.sco.HashSet.class);
092: classMap.put(java.util.Set.class,
093: com.sun.jdori.common.sco.HashSet.class);
094: classMap.put(com.sun.jdori.common.sco.HashSet.class,
095: com.sun.jdori.common.sco.HashSet.class);
096:
097: // java.util.List
098: classMap.put(java.util.ArrayList.class,
099: com.sun.jdori.common.sco.ArrayList.class);
100: classMap.put(java.util.AbstractList.class,
101: com.sun.jdori.common.sco.ArrayList.class);
102: classMap.put(java.util.List.class,
103: com.sun.jdori.common.sco.ArrayList.class);
104: classMap.put(java.util.AbstractCollection.class,
105: com.sun.jdori.common.sco.ArrayList.class);
106: classMap.put(java.util.Collection.class,
107: com.sun.jdori.common.sco.ArrayList.class);
108: classMap.put(com.sun.jdori.common.sco.ArrayList.class,
109: com.sun.jdori.common.sco.ArrayList.class);
110:
111: // java.util.Vector
112: classMap.put(java.util.Vector.class,
113: com.sun.jdori.common.sco.Vector.class);
114: classMap.put(com.sun.jdori.common.sco.Vector.class,
115: com.sun.jdori.common.sco.Vector.class);
116:
117: // java.util.SortedSet
118: classMap.put(java.util.TreeSet.class,
119: com.sun.jdori.common.sco.TreeSet.class);
120: classMap.put(java.util.SortedSet.class,
121: com.sun.jdori.common.sco.TreeSet.class);
122: classMap.put(com.sun.jdori.common.sco.TreeSet.class,
123: com.sun.jdori.common.sco.TreeSet.class);
124:
125: // java.util.LinkedList
126: classMap.put(java.util.LinkedList.class,
127: com.sun.jdori.common.sco.LinkedList.class);
128: classMap.put(java.util.AbstractSequentialList.class,
129: com.sun.jdori.common.sco.LinkedList.class);
130: classMap.put(com.sun.jdori.common.sco.LinkedList.class,
131: com.sun.jdori.common.sco.LinkedList.class);
132:
133: // java.util.Map
134: classMap.put(java.util.Map.class,
135: com.sun.jdori.common.sco.HashMap.class);
136: classMap.put(java.util.AbstractMap.class,
137: com.sun.jdori.common.sco.HashMap.class);
138: classMap.put(java.util.HashMap.class,
139: com.sun.jdori.common.sco.HashMap.class);
140: classMap.put(com.sun.jdori.common.sco.HashMap.class,
141: com.sun.jdori.common.sco.HashMap.class);
142:
143: // java.util.Hashtable
144: classMap.put(java.util.Hashtable.class,
145: com.sun.jdori.common.sco.Hashtable.class);
146: classMap.put(com.sun.jdori.common.sco.Hashtable.class,
147: com.sun.jdori.common.sco.Hashtable.class);
148:
149: // java.util.SortedMap
150: classMap.put(java.util.SortedMap.class,
151: com.sun.jdori.common.sco.TreeMap.class);
152: classMap.put(java.util.TreeMap.class,
153: com.sun.jdori.common.sco.TreeMap.class);
154: classMap.put(com.sun.jdori.common.sco.TreeMap.class,
155: com.sun.jdori.common.sco.TreeMap.class);
156:
157: return classMap;
158: }
159:
160: /**
161: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getOptionArray()
162: */
163: protected String[] getOptionArray() {
164: String[] optionsA = { "" };
165: return optionsA;
166: }
167:
168: /**
169: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#createPersistenceManager(String, String)
170: */
171: protected PersistenceManager createPersistenceManager(
172: String aUserid, String aPassword) {
173:
174: PersistenceManager result = null;
175: try {
176: result = new PersistenceManagerImpl(this , aUserid,
177: aPassword);
178: } catch (JDOException ex) {
179: throw ex;
180: } catch (Exception ex) {
181: throw new OjbStoreFatalInternalException(getClass(),
182: "createPersistenceManager(userid, password)", ex);
183: }
184: return result;
185: }
186:
187: /**
188: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setPMFClassProperty(Properties)
189: */
190: protected void setPMFClassProperty(Properties props) {
191: props.setProperty("javax.jdo.PersistenceManagerFactoryClass",
192: this .getClass().getName());
193: }
194:
195: /**
196: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#encrypt(String)
197: */
198: protected String encrypt(String s) {
199: return s;
200: }
201:
202: /**
203: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#decrypt(String)
204: */
205: protected String decrypt(String s) {
206: return s;
207: }
208:
209: /**
210: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setCFProperties(Properties)
211: */
212: protected void setCFProperties(Properties p) {
213: }
214:
215: /**
216: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getCFFromProperties(Properties)
217: */
218: protected void getCFFromProperties(Properties p) {
219: }
220:
221: /**
222: * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#isConnectionFactoryConfigured()
223: */
224: protected boolean isConnectionFactoryConfigured() {
225: return true;
226: }
227:
228: /**
229: * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTranscriberFactory()
230: */
231: public TranscriberFactory getTranscriberFactory() {
232: return null;
233: }
234:
235: /**
236: * @see com.sun.jdori.PersistenceManagerFactoryInternal#getObjectIdClass(Class)
237: */
238: public Class getObjectIdClass(Class cls) {
239: Class result = null;
240: if (null != cls
241: && PersistenceCapable.class.isAssignableFrom(cls)) {
242: result = Identity.class;
243: }
244: return result;
245: }
246:
247: /**
248: * @see com.sun.jdori.PersistenceManagerFactoryInternal#getStoreManager(PersistenceManager)
249: */
250: public StoreManager getStoreManager(PersistenceManager pm) {
251: OjbStoreManager result = null;
252: try {
253: result = (OjbStoreManager) storeManagers.get(pm);
254: if (null == result) {
255: result = new OjbStoreManager(this );
256: storeManagers.put(pm, result);
257: }
258: } catch (JDOException ex) {
259: throw ex;
260: } catch (Exception ex) {
261: throw new OjbStoreFatalInternalException(getClass(),
262: "getStoreManager", ex);
263: }
264: return result;
265: }
266:
267: /**
268: * @see com.sun.jdori.PersistenceManagerFactoryInternal#releaseStoreManager(PersistenceManager)
269: */
270: public void releaseStoreManager(PersistenceManager pm) {
271: try {
272: storeManagers.remove(pm);
273: } catch (JDOException ex) {
274: throw ex;
275: } catch (Exception ex) {
276: throw new OjbStoreFatalInternalException(getClass(),
277: "releaseStoreManager", ex);
278: }
279: }
280:
281: /**
282: * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTrackedClass(Class)
283: */
284: public Class getTrackedClass(Class type) {
285: return (Class) trackedClassesMap.get(type);
286: }
287:
288: }
|