org.mentabean.jdbc
Class AnsiSQLBeanSession

java.lang.Object
  extended by org.mentabean.jdbc.AnsiSQLBeanSession
All Implemented Interfaces:
BeanSession
Direct Known Subclasses:
FirebirdBeanSession, H2BeanSession, MySQLBeanSession, OracleBeanSession, PostgreSQLBeanSession

public class AnsiSQLBeanSession
extends Object
implements BeanSession

The bean session implementation based on JDBC and SQL.

Author:
soliveira

Nested Class Summary
protected  class AnsiSQLBeanSession.QueryAndValues
           
protected  class AnsiSQLBeanSession.Value
           
 
Field Summary
protected  BeanManager beanManager
           
protected  Connection conn
           
protected static boolean DEBUG
           
protected static boolean DEBUG_NATIVE
           
protected  TriggerDispatcher dispatcher
           
protected  IdentityHashMap<Object,Map<String,AnsiSQLBeanSession.Value>> loaded
           
 
Fields inherited from interface org.mentabean.BeanSession
INSERT, UPDATE
 
Constructor Summary
AnsiSQLBeanSession(BeanManager beanManager, Connection conn)
          Creates a JdbcBeanSession with a BeanManager and a Connection.
 
Method Summary
 void addTrigger(TriggerListener trigger)
          Add a TriggerListener in this session.
protected  Map<String,AnsiSQLBeanSession.Value> bindToInsertStatement(PreparedStatement stmt, List<AnsiSQLBeanSession.Value> values)
           
 QueryBuilder buildQuery()
          Builds a new QueryBuilder so it's possible to create fluent custom SQL queries
 String buildSelect(Class<? extends Object> beanClass)
          Build the column/field list for a SQL SELECT statement based on the bean configuration.
 String buildSelect(Class<? extends Object> beanClass, Object... properties)
           
 String buildSelect(Class<? extends Object> beanClass, String tablePrefix)
          Build a column/field list for a SQL SELECT statement based on the bean configuration.
 String buildSelect(Class<? extends Object> beanClass, String tablePrefix, Object... properties)
           
protected  String buildSelectImpl(Class<? extends Object> beanClass, String tablePrefix, String[] properties, String[] minus, boolean includePK, boolean addSuffix)
           
 String buildSelectMinus(Class<? extends Object> beanClass, Object... minus)
          Like buildSelect but you can exclude some properties from the resulting list.
 String buildSelectMinus(Class<? extends Object> beanClass, String tablePrefix, Object... minus)
          Same as buildSelectMinus with support for a database table prefix that will be applied on each field.
 String buildTableName(Class<? extends Object> clazz)
          Returns the table name configured for the given class
 int countList(Object bean)
          Count the number of beans that would be returned by a loadList method.
<E> E
createBasicInstance(E bean)
          Creates an single instance only with primary keys according the given object
protected  String createPKConstraintQuery(String table, Iterator<DBField> pks)
          Create a SQL query to add the primary key constraint
 void createTable(Class<? extends Object> beanKlass)
           
<E> TableAlias<E>
createTableAlias(Class<? extends E> beanClass)
          Return a table alias for this bean class
<E> TableAlias<E>
createTableAlias(Class<? extends E> beanClass, String prefix)
          Return a table alias for this bean class with a prefix.
 void createTables()
           
static void debugNativeSql(boolean b)
          Turn SQL native queries debugging on and off.
static void debugSql(boolean b)
          Turn SQL debugging on and off.
 boolean delete(Object bean)
          Delete the bean from the database.
protected  void dispatchAfterDelete(Object bean)
           
protected  void dispatchAfterInsert(Object bean)
           
protected  void dispatchAfterUpdate(Object bean)
           
protected  void dispatchBeforeDelete(Object bean)
           
protected  void dispatchBeforeInsert(Object bean)
           
protected  void dispatchBeforeUpdate(Object bean)
           
protected  void dispatchTrigger(TriggerDispatcher.Type type, Object bean)
          Dispatch all triggers from actual BeanSession and respective BeanConfig.
 void dropTable(Class<? extends Object> beanKlass)
           
 BeanConfig getConfigFor(Class<? extends Object> clazz)
          Returns the BeanConfig object from the given bean class
 Connection getConnection()
          Get the connection associated with this JdbcBeanSession.
