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

java.lang.Object
  extended by net.sourceforge.domian.repository.AbstractRepository<T>
      extended by net.sourceforge.domian.repository.AbstractDomianCoreRepository<T>
          extended by net.sourceforge.domian.repository.PartitionRepositoryInvocationHandler<T>
All Implemented Interfaces:
java.lang.reflect.InvocationHandler, PartitionRepository<T>, PersistentRepository<T>, Repository<T>
Direct Known Subclasses:
PartitionRepositoryReuseInvocationHandler

public class PartitionRepositoryInvocationHandler<T extends Entity>
extends AbstractDomianCoreRepository<T>
implements java.lang.reflect.InvocationHandler, PartitionRepository<T>, PersistentRepository<T>

InvocationHandler implementation for partition repositories. All repositories either consisting of, or belonging to a PartitionRepository may use this repository wrapper.

Since:
0.4
Author:
Eirik Torske

Nested Class Summary
private  class PartitionRepositoryInvocationHandler.FindAllEntitiesSpecifiedBy<V extends T>
           
private  class PartitionRepositoryInvocationHandler.IterateAllEntitiesSpecifiedBy<V extends T>
           
private static class PartitionRepositoryInvocationHandler.IteratorRegistry
          Class for keeping track of all repository iterators.
(package private)  class PartitionRepositoryInvocationHandler.PartitionAwareSpecification<V extends T>
           
private static class PartitionRepositoryInvocationHandler.PartitionRepositoryIterator<T extends Entity,V extends T>
          Inner iterator class for PartitionRepository.
private  class PartitionRepositoryInvocationHandler.Put<V extends T>
           
private  class PartitionRepositoryInvocationHandler.Remove<V extends T>
           
private  class PartitionRepositoryInvocationHandler.RemoveAllEntitiesSpecifiedBy<V extends T>
           
 
Field Summary
protected  boolean executeOperationsExclusivelyOnly
           
protected  PartitionRepositoryInvocationHandler.IteratorRegistry iteratorRegistry
          A internal registry keeping track of all active iterators.
protected  Specification<T> partitionSpecification
           
protected  Repository<T> repositoryDelegate
           
protected  boolean repositoryDelegateIsAlreadyPartitioned
           
protected  java.util.Map<Specification<? extends T>,PartitionRepository> subPartitions
          All sub-partition repositories, indexed by a unique specification.
protected  PartitionRepository<? super T> superPartitionRepository
           
protected  Specification<? super T> superPartitionSpecification
           
protected  Synchronizer synchronizer
          A synchronizer used to control concurrent and exclusive access to repository methods.
 
Fields inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
DEFAULT_DOMIAN_ROOT_DIR_NAME, DEFAULT_DOMIAN_ROOT_PATH, log
 
Fields inherited from class net.sourceforge.domian.repository.AbstractRepository
supportsRecursiveIndexing, usesNativePartitioningSupport
 
Constructor Summary
PartitionRepositoryInvocationHandler(Repository<T> repositoryDelegate, Synchronizer synchronizer, java.lang.Boolean executeOperationsExclusivelyOnly)
           
 
Method Summary
protected
<V extends T>
PartitionRepository<V>
addPartition(Specification<V> partitionSpecification, PartitionRepository<? extends V> partitionRepository)
           
<V extends T>
PartitionRepository<V>
addPartitionFor(Specification<V> partitionSpecification)
           
<V extends T>
PartitionRepository<V>
addPartitionFor(Specification<V> partitionSpecification, Repository<? super V> partitionRepository)
           
<V extends T>
PartitionRepository<V>
addPartitionFor(Specification<V> partitionSpecification, java.lang.String repositoryId)
           
 void close()
           
 void collectAllPartitions(java.util.Map<Specification<? extends T>,PartitionRepository> partitionMap)
           
<R extends Repository>
void
collectAllPartitionsWithRepositorySatisfying(Specification<R> specification, java.util.Map<Specification<? extends T>,PartitionRepository> partitionMap)
           
protected
<V> V
conditionalSynchronizedExecutionOf(java.util.concurrent.Callable<V> operation)
           
protected
<V extends T>
java.lang.Long
countAllEntitiesWithoutSpecificationSharpening(Specification<V> specification)
          Special count method without sharpening original specifications to fit partition specifications.
protected  java.lang.Boolean entityExists_PossiblyInWrongPartition(T entity)
           
