SRJRCFrames
v0.1.296

de.schwarzrot.data.access
Class Repository

java.lang.Object
  extended by de.schwarzrot.data.access.Repository
All Implemented Interfaces:
EntityDescriptorAccessor

public class Repository
extends Object
implements EntityDescriptorAccessor

application proxy to persistence. Cuts all persistence related code from application, where you only handle beans called Entity. With introduction of transaction handling at client level, Repository has moved behind the curtain. New application code does not need to use Repository directly. TransactionFactory should do all needed tasks.

The repository uses EntityManager that really perform the persistence tasks. An EntityManager is responsible for certain Entity and all its subclasses.

It is possible to use only one EntityManager to work together with a single data storage (database). Alternatively arbitrary EntityManager s could be used to distribute the Entity types between different data storages.

Currently exists three storage implementations:

a sample ApplicationContext setup for repository looks like:

  <bean id="repository" class="de.schwarzrot.data.access.Repository">
        <property name="userNameProvider">
           <!-- 
             // IMPORTANT: must be set before the managers-map!
             -->
           <ref bean="securityManager"/>
        </property>
        <property name="managers">
           <map>
              <entry key="de.schwarzrot.app.domain.AbstractConfigBase" value-ref="preferencesManager"/>
              <entry key="de.schwarzrot.epg.data.domain.Timer" value-ref="vdrEntityManager"/>
              <entry key="de.schwarzrot.data.Entity" value-ref="jdbcEntityManager"/>
              <entry key="java.lang.Object" value-ref="baseEntityManager"/>
           </map>
        </property>
        <property name="preloadEntities">
           <list>
             <value>de.schwarzrot.data.domain.AccessType</value>
             <value>de.schwarzrot.data.domain.AddressType</value>
           </list>
        </property>
     </bean>
 
The userNameProvider is mandatory, as well as (at least) one EntityManager. The setup of preloadEntities property is optional. If you need to load entities before the application starts, this is the place to do so.

Author:
Reinhard Mantey
See Also:
EntityManager

Constructor Summary
Repository()
           
 
Method Summary
protected  Transaction createTransaction()
           
 void dumpTypeCache()
           
 void executeTransaction(Transaction transaction)
          this call is not of public interest.
<E extends Entity>
List<E>
find(Class<E> entityType)
          find all instances of given type, without resolving relations.
<E extends Entity>
List<E>
find(Class<E> entityType, boolean readRelated)
          find all instances of given type, optionally with resolving of relations.
<E extends Entity>
List<E>
find(Class<E> entityType, int maxRows)
          find all instances of given type, without resolving relations.
<E extends Entity>
List<E>
find(Class<E> entityType, List<ConditionElement> args)
          find all instances of given type, that match given condition, without resolving relations.
<E extends Entity>
List<E>
find(Class<E> entityType, List<ConditionElement> args, boolean readRelated)
          find all instances of given type, that match given condition, with optionally resolving relations.
<E extends Entity>
List<E>
find(Class<E> entityType, List<ConditionElement> args, int maxRows)
          find all instances of given type, that match given condition, without resolving relations.
<E extends Entity>
List<E>
find(Class<E> entityType, List<ConditionElement> args, int maxRows, boolean readRelated)
          find all instances of given type, optionally with resolving of relations.
<E extends Entity>
TransactionStatus
find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType)
          read all entries of given entity type, without resolving relations and add the found instances to the given list.
<E extends Entity>
TransactionStatus
find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, boolean readRelated)
          read all entries of given entity type and add the found instances to the given list.
<E extends Entity>
TransactionStatus
find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, List<ConditionElement> args)
          read all entries of given entity type, that conform the given condition and add the found instances to the given list.
<E extends Entity>
TransactionStatus
find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, List<ConditionElement> args, int maxRows, boolean readRelated)
          read all entries of given entity type, that conform the given condition and add the found instances to the given list.
<E extends Entity>
List<E>
findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, boolean uniq)
          partially read instances of given entityType, that match given condition.
<E extends Entity>
List<E>
findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, int maxRows)
          partially read instances of given entityType, that match given condition.
<E extends Entity>
List<E>
findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, int maxRows, boolean uniq)
          partially read instances of given entityType, that match given condition.
<E extends Entity>
TransactionStatus
fullyRead(E instance)
          populate the unread properties of a partially read instance.
