net.sourceforge.domian.repository
Class AbstractRepository<T extends Entity>

java.lang.Object
  extended by net.sourceforge.domian.repository.AbstractRepository<T>
All Implemented Interfaces:
Repository<T>
Direct Known Subclasses:
HashSetRepository, InMemoryRepository, NotImplementedRepository, NullRepository, PartitionRepositoryInvocationHandler, UnsupportedRepository

public abstract class AbstractRepository<T extends Entity>
extends java.lang.Object
implements Repository<T>

All Repository classes should extend this abstract class. It makes sure that all aliased methods behaves like specified in the Repository interface. Also, some default method implementations are included in this class.

A SLF4J logger instance is provided in this class.

Since:
0.4
Author:
Eirik Torske

Field Summary
static java.lang.String DEFAULT_DOMIAN_ROOT_DIR_NAME
           
static java.lang.String DEFAULT_DOMIAN_ROOT_PATH
           
protected  org.slf4j.Logger log
           
protected  java.lang.Boolean supportsRecursiveIndexing
          Flag to indicate whether or not this particualar repository instance add entity members as first class entities in the repository.
protected  Synchronizer synchronizer
          A synchronizer used to control concurrent and exclusive access to repository methods.
protected  java.lang.Boolean usesNativeIndexing
          Flag to indicate whether or not this particualar repository instance inhibits and uses its own mechanism for indexing entities.
 
Constructor Summary
AbstractRepository()
           
 
Method Summary
protected  java.lang.Boolean contains(T entity)
           
<V extends T>
java.lang.Long
count(Specification<V> specification)
          Alias of countAllEntitiesSpecifiedBy(Specification).
<V extends T>
java.lang.Long
countAll(Specification<V> specification)
          Alias of countAllEntitiesSpecifiedBy(Specification).
<V extends T>
java.lang.Long
countAllEntitiesSpecifiedBy(Specification<V> specification)
          Counts the number of entities approved by the given specification.
<V extends T>
java.util.Collection<V>
find(Specification<V> specification)
          Alias of findAllEntitiesSpecifiedBy(Specification).
<V extends T>
java.util.Collection<V>
findAll(Specification<V> specification)
          Alias of findAllEntitiesSpecifiedBy(Specification).
<V extends T>
V
findSingle(Specification<V> specification)
          Alias of findSingleEntitySpecifiedBy(Specification).
<V extends T>
V
findSingleEntitySpecifiedBy(Specification<V> specification)
          Finds and returns one single entity approved by the given specification.
private static java.lang.Class[] getAllRelevantRepositoryInterfaces(Repository repository)
           
private  java.lang.reflect.InvocationHandler getInvocationHandler()
           
protected  Synchronizer getSynchronizer()
           
 java.lang.Boolean isDoingNativePartitioning()
          When true, the repository utilizes some sort of native partitioning mechanism, e.g.
 java.lang.Boolean isDoingRecursiveEntityAdding()
           
<V extends T>
java.util.Iterator<V>
iterate(Specification<V> specification)
          Alias of iterateAllEntitiesSpecifiedBy(Specification).
<V extends T>
java.util.Iterator<V>
iterateAll(Specification<V> specification)
          Alias of iterateAllEntitiesSpecifiedBy(Specification).
 PartitionRepository<T> makePartition()
           
protected  void onMakePartition()
          Template method for partitioning callbacks.
<V extends T>
void
putAll(java.util.Collection<? extends V> collectionOfEntities)
          Puts the given entities into this repository.
<V extends T>
java.lang.Long
remove(Specification<V> specification)
          Alias of removeAllEntitiesSpecifiedBy(Specification).
<V extends T>
java.lang.Long
removeAll(Specification<V> specification)
          Alias of removeAllEntitiesSpecifiedBy(Specification).
 void setSynchronizer(Synchronizer synchronizer)
          A synchronizer used to control concurrent and exclusive access to repository methods.
<V extends T>
void
update(V entity, CompositeSpecification<?> deltaSpecification)
          Updates an entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.domian.repository.Repository
findAllEntitiesSpecifiedBy, iterateAllEntitiesSpecifiedBy, put, remove, removeAllEntitiesSpecifiedBy, update
 

Field Detail

DEFAULT_DOMIAN_ROOT_DIR_NAME

public static final java.lang.String DEFAULT_DOMIAN_ROOT_DIR_NAME
See Also:
Constant Field Values

DEFAULT_DOMIAN_ROOT_PATH

public static final java.lang.String DEFAULT_DOMIAN_ROOT_PATH

log

protected final org.slf4j.Logger log

synchronizer

protected Synchronizer synchronizer
A synchronizer used to control concurrent and exclusive access to repository methods. E.g. all methods dealing with partitioning are run in an exclusive manner.


usesNativeIndexing

protected java.lang.Boolean usesNativeIndexing
Flag to indicate whether or not this particualar repository instance inhibits and uses its own mechanism for indexing entities. If true, this will be the case (as we know it from RDBMSs). Furthermore, if this flag is true, partitioned repositories will reuse the repository instance across partitions. To improve search response time for repository partitions, the internal indexing mechanism must be applied whenever partitions are added.

Default is false.


supportsRecursiveIndexing

protected java.lang.Boolean supportsRecursiveIndexing
Flag to indicate whether or not this particualar repository instance add entity members as first class entities in the repository. (a.k.a. recursive indexing). If true, this will be the case (as we know it from RDBMSs). Furthermore, if this flag is true, cascading puts, updates, and removals will also take place, if nothing else is stated in the Javadoc.

Default is false - only aggregate root is indexed/made searchable.

Constructor Detail

AbstractRepository

public AbstractRepository()
Method Detail

getSynchronizer

protected Synchronizer getSynchronizer()

