com.sibvisions.rad.persist.bean
Class BeanConverter

java.lang.Object
  extended by com.sibvisions.rad.persist.bean.BeanConverter

public class BeanConverter
extends java.lang.Object

The BeanConverter class allows to convert between Object[]s, IBeans and POJOs. This class keeps three important pieces in sync:

  1. The main IBeanType which is used for many operations.
  2. An array of POJO property names, which are generated from the IBeanType.
  3. A map of property names which allows to remap names.


Constructor Summary
BeanConverter()
          Creates a new instance of BeanConverter.
BeanConverter(IBeanType pBeanType)
          Creates a new instance of BeanConverter.
 
Method Summary
 java.lang.Object[] createArray(java.lang.Object pObject)
          Creates an array of values from a given object.
 IBean createBean(java.lang.Object pPOJO)
          Creates a bean from the given POJO.
 IBean createBean(java.lang.Object[] pValues)
          Creates a bean with given values.
 IBean createEmptyBean()
          Creates a new bean with all column names from the meta data.
<T> T
createPOJO(java.lang.Class<T> pClass, IBean pBean)
          Creates a POJO from the given type and with the values from a bean.
<T> T
createPOJO(java.lang.Class<T> pClass, java.lang.Object pPOJO)
          Creates a POJO from the given type and with the values from a POJO.
<T> T
createPOJO(java.lang.Class<T> pClass, java.lang.Object[] pValues)
          Creates a POJO from the given type and with given values.
 IBeanType getBeanType()
          Gets the IBeanType used by this BeanConverter.
 java.lang.String getPojoPropertyName(int pIndex)
          Returns the POJO property name at the given index.
 java.lang.String getPropertyNameForColumn(java.lang.String pColumnName)
          Gets the property name (Java standard) for the given column name.
 boolean isInitialized()
          Returns true if this BeanConverter has been initialized.
 void removePropertyNameForColumn(java.lang.String pColumnName)
          Removes the given column name.
 void setBeanType(IBeanType pBeanType)
          Sets the given IBeanType.
 void setPojoPropertyName(int pIndex, java.lang.String pPropertyName)
          Sets the given POJO property name at the given index.
 void setPropertyNameForColumn(java.lang.String pColumnName, java.lang.String pPropertyName)
          Sets the property name (Java standard) for a given column name.
 void updateArray(java.lang.Object[] pArray, java.lang.Object pPOJO)
          Updates the array with the values from the POJO.
 void updateBean(IBean pBean, java.lang.Object pPOJO)
          Updates a bean with values from a POJO.
 void updateBean(IBean pBean, java.lang.Object[] pValues)
          Updates a bean with values from an array.
 void updatePOJO(java.lang.Object pPOJO, java.lang.Object pNewPOJO)
          Updates a POJO with values from a POJO.
 void updatePOJO(java.lang.Object pPOJO, java.lang.Object[] pValues)
          Updates a POJO with values from an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanConverter

public BeanConverter()
Creates a new instance of BeanConverter. Note that the created instance is still missing a IBeanType, so it needs to be set afterwards.


BeanConverter

public BeanConverter(IBeanType pBeanType)
Creates a new instance of BeanConverter.

Parameters:
pBeanType - the IBeanType to use.
Method Detail

createArray

public java.lang.Object[] createArray(java.lang.Object pObject)
Creates an array of values from a given object. The array has the same element count as the meta data column count.

Parameters:
pObject - a POJO or bean
Returns:
an array containing the property values from the given object

createBean

public IBean createBean(java.lang.Object[] pValues)
Creates a bean with given values. The bean contains the property names from the column meta data and not more.

Parameters:
pValues - the values in same order as the meta data
Returns:
a new bean

createBean

public IBean createBean(java.lang.Object pPOJO)
Creates a bean from the given POJO. The bean contains the property names from the column meta data and not more.

Parameters:
pPOJO - the POJO from which to create the bean.
Returns:
a new bean

createEmptyBean

public IBean createEmptyBean()
Creates a new bean with all column names from the meta data. Only this column names are allowed.