<E extends Entity>
E
get(Class<E> entityType, int id)
          query instance for identity This call is just for conveniance to relax specifiing id as int.
<E extends Entity>
E
get(Class<E> entityType, long id)
          retrieve an entity by its id.
 EntityDescriptor getEntityDescriptor(Class<?> entityType)
           
protected  org.apache.commons.logging.Log getLogger()
           
 EntityManager getManager(Class<?> clazz)
           
<E extends Entity>
long
getNumberOf(Class<E> entityType)
          count number of persistent instances
<E extends Entity>
long
getNumberOf(Class<E> entityType, List<ConditionElement> args)
          count number of persistent instances, that match given condition
 Object loadUserByUsername(String username)
           
<E extends Entity>
String
performExport(E instance)
          export given instance using XML-format.
<E extends Entity>
void
performExport(E instance, File target)
          export given instance to target file using XML-format.
<E extends Entity>
void
performExport(E instance, Writer out)
          export given instance to given Writer using XML-format
 String performExport(List<?> lst, String id)
          export a list of Entity instances using XML-format and return the exported data as String.
 void performExport(List<?> lst, String id, File target)
          export a list of Entity instances to target file using XML-format
 void performExport(List<?> lst, String id, Writer out)
          export a list of Entity instances to target Writer using XML-format
 String performExport(Map<?,?> map, String id)
          export a map of Entity instances using XML-format and return the exported data as String.
 void performExport(Map<?,?> map, String id, File target)
          export a map of Entity instances to target file using XML-format
 void performExport(Map<?,?> map, String id, Writer out)
          export a map of Entity instances to given Writer using XML-format
 Object performImport(File source)
          import Entity instance(s) from the given XML file
 Object performImport(String source)
          import Entity instance(s) from xml, that has been read to a string buffer
protected  void preloadEntities()
           
<E extends Entity>
TransactionStatus
remove(Class<E> entityType, List<ConditionElement> args)
          remove all persistent instances that match given condition.
<E extends Entity>
TransactionStatus
remove(E instance)
          remove given instance from persistence.
<E extends Entity>
TransactionStatus
remove(List<E> instances)
          remove given instances from persistence.
<E extends Entity>
TransactionStatus
removeAll(Class<E> entityType)
           
<E extends Entity>
TransactionStatus
removeRelated(Class<?> childEntityType2Remove, E entity)
           
 void reset()
           
<E extends Entity>
TransactionStatus
save(E instance)
           
<E extends Entity>
TransactionStatus
save(List<E> instances)
           
<E extends Entity>
TransactionStatus
saveProperties(E instance, Collection<String> propertyNames)
          change given properties of already stored instance.
<E extends Entity>
TransactionStatus
saveProperties(E instance, Collection<String> propertyNames, List<ConditionElement> args)
          change given properties of already stored instances.
<E extends Entity>
TransactionStatus
saveProperties(E instance, String[] propertyNames)
           
<E extends Entity>
TransactionStatus
saveProperties(E instance, String[] propertyNames, List<ConditionElement> args)
           
 void setExporter(Exporter ee)
           
 void setImporter(Importer i)
           
 void setManagers(Map<String,EntityManager> managers)
          set the managers, that shall be used to handle datatransfer to and from persistence.
 void setPreloadEntities(List<String> entityNames)
           
 void setTransactionFactory(TransactionFactory tf)
           
 void setUserNameProvider(UserNameProvider userNameProvider)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Repository

public Repository()
Method Detail

dumpTypeCache

public void dumpTypeCache()

executeTransaction

public void executeTransaction(Transaction transaction)
this call is not of public interest. It is used by the ApplicationTransaction.execute . If an application does not use Transactions, it should use the convenience call interface. Otherwise it should use Transaction.execute.

Parameters:
transaction - the Transaction to execute

find

public <E extends Entity> List<E> find(Class<E> entityType)
find all instances of given type, without resolving relations. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
Returns:
a list of read instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       boolean readRelated)
find all instances of given type, optionally with resolving of relations. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
readRelated - true - the relations will be resolved
false - the relations will not be resolved
Returns:
a list of found instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       int maxRows)
find all instances of given type, without resolving relations. The result may be limited by usage of maxRows - 0 means unlimited result. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
maxRows - maximum number of instances to return
Returns:
a list of found instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       List<ConditionElement> args)
find all instances of given type, that match given condition, without resolving relations. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
args - condition, the instances must match
Returns:
a list of found instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       List<ConditionElement> args,
                                       boolean readRelated)
