org.openxava.model.impl
Class POJOPersistenceProviderBase

java.lang.Object
  extended by org.openxava.model.impl.POJOPersistenceProviderBase
All Implemented Interfaces:
IPersistenceProvider
Direct Known Subclasses:
HibernatePersistenceProvider, JPAPersistenceProvider

public abstract class POJOPersistenceProviderBase
extends java.lang.Object
implements IPersistenceProvider

Abstract class for create Persistence Providers based in POJOs.

Author:
Javier Paniza

Constructor Summary
POJOPersistenceProviderBase()
           
 
Method Summary
 java.lang.Object create(MetaModel metaModel, java.util.Map values)
          Create a persistent object (saved in database) from the data passed in map format.
 java.lang.Object createAggregate(MetaModel metaModel, java.util.Map values, MetaModel metaModelContainer, java.lang.Object containerModel, int number)
          Create an aggregate (saving it in database) from the data passed in map format.
protected abstract  java.lang.Object createQuery(java.lang.String query)
          Creates a query, it can be Hibernate query or JPA query.
protected abstract  java.lang.Object find(java.lang.Class pojoClass, java.io.Serializable key)
          Return the object associated to the sent key.
 java.lang.Object find(MetaModel metaModel, java.util.Map keyValues)
          Find an object from its key in map format.
protected  java.lang.Object find(MetaModel metaModel, java.util.Map keyValues, boolean useQueryForFind)
           
 java.lang.Object find(MetaModel metaModel, java.lang.Object key)
          Find a object from its key object.
 java.lang.Object findByAnyProperty(MetaModel metaModel, java.util.Map keyValues)
          Find an object by any property (or properties).
 java.lang.Object findByKeyUsingQuery(MetaModel metaModel, java.util.Map keyValues)
           
 java.lang.Object getContainer(MetaModel metaModel, java.util.Map containerKeyValues)
          Return the object that represents the container object.
 java.lang.Object getKey(MetaModel metaModel, java.util.Map keyValues)
          Return an object that can be used as primary key in model layer.
protected abstract  java.lang.Object getUniqueResult(java.lang.Object query)
          Returns the unique result of the sent query.
 java.util.Map keyToMap(MetaModel metaModel, java.lang.Object key)
          Returns a map that contains the value of primary key sent as object.
protected abstract  void persist(java.lang.Object object)
          Marks the object as persistent.
protected abstract  void setParameterToQuery(java.lang.Object query, java.lang.String name, java.lang.Object value)
          Sets the parameter to the indicated query.
 IPropertiesContainer toPropertiesContainer(MetaModel metaModel, java.lang.Object o)
          Return an IPropertiesContainer to manage using introspection the sent object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openxava.model.impl.IPersistenceProvider
begin, commit, flush, reassociate, refreshIfManaged, remove, rollback
 

Constructor Detail

POJOPersistenceProviderBase

public POJOPersistenceProviderBase()
Method Detail

find

protected abstract java.lang.Object find(java.lang.Class pojoClass,
                                         java.io.Serializable key)
Return the object associated to the sent key.


persist

protected abstract void persist(java.lang.Object object)
Marks the object as persistent.


createQuery

protected abstract java.lang.Object createQuery(java.lang.String query)
Creates a query, it can be Hibernate query or JPA query.


setParameterToQuery

protected abstract void setParameterToQuery(java.lang.Object query,
                                            java.lang.String name,
                                            java.lang.Object value)
Sets the parameter to the indicated query.

The query is of the type returned by createQuery method.


getUniqueResult

protected abstract java.lang.Object getUniqueResult(java.lang.Object query)
Returns the unique result of the sent query.

It does not fail if there more than one match, in this case must returns the first one.

Parameters:
query - Of the type returned by createQuery method.
Returns:
Null if not result.

find

public java.lang.Object find(MetaModel metaModel,
                             java.util.Map keyValues)
                      throws FinderException
Description copied from interface: IPersistenceProvider
Find an object from its key in map format.

Specified by:
find in interface IPersistenceProvider
Returns:
Never null.
Throws:
FinderException

find

protected java.lang.Object find(MetaModel metaModel,
                                java.util.Map keyValues,
                                boolean useQueryForFind)
                         throws FinderException
Throws:
FinderException

find

public java.lang.Object find(MetaModel metaModel,
                             java.lang.Object key)
                      throws FinderException
Description copied from interface: IPersistenceProvider
Find a object from its key object.

Specified by:
find in interface IPersistenceProvider
Returns:
Never null.
Throws:
FinderException

toPropertiesContainer

public IPropertiesContainer toPropertiesContainer(MetaModel metaModel,
                                                  java.lang.Object o)
                                           throws XavaException
Description copied from interface: IPersistenceProvider
Return an IPropertiesContainer to manage using introspection the sent object.

Specified by:
toPropertiesContainer in interface IPersistenceProvider
Throws:
XavaException

create

public java.lang.Object create(MetaModel metaModel,
                               java.util.Map values)
                        throws CreateException,
                               ValidationException,
                               XavaException
Description copied from interface: IPersistenceProvider
Create a persistent object (saved in database) from the data passed in map format.

Specified by:
create in interface IPersistenceProvider
Throws:
CreateException
ValidationException
XavaException

getKey

public java.lang.Object getKey(MetaModel metaModel,
                               java.util.Map keyValues)
                        throws XavaException
Description copied from interface: IPersistenceProvider
Return an object that can be used as primary key in model layer.

For example, in EJB2 will be the Key class, in Hibernate can be the POJO class, and JPA ...

Specified by:
getKey in interface IPersistenceProvider
Throws:
XavaException

getContainer

public java.lang.Object getContainer(MetaModel metaModel,
                                     java.util.Map containerKeyValues)
                              throws XavaException
Description copied from interface: IPersistenceProvider
Return the object that represents the container object.

The container object apply only to aggregates, and it's the object that containt to the aggregate. It can be a POJO or key class, depends on the implementation.

Specified by:
getContainer in interface IPersistenceProvider
Throws:
XavaException

keyToMap

public java.util.Map keyToMap(MetaModel metaModel,
                              java.lang.Object key)
                       throws XavaException
Description copied from interface: IPersistenceProvider
Returns a map that contains the value of primary key sent as object.

The map must contain at least the primary key value, but it can contains more, the rest is ignored.

Specified by:
keyToMap in interface IPersistenceProvider
Throws:
XavaException

createAggregate

public java.lang.Object createAggregate(MetaModel metaModel,
                                        java.util.Map values,
                                        MetaModel metaModelContainer,
                                        java.lang.Object containerModel,
                                        int number)
                                 throws CreateException,
                                        ValidationException,
                                        java.rmi.RemoteException,
                                        XavaException
Description copied from interface: IPersistenceProvider
Create an aggregate (saving it in database) from the data passed in map format.

Specified by:
createAggregate in interface IPersistenceProvider
Parameters:
metaModel - of the aggregate to create.
values - Values to fill aggregate before save.
metaModelContainer - of model that will contain the aggregate.
containerModel - The object that will contain the new aggregate.
number - This number will be passed to calculator of type IAggregateOidCalculator, it can use this number to calculate the oid. It's a simple counter.
Throws:
CreateException
ValidationException
java.rmi.RemoteException
XavaException

findByAnyProperty

public java.lang.Object findByAnyProperty(MetaModel metaModel,
                                          java.util.Map keyValues)
                                   throws ObjectNotFoundException,
                                          FinderException,
                                          XavaException
Description copied from interface: IPersistenceProvider
Find an object by any property (or properties).

Returns the first object that match with the sent arguments (searchingValues).

Specified by:
findByAnyProperty in interface IPersistenceProvider
Returns:
Never null.
Throws:
ObjectNotFoundException
FinderException
XavaException

findByKeyUsingQuery

public java.lang.Object findByKeyUsingQuery(MetaModel metaModel,
                                            java.util.Map keyValues)
                                     throws ObjectNotFoundException,
                                            FinderException,
                                            XavaException
Throws:
ObjectNotFoundException
FinderException
XavaException