net.sourceforge.floggy.persistence
Class PersistableManager

java.lang.Object
  extended by net.sourceforge.floggy.persistence.PersistableManager

public abstract class PersistableManager
extends Object

This is the main class of the framework. All persistence operations methods (such as loading, saving, deleting and searching for objects) are declared in this class.

Since:
1.0

Field Summary
static String BATCH_MODE
           
static String STORE_INDEX_AFTER_SAVE_OPERATION
           
 
Constructor Summary
PersistableManager()
           
 
Method Summary
abstract  int batchSave(Persistable persistable)
          Store an object in the repository, it will always create a new entry on the repository.
The main use of this method is to import data from a remote source.
Set the property BATCH_MODE to true to improve the performance and create only one object to save the data.
abstract  void delete(Persistable persistable)
          Removes an object from the repository.
abstract  void deleteAll()
          Removes all objects from the repository.
abstract  void deleteAll(Class persistableClass)
          Removes all objects that belongs to the class passed as parameter from the repository.
abstract  SingleObjectSet find(Class persistableClass, Filter filter, Comparator comparator)
          Searches objects of an especific persistable class from the repository.
abstract  SingleObjectSet find(Class persistableClass, Filter filter, Comparator comparator, boolean lazy)
          Searches objects of a specific persistable class from the repository.
abstract  SingleObjectSet find(Class persistableClass, IndexFilter indexFilter, boolean lazy)
          Searches objects of a specific persistable class from the repository.
abstract  int getId(Persistable persistable)
          Gets the id under the persistable is stored.
static PersistableManager getInstance()
          Returns the current instance of PersistableManager.
abstract  Object getProperty(String name)
          Get a property
abstract  boolean isPersisted(Persistable persistable)
          Check if the object is already persisted.
abstract  void load(Persistable persistable, int id)
          Load an previously stored object from the repository using the object ID.
The object ID is the result of a save operation or you can obtain it executing a search.
abstract  void load(Persistable persistable, int id, boolean lazy)
          Load an previously stored object from the repository using the object ID.
The object ID is the result of a save operation or you can obtain it executing a search.
abstract  PolymorphicObjectSet polymorphicFind(Class persistableClass, Filter filter, boolean lazy)
          Searches objects of an persistable class and its subclasses from the repository.
abstract  int save(Persistable persistable)
          Store an object in the repository.
abstract  void setProperty(String name, Object value)
          Set a property
abstract  void shutdown()
          Shutdown the PersistableManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BATCH_MODE

public static final String BATCH_MODE
See Also:
Constant Field Values

STORE_INDEX_AFTER_SAVE_OPERATION

public static final String STORE_INDEX_AFTER_SAVE_OPERATION
See Also:
Constant Field Values
Constructor Detail

PersistableManager

public PersistableManager()
Method Detail

getInstance

public static PersistableManager getInstance()
Returns the current instance of PersistableManager.

Returns:
The current instance of PersistableManager.
Throws:
RuntimeException - DOCUMENT ME!

batchSave

public abstract int batchSave(Persistable persistable)
                       throws FloggyException
Store an object in the repository, it will always create a new entry on the repository.
The main use of this method is to import data from a remote source.
Set the property BATCH_MODE to true to improve the performance and create only one object to save the data.

PersistableManager manager = PersistableManager.getInstance();
* manager.setProperty(PersistableManager.BATCH_MODE, Boolean.TRUE);
* Customer customer = new Customer();
* for(int i = 0; i < ...; i++) {
*   loadDataFromServerOnCustomer(customer);
*   manager.batchSave(customer);
* } manager.setProperty(PersistableManager.BATCH_MODE, Boolean.FALSE);
*


The object ID obtained from this operation can be used in the load operations.

Parameters:
persistable - Object to be stored.
Returns:
The ID of the object.
Throws:
FloggyException - Exception thrown if an error occurs while storing the object.
See Also:
load(Persistable, int)

delete

public abstract void delete(Persistable persistable)
                     throws FloggyException
Removes an object from the repository. If the object is not stored in the repository then a FloggyException will be thrown.

Parameters:
persistable - Object to be removed.
Throws:
FloggyException - Exception thrown if an error occurs while removing the object.

deleteAll

public abstract void deleteAll()
                        throws FloggyException
Removes all objects from the repository.

Throws:
FloggyException - Exception thrown if an error occurs while removing the objects.

deleteAll

public abstract void deleteAll(Class persistableClass)
                        throws FloggyException
Removes all objects that belongs to the class passed as parameter from the repository.

Parameters:
persistableClass - The persistable class to search the objects.
Throws:
FloggyException - Exception thrown if an error occurs while removing the objects.

find

