org.objectledge.database.persistence
Class DefaultPersistence

java.lang.Object
  extended by org.objectledge.database.persistence.DefaultPersistence
All Implemented Interfaces:
Persistence

public class DefaultPersistence
extends Object
implements Persistence

Provides Object-Relational DB mapping.

Version:
$Id: DefaultPersistence.java,v 1.5 2005/05/05 11:13:02 rafal Exp $
Author:
Rafal Krzewski, Pawel Potempski

Field Summary
private  Database database
          The Database.
private  org.jcontainer.dna.Logger logger
          The logger
 
Constructor Summary
DefaultPersistence(Database database, org.jcontainer.dna.Logger logger)
          Component constructor.
 
Method Summary
 int count(String table, String where)
          An utility method for checking the number of matching rows.
 void delete(Persistent object)
          Removes an object from the database.
 void delete(String where, PersistentFactory factory)
          Removes the objects from the database.
 boolean exists(String table, String where)
          An utility method for checking for existence of rows.
 Database getDatabase()
          Get the database component used by persistence.
 Persistent load(long id, PersistentFactory factory)
          Loads an object from the database.
 List load(String where, PersistentFactory factory)
          Loads objects from the database.
 void revert(Persistent object)
          Reverts the object to the saved state.
 void save(Persistent object)
          Saves an object in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

private Database database
The Database.


logger

private org.jcontainer.dna.Logger logger
The logger

Constructor Detail

DefaultPersistence

public DefaultPersistence(Database database,
                          org.jcontainer.dna.Logger logger)
Component constructor.

Parameters:
database - the database.
logger - the logger.
Method Detail

load

public Persistent load(long id,
                       PersistentFactory factory)
                throws PersistenceException
Loads an object from the database.

Specified by:
load in interface Persistence
Parameters:
id - the identifier of the object.
factory - the object instance factory.
Returns:
the presistent object.
Throws:
PersistenceException - if any exception occured.

load

public List load(String where,
                 PersistentFactory factory)
          throws PersistenceException
Loads objects from the database.

Note that joins are not supported. This package provides a means of converting objects to rows in a table and vice versa. If you want more, you need some different tool.

Specified by:
load in interface Persistence
Parameters:
where - the where clause to be used in the query
factory - the object instance factory.
Returns:
the list of presistent objects.
Throws:
PersistenceException - if any exception occured.

save

public void save(Persistent object)
          throws PersistenceException
Saves an object in the database.

Specified by:
save in interface Persistence
Parameters:
object - the object to be saved.
Throws:
PersistenceException - if any exception occured.

revert

public void revert(Persistent object)
            throws PersistenceException,
                   IllegalStateException
Reverts the object to the saved state.

Specified by:
revert in interface Persistence
Parameters:
object - the object to have it's state restored.
Throws:
PersistenceException - if any exception occured.
IllegalStateException - if no state has been saved yet for the object in question.

delete

public void delete(Persistent object)
            throws PersistenceException
Removes an object from the database.

Specified by:
delete in interface Persistence
Parameters:
object - the object to be removed.
Throws:
PersistenceException - if any exception occured.

delete

public void delete(String where,
                   PersistentFactory factory)
            throws PersistenceException
Removes the objects from the database.

Specified by:
delete in interface Persistence
Parameters:
where - the where clause to be used in the query
factory - the object instance factory.
Throws:
PersistenceException - if any exception occured.

exists

public boolean exists(String table,
                      String where)
               throws PersistenceException
An utility method for checking for existence of rows.

Specified by:
exists in interface Persistence
Parameters:
table - the table to be checked.
where - the condition.
Returns:
true if the condition is true for one or more rows in the table.
Throws:
PersistenceException - if any exception occured.

count

public int count(String table,
                 String where)
          throws PersistenceException
An utility method for checking the number of matching rows.

Specified by:
count in interface Persistence
Parameters:
table - the table to be chcked.
where - the condition.
Returns:
the number of table matching the condition.
Throws:
PersistenceException - if any exception occured.

getDatabase

public Database getDatabase()
Get the database component used by persistence.

Specified by:
getDatabase in interface Persistence
Returns:
the database.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.