protected  String getCurrentTimestampCommand()
          Get the command representing 'now' in this database.
protected  String getDatabaseType(DBType<?> dbType)
          Each dialect can override this to return the database column type it supports other than the ANSI standard.
static String[] getProperties(Object[] names)
           
protected  Object getPropertyBean(Object target, String name, boolean create)
          Get a value from target through reflection and tries to create a new instance if create parameter is true
protected  Object getValueFromBean(Object bean, String fieldName)
          Get a value from a bean through reflection.
protected  Object getValueFromBean(Object bean, String fieldName, Method m)
          Get a value from a bean through reflection.
protected  StringBuilder handleLimit(StringBuilder sb, OrderBy orderBy, Limit limit)
          Some databases will sort before applying the limit (MySql), others will not (Oracle).
protected  void injectValue(Object bean, String fieldName, Object value, Class<? extends Object> valueType)
          Inject a value in a bean through reflection.
 void insert(Object bean)
          Insert the bean in the database.
protected  boolean isSet(Object value, Class<? extends Object> returnType)
          if Boolean consider TRUE to be set and FALSE to be not set.
protected  boolean isVarcharUnlimitedSupported()
          Each dialect can override this to return true if the VARCHAR type supports unlimited size
 boolean load(Object bean)
          Load the bean from the database, injecting all its properties through reflection.
 boolean load(Object bean, Object... properties)
           
protected  boolean loadImpl(Object bean, String[] properties, String[] minus)
           
<E> List<E>
loadList(E bean)
          Load a list of beans based on the properties present in the bean passed.
<E> List<E>
loadList(E bean, Limit limit)
          Same as loadList(bean) except that you can limit the number of beans returned in the list.
<E> List<E>
loadList(E bean, Limit limit, Object... properties)
           
<E> List<E>
loadList(E bean, Object... properties)
           
<E> List<E>
loadList(E bean, OrderBy orderBy)
          Same as loadList(bean) except that you can order the list returned by passing an SQL orderBy clause.
<E> List<E>
loadList(E bean, OrderBy orderBy, Limit limit)
          Same as loadList(bean) except that you can limit the number of beans returned in the list as well as sort them by passing a orderBy SQL clause.
<E> List<E>
loadList(E bean, OrderBy orderBy, Limit limit, Object... properties)
           
<E> List<E>
loadList(E bean, OrderBy orderBy, Object... properties)
           
<E> List<E>
loadListMinus(E bean, Limit limit, Object... minus)
          Load a list of beans, but exclude some fields.
<E> List<E>
loadListMinus(E bean, Object... minus)
          Load a list of beans, but exclude some fields.
<E> List<E>
loadListMinus(E bean, OrderBy orderBy, Limit limit, Object... minus)
          Load a list of beans, but exclude some fields.
<E> List<E>
loadListMinus(E bean, OrderBy orderBy, Object... minus)
          Load a list of beans, but exclude some fields.
 boolean loadMinus(Object bean, Object... minus)
           
<E> E
loadUnique(E bean)
          Same as loadList(bean) but it attempts to load a single bean only.
<E> E
loadUnique(E bean, Object... properties)
           
protected
<E> E
loadUniqueImpl(E bean, String[] properties, String[] minus)
           
<E> E
loadUniqueMinus(E bean, Object... minus)
           
 void populateBean(ResultSet rset, Object bean)
          Populate a bean (insert all its properties) from the results in a result set, based on the bean configuration.
 void populateBean(ResultSet rset, Object bean, Object... properties)
           
 void populateBean(ResultSet rset, Object bean, String tablePrefix)
          Same as populateBean, but use a table prefix before fetching the values from the result set.
 void populateBean(ResultSet rset, Object bean, String tablePrefix, Object... properties)
           
protected  void populateBeanImpl(ResultSet rset, Object bean, String tablePrefix, String[] properties, String[] minus, boolean includePK)
           
 void populateBeanMinus(ResultSet rset, Object bean, Object... minus)
          Same as populateBean, but exclude some fields when populating.
 void populateBeanMinus(ResultSet rset, Object bean, String tablePrefix, Object... minus)
          Same as populateBean, but exclude some fields when populating and use a table prefix in front of the field names.
