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


001:        package org.apache.ojb.odmg.collections;
002:
003:        /* Copyright 2003-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.io.Serializable;
019:
020:        import org.apache.commons.lang.builder.ToStringBuilder;
021:        import org.apache.ojb.broker.Identity;
022:        import org.apache.ojb.broker.OJBRuntimeException;
023:        import org.apache.ojb.broker.PBKey;
024:        import org.apache.ojb.broker.PersistenceBroker;
025:        import org.apache.ojb.broker.PersistenceBrokerAware;
026:        import org.apache.ojb.broker.PersistenceBrokerException;
027:        import org.apache.ojb.broker.util.logging.Logger;
028:        import org.apache.ojb.broker.util.logging.LoggerFactory;
029:        import org.apache.ojb.odmg.PBCapsule;
030:        import org.apache.ojb.odmg.RuntimeObject;
031:        import org.apache.ojb.odmg.TransactionImpl;
032:        import org.apache.ojb.odmg.TxManagerFactory;
033:        import org.odmg.Transaction;
034:
035:        /**
036:         * Encapsulates an DList entry object.
037:         *
038:         * @version $Id: DListEntry.java,v 1.25.2.4 2005/12/21 22:29:50 tomdz Exp $
039:         */
040:        public class DListEntry implements  Serializable, PersistenceBrokerAware {
041:            private static final long serialVersionUID = 5251476492626009907L;
042:            /*
043:             * declare transient, because ManageableCollection entries need to be {@link java.io.Serializable}.
044:             */
045:            private transient Logger log;
046:            protected transient Object realSubject;
047:            protected PBKey pbKey;
048:
049:            protected Integer id;
050:            protected Integer dlistId;
051:            protected Identity oid;
052:            protected int position;
053:
054:            /**
055:             * Used to instantiate persistent DLists from DB by the kernel
056:             * FOR INTERNAL USE ONLY
057:             */
058:            public DListEntry() {
059:                /*
060:                arminw:
061:                When PB kernel fill DList with DListEntry, the DListEntry needs to know the current
062:                used PBKey, because we need to lookup the real objects when user iterates the list,
063:                thus we need the associated PBKey to find right PB/DB connection.
064:                TODO: Find a better solution
065:                 */
066:                //        if(getTransaction() == null)
067:                //        {
068:                //            throw new TransactionNotInProgressException("Materialization of DCollection instances must be done with a tx");
069:                //        }
070:                getPBKey();
071:            }
072:
073:            /**
074:             * Standard way to instantiate new entries
075:             */
076:            public DListEntry(DListImpl theDList, Object theObject) {
077:                this .dlistId = theDList.getId();
078:                this .position = theDList.size();
079:                this .realSubject = theObject;
080:                this .pbKey = getPBKey();
081:            }
082:
083:            protected Logger getLog() {
084:                if (log == null) {
085:                    log = LoggerFactory.getLogger(DListEntry.class);
086:                }
087:                return log;
088:            }
089:
090:            protected TransactionImpl getTransaction() {
091:                return TxManagerFactory.instance().getTransaction();
092:            }
093:
094:            public PBKey getPBKey() {
095:                if (pbKey == null) {
096:                    TransactionImpl tx = getTransaction();
097:                    if (tx != null && tx.isOpen()) {
098:                        pbKey = tx.getBroker().getPBKey();
099:                    }
100:                }
101:                return pbKey;
102:            }
103:
104:            protected void prepareForPersistency(PersistenceBroker broker) {
105:                if (oid == null) {
106:                    if (realSubject == null) {
107:                        throw new OJBRuntimeException(
108:                                "Identity and real object are 'null' - Can not persist empty entry");
109:                    } else {
110:                        oid = broker.serviceIdentity().buildIdentity(
111:                                realSubject);
112:                    }
113:                }
114:            }
115:
116:            protected void prepareRealSubject(PersistenceBroker broker) {
117:                if (oid == null) {
118:                    throw new OJBRuntimeException(
119:                            "can not return real object, real object and Identity is null");
120:                }
121:                realSubject = broker.getObjectByIdentity(oid);
122:            }
123:
124:            public Object getRealSubject() {
125:                if (realSubject != null) {
126:                    return realSubject;
127:                } else {
128:                    TransactionImpl tx = getTransaction();
129:                    if (tx != null && tx.isOpen()) {
130:                        prepareRealSubject(tx.getBroker());
131:                        if (realSubject != null) {
132:                            RuntimeObject rt = new RuntimeObject(realSubject,
133:                                    tx, false);
134:                            tx.lockAndRegister(rt, Transaction.READ, tx
135:                                    .getRegistrationList());
136:                        }
137:                    } else {
138:                        PBKey aPbKey = getPBKey();
139:                        if (aPbKey != null) {
140:                            PBCapsule capsule = new PBCapsule(aPbKey, null);
141:                            try {
142:                                prepareRealSubject(capsule.getBroker());
143:                            } finally {
144:                                capsule.destroy();
145:                            }
146:                        } else {
147:                            getLog().warn(
148:                                    "No tx, no PBKey - can't materialise object with Identity "
149:                                            + getOid());
150:                        }
151:                    }
152:                }
153:                return realSubject;
154:            }
155:
156:            public void setRealSubject(Object realSubject) {
157:                this .realSubject = realSubject;
158:            }
159:
160:            public int getPosition() {
161:                return position;
162:            }
163:
164:            public void setPosition(int newPosition) {
165:                position = newPosition;
166:            }
167:
168:            /**
169:             * Gets the dlistId.
170:             *
171:             * @return Returns a int
172:             */
173:            public Integer getDlistId() {
174:                return dlistId;
175:            }
176:
177:            /**
178:             * Sets the dlistId.
179:             *
180:             * @param dlistId The dlistId to set
181:             */
182:            public void setDlistId(Integer dlistId) {
183:                this .dlistId = dlistId;
184:            }
185:
186:            /**
187:             * Gets the id.
188:             *
189:             * @return Returns a int
190:             */
191:            public Integer getId() {
192:                return id;
193:            }
194:
195:            /**
196:             * Sets the id.
197:             *
198:             * @param id The id to set
199:             */
200:            public void setId(Integer id) {
201:                this .id = id;
202:            }
203:
204:            public Identity getOid() {
205:                return oid;
206:            }
207:
208:            public void setOid(Identity oid) {
209:                this .oid = oid;
210:            }
211:
212:            /**
213:             * return String representation.
214:             */
215:            public String toString() {
216:                ToStringBuilder buf = new ToStringBuilder(this );
217:                buf.append("id", id);
218:                buf.append("dListId", dlistId);
219:                buf.append("position", position);
220:                buf.append("identity", oid);
221:                buf.append("realSubject", realSubject);
222:                return buf.toString();
223:            }
224:
225:            //===================================================
226:            // PersistenceBrokerAware interface methods
227:            //===================================================
228:            public void beforeInsert(PersistenceBroker broker)
229:                    throws PersistenceBrokerException {
230:                // before insert we have to build the Identity objects of the persistent objects
231:                // we can't do this ealier, because we can now expect that the persistent object
232:                // was written to DB (we make sure in code that the persistent object was locked before
233:                // this entry) and the generated Identity is valid
234:                prepareForPersistency(broker);
235:            }
236:
237:            public void beforeUpdate(PersistenceBroker broker)
238:                    throws PersistenceBrokerException {
239:            }
240:
241:            public void beforeDelete(PersistenceBroker broker)
242:                    throws PersistenceBrokerException {
243:            }
244:
245:            public void afterLookup(PersistenceBroker broker)
246:                    throws PersistenceBrokerException {
247:            }
248:
249:            public void afterDelete(PersistenceBroker broker)
250:                    throws PersistenceBrokerException {
251:            }
252:
253:            public void afterInsert(PersistenceBroker broker)
254:                    throws PersistenceBrokerException {
255:            }
256:
257:            public void afterUpdate(PersistenceBroker broker)
258:                    throws PersistenceBrokerException {
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.