de.mathema.pride
Class DatabaseAdapter

java.lang.Object
  extended by de.mathema.pride.DatabaseAdapter
Direct Known Subclasses:
ObjectAdapter

public abstract class DatabaseAdapter
extends java.lang.Object

Convenience baseclass, providing a set of simple methods for interaction between the database and data entity objects. Most of the functions get an object 'entity' passed as the first parameter which is the data entity to extract data from for database manipulation resp. to pass data to returned from database queries.
This class is of minor importance. The derived types MappedObject or ValueObjectAdapter are usually sufficient and easier to use.

Author:
Jan Lessner

Field Summary
static java.lang.String REVISION_ID
           
 
Constructor Summary
DatabaseAdapter()
           
 
Method Summary
protected static void commit(RecordDescriptor red)
           
protected  java.lang.String constraint(java.lang.Object entity, java.lang.String[] dbfields, boolean byLike, RecordDescriptor red)
          Assembles an SQL constraint which would be used as a WHERE clause in a query.
protected static void create(java.lang.Object entity, ExtensionDescriptor xd)
           
protected static int create(java.lang.Object entity, RecordDescriptor red)
          Create a new record.
protected static int create(java.lang.Object entity, java.lang.String[] autoFields, RecordDescriptor red)
          Like function above but additionally allows to pass a set of fields which should be excluded from the SQL insert command.
protected static int delete(java.lang.Object entity, RecordDescriptor red)
           
protected static int delete(java.lang.Object entity, java.lang.String[] dbkeyfields, RecordDescriptor red)
           
protected static void fetch(java.lang.Object entity, ExtensionDescriptor xd)
           
protected static void fetch(java.lang.Object entity, ExtensionDescriptor xd, java.lang.String attrName)
           
protected static void fetch(java.lang.Object entity, ExtensionDescriptor xd, java.lang.String[] attrNames)
           
protected static void fetch(java.lang.Object entity, java.lang.Object key, RecordDescriptor red)
          Fetch an object by key.
protected static void find(java.lang.Object entity, RecordDescriptor red)
          Same like query() but takes the first record only
protected static void find(java.lang.Object entity, java.lang.String[] dbfields, RecordDescriptor red)
          Same like query() but takes the first record only
protected static void find(java.lang.Object entity, java.lang.String where, RecordDescriptor red)
          Same like query() but takes the first record only
protected static Database getDatabase(ExtensionDescriptor xd)
           
protected static Database getDatabase(RecordDescriptor red)
           
protected static void process(java.lang.Exception x, RecordDescriptor red)
           
protected static ResultIterator query(java.lang.Object entity, java.lang.String[] dbfields, RecordDescriptor red)
          Fetch an object by fields.
protected static ResultIterator query(java.lang.Object entity, java.lang.String where, RecordDescriptor red)
          Fetch an object by a self-made where clause
protected static ResultIterator queryAll(java.lang.Object entity, RecordDescriptor red)
          Fetch all objects
protected static void update(java.lang.Object entity, ExtensionDescriptor xd)
           
protected static void update(java.lang.Object entity, ExtensionDescriptor xd, java.lang.String attrName)
           
protected static void update(java.lang.Object entity, ExtensionDescriptor xd, java.lang.String[] attrNames)
           
protected static int update(java.lang.Object entity, RecordDescriptor red)
           
protected static int update(java.lang.Object entity, java.lang.String[] dbkeyfields, RecordDescriptor red)
           
protected static int update(java.lang.Object entity, java.lang.String[] dbkeyfields, java.lang.String[] updatefields, RecordDescriptor red)
           
protected static int update(java.lang.Object entity, java.lang.String where, RecordDescriptor red)
           
protected static int update(java.lang.Object entity, java.lang.String where, java.lang.String[] updatefields, RecordDescriptor red)
           
protected static ResultIterator wildcard(java.lang.Object entity, java.lang.String[] dbfields, RecordDescriptor red)
          Same like query() but performs a wildcard search
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION_ID

public static final java.lang.String REVISION_ID
See Also:
Constant Field Values
Constructor Detail

DatabaseAdapter

public DatabaseAdapter()
Method Detail

getDatabase

protected static Database getDatabase(RecordDescriptor red)

getDatabase

protected static Database getDatabase(ExtensionDescriptor xd)

