/**
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.genclass.jdo;
import org.objectweb.speedo.genclass.GenClass;
import org.objectweb.speedo.mim.api.LifeCycle;
import org.objectweb.speedo.mim.api.StateItf;
import org.objectweb.speedo.mim.jdo.api.JDOPersistentObjectItf;
import javax.jdo.JDOUnsupportedOptionException;
import javax.jdo.PersistenceManager;
import javax.jdo.spi.PersistenceCapable;
import javax.jdo.spi.StateManager;
/**
*
*
* @author S.Chassande-Barrioz
*/
public abstract class JDOGenClass extends GenClass implements JDOPersistentObjectItf {
// IMPLEMENTATION OF THE PersistentCapable INTERFACE //
//---------------------------------------------------//
// Speedo implements partialy the javax.jdo.spi package. Then only the
// minimal method are implemented. The others throw a
// JDOUnsupportedOptionException exception.
public PersistenceManager jdoGetPersistenceManager() {
return (PersistenceManager) (speedoIsActive ? speedoGetHome().getPOManagerFactory().lookup() : null);
}
public void jdoReplaceFlags() {
throw new JDOUnsupportedOptionException();
}
public PersistenceCapable jdoNewInstance(StateManager sm) {
throw new JDOUnsupportedOptionException();
}
public PersistenceCapable jdoNewInstance(StateManager sm, Object oid) {
throw new JDOUnsupportedOptionException();
}
public Object jdoNewObjectIdInstance(Object arg0) {
throw new JDOUnsupportedOptionException();
}
public Object jdoNewObjectIdInstance() {
throw new JDOUnsupportedOptionException();
}
public Object jdoGetObjectId() {
return getPName();
}
public Object jdoGetVersion() {
return getPName();
}
public Object jdoGetTransactionalObjectId() {
return getPName();
}
public void jdoReplaceField(int fieldNumber) {
throw new JDOUnsupportedOptionException();
}
public void jdoReplaceFields(int[] fieldNumbers) {
throw new JDOUnsupportedOptionException();
}
public void jdoProvideField(int fieldNumber) {
throw new JDOUnsupportedOptionException();
}
public void jdoProvideFields(int[] fieldNumbers) {
throw new JDOUnsupportedOptionException();
}
public void jdoCopyFields(Object pc, int[] fieldNumbers) {
throw new JDOUnsupportedOptionException();
}
public void jdoMakeDirty(String fieldName) {
// no fields => does nothing
}
public boolean jdoIsDirty() {
StateItf sa = speedoGetState();
return sa != null
&& !LifeCycle.isTransient(sa.speedoGetStatus())
&& LifeCycle.isDirty(sa.speedoGetStatus());
}
public boolean jdoIsDetached() {
//TODO: IMPLEMENT JDO 2
return false;
}
public void jdoReplaceObjectId(Object arg0) {
//TODO: IMPLEMENT JDO 2
}
public boolean jdoIsTransactional() {
StateItf sa = speedoGetState();
return sa != null
&& !LifeCycle.isTransient(sa.speedoGetStatus())
&& LifeCycle.isTransactional(sa.speedoGetStatus());
}
public boolean jdoIsPersistent() {
return speedoIsPersistent();
}
public boolean jdoIsNew() {
StateItf sa = speedoGetState();
return sa != null && LifeCycle.isNew(sa.speedoGetStatus());
}
public boolean jdoIsDeleted() {
StateItf sa = speedoGetState();
return sa != null && LifeCycle.isDeleted(sa.speedoGetStatus());
}
public void jdoReplaceStateManager(StateManager sm) {
// nothing to do, No StateItf manager is used
}
public Object jdoNewObjectIdInstance(String s) {
return null;
}
public void jdoCopyKeyFieldsToObjectId(Object o) {
throw new JDOUnsupportedOptionException();
}
public void jdoCopyKeyFieldsToObjectId(PersistenceCapable.ObjectIdFieldSupplier objectIdFieldSupplier, Object o) {
throw new JDOUnsupportedOptionException();
}
public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer objectIdFieldConsumer, Object o) {
throw new JDOUnsupportedOptionException();
}
}