protected  AnsiSQLBeanSession.QueryAndValues prepareInsertQuery(Object bean)
           
 String propertyToColumn(BeanConfig bc, Object property)
          Returns a database column name for a bean attribute.
 String propertyToColumn(Class<? extends Object> clazz, Object property)
           
 String propertyToColumn(Class<? extends Object> clazz, Object property, String alias)
           
 void removeTrigger(TriggerListener trigger)
          Removes the TriggerListener from session
protected  int save(Object bean, boolean dynUpdate, String[] nullProps)
          Update or insert a bean into database.
 int save(Object bean, Object... forceNull)
          Tries to update or insert a bean using the update method.
 int saveAll(Object bean)
          Tries to update or insert a bean object into database.
 int update(Object bean, Object... forceNull)
          Update the bean in the database.
 int updateAll(Object bean)
          Same as update(bean) but here you can turn off the default dynamic update behavior and force all bean properties to be updated regardless whether they have been modified or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static boolean DEBUG

DEBUG_NATIVE

protected static boolean DEBUG_NATIVE

loaded

protected IdentityHashMap<Object,Map<String,AnsiSQLBeanSession.Value>> loaded

conn

protected Connection conn

beanManager

protected final BeanManager beanManager

dispatcher

protected final TriggerDispatcher dispatcher
Constructor Detail

AnsiSQLBeanSession

public AnsiSQLBeanSession(BeanManager beanManager,
                          Connection conn)
Creates a JdbcBeanSession with a BeanManager and a Connection.

Parameters:
beanManager - The bean manager
conn - The database connection
Method Detail

debugSql

public static void debugSql(boolean b)
Turn SQL debugging on and off.

Parameters:
b - true if it should be debugged

debugNativeSql

public static void debugNativeSql(boolean b)
Turn SQL native queries debugging on and off.

Parameters:
b - true if it should be debugged

getConnection

public Connection getConnection()
Get the connection associated with this JdbcBeanSession.

Specified by:
getConnection in interface BeanSession
Returns:
the database connection

getCurrentTimestampCommand

protected String getCurrentTimestampCommand()
Get the command representing 'now' in this database. This base implementation returns null, in other words, no now command will be used.

Returns:
the command for now in this database (now(), sysdate, etc)

getValueFromBean

protected Object getValueFromBean(Object bean,
                                  String fieldName)
Get a value from a bean through reflection.

Parameters:
bean -
fieldName -
Returns:
The value of a bean property

getProperties

public static String[] getProperties(Object[] names)

getValueFromBean

protected Object getValueFromBean(Object bean,
                                  String fieldName,
                                  Method m)
Get a value from a bean through reflection.

Parameters:
bean -
fieldName -
m -
Returns:
The value of a bean property

load

public boolean load(Object bean)
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 otherwise there is no way we can load it from the database.

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

load

public boolean load(Object bean,
                    Object... properties)
Specified by:
load in interface BeanSession

loadMinus

public boolean loadMinus(Object bean,
                         Object... minus)
Specified by:
loadMinus in interface BeanSession

loadImpl

protected boolean loadImpl(Object bean,
                           String[] properties,
                           String[] minus)

getPropertyBean

protected Object getPropertyBean(Object target,
                                 String name,
                                 boolean create)
Get a value from target through reflection and tries to create a new instance if create parameter is true

Parameters:
target -
name -
create -
Returns:
The value from bean

injectValue

protected void injectValue(Object bean,
                           String fieldName,
                           Object value,
                           Class<? extends Object> valueType)
Inject a value in a bean through reflection.

Parameters:
bean -
fieldName -
value -
valueType -

handleLimit

protected StringBuilder handleLimit(StringBuilder sb,
                                    OrderBy orderBy,
                                    Limit limit)
Some databases will sort before applying the limit (MySql), others will not (Oracle). Handle each one accordingly. Note: This base implementation does nothing.

Parameters:
sb -
orderBy -
limit -
Returns:
A string builder with the the SQL modified for the limit operation

