|
||||||||||
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.InMemoryAndXStreamXmlFileRepository<T>
public class InMemoryAndXStreamXmlFileRepository<T extends Entity>
An in-memory repository with persistence capabilities. The persistence part is backed by XStream functionality.
The only persistence definition supported by this repository isPersistenceDefinition.INMEMORY_AND_FILE
.
All entities in this repository are persisted into one single file.
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.
PersistenceDefinition.INMEMORY_AND_FILE
Field Summary | |
---|---|
protected static java.lang.String |
DEFAULT_REPOSITORY_ROOT_DIR_NAME
|
protected static java.lang.String |
DEFAULT_REPOSITORY_ROOT_FILE_NAME
|
protected static java.lang.String |
DEFAULT_REPOSITORY_ROOT_PATH
|
protected InMemoryRepository<T> |
inMemoryRepositoryDelegate
The repository delegate dealing with the in-memory stuff. |
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 | |
---|---|
InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryId)
|
|
InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryRootPath,
java.lang.String repositoryId)
|
|
InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryRootPath,
java.lang.String repositoryId,
Synchronizer synchronizer)
|
|
InMemoryAndXStreamXmlFileRepository(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. |
|
protected void |
createRepositoryRootPathIfNotExist()
|
|
|
findAllEntitiesSpecifiedBy(Specification<V> specification)
Finds and returns all entities approved by the given specification. |
|
java.lang.String |
getEncoding()
|
|
java.lang.String |
getFormat()
|
|
java.lang.Integer |
getMaxNumberOfRetries()
|
|
EntityPersistenceMetaData |
getMetaDataFor(T notApplicableEntity)
|
|
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()
|
|
protected java.lang.String |
getRepositoryTypeName()
|
|
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 . |
|
protected void |
purgeRepositoryEntitiesFileOnly_IfExist()
|
|
protected void |
purgeRepositoryFilesIfExist()
|
|
protected void |
purgeRepositoryFilesIfExist(int filesToBePurgedLimit,
java.lang.Boolean purgeRepositoryFolder,
java.lang.Boolean purgeMetadata)
|
|
|
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.TextualFormatRepository |
---|
getEncoding |
Methods inherited from interface net.sourceforge.domian.repository.PersistentRepository |
---|
getMetaDataFor, getRepositoryDirectory, getRepositoryId |
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_FILE_NAME
protected static final java.lang.String DEFAULT_REPOSITORY_ROOT_DIR_NAME
protected static final java.lang.String DEFAULT_REPOSITORY_ROOT_PATH
protected InMemoryRepository<T extends Entity> inMemoryRepositoryDelegate
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 InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryId)
public InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryRootPath, java.lang.String repositoryId)
public InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryId, Synchronizer synchronizer)
public InMemoryAndXStreamXmlFileRepository(java.lang.String repositoryRootPath, java.lang.String repositoryId, Synchronizer synchronizer)
Method Detail |
---|
protected java.lang.String getRepositoryTypeName()
public <V extends T> java.util.Iterator<V> iterateAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
iterateAllEntitiesSpecifiedBy
in interface Repository<T extends Entity>
specification
- the entity specification
public <V extends T> java.util.Collection<V> findAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
findAllEntitiesSpecifiedBy
in interface Repository<T extends Entity>
specification
- the entity specification
public <V extends T> void put(V entity)
Repository
put
in interface Repository<T extends Entity>
entity
- the entity to be storedpublic <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.
update
in interface Repository<T extends Entity>
public <V extends T> java.lang.Long removeAllEntitiesSpecifiedBy(Specification<V> specification)
Repository
removeAllEntitiesSpecifiedBy
in interface Repository<T extends Entity>
specification
- the entity specification
public <V extends T> java.lang.Boolean remove(V entity)
Repository
remove
in interface Repository<T extends Entity>
entity
- the entity to be removed
true
if the entity is found and removed, otherwise false
public PersistenceDefinition getPersistenceDefinition()
getPersistenceDefinition
in interface PersistentRepository<T extends Entity>
public java.lang.String getFormat()
getFormat
in interface PersistentRepository<T extends Entity>
public void load()
PersistentRepository
Repository
's PersistenceDefinition
.
load
in interface PersistentRepository<T extends Entity>
public void persist()
PersistentRepository
Repository
's PersistenceDefinition
.
persist
in interface PersistentRepository<T extends Entity>
public void close()
PersistentRepository
close
in interface PersistentRepository<T extends Entity>
public EntityPersistenceMetaData getMetaDataFor(T notApplicableEntity)
protected void createRepositoryRootPathIfNotExist()
protected void purgeRepositoryFilesIfExist()
protected void purgeRepositoryEntitiesFileOnly_IfExist()
protected void purgeRepositoryFilesIfExist(int filesToBePurgedLimit, java.lang.Boolean purgeRepositoryFolder, java.lang.Boolean purgeMetadata)
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 |