<V extends T>
java.util.Collection<V>
findAllEntitiesSpecifiedBy(Specification<V> specification)
           
protected
<V extends T>
java.util.Collection<V>
findAllEntitiesSpecifiedBy(Specification<V> specification, java.lang.Boolean sharpenOriginalSpecificationsToFitPartitionSpecification)
           
<V extends T>
PartitionRepository
findPartitionFor(Specification<V> partitionSpecification)
           
<V extends T>
V
findSingleEntitySpecifiedBy(Specification<V> specification)
           
 java.util.Map<Specification<? extends T>,PartitionRepository> getAllPartitions()
           
protected  PartitionRepository getCorrectPartitionRepository(PartitionRepository originalPartitionRepository, PartitionRepository toBeReusedPartitionRepository)
           
 java.lang.String getFormat()
          This method applies to this partition only!
 EntityPersistenceMetaData getMetaDataFor(T entity)
           
 java.util.Set<T> getPartitionOnlyEntities()
           
 java.util.Map<Specification<? extends T>,PartitionRepository> getPartitions()
           
 Specification<T> getPartitionSpecification()
           
 PersistenceDefinition getPersistenceDefinition()
          This method applies to this partition only!
 java.io.File getRepositoryDirectory()
          This method applies to this partition only!
 java.lang.String getRepositoryId()
          This method applies to this partition only!
 PartitionRepository<? super T> getRootRepository()
           
 PartitionRepository<? super T> getSuperPartitionRepository()
           
 Specification<? super T> getSuperPartitionSpecification()
           
 Repository<T> getTargetRepository()
           
 java.lang.Class<T> getType()
           
protected  void handlePartitionRepositoryException(java.lang.Exception e, java.lang.String errorMessage)
           
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
 java.lang.Boolean isIndexingEntitiesRecursively()
           
 java.lang.Boolean isLeafPartition()
           
 java.lang.Boolean isPartitioningNatively()
           
 java.lang.Boolean isRootPartition()
           
<V extends T>
java.util.Iterator<V>
iterateAllEntitiesSpecifiedBy(Specification<V> specification)
           
 void load()
           
 void persist()
           
<V extends T>
void
put(V entity)
           
<V extends T>
java.lang.Boolean
remove(V entity)
           
<V extends T>
java.lang.Long
removeAllEntitiesSpecifiedBy(Specification<V> specification)
           
protected
<V extends T>
void
removePartitionOnlyEntity(V entity)
           
 void repartition()
           
<V extends T>
java.lang.Boolean
repartition(V entity)
           
protected  boolean repositoryExemptFromSyncronization()
           
protected  boolean repositoryOperationsNeedToBeExecutedExclusively()
           
 void setPartitionSpecification(Specification<T> partitionSpecification)
           
 void setSuperPartitionRepository(PartitionRepository<? super T> partitionRepository)
           
 void setSuperPartitionSpecification(Specification<? super T> specification)
           
<V extends T>
void
update(V entity)
           
protected  PartitionRepository wireUpPartition(Specification superPartitionSpecification, PartitionRepository superPartitionRepository, Specification partitionSpecification, PartitionRepository partitionRepository)
           
 
Methods inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
createUniqueSpecificationFor, getSynchronizer, makePartition, onMakePartition, setSynchronizer
 
Methods inherited from class net.sourceforge.domian.repository.AbstractRepository
contains, count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findSingle, iterate, iterateAll, putAll, remove, removeAll, update
 
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
count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findSingle, iterate, iterateAll, makePartition, putAll, remove, removeAll, update
 

Field Detail

synchronizer

protected final 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.


iteratorRegistry

protected final PartitionRepositoryInvocationHandler.IteratorRegistry iteratorRegistry
A internal registry keeping track of all active iterators.


executeOperationsExclusivelyOnly

protected boolean executeOperationsExclusivelyOnly

repositoryDelegateIsAlreadyPartitioned

protected boolean repositoryDelegateIsAlreadyPartitioned

superPartitionSpecification

protected Specification<? super T extends Entity> superPartitionSpecification

superPartitionRepository

protected PartitionRepository<? super T extends Entity> superPartitionRepository

partitionSpecification

protected Specification<T extends Entity> partitionSpecification

repositoryDelegate

protected Repository<T extends Entity> repositoryDelegate

subPartitions

protected final java.util.Map<Specification<? extends T extends Entity>,PartitionRepository> subPartitions
All sub-partition repositories, indexed by a unique specification.

Constructor Detail