buildSelect

public String buildSelect(Class<? extends Object> beanClass)
Build the column/field list for a SQL SELECT statement based on the bean configuration. Very useful to create select statements.

Specified by:
buildSelect in interface BeanSession
Parameters:
beanClass - the bean class
Returns:
the column/field list for a select

buildSelect

public String buildSelect(Class<? extends Object> beanClass,
                          Object... properties)
Specified by:
buildSelect in interface BeanSession

buildSelect

public String buildSelect(Class<? extends Object> beanClass,
                          String tablePrefix)
Build a column/field list for a SQL SELECT statement based on the bean configuration. A table prefix will be used on each field. Very useful to create select statements on multiple tables (joins).

Specified by:
buildSelect in interface BeanSession
Parameters:
beanClass - the bean class
tablePrefix - the table prefix to use before each field
Returns:
the column/field list for a select

buildSelect

public String buildSelect(Class<? extends Object> beanClass,
                          String tablePrefix,
                          Object... properties)
Specified by:
buildSelect in interface BeanSession

buildSelectMinus

public String buildSelectMinus(Class<? extends Object> beanClass,
                               Object... minus)
Like buildSelect but you can exclude some properties from the resulting list. Useful when you have a bean with too many properties and you just want to fetch a few. Note: The list of properties to exclude contains 'property names' and NOT database column names.

Specified by:
buildSelectMinus in interface BeanSession
Parameters:
beanClass - the bean class
minus - a list for property names to exclude
Returns:
the column/field list for a select

buildSelectMinus

public String buildSelectMinus(Class<? extends Object> beanClass,
                               String tablePrefix,
                               Object... minus)
Same as buildSelectMinus with support for a database table prefix that will be applied on each field.

Specified by:
buildSelectMinus in interface BeanSession
Parameters:
beanClass - the bean class
tablePrefix - the database table prefix
minus - a list of property names to exclude
Returns:
the column/field list for a select

buildSelectImpl

protected String buildSelectImpl(Class<? extends Object> beanClass,
                                 String tablePrefix,
                                 String[] properties,
                                 String[] minus,
                                 boolean includePK,
                                 boolean addSuffix)

populateBean

public void populateBean(ResultSet rset,
                         Object bean)
Populate a bean (insert all its properties) from the results in a result set, based on the bean configuration.

Specified by:
populateBean in interface BeanSession
Parameters:
rset - the result set from where to get the property values
bean - the bean to be populated
Throws:
Exception

populateBean

public void populateBean(ResultSet rset,
                         Object bean,
                         Object... properties)
Specified by:
populateBean in interface BeanSession

populateBean

public void populateBean(ResultSet rset,
                         Object bean,
                         String tablePrefix)
Same as populateBean, but use a table prefix before fetching the values from the result set. Useful when there are multiple tables involved and you want to avoid field name clashing.

Specified by:
populateBean in interface BeanSession
Parameters:
rset - the result set
bean - the bean to be populated
tablePrefix - the table prefix

populateBean

public void populateBean(ResultSet rset,
                         Object bean,
                         String tablePrefix,
                         Object... properties)
Specified by:
populateBean in interface BeanSession

populateBeanMinus

public void populateBeanMinus(ResultSet rset,
                              Object bean,
                              Object... minus)
Same as populateBean, but exclude some fields when populating.

Specified by:
populateBeanMinus in interface BeanSession
Parameters:
rset -
bean -
minus -

populateBeanMinus

public void populateBeanMinus(ResultSet rset,
                              Object bean,
                              String tablePrefix,
                              Object... minus)
Same as populateBean, but exclude some fields when populating and use a table prefix in front of the field names.

Specified by:
populateBeanMinus in interface BeanSession
Parameters:
rset -
bean -
tablePrefix -
minus -

populateBeanImpl

protected void populateBeanImpl(ResultSet rset,
                                Object bean,
                                String tablePrefix,
                                String[] properties,
                                String[] minus,
                                boolean includePK)

loadListMinus

public <E> List<E> loadListMinus(E bean,
                                 OrderBy orderBy,
                                 Limit limit,
                                 Object... minus)
Load a list of beans, but exclude some fields.