fetch

protected static void fetch(java.lang.Object entity,
                            java.lang.Object key,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Fetch an object by key.

Throws:
java.sql.SQLException

query

protected static ResultIterator query(java.lang.Object entity,
                                      java.lang.String[] dbfields,
                                      RecordDescriptor red)
                               throws java.sql.SQLException
Fetch an object by fields. The values are taken from the fields' accociated get-methods

Throws:
java.sql.SQLException

wildcard

protected static ResultIterator wildcard(java.lang.Object entity,
                                         java.lang.String[] dbfields,
                                         RecordDescriptor red)
                                  throws java.sql.SQLException
Same like query() but performs a wildcard search

Throws:
java.sql.SQLException

find

protected static void find(java.lang.Object entity,
                           java.lang.String[] dbfields,
                           RecordDescriptor red)
                    throws java.sql.SQLException
Same like query() but takes the first record only

Throws:
java.sql.SQLException

find

protected static void find(java.lang.Object entity,
                           RecordDescriptor red)
                    throws java.sql.SQLException
Same like query() but takes the first record only

Throws:
java.sql.SQLException

queryAll

protected static ResultIterator queryAll(java.lang.Object entity,
                                         RecordDescriptor red)
                                  throws java.sql.SQLException
Fetch all objects

Throws:
java.sql.SQLException

query

protected static ResultIterator query(java.lang.Object entity,
                                      java.lang.String where,
                                      RecordDescriptor red)
                               throws java.sql.SQLException
Fetch an object by a self-made where clause

Throws:
java.sql.SQLException

find

protected static void find(java.lang.Object entity,
                           java.lang.String where,
                           RecordDescriptor red)
                    throws java.sql.SQLException
Same like query() but takes the first record only

Throws:
java.sql.SQLException

update

protected static int update(java.lang.Object entity,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static int update(java.lang.Object entity,
                            java.lang.String[] dbkeyfields,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static int update(java.lang.Object entity,
                            java.lang.String[] dbkeyfields,
                            java.lang.String[] updatefields,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static int update(java.lang.Object entity,
                            java.lang.String where,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static int update(java.lang.Object entity,
                            java.lang.String where,
                            java.lang.String[] updatefields,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

create

protected static int create(java.lang.Object entity,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Create a new record. The values are taken from the passed object, according to the specifications of the provided RecordDescriptor

Throws:
java.sql.SQLException

create

protected static int create(java.lang.Object entity,
                            java.lang.String[] autoFields,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Like function above but additionally allows to pass a set of fields which should be excluded from the SQL insert command. This functon is required if the table containes any database-managed columns which must not be provided on creation (usually sequence columns).

Throws:
java.sql.SQLException

delete

protected static int delete(java.lang.Object entity,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

delete

protected static int delete(java.lang.Object entity,
                            java.lang.String[] dbkeyfields,
                            RecordDescriptor red)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

constraint

protected java.lang.String constraint(java.lang.Object entity,
                                      java.lang.String[] dbfields,
                                      boolean byLike,
                                      RecordDescriptor red)
Assembles an SQL constraint which would be used as a WHERE clause in a query.

Parameters:
entity - The object to take the attribute values from
dbfields - The database fields to consider
byLike - Use the like operator if set
red - The RecordDescriptor providing the attribute mappings
Returns:
The SQL constraint (without leading 'where')

commit

protected static void commit(RecordDescriptor red)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

process

protected static void process(java.lang.Exception x,
                              RecordDescriptor red)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static void update(java.lang.Object entity,
                             ExtensionDescriptor xd)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static void update(java.lang.Object entity,
                             ExtensionDescriptor xd,
                             java.lang.String attrName)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

update

protected static void update(java.lang.Object entity,
                             ExtensionDescriptor xd,
                             java.lang.String[] attrNames)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

fetch

protected static void fetch(java.lang.Object entity,
                            ExtensionDescriptor xd)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

fetch

protected static void fetch(java.lang.Object entity,
                            ExtensionDescriptor xd,
                            java.lang.String attrName)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

fetch

protected static void fetch(java.lang.Object entity,
                            ExtensionDescriptor xd,
                            java.lang.String[] attrNames)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

create

protected static void create(java.lang.Object entity,
                             ExtensionDescriptor xd)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException