com.xavax.xstore.tools
Class ProxyBuilder
Object
ProxyBuilder
- public class ProxyBuilder
- extends Object
ProxyBuilder is a tool for building proxy classes for persistent
objects. The Proxy pattern is essential to implementing demand-
loading of persistent objects which is a fundamental concept of
the persistence framework. When the client performs a query, what
is returned is a collection of proxies for persistent objects.
The first attempt to use a proxy object will result in loading
the persistent object if it is not already in the object cache.
When the client creates a new proxy object, the persistence
framework creates the actual persistent object and registers it
with the object directory of the current persistence context.
Before using ProxyBuilder, one must separate the interface from
the implementation of the class to be persisted. Typically, the
original class is renamed to become the implementation class and
an interface is defined using the old name. The generated proxy
class implements this interface; therefore, a proxy can be cast
as the interface, thereby reducing the need for changes to code
which used the old class name. The only lines of code which must
change are those which create new objects. For example: the class
User is renamed to UserImpl and an interface named User is created.
Since a UserProxy is a User, the proxy can be cast as a User
and passed to any code which previously used the old User class.
Instances of "new User(...)" must change to "new UserProxy(...)".
The generated proxy class extends AbstractProxy and implements all
methods defined by the interface and any superinterfaces. The
proxy contains a reference to a Link which is an object directory
entry. All methods delegate to methods in the implementation
class which are accessed via the link. The proxy class defines
a constructor with the same signature as each constructor defined
by the implementation class. Defining constructors allows the
creation of new proxy objects using the same parameters used to
create instances of the old class. The proxy constructors delegate
to implementation class constructors to create the implementation
object, then register the object in the object directory of the
current persistence context.
ProxyBuilder uses reflection to determine the methods defined by
the interface and any superinterfaces, and the constructors defined
by the implementation class. For this reason, it is essential for
these classes to appear in the classpath when running ProxyBuilder.
ProxyBuilder expects 4 command line parameters: the package name,
interface name, implementation class name, and proxy class name.
The interface and class names are unqualified and all must belong
to the specified package. ProxyBuilder is a Java application and
can be executed as follows.
TOOLS=com.xavax.xstore.tools
java ${TOOLS}.ProxyBuilder
package interface
implementation proxy [factory]
It is recommended that ProxyBuilder be invoked from a makefile or
Ant build file with automatic dependency rules that rebuild the
proxy class if the interface or implementation changes. See the
demo package for examples.
Method Summary |
static void |
main(String[] args)
Run the ProxyBuilder and generate a proxy class. |
Methods inherited from class Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
main
public static void main(String[] args)
- Run the ProxyBuilder and generate a proxy class.
- Parameters:
args
- the command line arguments.
args[0] | The package name. |
args[1] | The interface name. |
args[2] | The implementation class name. |
args[3] | The proxy class name. |
args[4] | The factory class name (optional). |