Specified by:
loadListMinus in interface BeanSession
Type Parameters:
E -
Parameters:
bean -
minus -
orderBy -
limit -
Returns:
A list of beans

loadList

public <E> List<E> loadList(E bean,
                            OrderBy orderBy,
                            Limit limit)
Description copied from interface: BeanSession
Same as loadList(bean) except that you can limit the number of beans returned in the list as well as sort them by passing a orderBy SQL clause.

Specified by:
loadList in interface BeanSession
Parameters:
bean - The bean holding the properties used by the list query.
orderBy - The orderBy SQL clause.
limit - The max number of beans returned in the list.
Returns:
A list of beans the match the properties in the given bean. Or an empty list if nothing was found.

loadList

public <E> List<E> loadList(E bean,
                            OrderBy orderBy,
                            Limit limit,
                            Object... properties)
Specified by:
loadList in interface BeanSession

propertyToColumn

public String propertyToColumn(BeanConfig bc,
                               Object property)
Returns a database column name for a bean attribute.

Parameters:
bc - - The BeanConfig object
property - - A bean property
Returns:
The database column name found if exists, otherwise will return the given bean property

propertyToColumn

public String propertyToColumn(Class<? extends Object> clazz,
                               Object property)
Specified by:
propertyToColumn in interface BeanSession

propertyToColumn

public String propertyToColumn(Class<? extends Object> clazz,
                               Object property,
                               String alias)
Specified by:
propertyToColumn in interface BeanSession

buildTableName

public String buildTableName(Class<? extends Object> clazz)
Description copied from interface: BeanSession
Returns the table name configured for the given class

Specified by:
buildTableName in interface BeanSession
Parameters:
clazz - - The bean class
Returns:
Table name

buildQuery

public QueryBuilder buildQuery()
Description copied from interface: BeanSession
Builds a new QueryBuilder so it's possible to create fluent custom SQL queries

Specified by:
buildQuery in interface BeanSession
Returns:
QueryBuilder object

countList

public int countList(Object bean)
Description copied from interface: BeanSession
Count the number of beans that would be returned by a loadList method.

Specified by:
countList in interface BeanSession
Parameters:
bean - The bean holding the properties used by the list query.
Returns:
the number of beans found in the database

isSet

protected boolean isSet(Object value,
                        Class<? extends Object> returnType)
if Boolean consider TRUE to be set and FALSE to be not set. if Character, cast to integer and assume it is set if different than 0 if Number consider everything different than zero to be set. Otherwise returns TRUE for anything different than null and FALSE for null.

Parameters:
value -
returnType -
Returns:
true if is set

update

public int update(Object bean,
                  Object... forceNull)
Description copied from interface: BeanSession
Update the bean in the database. Only the bean 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 modified in 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
forceNull - Database columns that will be forced to null (or zero) if the bean property is not set
Returns:
1 if update was successful, 0 if the update did not happen or was not necessary

updateAll

public int updateAll(Object bean)
Description copied from interface: BeanSession
Same as update(bean) but here you can turn off the default dynamic update behavior and force all bean properties to be updated regardless whether they have been modified or not.

Specified by:
updateAll in interface BeanSession
Returns:
the number of rows that were updated

createBasicInstance

public <E> E createBasicInstance(E bean)
Description copied from interface: BeanSession
Creates an single instance only with primary keys according the given object

Specified by:
createBasicInstance in interface BeanSession
Parameters:
bean - - The bean with all primary key set
Returns:
A new instance of the bean

save

public int save(Object bean,
                Object... forceNull)
Description copied from interface: BeanSession
Tries to update or insert a bean using the update method.

Specified by:
save in interface BeanSession
Parameters:
bean - The bean to update or insert
forceNull - Database columns that will be forced to null (or zero) if the bean property is not set
Returns:
A value 0 (zero) if operation executed an update and 1 (one) if insert method was executed
See Also:
BeanSession.saveAll(Object), BeanSession.update(Object, Object...)

saveAll

public int saveAll(Object bean)
Description copied from interface: BeanSession
Tries to update or insert a bean object into database. The update uses the updateAll method.