find all instances of given type, that match given condition, with optionally resolving relations. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
args - condition, the instances must match
readRelated - true - the relations will be resolved
false - the relations will not be resolved
Returns:
a list of found instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       List<ConditionElement> args,
                                       int maxRows)
find all instances of given type, that match given condition, without resolving relations. The result may be limited by given maxRows parameter - 0 means unlimited result. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
args - condition, the instances must match
maxRows - read maximum of maxRows instances - 0 means no limit
Returns:
a list of found instances

find

public <E extends Entity> List<E> find(Class<E> entityType,
                                       List<ConditionElement> args,
                                       int maxRows,
                                       boolean readRelated)
find all instances of given type, optionally with resolving of relations. The result may be limited by usage of maxRows - 0 means unlimited results. This is only a convenience method, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
args - the condition, the read instances must match
maxRows - read a maximum of given instances - 0 means no limit
readRelated - true - the relations will be resolved
false - the relations will not be resolved
Returns:
a list of found instances

find

public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList,
                                                 Class<E> entityType)
read all entries of given entity type, without resolving relations and add the found instances to the given list. This is only a method for convenience, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
resultList - the list to hold the read instances
entityType - the type of the instances to read
Returns:
the status of the implicit created Transaction

find

public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList,
                                                 Class<E> entityType,
                                                 boolean readRelated)
read all entries of given entity type and add the found instances to the given list. This is only a method for convenience, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
resultList - the list to hold the read instances
entityType - the type of the instances to read
readRelated - true - the relations will be resolved
false - the relations will not be resolved
Returns:
the status of the implicit created Transaction

find

public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList,
                                                 Class<E> entityType,
                                                 List<ConditionElement> args)
read all entries of given entity type, that conform the given condition and add the found instances to the given list. This is only a method for convenience, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
resultList - the list to hold the read instances
entityType - the type of the instances to read
args - the condition the read instances must match
Returns:
the status of the implicit created Transaction

find

public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList,
                                                 Class<E> entityType,
                                                 List<ConditionElement> args,
                                                 int maxRows,
                                                 boolean readRelated)
read all entries of given entity type, that conform the given condition and add the found instances to the given list. The result can be limited by the maxRows parameter. 0 means unlimited result. This is only a method for convenience, if you don't want to code Transactions for single read operations.

Type Parameters:
E - the type of the instances to read
Parameters:
resultList - the list to hold the read instances
entityType - the type of the instances to read
args - the condition the read instances must match
maxRows - the max number of instances to return
readRelated - true - the relations will be resolved
false - the relations will not be resolved
Returns:
the status of the implicit created Transaction

findProperties

public <E extends Entity> List<E> findProperties(Class<E> entityType,
                                                 Collection<String> properties,
                                                 List<ConditionElement> args,
                                                 boolean uniq)
partially read instances of given entityType, that match given condition. Only the properties from given Collection will be read. If uniq is set to true , the id of the instances will not be read, if it is not part of the properties Collection. That means, that the result instances are no valid instances. The result may only be used as a selection base or something similar.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
properties - the properties to populate
args - condition, the instances must match
uniq - if true, ensure that all returned instances differ at least with one read property
Returns:
a list of partially read instances

findProperties

public <E extends Entity> List<E> findProperties(Class<E> entityType,
                                                 Collection<String> properties,
                                                 List<ConditionElement> args,
                                                 int maxRows)
partially read instances of given entityType, that match given condition. Only the properties from given Collection will be read. Use fullyRead to populate the unread properties of such an partially read Entity.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
properties - the properties to populate
args - condition, the instances must match
maxRows - read a maximum of given instances - 0 means no limit
Returns:
a list of partially read instances

findProperties

public <E extends Entity> List<E> findProperties(Class<E> entityType,
                                                 Collection<String> properties,
                                                 List<ConditionElement> args,
                                                 int maxRows,
                                                 boolean uniq)