public abstract SingleObjectSet find(Class persistableClass,
                                     Filter filter,
                                     Comparator comparator)
                              throws FloggyException
Searches objects of an especific persistable class from the repository.

An optional application-defined search criteria can be defined using a Filter.

An optional application-defined sort order can be defined using a Comparator.

Parameters:
persistableClass - The persistable class to search the objects.
filter - An optional application-defined criteria for searching objects.
comparator - An optional application-defined criteria for sorting objects.
Returns:
List of objects that matches the defined criteria.
Throws:
FloggyException - DOCUMENT ME!

find

public abstract SingleObjectSet find(Class persistableClass,
                                     IndexFilter indexFilter,
                                     boolean lazy)
                              throws FloggyException
Searches objects of a specific persistable class from the repository. It uses an index as the base mechanism to evaluate the registers in the repository

Parameters:
persistableClass - The persistable class to search the objects.
indexFilter - The filter object based on an index.
lazy - A flag indicating to load or not all composite relationships.
Returns:
List of objects that matches the defined criteria.
Throws:
FloggyException - DOCUMENT ME!

find

public abstract SingleObjectSet find(Class persistableClass,
                                     Filter filter,
                                     Comparator comparator,
                                     boolean lazy)
                              throws FloggyException
Searches objects of a specific persistable class from the repository.

An optional application-defined search criteria can be defined using a Filter.

An optional application-defined sort order can be defined using a Comparator.

Parameters:
persistableClass - The persistable class to search the objects.
filter - An optional application-defined criteria for searching objects.
comparator - An optional application-defined criteria for sorting objects.
lazy - A flag indicating to load or not all composite relationships.
Returns:
List of objects that matches the defined criteria.
Throws:
FloggyException - DOCUMENT ME!

getId

public abstract int getId(Persistable persistable)
Gets the id under the persistable is stored.

Parameters:
persistable - Object to be retrieved the id.
Returns:
the id under the persistable is stored

getProperty

public abstract Object getProperty(String name)
Get a property

Parameters:
name - the property's name
Returns:
the property's value

isPersisted

public abstract boolean isPersisted(Persistable persistable)
Check if the object is already persisted.
WARNING The method only checks if the underline system has an entry for the given persistable object. The method doesn't checks if the fields have changed.

Parameters:
persistable - Object to be checked the persistable state.
Returns:
true if the object is already persisted in the underline system, false otherwise.

load

public abstract void load(Persistable persistable,
                          int id)
                   throws FloggyException
Load an previously stored object from the repository using the object ID.
The object ID is the result of a save operation or you can obtain it executing a search.

Parameters:
persistable - An instance where the object data will be loaded into. Cannot be null.
id - The ID of the object to be loaded from the repository.
Throws:
FloggyException - Exception thrown if an error occurs while loading the object.
See Also:
save(Persistable)

load

public abstract void load(Persistable persistable,
                          int id,
                          boolean lazy)
                   throws FloggyException
Load an previously stored object from the repository using the object ID.
The object ID is the result of a save operation or you can obtain it executing a search.

Parameters:
persistable - An instance where the object data will be loaded into. Cannot be null.
id - The ID of the object to be loaded from the repository.
lazy - A flag indicating to load or not all composite relationships.
Throws:
FloggyException - Exception thrown if an error occurs while loading the object.
See Also:
save(Persistable)

polymorphicFind

public abstract PolymorphicObjectSet polymorphicFind(Class persistableClass,
                                                     Filter filter,
                                                     boolean lazy)
                                              throws FloggyException
Searches objects of an persistable class and its subclasses from the repository.

An optional application-defined search criteria can be defined using a Filter.

An optional application-defined sort order can be defined using a Comparator.

Parameters:
persistableClass - The persistable class to search the objects.
filter - An optional application-defined criteria for searching objects.
lazy - A flag indicating to load or not all composite relationships.
Returns:
List of objects that matches the defined criteria.
Throws:
FloggyException - DOCUMENT ME!

save

public abstract int save(Persistable persistable)
                  throws FloggyException
Store an object in the repository. If the object is already in the repository, the object data will be overwritten.
The object ID obtained from this operation can be used in the load operations.

Parameters:
persistable - Object to be stored.
Returns:
The ID of the object.
Throws:
FloggyException - Exception thrown if an error occurs while storing the object.
See Also:
load(Persistable, int)

setProperty

public abstract void setProperty(String name,
                                 Object value)
Set a property

Parameters:
name - the property's name
value - the property's value

shutdown

public abstract void shutdown()
                       throws FloggyException
Shutdown the PersistableManager.

Throws:
FloggyException - DOCUMENT ME!


Copyright © 2006-2011 Floggy Open Source Group. All Rights Reserved.