001: /*
002: $Header: /cvsroot/xorm/xorm/src/org/xorm/PersistenceCapableImpl.java,v 1.5 2003/09/25 18:21:23 wbiggs Exp $
003:
004: This file is part of XORM.
005:
006: XORM is free software; you can redistribute it and/or modify
007: it under the terms of the GNU General Public License as published by
008: the Free Software Foundation; either version 2 of the License, or
009: (at your option) any later version.
010:
011: XORM is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU General Public License for more details.
015:
016: You should have received a copy of the GNU General Public License
017: along with XORM; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package org.xorm;
021:
022: import javax.jdo.PersistenceManager;
023: import javax.jdo.spi.PersistenceCapable;
024: import javax.jdo.spi.StateManager;
025:
026: /**
027: * This class is used to implement "lookalike" PersistenceCapable
028: * functionality in Enhancer-generated classes. It is separated from
029: * InterfaceInvocationHandler primarily to enforce a separation of
030: * concerns.
031: *
032: * These methods are typically not called on Enhancer-generated objects
033: * unless JDOHelper methods are used to interrogate the item.
034: * Methods that are only relevant to the interaction between an instance
035: * and a JDO StateManager throw UnsupportedOperationException. That
036: * means it is not possible for other JDO implementations to manage
037: * XORM objects at this time.
038: */
039: class PersistenceCapableImpl implements PersistenceCapable {
040: // 20.20.1 Generated fields
041: protected InterfaceInvocationHandler handler;
042:
043: PersistenceCapableImpl(InterfaceInvocationHandler handler) {
044: this .handler = handler;
045: }
046:
047: // 20.20.3 Generated interrogatives
048: public final boolean jdoIsPersistent() {
049: return handler.isPersistent();
050: }
051:
052: public final boolean jdoIsTransactional() {
053: return handler.isTransactional();
054: }
055:
056: public final boolean jdoIsNew() {
057: return handler.isNew();
058: }
059:
060: public final boolean jdoIsDirty() {
061: return handler.isDirty() || handler.isNew()
062: || handler.isDeleted();
063: }
064:
065: public final boolean jdoIsDeleted() {
066: return handler.isDeleted();
067: }
068:
069: public final void jdoMakeDirty(String fieldName) {
070: // TODO do this on a field basis
071: handler.makeDirty();
072: }
073:
074: public final PersistenceManager jdoGetPersistenceManager() {
075: return (handler.getStatus() == ObjectState.STATUS_TRANSIENT) ? null
076: : handler.getInterfaceManager();
077: }
078:
079: public final Object jdoGetObjectId() {
080: Object oid = handler.getObjectId();
081: return (!handler.isPersistent() && (oid instanceof TransientKey)) ? null
082: : new ObjectId(handler.getClassMapping()
083: .getMappedClass(), oid);
084: }
085:
086: public final Object jdoGetTransactionalObjectId() {
087: return jdoGetObjectId();
088: }
089:
090: // 20.20.4 Generated jdoReplaceStateManager
091: public final synchronized void jdoReplaceStateManager(
092: StateManager stateManager) {
093: throw new UnsupportedOperationException();
094: }
095:
096: // 20.20.5 Generated jdoReplaceFlags
097: public final void jdoReplaceFlags() {
098: throw new UnsupportedOperationException();
099: }
100:
101: // 20.20.6 Generated jdoNewInstance helpers
102: public PersistenceCapable jdoNewInstance(StateManager stateManager) {
103: return (PersistenceCapable) XORM.newInstance(handler
104: .getFactory(), handler.getClassMapping()
105: .getMappedClass());
106: }
107:
108: public PersistenceCapable jdoNewInstance(StateManager stateManager,
109: Object oid) {
110: // Because only datastore identity is supported, this method
111: // is functionally the same as the one-argument version.
112: return jdoNewInstance(stateManager);
113: }
114:
115: public Object jdoNewObjectIdInstance() {
116: throw new UnsupportedOperationException();
117: }
118:
119: public Object jdoNewObjectIdInstance(String arg) {
120: return new ObjectId(arg);
121: }
122:
123: // 20.20.10 Generated jdoReplaceField and jdoReplaceFields
124: public void jdoReplaceField(int fieldNumber) {
125: throw new UnsupportedOperationException();
126: }
127:
128: public void jdoReplaceFields(int[] fieldNumbers) {
129: throw new UnsupportedOperationException();
130: }
131:
132: // 20.20.11 Generated jdoProvideField and jdoProvideFields
133: public void jdoProvideField(int fieldNumber) {
134: throw new UnsupportedOperationException();
135: }
136:
137: public void jdoProvideFields(int[] fieldNumbers) {
138: throw new UnsupportedOperationException();
139: }
140:
141: // 20.20.12 Generated jdoCopyField and jdoCopyFields
142: public void jdoCopyFields(Object pc, int[] fieldNumbers) {
143: throw new UnsupportedOperationException();
144: }
145:
146: // 20.20.16
147: public void jdoCopyKeyFieldsToObjectId(
148: PersistenceCapable.ObjectIdFieldSupplier supplier,
149: Object oid) {
150: throw new UnsupportedOperationException();
151: }
152:
153: public void jdoCopyKeyFieldsToObjectId(Object oid) {
154: throw new UnsupportedOperationException();
155: }
156:
157: // 20.20.17
158: public void jdoCopyKeyFieldsFromObjectId(
159: PersistenceCapable.ObjectIdFieldConsumer consumer,
160: Object oid) {
161: throw new UnsupportedOperationException();
162: }
163: }
|