Class Beans

java.lang.Object
ch.autumo.commons.utils.bean.Beans

public class Beans extends Object
Beans helper methods.
  • Constructor Details

    • Beans

      public Beans()
  • Method Details

    • beanPropertyName2DbName

      public static String beanPropertyName2DbName(String beanPropName)
      Get database table column name by bean property name.
      Parameters:
      beanPropName - bean property name
      Returns:
      database table column name
    • classToRefBeanId

      public static String classToRefBeanId(Class<?> clz)
      Class to bean reference ID name.
      Parameters:
      clz - class
      Returns:
      name of the bean reference ID.
    • classToRefDbId

      public static String classToRefDbId(Class<?> clz)
      Class to database reference ID name.
      Parameters:
      clz - class
      Returns:
      name of the database reference ID.
    • classToTable

      public static String classToTable(Class<?> clz)
      Class to DB table.
      Parameters:
      clz - class
      Returns:
      name of table in DB
    • classToTable

      public static String classToTable(String clzName)
      Class to DB table.
      Parameters:
      clzName - class name
      Returns:
      name of table in DB
    • classNameToTable

      public static String classNameToTable(String clz)
      Class name to DB table.
      Parameters:
      clz - class name
      Returns:
      name of table in DB
    • makePlural

      public static String makePlural(String name)
      Make plural name.
      Parameters:
      name - singular name
      Returns:
      plural name
    • tableToClassName

      public static String tableToClassName(String tableName)
      Returns the class name without package or '.class'.extension.
      Parameters:
      tableName - DB table name
      Returns:
      class name
    • makeSingular

      public static String makeSingular(String name)
      Make singular name.
      Parameters:
      name - plural name
      Returns:
      singular name
    • createBean

      public static Model createBean(Class<?> beanClass) throws Exception
      Create empty bean.
      Parameters:
      beanClass - bean class, must be of type Entity.
      Returns:
      entity bean or null
      Throws:
      SQLException - SQL exception
      Exception
    • createBean

      public static Model createBean(Class<?> beanClass, ResultSet set) throws SQLException
      Create bean.
      Parameters:
      beanClass - bean class, must be of type Entity.
      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 type Entity.
      set - result set at current position the data is taken from
      processor - bean processor
      Returns:
      entity bean or null
      Throws:
      SQLException - SQL exception
    • getForeignReferences

      public static Map<String,Class<?>> getForeignReferences(Entity emptyBean) throws Exception
      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

      public static String getDisplayField(Entity emptyBean) throws Exception
      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

      public static void updateModel(Entity entity, Map<String,Map<String,BeanField>> model)
      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 - entity
      model - model
    • getBeanFields

      public static Map<String,BeanField> getBeanFields(Class<?> clz)
      Get bean fields.
      Parameters:
      clz - bean class
      Returns:
      bean fields map
    • getBeanFieldsAsArray

      public static BeanField[] getBeanFieldsAsArray(Class<?> clz)
      Get bean fields as array.
      Parameters:
      clz - bean class
      Returns:
      bean fields array