Holger's
Java API

com.antelmann.sql
Class JDBCRowProxy<T extends Resource>

java.lang.Object
  extended by com.antelmann.sql.JDBCRowProxy<T>
All Implemented Interfaces:
DBClassStore<T>

public class JDBCRowProxy<T extends Resource>
extends Object
implements DBClassStore<T>

provides JDBC persistence for Objects that have a corresponding ObjectRowMapper. For every access to the database, this implementation requires the database transaction to be active.

Author:
Holger Antelmann
See Also:
ObjectRowMapper

Field Summary
protected  Database<Connection> database
           
protected  ConnectionHelper helper
           
protected  ObjectRowMapper<T> mapper
           
 
Constructor Summary
JDBCRowProxy(Database<Connection> database, ObjectRowMapper<T> mapper)
           
 
Method Summary
 boolean contains(T entry)
          determines whether the given entry is present in the database; it may be, however, that the database object differs from the given object (but its IDs must be the same) if present.
 void delete(T entry)
          removes the given entry from the database
 AbstractIterator<T> fetch(Filter<T> filter)
          if the iteration fails at any point, an IterationException is thrown.
 Object generateNewID()
          returns a value supplied by the mapper
 Database<Connection> getDatabase()
          provides access to the database instance that also coordinates the transaction management.
 ObjectRowMapper<T> getMapper()
           
 T getResource(Object id)
          returns a Resource based on its ID.
 void insert(T entry)
          it is suggested to create the entry with an ID obtained through generateNewID() before passing it into this method.
 int size()
          returns the total number of T elements in this store
 void update(T entry)
          updates the given entry in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected Database<Connection> database

helper

protected ConnectionHelper helper

mapper

protected ObjectRowMapper<T extends Resource> mapper
Constructor Detail

JDBCRowProxy

public JDBCRowProxy(Database<Connection> database,
                    ObjectRowMapper<T> mapper)
Method Detail

getDatabase

public Database<Connection> getDatabase()
Description copied from interface: DBClassStore
provides access to the database instance that also coordinates the transaction management.

Specified by:
getDatabase in interface DBClassStore<T extends Resource>

getMapper

public ObjectRowMapper<T> getMapper()

contains

public boolean contains(T entry)
                 throws DatabaseException
Description copied from interface: DBClassStore
determines whether the given entry is present in the database; it may be, however, that the database object differs from the given object (but its IDs must be the same) if present.

Specified by:
contains in interface DBClassStore<T extends Resource>
Throws:
DatabaseException

delete

public void delete(T entry)
            throws DatabaseException
Description copied from interface: DBClassStore
removes the given entry from the database

Specified by:
delete in interface DBClassStore<T extends Resource>
Throws:
DatabaseException

insert

public void insert(T entry)
            throws DatabaseException
Description copied from interface: DBClassStore
it is suggested to create the entry with an ID obtained through generateNewID() before passing it into this method.

Specified by:
insert in interface DBClassStore<T extends Resource>
Throws:
DatabaseException
See Also:
DBClassStore.generateNewID()

update

public void update(T entry)
            throws DatabaseException
Description copied from interface: DBClassStore
updates the given entry in the database. If the entry didn't exist before calling this method, a DatabaseException is thrown.

Specified by:
update in interface DBClassStore<T extends Resource>
Throws:
DatabaseException

getResource

public T getResource(Object id)
                               throws DatabaseException
Description copied from interface: DBClassStore
returns a Resource based on its ID.

Specified by:
getResource in interface DBClassStore<T extends Resource>
Parameters:
id - the ID that is retrieved from Resource.getID()
Returns:
the associated resource or null if no resource is found
Throws:
DatabaseException
See Also:
Resource.getID()

fetch

public AbstractIterator<T> fetch(Filter<T> filter)
                                           throws DatabaseException
if the iteration fails at any point, an IterationException is thrown.

Specified by:
fetch in interface DBClassStore<T extends Resource>
Throws:
DatabaseException
See Also:
IterationException

generateNewID

public Object generateNewID()
                     throws DatabaseException
returns a value supplied by the mapper

Specified by:
generateNewID in interface DBClassStore<T extends Resource>
Throws:
DatabaseException
See Also:
ObjectRowMapper.generateNewID()

size

public int size()
         throws DatabaseException
Description copied from interface: DBClassStore
returns the total number of T elements in this store

Specified by:
size in interface DBClassStore<T extends Resource>
Throws:
DatabaseException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads