org.caleigo.core.service
Class MemoryDataService

java.lang.Object
  extended byorg.caleigo.core.AbstractDataService
      extended byorg.caleigo.core.service.MemoryDataService
All Implemented Interfaces:
IDataService, IDistributable, ISecureService, IService, java.io.Serializable
Direct Known Subclasses:
BinaryFileDataService, TextFileDataService, TextURLDataService

public class MemoryDataService
extends AbstractDataService

MemoryDataService provides a simple implementation of the IDataService interface that can be used to store entities in a non-persistent memory cache. By overiding the loadEntitySelection and storeEntitySelection entity pesistance can be added in a simple way. Note that the class is not suitable to store sensitive data. The class does not verify foreign keys and should only be used for temporary storage and/or for test or demonstration purposes. Note also that transaction handlig is currently not supported.

Version:
1.00
Author:
Dennis Zikovic
See Also:
Serialized Form

Nested Class Summary
protected  class MemoryDataService.DataTransaction
           
protected  class MemoryDataService.DefaultSelectionHolder
           
protected static interface MemoryDataService.ISelectionHolder
           
 
Nested classes inherited from class org.caleigo.core.AbstractDataService
AbstractDataService.AbstractDataTransaction
 
Field Summary
protected  java.util.Map mTableSelectionMap
           
 
Fields inherited from class org.caleigo.core.AbstractDataService
DEFAULT_TIMEOUT
 
Constructor Summary
MemoryDataService(IDataSourceDescriptor dataSourceDescriptor)
           
MemoryDataService(IDataSourceDescriptor dataSourceDescriptor, java.lang.Object serviceIdentity)
           
 
Method Summary
 boolean backupTo(java.io.File backupFile)
          Creates a complete backup of the called MemoryDataService to the provided file.
 boolean backupTo(java.io.File backupFile, IEntityDescriptor[] descriptorArray)
          Creates a backup of the tables defined by the provided descriptor array in the called MemoryDataService to the provided backup file.
static boolean copyDataSource(IDataService source, MemoryDataService target)
          Help method that makes a complete copy of the source data to the targeted MemoryDataService.
protected  MemoryDataService.ISelectionHolder createSelectionHolder(ISelection tableSelection)
          Can be overriden to provide a smarter ISelectionHolder class.
protected  void executeDelete(IEntity entity)
           
protected  void executeInsert(IEntity entity)
           
protected  void executeLoad(IEntity entity, Qualifier qualifier)
           
protected  void executeQuery(DataQuery query, ISelection selection)
           
protected  void executeUpdate(IEntity entity, Qualifier qualifier)
           
protected  void finalize()
           
protected  ISelection getTableSelection(IEntityDescriptor entityDescriptor)
           
 boolean isAutGenerateEnabled()
          Access method that returns true if autogeneration of identity fields with the autogen field flags set is enabled.
 boolean isSyncronized()
           
protected  ISelection loadTableSelection(IEntityDescriptor entityDescriptor)
          This method can be overriden to provide a simple persistent storage for the MemoryDataService.
protected  void markTableAsChanged(IEntityDescriptor entityDescriptor)
           
 IDataTransaction newTransaction()
          Returns a new IDataTransaction object that can be used to batch data operations and wrap them in a transaction.
 boolean ping()
          Should return true if the service is online and reponding to calls.
 boolean restoreFrom(java.io.File backupFile)
          Restores data from a backup file created by the backupTo method.
 boolean restoreFrom(java.io.File backupFile, IEntityDescriptor[] descriptorArray, boolean addDeleted)
          Restores data from a backup file created by the backupTo method.
 boolean restoreFromURL(java.net.URL backupURL)
           
 boolean restoreFromURL(java.net.URL backupURL, IEntityDescriptor[] descriptorArray, boolean addDeleted)
           
 void setAutGenerateEnabled(boolean enabled)
          Mutation method that controls true if autogeneration of identity fields with the autogen field flags should be enabled.
 void setSyncronized(boolean syncronize)
           
protected  void storeTableSelection(ISelection tableSelection)
          This method can be overriden to provide a simple persistent storage for the MemoryDataService.
 boolean syncronize()
          Can be called to syncronize changes against any persistent storage provided by a subclass.
 
Methods inherited from class org.caleigo.core.AbstractDataService
checkEntityAsDeletable, checkEntityAsStorable, delete, finalizeService, getCustomProxyService, getDataSourceDescriptor, getServiceIdentity, getServiceInterface, getServiceInterfaceClass, getServiceType, getTimeout, hasCustomProxyService, initializeService, isValidating, load, loadSelection, loadSelection, refresh, setEntityData, setTimeout, setValidating, store
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mTableSelectionMap