setSynchronizer

public void setSynchronizer(Synchronizer synchronizer)
Description copied from interface: Repository
A synchronizer used to control concurrent and exclusive access to repository methods. E.g. all methods dealing with partitioning should be run in an exclusive manner.

Specified by:
setSynchronizer in interface Repository<T extends Entity>

isDoingNativePartitioning

public java.lang.Boolean isDoingNativePartitioning()
Description copied from interface: Repository
When true, the repository utilizes some sort of native partitioning mechanism, e.g. RDBMS indices. If true, partition repositories may be reusing the same repository instance.

Specified by:
isDoingNativePartitioning in interface Repository<T extends Entity>
Returns:
true if repository utilizes some sort of native partitioning mechanism, e.g. RDBMS indices.

isDoingRecursiveEntityAdding

public java.lang.Boolean isDoingRecursiveEntityAdding()
Specified by:
isDoingRecursiveEntityAdding in interface Repository<T extends Entity>
Returns:
true if member entities are stored recursively, and made searchable - false if only aggregate root is stored.

contains

protected java.lang.Boolean contains(T entity)

getInvocationHandler

private java.lang.reflect.InvocationHandler getInvocationHandler()

makePartition

public PartitionRepository<T> makePartition()

onMakePartition

protected void onMakePartition()
Template method for partitioning callbacks.


countAllEntitiesSpecifiedBy

public <V extends T> java.lang.Long countAllEntitiesSpecifiedBy(Specification<V> specification)
Description copied from interface: Repository
Counts the number of entities approved by the given specification.

Specified by:
countAllEntitiesSpecifiedBy in interface Repository<T extends Entity>
Parameters:
specification - the entity specification
Returns:
the number of entities approved by the specification argument

countAll

public final <V extends T> java.lang.Long countAll(Specification<V> specification)
Description copied from interface: Repository
Alias of countAllEntitiesSpecifiedBy(Specification).

Specified by:
countAll in interface Repository<T extends Entity>

count

public final <V extends T> java.lang.Long count(Specification<V> specification)
Description copied from interface: Repository
Alias of countAllEntitiesSpecifiedBy(Specification).

Specified by:
count in interface Repository<T extends Entity>

iterateAll

public final <V extends T> java.util.Iterator<V> iterateAll(Specification<V> specification)
Description copied from interface: Repository
Alias of iterateAllEntitiesSpecifiedBy(Specification).

Specified by:
iterateAll in interface Repository<T extends Entity>

iterate

public final <V extends T> java.util.Iterator<V> iterate(Specification<V> specification)
Description copied from interface: Repository
Alias of iterateAllEntitiesSpecifiedBy(Specification).

Specified by:
iterate in interface Repository<T extends Entity>

findAll

public final <V extends T> java.util.Collection<V> findAll(Specification<V> specification)
Description copied from interface: Repository
Alias of findAllEntitiesSpecifiedBy(Specification).

Specified by:
findAll in interface Repository<T extends Entity>

find

public final <V extends T> java.util.Collection<V> find(Specification<V> specification)
Description copied from interface: Repository
Alias of findAllEntitiesSpecifiedBy(Specification).

Specified by:
find in interface Repository<T extends Entity>

findSingleEntitySpecifiedBy

public <V extends T> V findSingleEntitySpecifiedBy(Specification<V> specification)
Description copied from interface: Repository
Finds and returns one single entity approved by the given specification.

Specified by:
findSingleEntitySpecifiedBy in interface Repository<T extends Entity>
Parameters:
specification - the entity specification
Returns:
the sole entity specified by the specification argument, or null if no entity is found

findSingle

public final <V extends T> V findSingle(Specification<V> specification)
Description copied from interface: Repository
Alias of findSingleEntitySpecifiedBy(Specification).

Specified by:
findSingle in interface Repository<T extends Entity>

putAll

public <V extends T> void putAll(java.util.Collection<? extends V> collectionOfEntities)
Description copied from interface: Repository
Puts the given entities into this repository.

Specified by:
putAll in interface Repository<T extends Entity>
Parameters:
collectionOfEntities - the entities to be stored

update

public <V extends T> void update(V entity,
                                 CompositeSpecification<?> deltaSpecification)
Description copied from interface: Repository
Updates an entity. When an entity is (re)-retrieved, all state changes will be visible, no matter what kinds of repository implementations beeing involved. Do notice that for all memory-based repositories, entity updates are of course immediately visible.

(Only applicable for persistent repositories doing direct data writes, like PersistenceDefinition.FILE, and possibly PersistenceDefinition.DELEGATED... For all other persistence definitions, this method is redundant/not applicable. Anyway, by applying this method in a consistent manner, an eventual repository migration will not need any code changes.

Specified by:
update in interface Repository<T extends Entity>
Type Parameters:
V - the entity type
Parameters:
entity - the entity
deltaSpecification - for optimistic locking schemes: a specification specifying the differences/added state between this update and the previously retrieved entity version The specification should be a conjuction of field bound equality specifications only, or null if optimistic locking with automatic retries is completely out of scope

removeAll

public final <V extends T> java.lang.Long removeAll(Specification<V> specification)
Description copied from interface: Repository
Alias of removeAllEntitiesSpecifiedBy(Specification).

Specified by:
removeAll in interface Repository<T extends Entity>

remove

public final <V extends T> java.lang.Long remove(Specification<V> specification)
Description copied from interface: Repository
Alias of removeAllEntitiesSpecifiedBy(Specification).

Specified by:
remove in interface Repository<T extends Entity>

getAllRelevantRepositoryInterfaces

private static java.lang.Class[] getAllRelevantRepositoryInterfaces(Repository repository)


Copyright © 2006-2009. All Rights Reserved.