Package ch.autumo.commons.utils.bean
Class Beans
java.lang.Object
ch.autumo.commons.utils.bean.Beans
Beans helper methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
beanPropertyName2DbName
(String beanPropName) Get database table column name by bean property name.static String
classNameToTable
(String clz) Class name to DB table.static String
classToRefBeanId
(Class<?> clz) Class to bean reference ID name.static String
classToRefDbId
(Class<?> clz) Class to database reference ID name.static String
classToTable
(Class<?> clz) Class to DB table.static String
classToTable
(String clzName) Class to DB table.static Model
createBean
(Class<?> beanClass) Create empty bean.static Model
createBean
(Class<?> beanClass, ResultSet set) Create bean.static Model
createBean
(Class<?> beanClass, ResultSet set, BeanProcessor processor) Create bean.getBeanFields
(Class<?> clz) Get bean fields.static BeanField[]
getBeanFieldsAsArray
(Class<?> clz) Get bean fields as array.static String
getDisplayField
(Entity emptyBean) Get display field name of bean.getForeignReferences
(Entity emptyBean) Get foreign references map if any or null.static String
makePlural
(String name) Make plural name.static String
makeSingular
(String name) Make singular name.static String
tableToClassName
(String tableName) Returns the class name without package or '.class'.extension.static void
Update the given model with entity from bean/model annotations, if it hasn't been updated yet.
-
Constructor Details
-
Beans
public Beans()
-
-
Method Details
-
beanPropertyName2DbName
Get database table column name by bean property name.- Parameters:
beanPropName
- bean property name- Returns:
- database table column name
-
classToRefBeanId
Class to bean reference ID name.- Parameters:
clz
- class- Returns:
- name of the bean reference ID.
-
classToRefDbId
Class to database reference ID name.- Parameters:
clz
- class- Returns:
- name of the database reference ID.
-
classToTable
Class to DB table.- Parameters:
clz
- class- Returns:
- name of table in DB
-
classToTable
Class to DB table.- Parameters:
clzName
- class name- Returns:
- name of table in DB
-
classNameToTable
Class name to DB table.- Parameters:
clz
- class name- Returns:
- name of table in DB
-
makePlural
Make plural name.- Parameters:
name
- singular name- Returns:
- plural name
-
tableToClassName
Returns the class name without package or '.class'.extension.- Parameters:
tableName
- DB table name- Returns:
- class name
-
makeSingular
Make singular name.- Parameters:
name
- plural name- Returns:
- singular name
-
createBean
Create empty bean.- Parameters:
beanClass
- bean class, must be of typeEntity
.- Returns:
- entity bean or null
- Throws:
SQLException
- SQL exceptionException
-
createBean
Create bean.- Parameters:
beanClass
- bean class, must be of typeEntity
.set
- result set at current position the data is taken from- Returns:
- entity bean or null
- Throws:
SQLException
- SQL exception
-
createBean
public static Model createBean(Class<?> beanClass, ResultSet set, BeanProcessor processor) throws SQLException Create bean.- Parameters:
beanClass
- bean class, must be of typeEntity
.set
- result set at current position the data is taken fromprocessor
- bean processor- Returns:
- entity bean or null
- Throws:
SQLException
- SQL exception
-
getForeignReferences
Get foreign references map if any or null. The map holds pairs of DB foreign keys and referenced primary tabel names.- Parameters:
emptyBean
- an empty bean to access static references if any- Returns:
- foreign references map
- Throws:
Exception
- exception
-
getDisplayField
Get display field name of bean.- Parameters:
emptyBean
- an empty bean to access static references if any- Returns:
- display field name
- Throws:
Exception
- exception
-
updateModel
Update the given model with entity from bean/model annotations, if it hasn't been updated yet. We access information PLANT has generated us with annotations, so don't have to access database for meta data again!- Parameters:
entity
- entitymodel
- model
-
getBeanFields
Get bean fields.- Parameters:
clz
- bean class- Returns:
- bean fields map
-
getBeanFieldsAsArray
Get bean fields as array.- Parameters:
clz
- bean class- Returns:
- bean fields array
-