net.sf.beanlib.hibernate3
Class Hibernate3DtoCopier

java.lang.Object
  extended by net.sf.beanlib.hibernate3.Hibernate3DtoCopier

public class Hibernate3DtoCopier
extends Object

Hibernate 3 Data Transfer Object Copier.

A simple facade of HibernateBeanReplicator, this class provides a simplified (but limited) API for the common use cases to conveniently replicate Hibernate objects that follow the JavaBean getter/setter convention on a best attempt basis.

Those application specific Hibernate objects would typically have the same package prefix.

The replication is typically recursive in that the whole object graph of the input object is replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary. However, the exact behavior of the replication process can be controlled and/or supplemented by the client code via 3 main options:

  1. Specifying an application package prefix: property with a type of an entity bean class with package name that matchs the prefix will be replicated;
  2. Specifying a set of entity bean classes: property with a type of an entity bean class that is part of the set will be replicated;
  3. Specifying a set of collection and map properties that will be replicated;
For more advanced options and more control, consider using Hibernate3BeanReplicator directly.

Author:
Joe D. Velopar
See Also:
Hibernate3BeanReplicator

Field Summary
private  String applicationPackagePrefix
          An entity bean under a package with a name that matches this prefix will be included for replication, eagerly fetched if necessary.
 
Constructor Summary
Hibernate3DtoCopier()
          Constructs with application package prefix disabled.
Hibernate3DtoCopier(String applicationPackagePrefix)
          Constructs with an application package prefix.
Hibernate3DtoCopier(String applicationPackagePrefix, Class<?> applicationSampleClass)
          Constructs with an application package prefix, and a sample application class in a package with such prefix for sanity checking purposes.
 
Method Summary
private
<E> E
copy(Class<E> targetEntityType, Object from, Class<?>[] interestedEntityTypes)
          Returns a DTO of the specified target entity type by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, excluding all collection and map properties.
private
<E> E
copy(Class<E> targetEntityType, Object from, Class<?>[] interestedEntityTypes, CollectionPropertyName<?>[] collectionPropertyNames)
          Returns a DTO of the specified target entity type by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.
private  Object copy(Object from, Class<?>[] interestedEntityTypes)
          Returns a DTO by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, excluding all collection and map properties.
protected  Hibernate3BeanReplicator createHibernateBeanReplicator()
          Returns the implementation instance that performs the actual replication.
<E> List<E>
hibernate2dto(Class<E> targetEntityType, Collection<?> hibernateBeans, Class<?>[] interestedEntityTypes, CollectionPropertyName<?>[] collectionPropertyNames)
          Returns a list of DTO's of the specified target entity type by partially cloning the object graphs of the given collection of Hibernate entity beans that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.
<E,T> E
hibernate2dto(Class<E> targetEntityType, T entityBean)
          Returns a DTO of the specified target entity type by cloning portion of the object graph of the given Hibernate bean, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.
<E,T> E
hibernate2dto(Class<E> targetEntityType, T from, Class<?>[] interestedEntityTypes, CollectionPropertyName<?>[] collectionPropertyNames)
          Returns a DTO of the specified target entity type by partially cloning the object graphs of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.
 List<?> hibernate2dto(Collection<?> hibernateBeans)
          Returns a list of DTO's by partially cloning the object graphs of the given collection of Hibernate entity beans, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.
<T> T
hibernate2dto(Object entityBean)
          Returns a DTO by cloning portion of the object graph of the given Hibernate bean, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.
<T> T
hibernate2dto(T from, Class<?>[] interestedEntityTypes, CollectionPropertyName<?>[] collectionPropertyNames)
          Returns a DTO by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.
 List<?> hibernate2dtoFully(Collection<?> hibernateBeans)
          Returns a list of DTO's by deep cloning the application specific entities of the given collection of Hibernate beans.
<T> T
hibernate2dtoFully(Object from)
          Returns a DTO by deep cloning the application specific entities of the given Hibernate "from" instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationPackagePrefix

private final String applicationPackagePrefix
An entity bean under a package with a name that matches this prefix will be included for replication, eagerly fetched if necessary.

Constructor Detail

Hibernate3DtoCopier

public Hibernate3DtoCopier()
Constructs with application package prefix disabled.


Hibernate3DtoCopier

public Hibernate3DtoCopier(String applicationPackagePrefix)
Constructs with an application package prefix.

See Also:
applicationPackagePrefix

Hibernate3DtoCopier

public Hibernate3DtoCopier(String applicationPackagePrefix,
                           Class<?> applicationSampleClass)
Constructs with an application package prefix, and a sample application class in a package with such prefix for sanity checking purposes.

Throws:
IllegalArgumentException - if the given application package prefix does not match the package of the given sample application class.
See Also:
applicationPackagePrefix
Method Detail

createHibernateBeanReplicator

protected Hibernate3BeanReplicator createHibernateBeanReplicator()
Returns the implementation instance that performs the actual replication.


hibernate2dtoFully

public <T> T hibernate2dtoFully(Object from)
Returns a DTO by deep cloning the application specific entities of the given Hibernate "from" instance.

If you need to "blindly" deep clone the entire object graph, consider using hibernate2dto(Class, Object, Class[], CollectionPropertyName[]) specifying null for the interstedPropertyTypes and collectionPropertyNames.


hibernate2dtoFully

public List<?> hibernate2dtoFully(Collection<?> hibernateBeans)
Returns a list of DTO's by deep cloning the application specific entities of the given collection of Hibernate beans.

If you need to "blindly" deep clone the entire object graph, consider using hibernate2dto(Class, Collection, Class[], CollectionPropertyName[]) specifying null for the interstedPropertyTypes and collectionPropertyNames.


hibernate2dto

public <T> T hibernate2dto(Object entityBean)
Returns a DTO by cloning portion of the object graph of the given Hibernate bean, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
entityBean - Hibernate entity bean to be cloned
See Also:
applicationPackagePrefix

hibernate2dto

public <E,T> E hibernate2dto(Class<E> targetEntityType,
                             T entityBean)
Returns a DTO of the specified target entity type by cloning portion of the object graph of the given Hibernate bean, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
targetEntityType - target entity type
entityBean - Hibernate entity bean to be cloned
See Also:
applicationPackagePrefix

hibernate2dto

public <T> T hibernate2dto(T from,
                           Class<?>[] interestedEntityTypes,
                           CollectionPropertyName<?>[] collectionPropertyNames)
Returns a DTO by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.

Parameters:
from - given Hibernate entity bean to be cloned
interestedEntityTypes - properties of these types will be included for cloning
collectionPropertyNames - collection and map properties to be included in the cloning
See Also:
applicationPackagePrefix

hibernate2dto

public <E,T> E hibernate2dto(Class<E> targetEntityType,
                             T from,
                             Class<?>[] interestedEntityTypes,
                             CollectionPropertyName<?>[] collectionPropertyNames)
Returns a DTO of the specified target entity type by partially cloning the object graphs of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
targetEntityType - target entity type
from - given Hibernate entity bean to be cloned
interestedEntityTypes - properties of these types will be included for cloning
collectionPropertyNames - collection and map properties to be included in the cloning
See Also:
applicationPackagePrefix

hibernate2dto

public List<?> hibernate2dto(Collection<?> hibernateBeans)
Returns a list of DTO's by partially cloning the object graphs of the given collection of Hibernate entity beans, excluding all collection and map properties, and including only those properties with package names that match the application package prefix.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
hibernateBeans - given collection of Hibernate Beans.
See Also:
applicationPackagePrefix

hibernate2dto

public <E> List<E> hibernate2dto(Class<E> targetEntityType,
                                 Collection<?> hibernateBeans,
                                 Class<?>[] interestedEntityTypes,
                                 CollectionPropertyName<?>[] collectionPropertyNames)
Returns a list of DTO's of the specified target entity type by partially cloning the object graphs of the given collection of Hibernate entity beans that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.

Parameters:
hibernateBeans - given collection of Hibernate entity beans to be cloned
interestedEntityTypes - properties of these types will be included for cloning
collectionPropertyNames - collection and map properties to be included in the cloning
See Also:
applicationPackagePrefix

copy

private Object copy(Object from,
                    Class<?>[] interestedEntityTypes)
Returns a DTO by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, excluding all collection and map properties.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
from - given entity bean to be cloned
interestedEntityTypes - properties of these types will be included for cloning
See Also:
applicationPackagePrefix

copy

private <E> E copy(Class<E> targetEntityType,
                   Object from,
                   Class<?>[] interestedEntityTypes)
Returns a DTO of the specified target entity type by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, excluding all collection and map properties.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
targetEntityType - target entity type
from - given entity bean to be cloned
interestedEntityTypes - properties of these types will be included for cloning
See Also:
applicationPackagePrefix

copy

private <E> E copy(Class<E> targetEntityType,
                   Object from,
                   Class<?>[] interestedEntityTypes,
                   CollectionPropertyName<?>[] collectionPropertyNames)
Returns a DTO of the specified target entity type by partially cloning the object graph of the given Hibernate "from" instance that follows the JavaBean getter/setter convention on a best attempt basis, including only those properties that are explicitly specified, or implied by the application package prefix.

The replication is typically recursive in that the object graph of the input object is basically replicated into an equivalent output object graph, resolving circular references, and eagerly fetching proxied instances as necessary.

Parameters:
targetEntityType - target entity type
from - given Hibernate entity bean to be cloned
interestedEntityTypes - properties of these types will be included for cloning
collectionPropertyNames - collection and map properties to be included in the cloning
See Also:
applicationPackagePrefix