Returns:
a new instance of an IBean implementation

createPOJO

public <T> T createPOJO(java.lang.Class<T> pClass,
                        IBean pBean)
Creates a POJO from the given type and with the values from a bean.

Type Parameters:
T - the type of the POJO
Parameters:
pClass - the class of the POJO
pBean - the bean with values for the POJO
Returns:
the POJO

createPOJO

public <T> T createPOJO(java.lang.Class<T> pClass,
                        java.lang.Object pPOJO)
Creates a POJO from the given type and with the values from a POJO.

Type Parameters:
T - the type of the POJO
Parameters:
pClass - the class of the POJO
pPOJO - the POJO for the POJO
Returns:
the POJO

createPOJO

public <T> T createPOJO(java.lang.Class<T> pClass,
                        java.lang.Object[] pValues)
Creates a POJO from the given type and with given values.

Type Parameters:
T - the type of the POJO
Parameters:
pClass - the class of the POJO
pValues - the values for the properties in the same order as the meta data
Returns:
the POJO

getBeanType

public IBeanType getBeanType()
Gets the IBeanType used by this BeanConverter. Might return null if this hasn't been initialized by now.

Returns:
the IBeanType. null if this hasn't been initialized.

getPojoPropertyName

public java.lang.String getPojoPropertyName(int pIndex)
Returns the POJO property name at the given index.

Parameters:
pIndex - the index of the property.
Returns:
the POJO property name.

getPropertyNameForColumn

public java.lang.String getPropertyNameForColumn(java.lang.String pColumnName)
Gets the property name (Java standard) for the given column name.

Parameters:
pColumnName - the column name e.g. FIRST_NAME
Returns:
the java property name e.g. firstName instead of FIRST_NAME

isInitialized

public boolean isInitialized()
Returns true if this BeanConverter has been initialized.

Returns:
true if this is initialized.

removePropertyNameForColumn

public void removePropertyNameForColumn(java.lang.String pColumnName)
Removes the given column name.

Parameters:
pColumnName - the column name to remove.

setBeanType

public void setBeanType(IBeanType pBeanType)
Sets the given IBeanType.

Parameters:
pBeanType - the IBeanType to use.

setPojoPropertyName

public void setPojoPropertyName(int pIndex,
                                java.lang.String pPropertyName)
Sets the given POJO property name at the given index.

Parameters:
pIndex - the index at which to set the name.
pPropertyName - the POJO property name.

setPropertyNameForColumn

public void setPropertyNameForColumn(java.lang.String pColumnName,
                                     java.lang.String pPropertyName)
Sets the property name (Java standard) for a given column name. The name will be used for synchronizing POJOs with beans.

Parameters:
pColumnName - the column name
pPropertyName - the java property name e.g. firstName instead of FIRST_NAME

updateArray

public void updateArray(java.lang.Object[] pArray,
                        java.lang.Object pPOJO)
Updates the array with the values from the POJO.

Parameters:
pArray - the array.
pPOJO - the POJO.

updateBean

public void updateBean(IBean pBean,
                       java.lang.Object pPOJO)
Updates a bean with values from a POJO. Only values from known properties will be updated. The property names from the meta data will be used.

Parameters:
pBean - the bean
pPOJO - the POJO (or IBean)

updateBean

public void updateBean(IBean pBean,
                       java.lang.Object[] pValues)
Updates a bean with values from an array. Only values from known properties will be updated. The property names from the meta data will be used.

Parameters:
pBean - the bean.
pValues - the array.

updatePOJO

public void updatePOJO(java.lang.Object pPOJO,
                       java.lang.Object pNewPOJO)
Updates a POJO with values from a POJO. Only values from known properties will be updated. The property names from the meta data will be used.

Parameters:
pPOJO - the POJO to update.
pNewPOJO - the new POJO.

updatePOJO

public void updatePOJO(java.lang.Object pPOJO,
                       java.lang.Object[] pValues)
Updates a POJO with values from an array. Only values from known properties will be updated. The property names from the meta data will be used.

Parameters:
pPOJO - the POJO to update.
pValues - the array.


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.