Specified by:
saveAll in interface BeanSession
Parameters:
bean - The bean to update or insert
Returns:
A value 0 (zero) if operation executed an update and 1 (one) if insert method was executed
See Also:
BeanSession.updateAll(Object)

save

protected int save(Object bean,
                   boolean dynUpdate,
                   String[] nullProps)
Update or insert a bean into database. It tries to update first and then insert

Parameters:
bean - Object to update or insert
dynUpdate - flag indicating a dynamic update
Returns:
A value 0 (zero) if operation was an update, 1 (one) if insert method was executed
See Also:
saveAll(Object), save(Object, Object...)

prepareInsertQuery

protected AnsiSQLBeanSession.QueryAndValues prepareInsertQuery(Object bean)

bindToInsertStatement

protected Map<String,AnsiSQLBeanSession.Value> bindToInsertStatement(PreparedStatement stmt,
                                                                     List<AnsiSQLBeanSession.Value> values)

insert

public void insert(Object bean)
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, before the method returns. The default, database-independent implementation of this method, insert all fields in the database not worrying about PK generation strategies.

Specified by:
insert in interface BeanSession
Parameters:
bean - The bean to insert

delete

public boolean delete(Object bean)
Description copied from interface: BeanSession
Delete the bean from the database. The PK of the bean MUST be set. The bean can only be deleted by its PK.

Specified by:
delete in interface BeanSession
Returns:
true if it was deleted or false if it did not exist

loadList

public <E> List<E> loadList(E bean)
Description copied from interface: BeanSession
Load a list of beans based on the properties present in the bean passed. For example, if you want to load all users with lastName equal to 'saoj' you would instantiate a bean and set its lastName property to 'saoj' before passing it as an argument to this method.

Specified by:
loadList in interface BeanSession
Parameters:
bean - The bean holding the properties used by the list query.
Returns:
A list of beans the match the properties in the given bean. Or an empty list if nothing was found.

loadList

public <E> List<E> loadList(E bean,
                            Object... properties)
Specified by:
loadList in interface BeanSession

loadUnique

public <E> E loadUnique(E bean)
Description copied from interface: BeanSession
Same as loadList(bean) but it attempts to load a single bean only. If more than one bean is found it throws an exception. NOTE: The returned bean will be attached by the session so only the modified properties will be updated in case update() is called.

Specified by:
loadUnique in interface BeanSession
Parameters:
bean - The bean holding the properties used by the load query.
Returns:
A unique bean that match the properties in the given bean. Or null if nothing was found.

loadUnique

public <E> E loadUnique(E bean,
                        Object... properties)
Specified by:
loadUnique in interface BeanSession

loadUniqueMinus

public <E> E loadUniqueMinus(E bean,
                             Object... minus)
Specified by:
loadUniqueMinus in interface BeanSession

loadUniqueImpl

protected <E> E loadUniqueImpl(E bean,
                               String[] properties,
                               String[] minus)

loadList

public <E> List<E> loadList(E bean,
                            OrderBy orderBy)
Description copied from interface: BeanSession
Same as loadList(bean) except that you can order the list returned by passing an SQL orderBy clause.

Specified by:
loadList in interface BeanSession
Parameters:
bean - The bean holding the properties used by the list query.
orderBy - The orderBy SQL clause.
Returns:
A list of beans the match the properties in the given bean. Or an empty list if nothing was found.

loadList

public <E> List<E> loadList(E bean,
                            OrderBy orderBy,
                            Object... properties)
Specified by:
loadList in interface BeanSession

loadList

public <E> List<E> loadList(E bean,
                            Limit limit)
Description copied from interface: BeanSession
Same as loadList(bean) except that you can limit the number of beans returned in the list.

Specified by:
loadList in interface BeanSession
Parameters:
bean - The bean holding the properties used by the list query.
limit - The max number of beans returned in the list.
Returns:
A list of beans the match the properties in the given bean. Or an empty list if nothing was found.

loadList

public <E> List<E> loadList(E bean,
                            Limit limit,
                            Object... properties)
Specified by:
loadList in interface BeanSession

loadListMinus

public <E> List<E> loadListMinus(E bean,
                                 Object... minus)
