/*
$Header: /cvsroot/xorm/xorm/tests/src/org/xorm/tests/model/JDOEnhanced.java,v 1.1 2002/09/30 03:26:08 wbiggs Exp $
This file is part of XORM.
XORM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
XORM 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with XORM; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xorm.tests.model;
import javax.jdo.spi.PersistenceCapable;
import javax.jdo.spi.StateManager;
import javax.jdo.PersistenceManager;
/**
* This class simulates the structure of a reference-enhanced JDO class.
*/
public class JDOEnhanced implements PersistenceCapable {
private String str;
public String getStr() {
return jdoGetstr(this);
}
public void setStr(String str) {
jdoSetstr(this, str);
}
// 20.20.1 Generated fields
protected transient StateManager jdoStateManager = null;
protected transient byte jdoFlags = PersistenceCapable.READ_WRITE_OK;
private final static int jdoInheritedFieldCount = 0;
private final static String[] jdoFieldNames = { "str" };
private final static Class[] jdoFieldTypes = { String.class };
private final static byte[] jdoFieldFlags = { CHECK_READ + CHECK_WRITE };
private final static Class jdoPersistenceCapableSuperclass = null;
// 20.20.2 Generated static initializer
static {
javax.jdo.spi.JDOImplHelper.registerClass
(JDOEnhanced.class,
jdoFieldNames,
jdoFieldTypes,
jdoFieldFlags,
jdoPersistenceCapableSuperclass,
new JDOEnhanced());
}
// 20.20.3 Generated interrogatives
public final boolean jdoIsPersistent() {
return jdoStateManager==null?false:
jdoStateManager.isPersistent(this);
}
public final boolean jdoIsTransactional(){
return jdoStateManager==null?false:
jdoStateManager.isTransactional(this);
}
public final boolean jdoIsNew(){
return jdoStateManager==null?false:
jdoStateManager.isNew(this);
}
public final boolean jdoIsDirty(){
return jdoStateManager==null?false:
jdoStateManager.isDirty(this);
}
public final boolean jdoIsDeleted(){
return jdoStateManager==null?false:
jdoStateManager.isDeleted(this);
}
public final void jdoMakeDirty (String fieldName){
if (jdoStateManager==null) return;
jdoStateManager.makeDirty(this, fieldName);
}
public final PersistenceManager jdoGetPersistenceManager(){
return jdoStateManager==null?null:
jdoStateManager.getPersistenceManager(this);
}
public final Object jdoGetObjectId(){
return jdoStateManager==null?null:
jdoStateManager.getObjectId(this);
}
public final Object jdoGetTransactionalObjectId(){
return jdoStateManager==null?null:
jdoStateManager.getTransactionalObjectId(this);
}
// 20.20.4 Generated jdoReplaceStateManager
public final synchronized void jdoReplaceStateManager(StateManager sm) {
// throws exception if current sm didn't request the change
if (jdoStateManager != null) {
jdoStateManager = jdoStateManager.replacingStateManager (this,
sm);
} else {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission( // throws exception if not authorized
javax.jdo.spi.JDOPermission.SET_STATE_MANAGER);
}
jdoStateManager = sm;
}
}
// 20.20.5 Generated jdoReplaceFlags
public final void jdoReplaceFlags() {
if (jdoStateManager != null) {
jdoFlags = jdoStateManager.replacingFlags (this);
}
}
// 20.20.6 Generated jdoNewInstance helpers
public PersistenceCapable jdoNewInstance(StateManager sm) {
// if class is abstract, throw new JDOFatalInternalException()
JDOEnhanced pc = new JDOEnhanced ();
pc.jdoStateManager = sm;
pc.jdoFlags = LOAD_REQUIRED;
return pc;
}
public PersistenceCapable jdoNewInstance(StateManager sm, Object object) {
// if class is abstract, throw new JDOFatalInternalException()
JDOEnhanced pc = new JDOEnhanced ();
pc.jdoStateManager = sm;
pc.jdoFlags = LOAD_REQUIRED;
// now copy the key fields into the new instance
//jdoCopyKeyFieldsFromObjectId (oid);
return pc;
}
// 20.20.7
public int jdoGetManagedFieldCount() {
return jdoFieldNames.length;
}
// 20.20.8
private final static String jdoGetstr(JDOEnhanced x) {
// this field is in the default fetch group (CHECK_READ)
if (x.jdoFlags <= READ_WRITE_OK) {
// ok to read
return x.str;
}
// field needs to be fetched from StateManager
// this call might result in str being stored in instance
StateManager sm = x.jdoStateManager;
if (sm != null) {
if (sm.isLoaded (x, 0))
return x.str;
return sm.getStringField(x, 0,
x.str);
} else {
return x.str;
}
}
private final static void
jdoSetstr(JDOEnhanced x, String newValue) {
// this field is in the default fetch group
if (x.jdoFlags == READ_WRITE_OK) {
// ok to read, write
x.str = newValue;
return;
}
StateManager sm = x.jdoStateManager;
if (sm != null) {
sm.setStringField(x, 0, x.str, newValue);
} else {
x.str = newValue;
}
}
// 20.20.10 Generated jdoReplaceField and jdoReplaceFields
public void jdoReplaceField(int fieldNumber) {
switch (fieldNumber) {
case 0:
str = jdoStateManager.replacingStringField (this,
fieldNumber);
break;
default:
throw new IllegalArgumentException("fieldNumber");
}
}
public void jdoReplaceFields(int[] fieldNumbers) {
for (int i = 0; i < fieldNumbers.length; ++i) {
int fieldNumber = fieldNumbers[i];
jdoReplaceField (fieldNumber);
}
}
// 20.20.11 Generated jdoProvideField and jdoProvideFields
public void jdoProvideField(int fieldNumber) {
switch (fieldNumber) {
case 0:
jdoStateManager.providedStringField (this, fieldNumber, str);
break;
default:
throw new IllegalArgumentException("fieldNumber");
}
}
public void jdoProvideFields(int[] fieldNumbers) {
for (int i = 0; i < fieldNumbers.length; ++i) {
int fieldNumber = fieldNumbers[i];
jdoProvideField (fieldNumber);
}
}
// 20.20.12 Generated jdoCopyField and jdoCopyFields
public void jdoCopyFields(Object pc, int[] fieldNumbers) {
// the other instance must be owned by the same StateManager
// and our StateManager must not be null!
if (((JDOEnhanced)pc).jdoStateManager
!= this.jdoStateManager)
throw new IllegalArgumentException("this.jdoStateManager != other.jdoStateManager");
if (this.jdoStateManager == null)
throw new IllegalStateException("this.jdoStateManager == null");
// throw ClassCastException if other class is the wrong class
JDOEnhanced other = (JDOEnhanced) pc;
for (int i = 0; i < fieldNumbers.length; ++i) {
jdoCopyField (other, fieldNumbers[i]);
} // for loop
}
protected void jdoCopyField(JDOEnhanced other, int fieldNumber) {
switch (fieldNumber) {
case 0:
this.str = other.str;
break;
default:
throw new IllegalArgumentException("fieldNumber");
}
}
// 20.20.13
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException{
jdoPreSerialize();
out.defaultWriteObject ();
}
// 20.20.14
private final void jdoPreSerialize() {
if (jdoStateManager != null)
jdoStateManager.preSerialize(this);
}
// 20.20.15
public Object jdoNewObjectIdInstance() {
return null;
}
public Object jdoNewObjectIdInstance(String arg) {
return null;
}
// 20.20.16
public void jdoCopyKeyFieldsToObjectId(PersistenceCapable.ObjectIdFieldSupplier supplier, Object oid) {
}
public void jdoCopyKeyFieldsToObjectId(Object oid) {
}
// 20.20.17
public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer consumer, Object oid) {
}
}