protected final java.util.Map mTableSelectionMap
Constructor Detail

MemoryDataService

public MemoryDataService(IDataSourceDescriptor dataSourceDescriptor)

MemoryDataService

public MemoryDataService(IDataSourceDescriptor dataSourceDescriptor,
                         java.lang.Object serviceIdentity)
Method Detail

copyDataSource

public static boolean copyDataSource(IDataService source,
                                     MemoryDataService target)
Help method that makes a complete copy of the source data to the targeted MemoryDataService. The method returns true if the copy was succesfull.


finalize

protected void finalize()

newTransaction

public IDataTransaction newTransaction()
Returns a new IDataTransaction object that can be used to batch data operations and wrap them in a transaction.

Specified by:
newTransaction in interface IDataService
Specified by:
newTransaction in class AbstractDataService

ping

public boolean ping()
Description copied from class: AbstractDataService
Should return true if the service is online and reponding to calls. Note that initializeService() must be called prior to this method.

Specified by:
ping in interface IService
Specified by:
ping in class AbstractDataService

syncronize

public boolean syncronize()
Can be called to syncronize changes against any persistent storage provided by a subclass. This mehod does only have to be called if MemoroDataService is not in a suncronized mode. Calling the method will have no effect if no persistent storage is provided by a subclass.


backupTo

public boolean backupTo(java.io.File backupFile)
Creates a complete backup of the called MemoryDataService to the provided file. Returns true is the backup was successfull.


backupTo

public boolean backupTo(java.io.File backupFile,
                        IEntityDescriptor[] descriptorArray)
Creates a backup of the tables defined by the provided descriptor array in the called MemoryDataService to the provided backup file. Returns true is the backup was successfull.


restoreFrom

public boolean restoreFrom(java.io.File backupFile)
Restores data from a backup file created by the backupTo method. Changed data will be restored and deleted entities will be re-added.


restoreFrom

public boolean restoreFrom(java.io.File backupFile,
                           IEntityDescriptor[] descriptorArray,
                           boolean addDeleted)
Restores data from a backup file created by the backupTo method.

Parameters:
backupFile - The file containing backup data to restore from.
descriptorArray - This array specifies what entity type that should be restored. If set to null all entities will be restored.
addDeleted - The addDeleted flag defines if entities that have been delted should be re-added or not. Normally this should be set to true.

restoreFromURL

public boolean restoreFromURL(java.net.URL backupURL)

restoreFromURL

public boolean restoreFromURL(java.net.URL backupURL,
                              IEntityDescriptor[] descriptorArray,
                              boolean addDeleted)

isSyncronized

public boolean isSyncronized()

setSyncronized

public void setSyncronized(boolean syncronize)

isAutGenerateEnabled

public boolean isAutGenerateEnabled()
Access method that returns true if autogeneration of identity fields with the autogen field flags set is enabled.


setAutGenerateEnabled

public void setAutGenerateEnabled(boolean enabled)
Mutation method that controls true if autogeneration of identity fields with the autogen field flags should be enabled. This should normally allways be set to true (default). It can be usable to turn off generation when copying data between sources in which case the identity data must be provided.


executeLoad

protected void executeLoad(IEntity entity,
                           Qualifier qualifier)
                    throws DataServiceException
Throws:
DataServiceException

executeQuery

protected void executeQuery(DataQuery query,
                            ISelection selection)
                     throws DataServiceException
Throws:
DataServiceException

executeInsert

protected void executeInsert(IEntity entity)
                      throws DataServiceException
Throws:
DataServiceException

executeUpdate

protected void executeUpdate(IEntity entity,
                             Qualifier qualifier)
                      throws DataServiceException
Throws:
DataServiceException

executeDelete

protected void executeDelete(IEntity entity)
                      throws DataServiceException
Throws:
DataServiceException

markTableAsChanged

protected void markTableAsChanged(IEntityDescriptor entityDescriptor)

getTableSelection

protected ISelection getTableSelection(IEntityDescriptor entityDescriptor)

loadTableSelection

protected ISelection loadTableSelection(IEntityDescriptor entityDescriptor)
This method can be overriden to provide a simple persistent storage for the MemoryDataService. The method is called prior to any access of addressed table.


storeTableSelection

protected void storeTableSelection(ISelection tableSelection)
This method can be overriden to provide a simple persistent storage for the MemoryDataService. The method is called to store changes when neaded.


createSelectionHolder

protected MemoryDataService.ISelectionHolder createSelectionHolder(ISelection tableSelection)
Can be overriden to provide a smarter ISelectionHolder class.



Copyright © 2005 Caleigo. All Rights Reserved.