001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.genclass.jdo;
018:
019: import org.objectweb.speedo.genclass.GenClass;
020: import org.objectweb.speedo.mim.api.LifeCycle;
021: import org.objectweb.speedo.mim.api.StateItf;
022: import org.objectweb.speedo.mim.jdo.api.JDOPersistentObjectItf;
023:
024: import javax.jdo.JDOUnsupportedOptionException;
025: import javax.jdo.PersistenceManager;
026: import javax.jdo.spi.PersistenceCapable;
027: import javax.jdo.spi.StateManager;
028:
029: /**
030: *
031: *
032: * @author S.Chassande-Barrioz
033: */
034: public abstract class JDOGenClass extends GenClass implements
035: JDOPersistentObjectItf {
036:
037: // IMPLEMENTATION OF THE PersistentCapable INTERFACE //
038: //---------------------------------------------------//
039: // Speedo implements partialy the javax.jdo.spi package. Then only the
040: // minimal method are implemented. The others throw a
041: // JDOUnsupportedOptionException exception.
042:
043: public PersistenceManager jdoGetPersistenceManager() {
044: return (PersistenceManager) (speedoIsActive ? speedoGetHome()
045: .getPOManagerFactory().lookup() : null);
046: }
047:
048: public void jdoReplaceFlags() {
049: throw new JDOUnsupportedOptionException();
050: }
051:
052: public PersistenceCapable jdoNewInstance(StateManager sm) {
053: throw new JDOUnsupportedOptionException();
054: }
055:
056: public PersistenceCapable jdoNewInstance(StateManager sm, Object oid) {
057: throw new JDOUnsupportedOptionException();
058: }
059:
060: public Object jdoNewObjectIdInstance(Object arg0) {
061: throw new JDOUnsupportedOptionException();
062: }
063:
064: public Object jdoNewObjectIdInstance() {
065: throw new JDOUnsupportedOptionException();
066: }
067:
068: public Object jdoGetObjectId() {
069: return getPName();
070: }
071:
072: public Object jdoGetVersion() {
073: return getPName();
074: }
075:
076: public Object jdoGetTransactionalObjectId() {
077: return getPName();
078: }
079:
080: public void jdoReplaceField(int fieldNumber) {
081: throw new JDOUnsupportedOptionException();
082: }
083:
084: public void jdoReplaceFields(int[] fieldNumbers) {
085: throw new JDOUnsupportedOptionException();
086: }
087:
088: public void jdoProvideField(int fieldNumber) {
089: throw new JDOUnsupportedOptionException();
090: }
091:
092: public void jdoProvideFields(int[] fieldNumbers) {
093: throw new JDOUnsupportedOptionException();
094: }
095:
096: public void jdoCopyFields(Object pc, int[] fieldNumbers) {
097: throw new JDOUnsupportedOptionException();
098: }
099:
100: public void jdoMakeDirty(String fieldName) {
101: // no fields => does nothing
102: }
103:
104: public boolean jdoIsDirty() {
105: StateItf sa = speedoGetState();
106: return sa != null
107: && !LifeCycle.isTransient(sa.speedoGetStatus())
108: && LifeCycle.isDirty(sa.speedoGetStatus());
109: }
110:
111: public boolean jdoIsDetached() {
112: //TODO: IMPLEMENT JDO 2
113: return false;
114: }
115:
116: public void jdoReplaceObjectId(Object arg0) {
117: //TODO: IMPLEMENT JDO 2
118: }
119:
120: public boolean jdoIsTransactional() {
121: StateItf sa = speedoGetState();
122: return sa != null
123: && !LifeCycle.isTransient(sa.speedoGetStatus())
124: && LifeCycle.isTransactional(sa.speedoGetStatus());
125: }
126:
127: public boolean jdoIsPersistent() {
128: return speedoIsPersistent();
129: }
130:
131: public boolean jdoIsNew() {
132: StateItf sa = speedoGetState();
133: return sa != null && LifeCycle.isNew(sa.speedoGetStatus());
134: }
135:
136: public boolean jdoIsDeleted() {
137: StateItf sa = speedoGetState();
138: return sa != null && LifeCycle.isDeleted(sa.speedoGetStatus());
139: }
140:
141: public void jdoReplaceStateManager(StateManager sm) {
142: // nothing to do, No StateItf manager is used
143: }
144:
145: public Object jdoNewObjectIdInstance(String s) {
146: return null;
147: }
148:
149: public void jdoCopyKeyFieldsToObjectId(Object o) {
150: throw new JDOUnsupportedOptionException();
151: }
152:
153: public void jdoCopyKeyFieldsToObjectId(
154: PersistenceCapable.ObjectIdFieldSupplier objectIdFieldSupplier,
155: Object o) {
156: throw new JDOUnsupportedOptionException();
157: }
158:
159: public void jdoCopyKeyFieldsFromObjectId(
160: PersistenceCapable.ObjectIdFieldConsumer objectIdFieldConsumer,
161: Object o) {
162: throw new JDOUnsupportedOptionException();
163: }
164:
165: }
|