Permalink
Browse files

Issue 111/112

  • Loading branch information...
tzaeschke committed Aug 26, 2018
1 parent 57e4728 commit c9d64ba761ff579e5c70ed6e01ea8c6af7c3165a
View
@@ -10,6 +10,7 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="examples">
@@ -36,6 +37,7 @@
<classpathentry excluding="**" kind="src" output="target/test-classes" path="tstresources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
@@ -103,4 +103,5 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
@@ -20,6 +20,11 @@
*/
package org.zoodb.api.impl;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
import javax.jdo.ObjectState;
import javax.jdo.listener.ClearCallback;
@@ -44,7 +49,7 @@
*
* @author Tilmann Zaeschke
*/
public abstract class ZooPC {
public abstract class ZooPC implements Serializable {
private static final byte PS_PERSISTENT = 1;
private static final byte PS_TRANSACTIONAL = 2;
@@ -84,29 +89,58 @@
//string indexes. See Issue #55 in Test_091.
private transient Pair<long[], Object[]> prevValues = null;
private transient long txTimestamp = Session.TIMESTAMP_NOT_ASSIGNED;
// private long jdoZooFlags = 0;
//The following are NOT transient because they should survive (de-)serialization
//by third parties.
private long jdoZooOid = Session.OID_NOT_ASSIGNED;
private long txTimestamp = Session.TIMESTAMP_NOT_ASSIGNED;
public final boolean jdoZooIsDirty() {
return (stateFlags & PS_DIRTY) != 0;
return (getStatusFlags() & PS_DIRTY) != 0;
}
public final boolean jdoZooIsNew() {
return (stateFlags & PS_NEW) != 0;
return (getStatusFlags() & PS_NEW) != 0;
}
public final boolean jdoZooIsDeleted() {
return (stateFlags & PS_DELETED) != 0;
return (getStatusFlags() & PS_DELETED) != 0;
}
public final boolean jdoZooIsDetached() {
return (stateFlags & PS_DETACHED) != 0;
return (getStatusFlags() & PS_DETACHED) != 0;
}
public final boolean jdoZooIsTransactional() {
return (stateFlags & PS_TRANSACTIONAL) != 0;
return (getStatusFlags() & PS_TRANSACTIONAL) != 0;
}
public final boolean jdoZooIsPersistent() {
return (stateFlags & PS_PERSISTENT) != 0;
return (getStatusFlags() & PS_PERSISTENT) != 0;
}
public final Node jdoZooGetNode() {
return context.getNode();
}
private ObjectState getStatus() {
recoverFromSerialization();
return status;
}
private byte getStatusFlags() {
recoverFromSerialization();
return stateFlags;
}
private void recoverFromSerialization() {
//This is required in case the Object had been serialized/deserialized,
//which sets the status to null. Spec say it should become DETACHED.
//Implementation or Serializable interface is not suggested by spec.
if (status == null) {
if (jdoZooOid <= 0) {
setTransient();
} else {
setDetachedClean();
}
}
}
//not to be used from outside
private final void setPersNew() {
status = ObjectState.PERSISTENT_NEW;
@@ -167,7 +201,7 @@ public final void jdoZooMarkClean() {
// }
public final void jdoZooMarkDirty() {
jdoZooGetContext().getSession().internalGetCache().flagOGTraversalRequired();
switch (status) {
switch (getStatus()) {
case DETACHED_DIRTY:
//is already dirty
return;
@@ -197,14 +231,14 @@ public final void jdoZooMarkDirty() {
jdoZooMarkDirty();
break;
default:
throw new IllegalStateException("Illegal state transition: " + status + "->Dirty: " +
Util.oidToString(jdoZooOid));
throw new IllegalStateException("Illegal state transition: " + getStatus() +
"->Dirty: " + Util.oidToString(jdoZooOid));
}
context.notifyEvent(this, ZooInstanceEvent.POST_DIRTY);
}
public final void jdoZooMarkDeleted() {
switch (status) {
switch (getStatus()) {
case PERSISTENT_CLEAN:
case PERSISTENT_DIRTY:
setPersDeleted(); break;
@@ -228,12 +262,12 @@ public final void jdoZooMarkDeleted() {
Util.oidToString(jdoZooOid));
default:
throw new IllegalStateException("Illegal state transition(" +
Util.oidToString(jdoZooGetOid()) + "): " + status + "->Deleted");
Util.oidToString(jdoZooGetOid()) + "): " + getStatus() + "->Deleted");
}
}
public final void jdoZooMarkDetached() {
switch (status) {
switch (getStatus()) {
case DETACHED_CLEAN:
case DETACHED_DIRTY:
throw new IllegalStateException("Object is already detached");
@@ -249,7 +283,7 @@ public final void jdoZooMarkHollow() {
}
public final void jdoZooMarkTransient() {
switch (status) {
switch (getStatus()) {
case TRANSIENT:
//nothing to do
break;
@@ -266,7 +300,8 @@ public final void jdoZooMarkTransient() {
case PERSISTENT_NEW_DELETED :
setTransient(); break;
default:
throw new IllegalStateException("Illegal state transition: " + status + "->Deleted");
throw new IllegalStateException("Illegal state transition: " +
getStatus() + "->Deleted");
}
}
@@ -356,7 +391,7 @@ private final void getPrevValues() {
*/
public final void zooActivateRead() {
if (DBTracer.TRACE) DBTracer.logCall(this);
switch (status) {
switch (getStatus()) {
case DETACHED_CLEAN:
//nothing to do
return;
@@ -391,7 +426,7 @@ public final void zooActivateRead() {
return;
default:
throw new IllegalStateException("" + status);
throw new IllegalStateException("" + getStatus());
}
}
@@ -406,7 +441,7 @@ public final void zooActivateRead() {
*/
public final void zooActivateWrite() {
if (DBTracer.TRACE) DBTracer.logCall(this);
switch (status) {
switch (getStatus()) {
case HOLLOW_PERSISTENT_NONTRANSACTIONAL:
try {
context.getSession().lock();
@@ -449,7 +484,7 @@ public final void zooActivateWrite() {
}
default:
}
throw new UnsupportedOperationException(status.toString());
throw new UnsupportedOperationException(getStatus().toString());
}
private void checkActiveForWrite() {
@@ -467,10 +502,6 @@ public final void zooActivateWrite(String field) {
zooActivateWrite();
}
// private long jdoZooFlags = 0;
//TODO instead use some fixed value like INVALID_OID
private transient long jdoZooOid = Session.OID_NOT_ASSIGNED;
// void jdoZooSetFlag(long flag) {
// jdoZooFlags |= flag;
// }
@@ -502,7 +533,8 @@ public ZooPC() {
@Override
public String toString() {
return super.toString() + " oid=" + Util.oidToString(jdoZooOid) + " state=" + status;
return super.toString() + " oid=" + Util.oidToString(jdoZooOid) +
" state=" + getStatus();
}
public void jdoZooSetTimestamp(long ts) {
@@ -512,5 +544,26 @@ public void jdoZooSetTimestamp(long ts) {
public long jdoZooGetTimestamp() {
return txTimestamp;
}
} // end class definition
// private void writeObject(java.io.ObjectOutputStream out) throws IOException {
// out.writeLong(jdoZooOid);
// out.writeObject(status);
// out.writeByte(stateFlags);
//// throw new UnsupportedOperationException();
// }
//
// private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
// jdoZooOid = in.readLong();
// status = (ObjectState) in.readObject();
// stateFlags = in.readByte();
//// throw new UnsupportedOperationException();
// if (status != ObjectState.TRANSIENT) {
// setDetachedClean();
// }
// }
// private void readObjectNoData() throws ObjectStreamException {
// throw new UnsupportedOperationException();
// }
}
@@ -434,6 +434,7 @@ public void associateJavaTypes() {
public void associateJavaTypes(boolean failForMismatch) {
if (cls != null) {
//TODO Why are checking this? String.equals is expensive...
if (!className.equals(ZooClassDef.class.getName()) &&
!className.equals(ZooPC.class.getName())) {
System.out.println("This is new, FIX this!"); //TODO remove
@@ -479,12 +480,15 @@ public void associateJavaTypes(boolean failForMismatch) {
// Now check field count, this should cover missing schema fields (too many Java fields).
// we need to filter out transient and static fields
int n = 0;
for (Field f: cls.getDeclaredFields()) {
int mod = f.getModifiers();
if (Modifier.isTransient(mod) || Modifier.isStatic(mod)) {
continue;
//Ignore any fields in ZooPC
if (cls != ZooPC.class) {
for (Field f: cls.getDeclaredFields()) {
int mod = f.getModifiers();
if (Modifier.isTransient(mod) || Modifier.isStatic(mod)) {
continue;
}
n++;
}
n++;
}
if (localFields.size() != n) {
cls = null;
@@ -545,8 +545,7 @@ public void jdoReplaceDetachedState() {
@Override
public Object jdoGetVersion() {
// TODO Auto-generated method stub
return null;
return jdoZooGetTimestamp();
}
} // end class definition
@@ -249,9 +249,8 @@ public void makeDirty(PersistenceCapable arg0, String arg1) {
@Override
public void preSerialize(PersistenceCapable arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
//return null;
//Materialize object, see 23.7
((PersistenceCapableImpl)arg0).zooActivateRead();
}
Oops, something went wrong.

0 comments on commit c9d64ba

Please sign in to comment.