PartitionRepositoryInvocationHandler

PartitionRepositoryInvocationHandler(Repository<T> repositoryDelegate,
                                     Synchronizer synchronizer,
                                     java.lang.Boolean executeOperationsExclusivelyOnly)
Method Detail

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable

getType

public java.lang.Class<T> getType()
Specified by:
getType in interface PartitionRepository<T extends Entity>

getRootRepository

public PartitionRepository<? super T> getRootRepository()
Specified by:
getRootRepository in interface PartitionRepository<T extends Entity>

getSuperPartitionSpecification

public Specification<? super T> getSuperPartitionSpecification()

setSuperPartitionSpecification

public void setSuperPartitionSpecification(Specification<? super T> specification)
Specified by:
setSuperPartitionSpecification in interface PartitionRepository<T extends Entity>

getSuperPartitionRepository

public PartitionRepository<? super T> getSuperPartitionRepository()
Specified by:
getSuperPartitionRepository in interface PartitionRepository<T extends Entity>

setSuperPartitionRepository

public void setSuperPartitionRepository(PartitionRepository<? super T> partitionRepository)
Specified by:
setSuperPartitionRepository in interface PartitionRepository<T extends Entity>

getPartitionSpecification

public Specification<T> getPartitionSpecification()
Specified by:
getPartitionSpecification in interface PartitionRepository<T extends Entity>

setPartitionSpecification

public void setPartitionSpecification(Specification<T> partitionSpecification)
Specified by:
setPartitionSpecification in interface PartitionRepository<T extends Entity>

getTargetRepository

public Repository<T> getTargetRepository()
Specified by:
getTargetRepository in interface PartitionRepository<T extends Entity>

isRootPartition

public java.lang.Boolean isRootPartition()
Specified by:
isRootPartition in interface PartitionRepository<T extends Entity>

isLeafPartition

public java.lang.Boolean isLeafPartition()
Specified by:
isLeafPartition in interface PartitionRepository<T extends Entity>

repositoryOperationsNeedToBeExecutedExclusively

protected boolean repositoryOperationsNeedToBeExecutedExclusively()

repositoryExemptFromSyncronization

protected boolean repositoryExemptFromSyncronization()

wireUpPartition

protected PartitionRepository wireUpPartition(Specification superPartitionSpecification,
                                              PartitionRepository superPartitionRepository,
                                              Specification partitionSpecification,
                                              PartitionRepository partitionRepository)

conditionalSynchronizedExecutionOf

protected <V> V conditionalSynchronizedExecutionOf(java.util.concurrent.Callable<V> operation)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

handlePartitionRepositoryException

protected void handlePartitionRepositoryException(java.lang.Exception e,
                                                  java.lang.String errorMessage)

iterateAllEntitiesSpecifiedBy

public <V extends T> java.util.Iterator<V> iterateAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
iterateAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

countAllEntitiesWithoutSpecificationSharpening

protected <V extends T> java.lang.Long countAllEntitiesWithoutSpecificationSharpening(Specification<V> specification)
Special count method without sharpening original specifications to fit partition specifications.


findSingleEntitySpecifiedBy

public <V extends T> V findSingleEntitySpecifiedBy(Specification<V> specification)
Specified by:
findSingleEntitySpecifiedBy in interface Repository<T extends Entity>
Overrides:
findSingleEntitySpecifiedBy in class AbstractRepository<T extends Entity>

findAllEntitiesSpecifiedBy

public <V extends T> java.util.Collection<V> findAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
findAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

findAllEntitiesSpecifiedBy

protected <V extends T> java.util.Collection<V> findAllEntitiesSpecifiedBy(Specification<V> specification,
                                                                           java.lang.Boolean sharpenOriginalSpecificationsToFitPartitionSpecification)

put

public <V extends T> void put(V entity)
Specified by:
put in interface Repository<T extends Entity>

update

public <V extends T> void update(V entity)
Specified by:
update in interface Repository<T extends Entity>

removeAllEntitiesSpecifiedBy

public <V extends T> java.lang.Long removeAllEntitiesSpecifiedBy(Specification<V> specification)
Specified by:
removeAllEntitiesSpecifiedBy in interface Repository<T extends Entity>

remove

public <V extends T> java.lang.Boolean remove(V entity)
Specified by:
remove in interface Repository<T extends Entity>

isPartitioningNatively

public java.lang.Boolean isPartitioningNatively()
Specified by:
isPartitioningNatively in interface Repository<T extends Entity>
Overrides:
isPartitioningNatively in class AbstractRepository<T extends Entity>

