|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mentabean.jdbc.JdbcBeanSession
public class JdbcBeanSession
The bean session implementation based on JDBC and SQL.
| Field Summary | |
|---|---|
protected BeanManager |
beanManager
|
protected Connection |
conn
|
protected static boolean |
DEBUG
|
protected IdentityHashMap<Object,Map<String,org.mentabean.jdbc.JdbcBeanSession.Value>> |
loaded
|
| Constructor Summary | |
|---|---|
JdbcBeanSession(BeanManager beanManager,
Connection conn)
Creates a JdbcBeanSession with a BeanManager and a Connection. |
|
| Method Summary | ||
|---|---|---|
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 |
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. |
|
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 |
getNow()
Get the command representing 'now' in this database. |
|
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,
String orderBy)
Same as loadList(bean) except that you can order the list returned by passing an SQL orderBy clause. |
|
|
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. |
|
|
loadListMinus(E bean,
String[] minus)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String[] minus,
int limit)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String[] minus,
String orderBy)
Load a list of beans, but exclude some fields. |
|
|
loadListMinus(E bean,
String[] minus,
String orderBy,
int limit)
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 |
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. |
|
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,org.mentabean.jdbc.JdbcBeanSession.Value>> loaded
protected Connection conn
protected final BeanManager beanManager
| Constructor Detail |
|---|
public JdbcBeanSession(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()
protected String getNow()
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)
beanClass - the bean class
public String buildSelect(Class<? extends Object> beanClass,
String tablePrefix)
beanClass - the bean classtablePrefix - the table prefix to use before each field
public String buildSelectMinus(Class<? extends Object> beanClass,
String[] minus)
beanClass - the bean classminus - a list for property names to exclude
public String buildSelectMinus(Class<? extends Object> beanClass,
String tablePrefix,
String[] minus)
beanClass - the bean classtablePrefix - the database table prefixminus - a list of property names to exclude
public void populateBean(ResultSet rset,
Object bean)
rset - the result set from where to get the property valuesbean - the bean to be populated
Exception
public void populateBean(ResultSet rset,
Object bean,
String tablePrefix)
rset - the result setbean - the bean to be populatedtablePrefix - the table prefix
public void populateBeanMinus(ResultSet rset,
Object bean,
String[] minus)
rset - bean - minus -
public void populateBeanMinus(ResultSet rset,
Object bean,
String tablePrefix,
String[] minus)
rset - bean - tablePrefix - minus -
public <E> List<E> loadListMinus(E bean,
String[] minus,
String orderBy,
int limit)
E - 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 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 BeanSessionpublic 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> 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,
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> loadListMinus(E bean,
String[] minus)
E - bean - minus -
public <E> List<E> loadListMinus(E bean,
String[] minus,
String orderBy)
E - bean - minus - orderBy -
public <E> List<E> loadListMinus(E bean,
String[] minus,
int limit)
E - bean - minus - limit -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||