Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.enableit.db.daf.jdbc
Class JdbcDaf  view JdbcDaf download JdbcDaf.java

java.lang.Object
  extended byorg.enableit.db.daf.jdbc.JdbcDaf
All Implemented Interfaces:
org.enableit.db.daf.DataAbstractionFacade

public class JdbcDaf
extends java.lang.Object
implements org.enableit.db.daf.DataAbstractionFacade

Implementation of DataAbstractionFacade backed by JDBC calls.
Since this class requires no additional metadata file to map Bean properties to database columns, it must rely on a naming convention in order to construct the correct SQL. It is expected that this restriction will be acceptable for applications where UI and function is more important than database design, and where there is no existing database.
The convention is as follows:


Field Summary
protected  java.lang.String dataSourceName
           
protected  java.lang.String driverClass
           
protected static org.apache.log4j.Category logger
          The Log4J Category doing the logging.
protected  java.lang.String password
           
protected  java.lang.String url
           
protected  java.lang.String username
           
 
Constructor Summary
JdbcDaf(org.enableit.db.daf.conf.ProviderDetails pd)
          Construct and configure a new instance.
 
Method Summary
 java.lang.Object create(java.lang.Object bean)
          Create a persistent copy of the received JavaBean.
 boolean exists(java.lang.Object bean)
          Test if the bean exists in the configured data store.
protected  java.lang.String getDeleteSql(java.lang.Object bean, java.lang.String tableName, java.lang.String keyColumn)
          Returns SQL to do a delete, providing that naming convention has been observed.
protected  java.lang.String getFindSql(java.lang.Object bean)
          Return the SQL to find a bean.
protected  java.lang.String getFindSql(java.lang.Object bean, java.util.List equalityProps)
          Return the SQL to find a bean.
protected  java.lang.String getInsertSql(java.lang.Object bean, java.lang.String tableName)
          Returns SQL to do an insert, providing that naming convention has been observed.
protected  java.lang.String getKeyColumn(java.lang.String tableName)
           
protected  java.sql.Connection getPooledConnection()
          Return a connection to the database.
protected  java.lang.String getSelectSql(java.lang.Object bean, java.lang.String tableName, java.lang.String keyColumn)
          Returns SQL to do a select, providing that naming convention has been observed.
protected  java.lang.String getTableName(java.lang.Object bean)
          Returns the name of the table derived from the Bean name according to conventions.
protected  java.lang.String getUpdateSql(java.lang.Object bean, java.lang.String tableName, java.lang.String keyColumn)
          Returns SQL to do an update, providing that naming convention has been observed.
 java.lang.Object load(java.lang.Object bean)
          Load a JavaBean from the data store.
 java.lang.Object modify(java.lang.Object bean)
           
 java.lang.Object remove(java.lang.Object bean)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Category logger
The Log4J Category doing the logging.


dataSourceName

protected java.lang.String dataSourceName

driverClass

protected java.lang.String driverClass

url

protected java.lang.String url

username

protected java.lang.String username

password

protected java.lang.String password
Constructor Detail

JdbcDaf

public JdbcDaf(org.enableit.db.daf.conf.ProviderDetails pd)
Construct and configure a new instance.

Method Detail

exists

public boolean exists(java.lang.Object bean)
               throws org.enableit.db.daf.QueryException
Test if the bean exists in the configured data store.

If the bean implements org.enableit.db.daf.ComparableBean then the Persistent datastore will be queried for an entry that matches just those properties defined by the getEqualityPropertyList. Otherwise every accessible property will be used in the query.

Specified by:
exists in interface org.enableit.db.daf.DataAbstractionFacade

create

public java.lang.Object create(java.lang.Object bean)
                        throws org.enableit.db.daf.NotPersistedException
Create a persistent copy of the received JavaBean.

Specified by:
create in interface org.enableit.db.daf.DataAbstractionFacade

modify

public java.lang.Object modify(java.lang.Object bean)
                        throws org.enableit.db.daf.NotPersistedException
Specified by:
modify in interface org.enableit.db.daf.DataAbstractionFacade

remove

public java.lang.Object remove(java.lang.Object bean)
                        throws org.enableit.db.daf.NotPersistedException
Specified by:
remove in interface org.enableit.db.daf.DataAbstractionFacade

load

public java.lang.Object load(java.lang.Object bean)
                      throws org.enableit.db.daf.QueryException
Load a JavaBean from the data store.

Specified by:
load in interface org.enableit.db.daf.DataAbstractionFacade

getPooledConnection

protected java.sql.Connection getPooledConnection()
Return a connection to the database.

Using this method allows pooling of connections.


getTableName

protected java.lang.String getTableName(java.lang.Object bean)
Returns the name of the table derived from the Bean name according to conventions. TODO detail conventions.


getKeyColumn

protected java.lang.String getKeyColumn(java.lang.String tableName)

getFindSql

protected java.lang.String getFindSql(java.lang.Object bean)
                               throws org.enableit.db.daf.QueryException
Return the SQL to find a bean.


getFindSql

protected java.lang.String getFindSql(java.lang.Object bean,
                                      java.util.List equalityProps)
                               throws org.enableit.db.daf.QueryException
Return the SQL to find a bean.


getInsertSql

protected java.lang.String getInsertSql(java.lang.Object bean,
                                        java.lang.String tableName)
                                 throws org.enableit.db.daf.NotPersistedException
Returns SQL to do an insert, providing that naming convention has been observed.


getUpdateSql

protected java.lang.String getUpdateSql(java.lang.Object bean,
                                        java.lang.String tableName,
                                        java.lang.String keyColumn)
                                 throws org.enableit.db.daf.NotPersistedException
Returns SQL to do an update, providing that naming convention has been observed.


getDeleteSql

protected java.lang.String getDeleteSql(java.lang.Object bean,
                                        java.lang.String tableName,
                                        java.lang.String keyColumn)
                                 throws org.enableit.db.daf.NotPersistedException
Returns SQL to do a delete, providing that naming convention has been observed.


getSelectSql

protected java.lang.String getSelectSql(java.lang.Object bean,
                                        java.lang.String tableName,
                                        java.lang.String keyColumn)
                                 throws org.enableit.db.daf.QueryException
Returns SQL to do a select, providing that naming convention has been observed.