Load a list of beans, but exclude some fields. Useful when the bean has too many properties and you don't want to fetch everything from the database.

Specified by:
loadListMinus in interface BeanSession
Type Parameters:
E -
Parameters:
bean -
minus -
Returns:
A list of beans

loadListMinus

public <E> List<E> loadListMinus(E bean,
                                 OrderBy orderBy,
                                 Object... minus)
Load a list of beans, but exclude some fields. Useful when the bean has too many properties and you don't want to fetch everything from the database.

Specified by:
loadListMinus in interface BeanSession
Type Parameters:
E -
Parameters:
bean -
minus -
orderBy -
Returns:
A list of beans

loadListMinus

public <E> List<E> loadListMinus(E bean,
                                 Limit limit,
                                 Object... minus)
Load a list of beans, but exclude some fields. Useful when the bean has too many properties and you don't want to fetch everything from the database.

Specified by:
loadListMinus in interface BeanSession
Type Parameters:
E -
Parameters:
bean -
minus -
limit -
Returns:
A list of beans

getDatabaseType

protected String getDatabaseType(DBType<?> dbType)
Each dialect can override this to return the database column type it supports other than the ANSI standard.

Parameters:
dbType -
Returns:
The string representation of this database type to be used with create table statement

isVarcharUnlimitedSupported

protected boolean isVarcharUnlimitedSupported()
Each dialect can override this to return true if the VARCHAR type supports unlimited size

Returns:
true if database supports VARCHAR with no limit, false otherwise

createTable

public void createTable(Class<? extends Object> beanKlass)
Specified by:
createTable in interface BeanSession

createTables

public void createTables()
Specified by:
createTables in interface BeanSession

dropTable

public void dropTable(Class<? extends Object> beanKlass)
Specified by:
dropTable in interface BeanSession

createPKConstraintQuery

protected String createPKConstraintQuery(String table,
                                         Iterator<DBField> pks)
Create a SQL query to add the primary key constraint

Parameters:
table - - The table name
pks - - An iterator of all primary key fields that will be added to the table
Returns:
A String containing the resulting alter table constraint query

getConfigFor

public BeanConfig getConfigFor(Class<? extends Object> clazz)
Description copied from interface: BeanSession
Returns the BeanConfig object from the given bean class

Specified by:
getConfigFor in interface BeanSession
Returns:
BeanConfig

addTrigger

public void addTrigger(TriggerListener trigger)
Description copied from interface: BeanSession
Add a TriggerListener in this session. Remember that it's not added in BeanConfig, only in current session

Specified by:
addTrigger in interface BeanSession

removeTrigger

public void removeTrigger(TriggerListener trigger)
Description copied from interface: BeanSession
Removes the TriggerListener from session

Specified by:
removeTrigger in interface BeanSession

dispatchBeforeInsert

protected void dispatchBeforeInsert(Object bean)

dispatchAfterInsert

protected void dispatchAfterInsert(Object bean)

dispatchBeforeUpdate

protected void dispatchBeforeUpdate(Object bean)

dispatchAfterUpdate

protected void dispatchAfterUpdate(Object bean)

dispatchBeforeDelete

protected void dispatchBeforeDelete(Object bean)

dispatchAfterDelete

protected void dispatchAfterDelete(Object bean)

dispatchTrigger

protected void dispatchTrigger(TriggerDispatcher.Type type,
                               Object bean)
Dispatch all triggers from actual BeanSession and respective BeanConfig. This method is called when insert, update or delete operation occurs.

Parameters:
type - - TriggerType indicating what trigger event will be dispatched
bean - - Bean that will be set into TriggerEvent object

createTableAlias

public <E> TableAlias<E> createTableAlias(Class<? extends E> beanClass)
Description copied from interface: BeanSession
Return a table alias for this bean class

Specified by:
createTableAlias in interface BeanSession
Returns:
TableAlias

createTableAlias

public <E> TableAlias<E> createTableAlias(Class<? extends E> beanClass,
                                          String prefix)
Description copied from interface: BeanSession
Return a table alias for this bean class with a prefix.

Specified by:
createTableAlias in interface BeanSession
Returns:
TableAlias


Copyright © 2013. All Rights Reserved.