partially read instances of given entityType, that match given condition. Only the properties from given Collection will be read. If uniq is set to true , the id of the instances will not be read, if it is not part of the properties Collection. That means, that the result instances are no valid instances. The result may only be used as a selection base or something similar.

Type Parameters:
E - the type of the instances to read
Parameters:
entityType - the type of the instances to read
properties - the properties to populate
args - condition, the instances must match
maxRows - limit result to given number of rows - 0 means unlimited result
uniq - if true, ensure that all returned instances differ at least with one read property
Returns:
a list of partially read instances

fullyRead

public <E extends Entity> TransactionStatus fullyRead(E instance)
populate the unread properties of a partially read instance. The instance must be persistent and have the id property already populated.

Type Parameters:
E - the type of the instance to read again
Parameters:
instance - the partially read instance to populate
Returns:
- status of the transaction

get

public <E extends Entity> E get(Class<E> entityType,
                                int id)
query instance for identity

This call is just for conveniance to relax specifiing id as int.

Type Parameters:
E - the entity to retrieve
Parameters:
entityType - the type of that entity
id - the id to search for
Returns:
the searched entity or null

get

public <E extends Entity> E get(Class<E> entityType,
                                long id)
retrieve an entity by its id.

Type Parameters:
E - the entity to retrieve
Parameters:
entityType - the type of that entity
id - the id to search for
Returns:
the searched entity or null

getEntityDescriptor

public final EntityDescriptor getEntityDescriptor(Class<?> entityType)
Specified by:
getEntityDescriptor in interface EntityDescriptorAccessor

getManager

public EntityManager getManager(Class<?> clazz)

getNumberOf

public <E extends Entity> long getNumberOf(Class<E> entityType)
count number of persistent instances

Type Parameters:
E - type of instances to count
Parameters:
entityType - type of instances to count
Returns:
number of stored instances

getNumberOf

public <E extends Entity> long getNumberOf(Class<E> entityType,
                                           List<ConditionElement> args)
count number of persistent instances, that match given condition

Type Parameters:
E - type of instances to count
Parameters:
entityType - type of instances to count
args - condition, instances must match
Returns:
number of stored instances, that match given condition

loadUserByUsername

public Object loadUserByUsername(String username)

performExport

public <E extends Entity> String performExport(E instance)
                     throws Exception
export given instance using XML-format. The exported data will be returned as String.

Type Parameters:
E - the type of the instance to export
Parameters:
instance - the instance to export
Returns:
the exported XML data
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public <E extends Entity> void performExport(E instance,
                                             File target)
                   throws Exception
export given instance to target file using XML-format.

Type Parameters:
E - the type of the instance to export
Parameters:
instance - the instance to export
target - the file to create with the XML representation of the instance
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public <E extends Entity> void performExport(E instance,
                                             Writer out)
                   throws Exception
export given instance to given Writer using XML-format

Type Parameters:
E - the type of the instance to export
Parameters:
instance - the instance to export
out - the Writer to handle the exported data
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public String performExport(List<?> lst,
                            String id)
                     throws Exception
export a list of Entity instances using XML-format and return the exported data as String.

Parameters:
lst - holds the instances to export
id - the id of the list, i.e. the parents property name
Returns:
the exported data as String
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public void performExport(List<?> lst,
                          String id,
                          File target)
                   throws Exception
export a list of Entity instances to target file using XML-format

Parameters:
lst - holds the instances to export
id - the id of the list, i.e. the parents property name
target - the file to create with the XML representation of the list of instances
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public void performExport(List<?> lst,
                          String id,
                          Writer out)
                   throws Exception
export a list of Entity instances to target Writer using XML-format

Parameters:
lst - holds the instances to export
id - the id of the list, i.e. the parents property name
out - the Writer to handle the exported data
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public String performExport(Map<?,?> map,
                            String id)
                     throws Exception
export a map of Entity instances using XML-format and return the exported data as String.

Parameters:
map - holds the instances to export
id - the id of the map, i.e. the parents property name
Returns:
the exported data as String
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public void performExport(Map<?,?> map,
                          String id,
                          File target)
                   throws Exception
export a map of Entity instances to target file using XML-format

Parameters:
map - holds the instances to export
id - the id of the map, i.e. the parents property name
target - the file to create with the XML representation of the map of instances
Throws:
Exception - - just let the exception from underlying layers pass to application

performExport