isIndexingEntitiesRecursively

public java.lang.Boolean isIndexingEntitiesRecursively()
Specified by:
isIndexingEntitiesRecursively in interface Repository<T extends Entity>
Overrides:
isIndexingEntitiesRecursively in class AbstractRepository<T extends Entity>

getRepositoryDirectory

public java.io.File getRepositoryDirectory()
This method applies to this partition only!

Specified by:
getRepositoryDirectory in interface PersistentRepository<T extends Entity>

getRepositoryId

public java.lang.String getRepositoryId()
This method applies to this partition only!

Specified by:
getRepositoryId in interface PersistentRepository<T extends Entity>

getPersistenceDefinition

public PersistenceDefinition getPersistenceDefinition()
This method applies to this partition only!

Specified by:
getPersistenceDefinition in interface PersistentRepository<T extends Entity>

getFormat

public java.lang.String getFormat()
This method applies to this partition only!

Specified by:
getFormat in interface PersistentRepository<T extends Entity>

load

public void load()
Specified by:
load in interface PersistentRepository<T extends Entity>

persist

public void persist()
Specified by:
persist in interface PersistentRepository<T extends Entity>

getMetaDataFor

public EntityPersistenceMetaData getMetaDataFor(T entity)
Specified by:
getMetaDataFor in interface PersistentRepository<T extends Entity>

close

public void close()
Specified by:
close in interface PersistentRepository<T extends Entity>

getCorrectPartitionRepository

protected PartitionRepository getCorrectPartitionRepository(PartitionRepository originalPartitionRepository,
                                                            PartitionRepository toBeReusedPartitionRepository)

addPartition

protected <V extends T> PartitionRepository<V> addPartition(Specification<V> partitionSpecification,
                                                            PartitionRepository<? extends V> partitionRepository)

addPartitionFor

public <V extends T> PartitionRepository<V> addPartitionFor(Specification<V> partitionSpecification)
Specified by:
addPartitionFor in interface PartitionRepository<T extends Entity>

addPartitionFor

public <V extends T> PartitionRepository<V> addPartitionFor(Specification<V> partitionSpecification,
                                                            java.lang.String repositoryId)
Specified by:
addPartitionFor in interface PartitionRepository<T extends Entity>

addPartitionFor

public <V extends T> PartitionRepository<V> addPartitionFor(Specification<V> partitionSpecification,
                                                            Repository<? super V> partitionRepository)
Specified by:
addPartitionFor in interface PartitionRepository<T extends Entity>

repartition

public <V extends T> java.lang.Boolean repartition(V entity)
Specified by:
repartition in interface PartitionRepository<T extends Entity>

repartition

public void repartition()
Specified by:
repartition in interface PartitionRepository<T extends Entity>

entityExists_PossiblyInWrongPartition

protected java.lang.Boolean entityExists_PossiblyInWrongPartition(T entity)

getPartitions

public java.util.Map<Specification<? extends T>,PartitionRepository> getPartitions()
Specified by:
getPartitions in interface PartitionRepository<T extends Entity>

getAllPartitions

public java.util.Map<Specification<? extends T>,PartitionRepository> getAllPartitions()
Specified by:
getAllPartitions in interface PartitionRepository<T extends Entity>

collectAllPartitions

public void collectAllPartitions(java.util.Map<Specification<? extends T>,PartitionRepository> partitionMap)
Specified by:
collectAllPartitions in interface PartitionRepository<T extends Entity>

collectAllPartitionsWithRepositorySatisfying

public <R extends Repository> void collectAllPartitionsWithRepositorySatisfying(Specification<R> specification,
                                                                                java.util.Map<Specification<? extends T>,PartitionRepository> partitionMap)
Specified by:
collectAllPartitionsWithRepositorySatisfying in interface PartitionRepository<T extends Entity>

findPartitionFor

public <V extends T> PartitionRepository findPartitionFor(Specification<V> partitionSpecification)
Specified by:
findPartitionFor in interface PartitionRepository<T extends Entity>

getPartitionOnlyEntities

public java.util.Set<T> getPartitionOnlyEntities()
Specified by:
getPartitionOnlyEntities in interface PartitionRepository<T extends Entity>

removePartitionOnlyEntity

protected <V extends T> void removePartitionOnlyEntity(V entity)


Copyright © 2006-2010. All Rights Reserved.