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


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.BitSet;
019:        import java.util.Iterator;
020:
021:        import javax.jdo.Extent;
022:        import javax.jdo.JDOFatalInternalException;
023:        import javax.jdo.JDOUserException;
024:        import javax.jdo.spi.PersistenceCapable;
025:
026:        import org.apache.ojb.broker.Identity;
027:        import org.apache.ojb.broker.PersistenceBroker;
028:        import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
029:        import org.apache.ojb.broker.util.logging.Logger;
030:        import org.apache.ojb.broker.util.logging.LoggerFactory;
031:
032:        import com.sun.jdori.Connector;
033:        import com.sun.jdori.FieldManager;
034:        import com.sun.jdori.PersistenceManagerInternal;
035:        import com.sun.jdori.StateManagerInternal;
036:        import com.sun.jdori.StoreManager;
037:        import com.sun.jdori.common.query.BasicQueryResult;
038:        import com.sun.jdori.model.jdo.JDOClass;
039:        import com.sun.jdori.query.QueryResult;
040:        import com.sun.jdori.query.QueryResultHelper;
041:
042:        /**
043:         * StoreManager represents the datastore to the rest of the JDO components.
044:         * It provides the means to write and read instances, to get the extent of
045:         * classes, and to get the object id for a persistence capable object.
046:         *
047:         * @author Thomas Mahler
048:         */
049:        class OjbStoreManager implements  StoreManager {
050:            private final OjbStorePMF pmf;
051:            private final OjbStoreConnector connector;
052:
053:            private boolean optimistic;
054:
055:            /** the logger used for debugging*/
056:            private Logger logger = LoggerFactory.getLogger("JDO");
057:
058:            OjbStoreManager(OjbStorePMF pmf) {
059:                this .pmf = pmf;
060:                this .connector = new OjbStoreConnector(pmf);
061:            }
062:
063:            /**
064:             * @see com.sun.jdori.StoreManager#getConnector
065:             */
066:            public Connector getConnector() {
067:                return connector;
068:            }
069:
070:            /**
071:             * @see com.sun.jdori.StoreManager#getConnector(String userid,
072:             * String password)
073:             */
074:            public Connector getConnector(String userid, String password) {
075:                throw new JDOUserException("Not implemented");
076:            }
077:
078:            /**
079:             * @see com.sun.jdori.StoreManager#insert(BitSet, BitSet, StateManagerInternal)
080:             */
081:            public synchronized int insert(BitSet loadedFields,
082:                    BitSet dirtyFields, StateManagerInternal sm) {
083:
084:                try {
085:                    logger.debug("OjbStoreManager.insert");
086:                    PersistenceBroker broker = connector.getBroker();
087:                    Object instance = sm.getObject();
088:                    broker
089:                            .store(instance,
090:                                    ObjectModificationDefaultImpl.INSERT);
091:                } catch (Exception ex) {
092:                    throw new OjbStoreFatalInternalException(getClass(),
093:                            "insert", ex);
094:                }
095:                dirtyFields.xor(dirtyFields);
096:                return StateManagerInternal.FLUSHED_COMPLETE;
097:            }
098:
099:            /**
100:             * @see com.sun.jdori.StoreManager#update(BitSet, BitSet, StateManagerInternal)
101:             */
102:            public synchronized int update(BitSet loadedFields,
103:                    BitSet dirtyFields, StateManagerInternal sm) {
104:
105:                try {
106:                    logger.debug("OjbStoreManager.update");
107:                    PersistenceBroker broker = connector.getBroker();
108:                    fetch(sm, null);
109:                    Object instance = sm.getObject();
110:                    broker
111:                            .store(instance,
112:                                    ObjectModificationDefaultImpl.UPDATE);
113:                } catch (Exception ex) {
114:                    throw new OjbStoreFatalInternalException(getClass(),
115:                            "update", ex);
116:                }
117:                dirtyFields.xor(dirtyFields);
118:                return StateManagerInternal.FLUSHED_COMPLETE;
119:            }
120:
121:            /**
122:             * @see com.sun.jdori.StoreManager#verifyFields(BitSet, BitSet, StateManagerInternal)
123:             */
124:            public synchronized int verifyFields(BitSet ignoredFields,
125:                    BitSet fieldsToVerify, StateManagerInternal sm) {
126:                fieldsToVerify.xor(fieldsToVerify);
127:                return StateManagerInternal.FLUSHED_COMPLETE;
128:            }
129:
130:            /**
131:             * @see com.sun.jdori.StoreManager#delete(BitSet, BitSet, StateManagerInternal)
132:             */
133:            public synchronized int delete(BitSet loadedFields,
134:                    BitSet dirtyFields, StateManagerInternal sm) {
135:                Identity oid = (Identity) sm.getInternalObjectId();
136:                logger.debug("OjbStoreManager.delete(" + oid + ")");
137:                try {
138:                    fetch(sm, null);
139:                    connector.getBroker().delete(sm.getObject());
140:                } catch (Exception ex) {
141:                    throw new OjbStoreFatalInternalException(getClass(),
142:                            "delete", ex);
143:                }
144:                dirtyFields.xor(dirtyFields);
145:                return StateManagerInternal.FLUSHED_COMPLETE;
146:            }
147:
148:            /**
149:             * @see com.sun.jdori.StoreManager#fetch
150:             */
151:            public synchronized void fetch(StateManagerInternal sm,
152:                    int fieldNums[]) {
153:                PersistenceBroker broker = connector.getBroker();
154:                try {
155:                    Object instance = sm.getObject();
156:                    Identity oid = (Identity) sm.getInternalObjectId();
157:                    if (oid == null) {
158:                        oid = new Identity(instance, broker);
159:                    }
160:                    broker.removeFromCache(instance);
161:                    PersistenceCapable pc = (PersistenceCapable) broker
162:                            .getObjectByIdentity(oid);
163:
164:                    JDOClass jdoClass = Helper.getJDOClass(pc.getClass());
165:                    if (fieldNums == null) {
166:                        fieldNums = jdoClass.getManagedFieldNumbers();
167:                    }
168:
169:                    FieldManager fm = new OjbFieldManager(pc, broker);
170:                    sm.replaceFields(fieldNums, fm);
171:
172:                    getConnector().flush();
173:                }
174:
175:                catch (Exception ex) {
176:                    throw new OjbStoreFatalInternalException(getClass(),
177:                            "fetch", ex);
178:                }
179:            }
180:
181:            /**
182:             * @see com.sun.jdori.StoreManager#getExtent
183:             */
184:            public synchronized Extent getExtent(Class pcClass,
185:                    boolean subclasses, PersistenceManagerInternal pm) {
186:                PersistenceBroker broker = connector.getBroker();
187:                return new OjbExtent(pcClass, broker, pm);
188:            }
189:
190:            /**
191:             * @see com.sun.jdori.StoreManager#createObjectId
192:             */
193:            public synchronized Object createObjectId(StateManagerInternal sm,
194:                    PersistenceManagerInternal pm) {
195:                PersistenceCapable obj = sm.getObject();
196:                Identity oid = new Identity(obj, connector.getBroker());
197:                return oid;
198:            }
199:
200:            /**
201:             * @see com.sun.jdori.StoreManager#createObjectId
202:             */
203:            public synchronized Object createInternalObjectId(
204:                    StateManagerInternal sm, PersistenceCapable pc, Object oid,
205:                    Class cls, PersistenceManagerInternal pm) {
206:                return new Identity(pc, connector.getBroker());
207:            }
208:
209:            /**
210:             * @see com.sun.jdori.StoreManager#getExternalObjectId(Object oid,
211:             * PersistenceCapable pc)
212:             */
213:            public synchronized Object getExternalObjectId(Object objectId,
214:                    PersistenceCapable pc) {
215:                return new Identity(pc, connector.getBroker());
216:            }
217:
218:            /**
219:             * @see com.sun.jdori.StoreManager#copyKeyFieldsFromObjectId
220:             */
221:            public void copyKeyFieldsFromObjectId(StateManagerInternal sm,
222:                    Class pcClass) {
223:                new Identity(sm.getObject(), connector.getBroker());
224:            }
225:
226:            /**
227:             * @see com.sun.jdori.StoreManager#hasActualPCClass
228:             */
229:            public boolean hasActualPCClass(Object objectId) {
230:                boolean rc = true;
231:                return rc;
232:            }
233:
234:            /**
235:             * @see com.sun.jdori.StoreManager#getInternalObjectId
236:             */
237:            public synchronized Object getInternalObjectId(Object objectId,
238:                    PersistenceManagerInternal pm) {
239:                return objectId;
240:            }
241:
242:            /**
243:             * @see com.sun.jdori.StoreManager#getPCClassForOid
244:             */
245:            public synchronized Class getPCClassForOid(Object objectId,
246:                    PersistenceManagerInternal pm) {
247:                return ((Identity) objectId).getObjectsTopLevelClass();
248:            }
249:
250:            /**
251:             * @see com.sun.jdori.StoreManager#newObjectIdInstance
252:             */
253:            public Object newObjectIdInstance(Class pcClass, String str) {
254:                return Identity.fromByteArray(str.getBytes());
255:            }
256:
257:            /**
258:             * @see com.sun.jdori.StoreManager#flush
259:             */
260:            public void flush(Iterator it, PersistenceManagerInternal pm) {
261:                this .optimistic = pm.currentTransaction().getOptimistic();
262:                boolean err = false;
263:
264:                while (it.hasNext()) {
265:                    StateManagerInternal sm = (StateManagerInternal) it.next();
266:                    logger.debug("OjbStoreManager.flush: "
267:                            + sm.getInternalObjectId() + ", "
268:                            + Helper.getLCState(sm));
269:                    sm.preStore();
270:                    sm.replaceSCOFields();
271:                    sm.flush(this );
272:                    if (!sm.isFlushed()) {
273:                        err = true;
274:                        break;
275:                    }
276:                }
277:
278:                logger.debug("OjbStoreManager.flush: end, err=" + err);
279:
280:                if (err) {
281:                    throw new JDOFatalInternalException("Error in flush");
282:                }
283:            }
284:
285:            /**
286:             * @see com.sun.jdori.StoreManager#newObjectIdInstance
287:             */
288:            public QueryResult newQueryResult(
289:                    QueryResultHelper queryResultHelper) {
290:                return new BasicQueryResult(queryResultHelper);
291:            }
292:
293:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.