|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.schwarzrot.data.access.Repository
public class Repository
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:
JDBCEntityManager
for JDBC access
(currently only mysql tested)PreferencesEntityManager
for
storing entity instances using java preferencesde.schwarzrot.data.access.vdr.VdrEntityManager
for handling vdr
datastreams. This entity manager is also a sample for data migration, as it
uses different persistence for reading and writing.
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.
EntityManager
Constructor Summary | |
---|---|
Repository()
|
Method Summary | ||
---|---|---|
protected Transaction |
createTransaction()
|
|
void |
dumpTypeCache()
|
|
void |
executeTransaction(Transaction transaction)
this call is not of public interest. |
|
|
find(Class<E> entityType)
find all instances of given type, without resolving relations. |
|
|
find(Class<E> entityType,
boolean readRelated)
find all instances of given type, optionally with resolving of relations. |
|
|
find(Class<E> entityType,
int maxRows)
find all instances of given type, without resolving relations. |
|
|
find(Class<E> entityType,
List<ConditionElement> args)
find all instances of given type, that match given condition, without resolving relations. |
|
|
find(Class<E> entityType,
List<ConditionElement> args,
boolean readRelated)
find all instances of given type, that match given condition, with optionally resolving relations. |
|
|
find(Class<E> entityType,
List<ConditionElement> args,
int maxRows)
find all instances of given type, that match given condition, without resolving relations. |
|
|
find(Class<E> entityType,
List<ConditionElement> args,
int maxRows,
boolean readRelated)
find all instances of given type, optionally with resolving of relations. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
findProperties(Class<E> entityType,
Collection<String> properties,
List<ConditionElement> args,
boolean uniq)
partially read instances of given entityType , that match given
condition. |
|
|
findProperties(Class<E> entityType,
Collection<String> properties,
List<ConditionElement> args,
int maxRows)
partially read instances of given entityType , that match given
condition. |
|
|
findProperties(Class<E> entityType,
Collection<String> properties,
List<ConditionElement> args,
int maxRows,
boolean uniq)
partially read instances of given entityType , that match given
condition. |
|
|
fullyRead(E instance)
populate the unread properties of a partially read instance. |
|
|
get(Class<E> entityType,
int id)
query instance for identity This call is just for conveniance to relax specifiing id as int. |
|
|
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)
|
|
|
getNumberOf(Class<E> entityType)
count number of persistent instances |
|
|
getNumberOf(Class<E> entityType,
List<ConditionElement> args)
count number of persistent instances, that match given condition |
|
Object |
loadUserByUsername(String username)
|
|
|
performExport(E instance)
export given instance using XML-format. |
|
|
performExport(E instance,
File target)
export given instance to target file using XML-format. |
|
|
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()
|
|
|
remove(Class<E> entityType,
List<ConditionElement> args)
remove all persistent instances that match given condition. |
|
|
remove(E instance)
remove given instance from persistence. |
|
|
remove(List<E> instances)
remove given instances from persistence. |
|
|
removeAll(Class<E> entityType)
|
|
|
removeRelated(Class<?> childEntityType2Remove,
E entity)
|
|
void |
reset()
|
|
|
save(E instance)
|
|
|
save(List<E> instances)
|
|
|
saveProperties(E instance,
Collection<String> propertyNames)
change given properties of already stored instance. |
|
|
saveProperties(E instance,
Collection<String> propertyNames,
List<ConditionElement> args)
change given properties of already stored instances. |
|
|
saveProperties(E instance,
String[] propertyNames)
|
|
|
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 |
---|
public Repository()
Method Detail |
---|
public void dumpTypeCache()
public void executeTransaction(Transaction transaction)
ApplicationTransaction.execute
. If an application does not use
Transactions, it should use the convenience call interface. Otherwise it
should use Transaction.execute
.
transaction
- the Transaction
to executepublic <E extends Entity> List<E> find(Class<E> entityType)
Transaction
s
for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to read
public <E extends Entity> List<E> find(Class<E> entityType, boolean readRelated)
Transaction
s for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to readreadRelated
- true - the relations will be resolvedpublic <E extends Entity> List<E> find(Class<E> entityType, int maxRows)
maxRows
- 0 means unlimited result.
This is only a convenience method, if you don't want to code
Transaction
s for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to readmaxRows
- maximum number of instances to return
public <E extends Entity> List<E> find(Class<E> entityType, List<ConditionElement> args)
Transaction
s for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to readargs
- condition, the instances must match
public <E extends Entity> List<E> find(Class<E> entityType, List<ConditionElement> args, boolean readRelated)
Transaction
s for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to readargs
- condition, the instances must matchreadRelated
- true - the relations will be resolvedpublic <E extends Entity> List<E> find(Class<E> entityType, List<ConditionElement> args, int maxRows)
maxRows
parameter - 0 means unlimited result. This is only a convenience method,
if you don't want to code Transaction
s for single read
operations.
E
- the type of the instances to readentityType
- the type of the instances to readargs
- condition, the instances must matchmaxRows
- read maximum of maxRows
instances - 0 means no limit
public <E extends Entity> List<E> find(Class<E> entityType, List<ConditionElement> args, int maxRows, boolean readRelated)
maxRows
- 0 means unlimited
results. This is only a convenience method, if you don't want to code
Transaction
s for single read operations.
E
- the type of the instances to readentityType
- the type of the instances to readargs
- the condition, the read instances must matchmaxRows
- read a maximum of given instances - 0 means no limitreadRelated
- true - the relations will be resolvedpublic <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType)
Transaction
s for single
read operations.
E
- the type of the instances to readresultList
- the list to hold the read instancesentityType
- the type of the instances to read
Transaction
public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, boolean readRelated)
Transaction
s for single read operations.
E
- the type of the instances to readresultList
- the list to hold the read instancesentityType
- the type of the instances to readreadRelated
- true - the relations will be resolvedTransaction
public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, List<ConditionElement> args)
Transaction
s for single
read operations.
E
- the type of the instances to readresultList
- the list to hold the read instancesentityType
- the type of the instances to readargs
- the condition the read instances must match
Transaction
public <E extends Entity> TransactionStatus find(ca.odell.glazedlists.EventList<E> resultList, Class<E> entityType, List<ConditionElement> args, int maxRows, boolean readRelated)
maxRows
parameter. 0 means unlimited result. This is only
a method for convenience, if you don't want to code Transaction
s
for single read operations.
E
- the type of the instances to readresultList
- the list to hold the read instancesentityType
- the type of the instances to readargs
- the condition the read instances must matchmaxRows
- the max number of instances to returnreadRelated
- true - the relations will be resolvedTransaction
public <E extends Entity> List<E> findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, boolean uniq)
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.
E
- the type of the instances to readentityType
- the type of the instances to readproperties
- the properties to populateargs
- condition, the instances must matchuniq
- if true, ensure that all returned instances differ at least
with one read property
public <E extends Entity> List<E> findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, int maxRows)
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
.
E
- the type of the instances to readentityType
- the type of the instances to readproperties
- the properties to populateargs
- condition, the instances must matchmaxRows
- read a maximum of given instances - 0 means no limit
public <E extends Entity> List<E> findProperties(Class<E> entityType, Collection<String> properties, List<ConditionElement> args, int maxRows, boolean uniq)
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.
E
- the type of the instances to readentityType
- the type of the instances to readproperties
- the properties to populateargs
- condition, the instances must matchmaxRows
- limit result to given number of rows - 0 means unlimited
resultuniq
- if true, ensure that all returned instances differ at least
with one read property
public <E extends Entity> TransactionStatus fullyRead(E instance)
E
- the type of the instance to read againinstance
- the partially read instance to populate
public <E extends Entity> E get(Class<E> entityType, int id)
This call is just for conveniance to relax specifiing id as int.
E
- the entity to retrieveentityType
- the type of that entityid
- the id to search for
public <E extends Entity> E get(Class<E> entityType, long id)
E
- the entity to retrieveentityType
- the type of that entityid
- the id to search for
public final EntityDescriptor getEntityDescriptor(Class<?> entityType)
getEntityDescriptor
in interface EntityDescriptorAccessor
public EntityManager getManager(Class<?> clazz)
public <E extends Entity> long getNumberOf(Class<E> entityType)
E
- type of instances to countentityType
- type of instances to count
public <E extends Entity> long getNumberOf(Class<E> entityType, List<ConditionElement> args)
E
- type of instances to countentityType
- type of instances to countargs
- condition, instances must match
public Object loadUserByUsername(String username)
public <E extends Entity> String performExport(E instance) throws Exception
String
.
E
- the type of the instance to exportinstance
- the instance to export
Exception
- - just let the exception from underlying layers pass to
applicationpublic <E extends Entity> void performExport(E instance, File target) throws Exception
E
- the type of the instance to exportinstance
- the instance to exporttarget
- the file to create with the XML representation of the instance
Exception
- - just let the exception from underlying layers pass to
applicationpublic <E extends Entity> void performExport(E instance, Writer out) throws Exception
Writer
using XML-format
E
- the type of the instance to exportinstance
- the instance to exportout
- the Writer
to handle the exported data
Exception
- - just let the exception from underlying layers pass to
applicationpublic String performExport(List<?> lst, String id) throws Exception
Entity
instances using XML-format and return the
exported data as String
.
lst
- holds the instances to exportid
- the id of the list, i.e. the parents property name
String
Exception
- - just let the exception from underlying layers pass to
applicationpublic void performExport(List<?> lst, String id, File target) throws Exception
Entity
instances to target file using XML-format
lst
- holds the instances to exportid
- the id of the list, i.e. the parents property nametarget
- the file to create with the XML representation of the list of
instances
Exception
- - just let the exception from underlying layers pass to
applicationpublic void performExport(List<?> lst, String id, Writer out) throws Exception
Entity
instances to target Writer
using
XML-format
lst
- holds the instances to exportid
- the id of the list, i.e. the parents property nameout
- the Writer
to handle the exported data
Exception
- - just let the exception from underlying layers pass to
applicationpublic String performExport(Map<?,?> map, String id) throws Exception
Entity
instances using XML-format and return the
exported data as String.
map
- holds the instances to exportid
- the id of the map, i.e. the parents property name
String
Exception
- - just let the exception from underlying layers pass to
applicationpublic void performExport(Map<?,?> map, String id, File target) throws Exception
Entity
instances to target file using XML-format
map
- holds the instances to exportid
- the id of the map, i.e. the parents property nametarget
- the file to create with the XML representation of the map of
instances
Exception
- - just let the exception from underlying layers pass to
applicationpublic void performExport(Map<?,?> map, String id, Writer out) throws Exception
Entity
instances to given Writer
using
XML-format
map
- holds the instances to exportid
- the id of the map, i.e. the parents property nameout
- the Writer
to handle exported data
Exception
- - just let the exception from underlying layers pass to
applicationpublic Object performImport(File source) throws Exception
Entity
instance(s) from the given XML file
source
- the file that holds exported Entity
instances
Exception
- - just let the exception from underlying layers pass to
applicationpublic Object performImport(String source) throws Exception
Entity
instance(s) from xml, that has been read to a
string buffer
source
- the string buffer, that holds the xml data
Exception
- - just let the exception from underlying layers pass to
applicationpublic <E extends Entity> TransactionStatus remove(Class<E> entityType, List<ConditionElement> args)
E
- the type of the instances to removeentityType
- the type of the instances to removeargs
- condition the instances must match
TransactionStatus
of the internally created
transaction.public <E extends Entity> TransactionStatus remove(E instance)
Transaction
for a single remove call.
E
- the type of the instance to removeinstance
- the instance to remove
TransactionStatus
of the internally created
transaction.public <E extends Entity> TransactionStatus remove(List<E> instances)
Transaction
for a single remove call.
E
- the type of the instances to removeinstances
- the instances to remove
TransactionStatus
of the internally created
transaction.public <E extends Entity> TransactionStatus removeAll(Class<E> entityType)
public <E extends Entity> TransactionStatus removeRelated(Class<?> childEntityType2Remove, E entity)
public void reset()
public <E extends Entity> TransactionStatus save(E instance)
public <E extends Entity> TransactionStatus save(List<E> instances)
public <E extends Entity> TransactionStatus saveProperties(E instance, Collection<String> propertyNames)
save
without property-limitations.
E
- the type of instance to changeinstance
- the entity that holds the property valuespropertyNames
- the property names to change
public <E extends Entity> TransactionStatus saveProperties(E instance, Collection<String> propertyNames, List<ConditionElement> args)
args
, so null
as args
will affect all instances.
E
- the type of the instances to changeinstance
- the entity, that holds the property valuespropertyNames
- the names of properties to changeargs
- the condition to selected the instances to change
public <E extends Entity> TransactionStatus saveProperties(E instance, String[] propertyNames)
public <E extends Entity> TransactionStatus saveProperties(E instance, String[] propertyNames, List<ConditionElement> args)
public final void setExporter(Exporter ee)
public final void setImporter(Importer i)
public final void setManagers(Map<String,EntityManager> managers)
Repository
is a wrapper around all EntityManager
s to hide implementation
details, but is also a service provider to the internals of the
EntityManager
s, that need to be shared between i.e.
Importer
or Exporter
.
managers
- - the map of EntityManager
s to usepublic final void setPreloadEntities(List<String> entityNames)
public final void setTransactionFactory(TransactionFactory tf)
public final void setUserNameProvider(UserNameProvider userNameProvider)
protected Transaction createTransaction()
protected final org.apache.commons.logging.Log getLogger()
protected void preloadEntities()
|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |