|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mentabean.jdbc.AnsiSQLBeanSession
public class AnsiSQLBeanSession
The bean session implementation based on JDBC and SQL.
| Nested Class Summary | |
|---|---|
protected class |
AnsiSQLBeanSession.QueryAndValues
|
protected class |
AnsiSQLBeanSession.Value
|
| Field Summary | |
|---|---|
protected BeanManager |
beanManager
|
protected Connection |
conn
|
protected static boolean |
DEBUG
|
protected IdentityHashMap<Object,Map<String,AnsiSQLBeanSession.Value>> |
loaded
|
| Constructor Summary | |
|---|---|
AnsiSQLBeanSession(BeanManager beanManager,
Connection conn)
Creates a JdbcBeanSession with a BeanManager and a Connection. |
|
| Method Summary | ||
|---|---|---|
protected Map<String,AnsiSQLBeanSession.Value> |
bindToInsertStatement(PreparedStatement stmt,
List<AnsiSQLBeanSession.Value> values)
|
|
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,
String tablePrefix)
Build a column/field list for a SQL SELECT statement based on the bean configuration. |
|
String |
buildSelect(Class<? extends Object> beanClass,
String[] properties)
|
|
String |
buildSelect(Class<? extends Object> beanClass,
String tablePrefix,
String[] properties)
|
|
String |
buildSelectMinus(Class<? extends Object> beanClass,
String[] minus)
Like buildSelect but you can exclude some properties from the resulting list. |
|
String |
buildSelectMinus(Class<? extends Object> beanClass,
String tablePrefix,
String[] minus)
Same as buildSelectMinus with support for a database table prefix that will be applied on each field. |
|
int |
countList(Object bean)
Count the number of beans that would be returned by a loadList method. |
|
protected String |
createPKConstraintQuery(String table,
Iterator<DBField> pks)
Create a SQL query to add the primary key constraint |
|
void |
createTable(Class<? extends Object> beanKlass)
|
|
void |
createTables()
|
|
static void |
debugSql(boolean b)
Turn SQL debugging on and off. |
|
boolean |
delete(Object bean)
Delete the bean from the database. |
|
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. |
|
protected static Object |
getValueFromBean(Object bean,
String fieldName)
Get a value from a bean through reflection. |
|
protected static Object |
getValueFromBean(Object bean,
String fieldName,
Method m)
Get a value from a bean through reflection. |
|
protected StringBuilder |
handleLimit(StringBuilder sb,
String orderBy,
int limit)
Some databases will sort before applying the limit (MySql), others will not (Oracle). |
|
protected static 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. |
|
boolean |
load(Object bean)
Load the bean from the database, injecting all its properties through reflection. |
|
|
loadList(E bean)
Load a list of beans based on the properties present in the bean passed. |
|
|
loadList(E bean,
int limit)
Same as loadList(bean) except that you can limit the number of beans returned in the list. |
|
|
loadList(E bean,
int limit,
String[] properties)
|
|
|
loadList(E bean,
String orderBy)
Same as loadList(bean) except that you can order the list returned by passing an SQL orderBy clause. |
|
|
loadList(E bean,
String[] properties)
|
|
|
loadList(E bean,
String orderBy,
int 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. |
|
|
loadList(E bean,
String orderBy,
int limit,
String[] properties)
|
|
|
loadList(E bean,
String orderBy,
String[] properties)
|
|
|
loadListMinus(E bean,
int limit,
String[] minus)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String[] minus)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String orderBy,
int limit,
String[] minus)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String orderBy,
String[] minus)
Load a list of beans, but exclude some fields. |
|
|
loadUnique(E bean)
Same as loadList(bean) but it attempts to load a single bean only. |
|
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,
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[] properties)
|
|
void |
populateBean(ResultSet rset,
Object bean,
String tablePrefix,
String[] properties)
|
|
void |
populateBeanMinus(ResultSet rset,
Object bean,
String[] minus)
Same as populateBean, but exclude some fields when populating. |
|
void |
populateBeanMinus(ResultSet rset,
Object bean,
String tablePrefix,
String[] 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)
|
|
int |
update(Object bean)
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 |
|---|
protected static boolean DEBUG
protected IdentityHashMap<Object,Map<String,AnsiSQLBeanSession.Value>> loaded
protected Connection conn
protected final BeanManager beanManager
| Constructor Detail |
|---|
public AnsiSQLBeanSession(BeanManager beanManager,
Connection conn)
beanManager - The bean managerconn - The database connection| Method Detail |
|---|
public static void debugSql(boolean b)
b - true if it should be debuggedpublic Connection getConnection()
getConnection in interface BeanSessionprotected String getCurrentTimestampCommand()
protected static Object getValueFromBean(Object bean,
String fieldName)
bean - fieldName -
protected static Object getValueFromBean(Object bean,
String fieldName,
Method m)
bean - fieldName - m -
public boolean load(Object bean)
BeanSession
load in interface BeanSessionbean - The bean we want to load from the DB.
protected static void injectValue(Object bean,
String fieldName,
Object value,
Class<? extends Object> valueType)
bean - fieldName - value - valueType -
protected StringBuilder handleLimit(StringBuilder sb,
String orderBy,
int limit)
sb - orderBy - limit -
public String buildSelect(Class<? extends Object> beanClass)
buildSelect in interface BeanSessionbeanClass - the bean class
public String buildSelect(Class<? extends Object> beanClass,
String[] properties)
buildSelect in interface BeanSession
public String buildSelect(Class<? extends Object> beanClass,
String tablePrefix)
buildSelect in interface BeanSessionbeanClass - the bean classtablePrefix - the table prefix to use before each field
public String buildSelect(Class<? extends Object> beanClass,
String tablePrefix,
String[] properties)
buildSelect in interface BeanSession
public String buildSelectMinus(Class<? extends Object> beanClass,
String[] minus)
buildSelectMinus in interface BeanSessionbeanClass - the bean classminus - a list for property names to exclude
public String buildSelectMinus(Class<? extends Object> beanClass,
String tablePrefix,
String[] minus)
buildSelectMinus in interface BeanSessionbeanClass - the bean classtablePrefix - the database table prefixminus - a list of property names to exclude
public void populateBean(ResultSet rset,
Object bean)
populateBean in interface BeanSessionrset - the result set from where to get the property valuesbean - the bean to be populated
Exception
public void populateBean(ResultSet rset,
Object bean,
String[] properties)
populateBean in interface BeanSession
public void populateBean(ResultSet rset,
Object bean,
String tablePrefix)
populateBean in interface BeanSessionrset - the result setbean - the bean to be populatedtablePrefix - the table prefix
public void populateBean(ResultSet rset,
Object bean,
String tablePrefix,
String[] properties)
populateBean in interface BeanSession
public void populateBeanMinus(ResultSet rset,
Object bean,
String[] minus)
populateBeanMinus in interface BeanSessionrset - bean - minus -
public void populateBeanMinus(ResultSet rset,
Object bean,
String tablePrefix,
String[] minus)
populateBeanMinus in interface BeanSessionrset - bean - tablePrefix - minus -
public <E> List<E> loadListMinus(E bean,
String orderBy,
int limit,
String[] minus)
loadListMinus in interface BeanSessionE - bean - minus - orderBy - limit -
public <E> List<E> loadList(E bean,
String orderBy,
int limit)
BeanSession
loadList in interface BeanSessionbean - 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.
public <E> List<E> loadList(E bean,
String orderBy,
int limit,
String[] properties)
loadList in interface BeanSessionpublic int countList(Object bean)
BeanSession
countList in interface BeanSessionbean - The bean holding the properties used by the list query.
protected boolean isSet(Object value,
Class<? extends Object> returnType)
value - returnType -
public int update(Object bean)
BeanSession
update in interface BeanSessionbean - The bean to be updated
public int updateAll(Object bean)
BeanSession
updateAll in interface BeanSessionprotected AnsiSQLBeanSession.QueryAndValues prepareInsertQuery(Object bean)
protected Map<String,AnsiSQLBeanSession.Value> bindToInsertStatement(PreparedStatement stmt,
List<AnsiSQLBeanSession.Value> values)
public void insert(Object bean)
BeanSession
insert in interface BeanSessionbean - The bean to insertpublic boolean delete(Object bean)
BeanSession
delete in interface BeanSessionpublic <E> List<E> loadList(E bean)
BeanSession
loadList in interface BeanSessionbean - The bean holding the properties used by the list query.
public <E> List<E> loadList(E bean,
String[] properties)
loadList in interface BeanSessionpublic <E> E loadUnique(E bean)
BeanSession
loadUnique in interface BeanSessionbean - The bean holding the properties used by the load query.
public <E> List<E> loadList(E bean,
String orderBy)
BeanSession
loadList in interface BeanSessionbean - The bean holding the properties used by the list query.orderBy - The orderBy SQL clause.
public <E> List<E> loadList(E bean,
String orderBy,
String[] properties)
loadList in interface BeanSession
public <E> List<E> loadList(E bean,
int limit)
BeanSession
loadList in interface BeanSessionbean - The bean holding the properties used by the list query.limit - The max number of beans returned in the list.
public <E> List<E> loadList(E bean,
int limit,
String[] properties)
loadList in interface BeanSession
public <E> List<E> loadListMinus(E bean,
String[] minus)
loadListMinus in interface BeanSessionE - bean - minus -
public <E> List<E> loadListMinus(E bean,
String orderBy,
String[] minus)
loadListMinus in interface BeanSessionE - bean - minus - orderBy -
public <E> List<E> loadListMinus(E bean,
int limit,
String[] minus)
loadListMinus in interface BeanSessionE - bean - minus - limit -
protected String getDatabaseType(DBType<?> dbType)
dbType -
public void createTable(Class<? extends Object> beanKlass)
createTable in interface BeanSessionpublic void createTables()
createTables in interface BeanSession
protected String createPKConstraintQuery(String table,
Iterator<DBField> pks)
table - - The table namepks - - An iterator of all primary key fields that will be added to the table
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||