org.mentawai.bean
Interface BeanSession

All Known Implementing Classes:
H2BeanSession, JdbcBeanSession, MySQLBeanSession, OracleBeanSession

public interface BeanSession

Describe a simple ORM interface that can perform CRUD for Beans, Joins for relationships and load a list of beans according to properties.

Author:
Sergio Oliveira Jr.

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.
 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.
 void insert(java.lang.Object bean)
          Insert the bean in the database.
 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)
           
 boolean remove(java.lang.Object bean1, java.lang.Object bean2)
          Remove a dependency based on a relationship OneToMany/ManyToMany.
 int update(java.lang.Object bean)
          Update the bean in the database.
 int update(java.lang.Object bean, boolean dynUpdate)
           
 

Method Detail

load

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

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

update

int update(java.lang.Object bean)
           throws java.lang.Exception
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.

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

int update(java.lang.Object bean,
           boolean dynUpdate)
           throws java.lang.Exception
Throws:
java.lang.Exception

insert

void insert(java.lang.Object bean)
            throws java.lang.Exception
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.

Parameters:
bean - The bean to insert
Throws:
java.lang.Exception

add

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

Parameters:
bean1 -
bean2 -
Throws:
java.lang.Exception

remove

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

Parameters:
bean1 -
bean2 -
Returns:
true if the dependency was really removed or false if it was not there.
Throws:
java.lang.Exception

delete

boolean delete(java.lang.Object bean)
               throws java.lang.Exception
Delete the bean from the database. The PK of the bean MUST be set.

Parameters:
bean -
Returns:
true if it was deleted or false if it did not exist
Throws:
java.lang.Exception

beginTransaction

Transaction beginTransaction()
                             throws java.lang.Exception
Create a transaction for this session. Please check org.mentawai.transaction package.

Returns:
The org.mentawai.transaction.Transaction
Throws:
java.lang.Exception

loadJoinIds

java.util.List<java.lang.Integer> loadJoinIds(java.lang.Object bean,
                                              java.lang.Class<? extends java.lang.Object> klass)
                                              throws java.lang.Exception
Throws:
java.lang.Exception

loadJoin

<E> java.util.List<E> loadJoin(java.lang.Object bean,
                               java.lang.Class<? extends E> klass)
                           throws java.lang.Exception
Throws:
java.lang.Exception

countJoin

int countJoin(java.lang.Object bean,
              java.lang.Class<? extends java.lang.Object> klass)
              throws java.lang.Exception
Throws:
java.lang.Exception

loadList

<E> java.util.List<E> loadList(E bean)
                           throws java.lang.Exception
Throws:
java.lang.Exception

loadList

<E> java.util.List<E> loadList(E bean,
                               java.lang.String orderBy)
                           throws java.lang.Exception
Throws:
java.lang.Exception

loadList

<E> java.util.List<E> loadList(E bean,
                               int limit)
                           throws java.lang.Exception
Throws:
java.lang.Exception

loadList

<E> java.util.List<E> loadList(E bean,
                               java.lang.String orderBy,
                               int limit)
                           throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2005 Mentawai Team. All Rights Reserved.