JPOX
JPOX
 JPOX Version 1.0
Configuration | Tutorials | Worked Examples | Developer
JPOX Design
JPOX Tests
Introduction
About

This document contains general documentation of JPOX design and behaviour.

Guidelines on writing this document

Try to use a simple language, End User language, so this documentation can also be applied to user documentation after review.

JDO - General Information
Clone

The JDO 1.01 specification §20.7 does not completely says how a JDO implementation should behave when instances of FCO are cloned. Here is how JPOX works:

FCO with simple persistent fields that have not been loaded, have their values set to the default java values. The FCO instance get its reference to the StateManager cleared and the FCO changes it state to transient. When the FCO instances have SCO fields, users should implement the clone method to clone the SCO fields, otherwise the newly created instance for the cloned FCO will still refer to the SCO instances refered in the source FCO.

    
public class TheClassName
{
	List fieldList;
	Set fieldSet;
	
	//... getters setters and everything else...
	
	public Object clone()
	{
		Object obj = null;
		try
	    {
	    	obj = super.clone();
	
			List tempList = new ArrayList(fieldList);
			((TheClassName)obj).fieldList = tempList;
	
			Set tempSet = new HashSet(this.fieldSet);
			((TheClassName)obj).fieldSet = tempSet;	
	    }
	    catch (CloneNotSupportedException e) {}
	   	
	    return obj;
	}                
}
Disconnect PC objects from PMs

A PersistenceCapable object instance being disconnected changes to transient state and have its reference to the StateManager cleared. SCO persistent fields in the PersistenceCapable object hold a reference to the PersistenceCapable object, and in the moment the PersistenceCapable object is disconnected this reference is cleared in the SCO. This reference from the SCO to PersistenceCapable object is called owner, and the reason of clearing it is to avoid the SCO refer to the database when doing SCO operations, like iterator(), size(), etc. The SCO can't refer to the database when his owner is empty or his owner is not associated to a PersistenceManager. A SCO with no reference to an owner will not refer to the database to read the data it holds. With this reason, JPOX get a snapshot from the database and populate the SCO instance, and later disconnect the SCO instance from a managed state.

Making objects transient

To make an object transient, JPOX disconnects the object from the PersistenceManager. You can optionally disconnect its fields from the PersistenceManager by using makeTransient(All) on these fields.

To make an Persistence Capable object transient together with a field collection, the user should use a code like this:

public class PcClass
{
	Set elements;
	
	// getter and setters
}
    
...
tx.begin();
PcClass pcObject = (PcClass) pm.getObjectById(id,true);

//the relevant code:

//first retrieve the fields
pm.retrieveAll(pcObject.getElements());

//second, make the FCO object transient
pm.makeTransient(pcObject);

//third, make all elements inside the SCO transient
pm.makeTransientAll(pcObject.getElements());
tx.commit();
JPOX Enhancer
Verifying classes after enhancement

You can use BCEL to verify the compability of a class file and check if it the bytecode generated conforms to the Java VM specification

    
java -cp bcel-5.1.jar;JarWithEnhancedFiles.jar org.apache.bcel.verifier.Verifier xxx.xxx.xxx.JavaClassNameToVerify