|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.domian.repository.AbstractRepository<T> net.sourceforge.domian.repository.AbstractDomianCoreRepository<T> net.sourceforge.domian.repository.XStreamXmlFilePerEntityRepository<T>
public class XStreamXmlFilePerEntityRepository<T extends Entity>
A persistent repository backed by XStream functionality.
The only persistence definition supported by this repository isPersistenceDefinition.FILE
.
All repository operations are executed in an exclusive fashion, applying pessimistic locking.
Translated into ACID terms, this corresponds to isolation level SERIALIZABLE
.
All entities in this repository are persisted into individual XML files.
The typical disc footprint is 1KB per entity.
The persistence format is human readable XStream XML.
The file encoding is UTF-8.
File-based stores counts as persistent storage media,
although the nature of the synchronous writings to disc obviously depends on the file system implementations involved.
NB! When used as a partition repository, this repository implementation does not reflect altered state between partitions.
When changing state in entities residing in more han one partition,
for which at least one of them is a XStreamXmlFilePerEntityRepository
,
explicit updates for all partitions involved are needed.
PersistenceDefinition.FILE
Nested Class Summary | |
---|---|
protected static class |
AbstractXStreamXmlFilePerEntityRepository.EntityId_NamedXStreamFilePersistenceStrategy
Custom FilePersistenceStrategy class. |
Field Summary | |
---|---|
protected static java.lang.String |
DEFAULT_REPOSITORY_ROOT_DIR_NAME
|
protected static java.lang.String |
DEFAULT_REPOSITORY_ROOT_PATH
|
protected java.lang.String |
repositoryId
The repository-ID the name of the repository. |
protected java.lang.String |
repositoryRootPath
For file-based repositories the repositoryRootPath is the absolute path for all repositories of the same type. |
protected static java.lang.String |
XSTREAM_XML_FILE_SUFFIX
|
Fields inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository |
---|
DEFAULT_DOMIAN_ROOT_DIR_NAME, DEFAULT_DOMIAN_ROOT_PATH, log, synchronizer |
Fields inherited from class net.sourceforge.domian.repository.AbstractRepository |
---|
supportsRecursiveIndexing, usesNativePartitioningSupport |
Constructor Summary | |
---|---|
XStreamXmlFilePerEntityRepository(java.lang.String repositoryId)
|
|
XStreamXmlFilePerEntityRepository(java.lang.String repositoryRootPath,
java.lang.String repositoryId)
|
|
XStreamXmlFilePerEntityRepository(java.lang.String repositoryRootPath,
java.lang.String repositoryId,
Synchronizer synchronizer)
|
|
XStreamXmlFilePerEntityRepository(java.lang.String repositoryId,
Synchronizer synchronizer)
|
Method Summary | ||
---|---|---|
protected void |
call(java.util.concurrent.Callable<T> callable)
Added for completeness. |
|
protected
|
callConcurrently(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in a concurrent manner. |
|
protected
|
callConcurrentlyInNewThread(java.util.concurrent.Callable<T> callable)
|
|
protected
|
callConcurrentlyWithRetry(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in a concurrent manner. |
|
protected
|
callExclusively(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in an exclusively manner. |
|
protected
|
callExclusivelyInNewThread(java.util.concurrent.Callable<T> callable)
|
|
protected
|
callExclusivelyWithRetry(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in an exclusively manner. |
|
void |
close()
Closes the repository and releases all resources. |
|
java.lang.Long |
countAllEntities()
|
|
protected void |
createRepositoryFilesIfNotExist()
|
|
|
findAllEntitiesSpecifiedBy(Specification<V> specification)
Finds and returns all entities approved by the given specification. |
|
java.lang.String |
getEncoding()
|
|
protected static java.lang.String |
getEntityIdBasedFilenameFrom(Entity entity)
A naming scheme for file-per-entity Domian XStream persistence. |
|
java.lang.String |
getFormat()
|
|
java.lang.Integer |
getMaxNumberOfRetries()
|
|
EntityMetaData |
getMetaDataFor(T entity)
|
|
PersistenceDefinition |
getPersistenceDefinition()
|
|
java.io.File |
getRepositoryDirectory()
The unique file directory in which the repository data files resides. |
|
java.lang.String |
getRepositoryId()
The repository-ID the name of the repository. |
|
protected java.lang.String |
getRepositoryPath(java.lang.String repositoryRootPath,
PersistentRepository<T> repository)
|
|
java.lang.String |
getRepositoryPathString()
|
|
java.lang.String |
getRepositoryRootPath()
|
|
java.lang.Integer |
getRetryTimeoutInMilliseconds()
|
|
|
iterateAllEntitiesSpecifiedBy(Specification<V> specification)
Finds and returns all entities approved by the given specification. |
|
void |
load()
The semantics of this operation depends on the Repository 's PersistenceDefinition . |
|
void |
persist()
The semantics of this operation depends on the Repository 's PersistenceDefinition . |
|
|
put(V entity)
Puts the given entity into this repository. |
|
|
remove(V entity)
Removes the given entity from this repository. |
|
|
removeAllEntitiesSpecifiedBy(Specification<V> specification)
Removes all entities approved by the given specification. |
|
protected void |
run(java.lang.Runnable runnable)
Added for completeness. |
|
protected void |
runAsynchronously(java.lang.Runnable runnable)
Executes the given Runnable in a fresh and independent thread. |
|
protected void |
runConcurrently(java.lang.Runnable runnable)
Convenience method for running a Runnable in a concurrent manner. |
|
void |
setMaxNumberOfRetries(java.lang.Integer maxNumberOfRetries)
|
|
void |
setRetryTimeoutInMilliseconds(java.lang.Integer retryTimeoutInMilliseconds)
|
|
|
update(V entity)
Updates an entity. |
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, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, 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, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, iterate, iterateAll, makePartition, putAll, remove, removeAll, update |
Field Detail |
---|
protected static final java.lang.String DEFAULT_REPOSITORY_ROOT_DIR_NAME
protected static final java.lang.String DEFAULT_REPOSITORY_ROOT_PATH
protected static final java.lang.String XSTREAM_XML_FILE_SUFFIX
protected java.lang.String repositoryRootPath
repositoryRootPath
is the absolute path for all repositories of the same type.
protected java.lang.String repositoryId
${repositoryRootPath}/${repositoryId}
forms the absolute folder path in which the repository data resides.
Constructor Detail |
---|
public XStreamXmlFilePerEntityRepository(java.lang.String repositoryId)
public XStreamXmlFilePerEntityRepository(java.lang.String repositoryId, Synchronizer synchronizer)
public XStreamXmlFilePerEntityRepository(java.lang.String repositoryRootPath, java.lang.String repositoryId)
public XStreamXmlFilePerEntityRepository(java.lang.String repositoryRootPath, java.lang.String repositoryId, Synchronizer synchronizer)
Method Detail |
---|
public java.lang.Long countAllEntities()
public <V extends T> java.util.Iterator<V> iterateAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
specification
- the entity specification
public <V extends T> java.util.Collection<V> findAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
specification
- the entity specification
public <V extends T> void put(V entity)
Repository
entity
- the entity to be storedpublic <V extends T> java.lang.Long removeAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
specification
- the entity specification
public <V extends T> java.lang.Boolean remove(V entity)
Repository
entity
- the entity to be removed
true
if the entity is found and removed, otherwise false
public PersistenceDefinition getPersistenceDefinition()
public java.lang.String getFormat()
public void load()
PersistentRepository
Repository
's PersistenceDefinition
.
public void persist()
PersistentRepository
Repository
's PersistenceDefinition
.
public <V extends T> void update(V entity)
Repository
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.
public EntityMetaData getMetaDataFor(T entity)
public void close()
PersistentRepository
protected static java.lang.String getEntityIdBasedFilenameFrom(Entity entity)
protected void createRepositoryFilesIfNotExist()
public java.lang.String getRepositoryRootPath()
public java.lang.String getRepositoryId()
PersistentRepository
getRepositoryId
in interface PersistentRepository<T extends Entity>
public java.lang.String getRepositoryPathString()
public java.io.File getRepositoryDirectory()
PersistentRepository
getRepositoryDirectory
in interface PersistentRepository<T extends Entity>
public java.lang.Integer getMaxNumberOfRetries()
public void setMaxNumberOfRetries(java.lang.Integer maxNumberOfRetries)
public java.lang.Integer getRetryTimeoutInMilliseconds()
public void setRetryTimeoutInMilliseconds(java.lang.Integer retryTimeoutInMilliseconds)
public java.lang.String getEncoding()
getEncoding
in interface TextualFormatRepository<T extends Entity>
protected java.lang.String getRepositoryPath(java.lang.String repositoryRootPath, PersistentRepository<T> repository)
protected void run(java.lang.Runnable runnable)
protected void call(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
java.lang.Exception
protected void runConcurrently(java.lang.Runnable runnable)
Runnable
in a concurrent manner.
Synchronizer
protected <T> T callConcurrently(java.util.concurrent.Callable<T> callable)
Callable
in a concurrent manner.
Synchronizer
protected <T> T callExclusively(java.util.concurrent.Callable<T> callable)
Callable
in an exclusively manner.
Synchronizer
protected <T> T callConcurrentlyWithRetry(java.util.concurrent.Callable<T> callable)
Callable
in a concurrent manner.
If an exception is thrown, the Callable
will be immediately retried.
The nature of the retries are further defined by the maxNumberOfRetries
and
retryTimeoutInMilliseconds
member values.
protected <T> T callExclusivelyWithRetry(java.util.concurrent.Callable<T> callable)
Callable
in an exclusively manner.
If an exception is thrown, the Callable
will be immediately queued for retrial.
The nature of the retries are further defined by the maxNumberOfRetries
and
retryTimeoutInMilliseconds
member values.
protected <T> T callConcurrentlyInNewThread(java.util.concurrent.Callable<T> callable) throws java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
java.lang.InterruptedException
protected <T> T callExclusivelyInNewThread(java.util.concurrent.Callable<T> callable) throws java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
java.lang.InterruptedException
protected void runAsynchronously(java.lang.Runnable runnable)
Runnable
in a fresh and independent thread.
This method does not block the original thread.
The Synchronizer
mode is concurrent.
(An asynchronous version of Synchronizer
in exclusive mode has no meaning,
as it is a "stop-the-world" kind of mode.)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |