org.mentawai.bean.jdbc
Class JdbcBeanSession

java.lang.Object
  extended by org.mentawai.bean.jdbc.JdbcBeanSession
All Implemented Interfaces:
BeanSession
Direct Known Subclasses:
H2BeanSession, MySQLBeanSession, OracleBeanSession

public class JdbcBeanSession
extends java.lang.Object
implements BeanSession


Field Summary
protected  ApplicationManager appManager
           
protected  java.sql.Connection conn
           
static boolean DEBUG
           
protected  java.util.IdentityHashMap<java.lang.Object,java.util.Map<java.lang.String,org.mentawai.bean.jdbc.JdbcBeanSession.Value>> loaded
           
 
Constructor Summary
JdbcBeanSession()
           
JdbcBeanSession(java.sql.Connection conn)
           
 
Method Summary
 boolean add(java.lang.Object bean1, java.lang.Object bean2)
          Add a dependency based on a relationship OneToMany/ManyToMany.
 Transaction beginTransaction()
          Create a transaction for this session.
 java.lang.String buildSelect(java.lang.Class<? extends java.lang.Object> beanClass)
           
 java.lang.String buildSelect(java.lang.Class<? extends java.lang.Object> beanClass, java.lang.String tablePrefix)
           
 java.lang.String buildSelectMinus(java.lang.Class<? extends java.lang.Object> beanClass, java.lang.String[] minus)
           
 java.lang.String buildSelectMinus(java.lang.Class<? extends java.lang.Object> beanClass, java.lang.String tablePrefix, java.lang.String[] minus)
           
 int countJoin(java.lang.Object bean, java.lang.Class<? extends java.lang.Object> klass)
           
 boolean delete(java.lang.Object bean)
          Delete the bean from the database.
 java.sql.Connection getConnection()
           
protected  java.lang.String getNow()
           
protected static java.lang.Object getValueFromBean(java.lang.Object bean, java.lang.String fieldName)
           
protected static java.lang.Object getValueFromBean(java.lang.Object bean, java.lang.String fieldName, java.lang.reflect.Method m)
           
protected  java.lang.StringBuilder handleLimit(java.lang.StringBuilder sb, java.lang.String orderBy, int limit)
           
protected static void injectValue(java.lang.Object bean, java.lang.String fieldName, java.lang.Object value, java.lang.Class<? extends java.lang.Object> valueType)
           
 void insert(java.lang.Object bean)
          Insert the bean in the database.
protected  boolean isSet(java.lang.Object value, java.lang.Class<? extends java.lang.Object> returnType)
           
 boolean load(java.lang.Object bean)
          Load the bean from the database, injecting all its properties through reflection.
<E> java.util.List<E>
loadJoin(java.lang.Object bean, java.lang.Class<? extends E> klass)
           
 java.util.List<java.lang.Integer> loadJoinIds(java.lang.Object bean, java.lang.Class<? extends java.lang.Object> klass)
           
<E> java.util.List<E>
loadList(E bean)
           
<E> java.util.List<E>
loadList(E bean, int limit)
           
<E> java.util.List<E>
loadList(E bean, java.lang.String orderBy)
           
<E> java.util.List<E>
loadList(E bean, java.lang.String orderBy, int limit)
           
<E> java.util.List<E>
loadListMinus(E bean, java.lang.String[] minus)
           
<E> java.util.List<E>
loadListMinus(E bean, java.lang.String[] minus, int limit)
           
<E> java.util.List<E>
loadListMinus(E bean, java.lang.String[] minus, java.lang.String orderBy)
           