public void performExport(Map<?,?> map,
                          String id,
                          Writer out)
                   throws Exception
export a map of Entity instances to given Writer using XML-format

Parameters:
map - holds the instances to export
id - the id of the map, i.e. the parents property name
out - the Writer to handle exported data
Throws:
Exception - - just let the exception from underlying layers pass to application

performImport

public Object performImport(File source)
                     throws Exception
import Entity instance(s) from the given XML file

Parameters:
source - the file that holds exported Entity instances
Returns:
the created object from import file
Throws:
Exception - - just let the exception from underlying layers pass to application

performImport

public Object performImport(String source)
                     throws Exception
import Entity instance(s) from xml, that has been read to a string buffer

Parameters:
source - the string buffer, that holds the xml data
Returns:
the created object from import data
Throws:
Exception - - just let the exception from underlying layers pass to application

remove

public <E extends Entity> TransactionStatus remove(Class<E> entityType,
                                                   List<ConditionElement> args)
remove all persistent instances that match given condition. This call is useable only for mass removal without handling relations, so watch out, when to use.

Type Parameters:
E - the type of the instances to remove
Parameters:
entityType - the type of the instances to remove
args - condition the instances must match
Returns:
the TransactionStatus of the internally created transaction.

remove

public <E extends Entity> TransactionStatus remove(E instance)
remove given instance from persistence. This is a convenience call to not have to code a Transaction for a single remove call.

Type Parameters:
E - the type of the instance to remove
Parameters:
instance - the instance to remove
Returns:
the TransactionStatus of the internally created transaction.

remove

public <E extends Entity> TransactionStatus remove(List<E> instances)
remove given instances from persistence. This is a convenience call to not have to code a Transaction for a single remove call.

Type Parameters:
E - the type of the instances to remove
Parameters:
instances - the instances to remove
Returns:
the TransactionStatus of the internally created transaction.

removeAll

public <E extends Entity> TransactionStatus removeAll(Class<E> entityType)

removeRelated

public <E extends Entity> TransactionStatus removeRelated(Class<?> childEntityType2Remove,
                                                          E entity)

reset

public void reset()

save

public <E extends Entity> TransactionStatus save(E instance)

save

public <E extends Entity> TransactionStatus save(List<E> instances)

saveProperties

public <E extends Entity> TransactionStatus saveProperties(E instance,
                                                           Collection<String> propertyNames)
change given properties of already stored instance. If the given entity does not contain a valid id, this call will redirect to save without property-limitations.

Type Parameters:
E - the type of instance to change
Parameters:
instance - the entity that holds the property values
propertyNames - the property names to change
Returns:
the number of affected persistent instances, which may be 0 or 1

saveProperties

public <E extends Entity> TransactionStatus saveProperties(E instance,
                                                           Collection<String> propertyNames,
                                                           List<ConditionElement> args)
change given properties of already stored instances. The instances to change is determined by the given condition args, so null as args will affect all instances.

Type Parameters:
E - the type of the instances to change
Parameters:
instance - the entity, that holds the property values
propertyNames - the names of properties to change
args - the condition to selected the instances to change
Returns:
the number of affected persistent instances

saveProperties

public <E extends Entity> TransactionStatus saveProperties(E instance,
                                                           String[] propertyNames)

saveProperties

public <E extends Entity> TransactionStatus saveProperties(E instance,
                                                           String[] propertyNames,
                                                           List<ConditionElement> args)

setExporter

public final void setExporter(Exporter ee)

setImporter

public final void setImporter(Importer i)

setManagers

public final void setManagers(Map<String,EntityManager> managers)
set the managers, that shall be used to handle datatransfer to and from persistence. This call is used for context setup. The Repository is a wrapper around all EntityManagers to hide implementation details, but is also a service provider to the internals of the EntityManagers, that need to be shared between i.e. Importer or Exporter.

Parameters:
managers - - the map of EntityManagers to use

setPreloadEntities

public final void setPreloadEntities(List<String> entityNames)

setTransactionFactory

public final void setTransactionFactory(TransactionFactory tf)

setUserNameProvider

public final void setUserNameProvider(UserNameProvider userNameProvider)

createTransaction

protected Transaction createTransaction()

getLogger

protected final org.apache.commons.logging.Log getLogger()

preloadEntities

protected void preloadEntities()

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.