<E> java.util.List<E>
loadListMinus(E bean, java.lang.String[] minus, java.lang.String orderBy, int limit)
           
 void populateBean(java.sql.ResultSet rset, java.lang.Object bean)
           
 void populateBean(java.sql.ResultSet rset, java.lang.Object bean, java.lang.String tablePrefix)
           
 void populateBeanMinus(java.sql.ResultSet rset, java.lang.Object bean, java.lang.String[] minus)
           
 void populateBeanMinus(java.sql.ResultSet rset, java.lang.Object bean, java.lang.String tablePrefix, java.lang.String[] minus)
           
 boolean remove(java.lang.Object bean1, java.lang.Object bean2)
          Remove a dependency based on a relationship OneToMany/ManyToMany.
 void setConn(java.sql.Connection conn)
           
 void setConnection(java.sql.Connection conn)
           
 int update(java.lang.Object bean)
          Update the bean in the database.
 int update(java.lang.Object bean, boolean dynUpdate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG

loaded

protected java.util.IdentityHashMap<java.lang.Object,java.util.Map<java.lang.String,org.mentawai.bean.jdbc.JdbcBeanSession.Value>> loaded

conn

protected java.sql.Connection conn

appManager

protected final ApplicationManager appManager
Constructor Detail

JdbcBeanSession

public JdbcBeanSession()

JdbcBeanSession

public JdbcBeanSession(java.sql.Connection conn)
Method Detail

setConn

public void setConn(java.sql.Connection conn)

setConnection

public void setConnection(java.sql.Connection conn)

getConnection

public java.sql.Connection getConnection()

getNow

protected java.lang.String getNow()

beginTransaction

public Transaction beginTransaction()
                             throws java.lang.Exception
Description copied from interface: BeanSession
Create a transaction for this session. Please check org.mentawai.transaction package.

Specified by:
beginTransaction in interface BeanSession
Returns:
The org.mentawai.transaction.Transaction
Throws:
java.lang.Exception

getValueFromBean

protected static java.lang.Object getValueFromBean(java.lang.Object bean,
                                                   java.lang.String fieldName)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

getValueFromBean

protected static java.lang.Object getValueFromBean(java.lang.Object bean,
                                                   java.lang.String fieldName,
                                                   java.lang.reflect.Method m)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

load

public boolean load(java.lang.Object bean)
             throws java.lang.Exception
Description copied from interface: BeanSession
Load the bean from the database, injecting all its properties through reflection. Note that the bean passed MUST have its primary key set.

Specified by:
load in interface BeanSession
Parameters:
bean - The bean we want to load from the DB.
Returns:
true if the bean was found in the database, false otherwise
Throws:
java.lang.Exception - if bean was found but could not be loaded for some error condition

injectValue

protected static void injectValue(java.lang.Object bean,
                                  java.lang.String fieldName,
                                  java.lang.Object value,
                                  java.lang.Class<? extends java.lang.Object> valueType)
                           throws BeanException
Throws:
BeanException

handleLimit

protected java.lang.StringBuilder handleLimit(java.lang.StringBuilder sb,
                                              java.lang.String orderBy,
                                              int limit)

buildSelect

public java.lang.String buildSelect(java.lang.Class<? extends java.lang.Object> beanClass)

buildSelect

public java.lang.String buildSelect(java.lang.Class<? extends java.lang.Object> beanClass,
                                    java.lang.String tablePrefix)

buildSelectMinus

public java.lang.String buildSelectMinus(java.lang.Class<? extends java.lang.Object> beanClass,
                                         java.lang.String[] minus)

buildSelectMinus

public java.lang.String buildSelectMinus(java.lang.Class<? extends java.lang.Object> beanClass,
                                         java.lang.String tablePrefix,
                                         java.lang.String[] minus)

populateBean

public void populateBean(java.sql.ResultSet rset,
                         java.lang.Object bean)
                  throws java.lang.Exception
Throws:
java.lang.Exception

populateBean

public void populateBean(java.sql.ResultSet rset,
                         java.lang.Object bean,
                         java.lang.String tablePrefix)
                  throws java.lang.Exception
Throws:
java.lang.Exception

populateBeanMinus

public void populateBeanMinus(java.sql.ResultSet rset,
                              java.lang.Object bean,
                              java.lang.String[] minus)
                       throws java.lang.Exception
Throws:
java.lang.Exception

populateBeanMinus

public void populateBeanMinus(java.sql.ResultSet rset,
                              java.lang.Object bean,
                              java.lang.String tablePrefix,
                              java.lang.String[] minus)
                       throws java.lang.Exception
Throws:
java.lang.Exception

loadListMinus

public <E> java.util.List<E> loadListMinus(E bean,
                                           java.lang.String[] minus,
                                           java.lang.String orderBy,
                                           int limit)
                                throws java.lang.Exception
Throws:
java.lang.Exception

loadList

public <E> java.util.List<E> loadList(E bean,
                                      java.lang.String orderBy,
                                      int limit)
                           throws java.lang.Exception
Specified by:
loadList in interface BeanSession
Throws:
java.lang.Exception

isSet

protected boolean isSet(java.lang.Object value,
                        java.lang.Class<? extends java.lang.Object> returnType)

update

public int update(java.lang.Object bean)
           throws java.lang.Exception
Description copied from interface: BeanSession
Update the bean in the database. Only the fields that have been modified (dirty) will be updated. It will return 1 if an update did happen or 0 if the bean could not be found in the database or if there was nothing to update in the bean. The bean MUST have its primary key set, otherwise it is impossible to update the bean in the database, and an exception will be thrown.

Specified by:
update in interface BeanSession
Parameters:
bean - The bean to be updated
Returns:
1 if update was successful, 0 if the update did not happen
Throws:
java.lang.Exception

update

public int update(java.lang.Object bean,
                  boolean dynUpdate)
           throws java.lang.Exception
Specified by:
update in interface BeanSession
Throws:
java.lang.Exception

insert

public void insert(java.lang.Object bean)
            throws java.lang.Exception
Description copied from interface: BeanSession
Insert the bean in the database. Depending on the type of PK, the generation of the PK can and should be taken care by the DB itself. The generated PK should be inserted in the bean by reflection. The default, database-independent implementation of this method must only insert all fields in the database not worrying about PK generation issues.

Specified by:
insert in interface BeanSession
Parameters:
bean - The bean to insert
Throws:
java.lang.Exception

delete

public boolean delete(java.lang.Object bean)
               throws java.lang.Exception
Description copied from interface: BeanSession
Delete the bean from the database. The PK of the bean MUST be set.

Specified by:
delete in interface BeanSession
Returns:
true if it was deleted or false if it did not exist
Throws:
java.lang.Exception

loadJoin

public <E> java.util.List<E> loadJoin(java.lang.Object bean,
                                      java.lang.Class<? extends E> klass)
                           throws java.lang.Exception
Specified by:
loadJoin in interface BeanSession
Throws:
java.lang.Exception

loadJoinIds

public java.util.List<java.lang.Integer> loadJoinIds(java.lang.Object bean,
                                                     java.lang.Class<? extends java.lang.Object> klass)
                                              throws java.lang.Exception
Specified by:
loadJoinIds in interface BeanSession
Throws:
java.lang.Exception

add

public boolean add(java.lang.Object bean1,
                   java.lang.Object bean2)
            throws java.lang.Exception
Description copied from interface: BeanSession
Add a dependency based on a relationship OneToMany/ManyToMany. Returns true if the dependency was really added or false if it was already there.

Specified by:
add in interface BeanSession
Throws:
java.lang.Exception

remove

public boolean remove(java.lang.Object bean1,
                      java.lang.Object bean2)
               throws java.lang.Exception
Description copied from interface: BeanSession
Remove a dependency based on a relationship OneToMany/ManyToMany. Returns true if the dependency was really removed or false if it was not there.

Specified by:
remove in interface BeanSession
Returns:
true if the dependency was really removed or false if it was not there.
Throws:
java.lang.Exception

countJoin

public int countJoin(java.lang.Object bean,
                     java.lang.Class<? extends java.lang.Object> klass)
              throws java.lang.Exception
Specified by:
countJoin in interface BeanSession
Throws:
java.lang.Exception

loadList

public <E> java.util.List<E> loadList(E bean)
                           throws java.lang.Exception
Specified by:
loadList in interface BeanSession
Throws:
java.lang.Exception

loadList

public <E> java.util.List<E> loadList(E bean,
                                      java.lang.String orderBy)
                           throws java.lang.Exception
Specified by:
loadList in interface BeanSession
Throws:
java.lang.Exception

loadList

public <E> java.util.List<E> loadList(E bean,
                                      int limit)
                           throws java.lang.Exception
Specified by:
loadList in interface BeanSession
Throws:
java.lang.Exception

loadListMinus

public <E> java.util.List<E> loadListMinus(E bean,
                                           java.lang.String[] minus)
                                throws java.lang.Exception
Throws:
java.lang.Exception

loadListMinus

public <E> java.util.List<E> loadListMinus(E bean,
                                           java.lang.String[] minus,
                                           java.lang.String orderBy)
                                throws java.lang.Exception
Throws:
java.lang.Exception

loadListMinus

public <E> java.util.List<E> loadListMinus(E bean,
                                           java.lang.String[] minus,
                                           int limit)
                                throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2005 Mentawai Team. All Rights Reserved.