org.mentabean
Class BeanConfig

java.lang.Object
  extended by org.mentabean.BeanConfig
Direct Known Subclasses:
AutoBeanConfig

public class BeanConfig
extends Object

A class representing a bean configuration, like table name, primary keys and fields in the database.

Author:
sergio.oliveira.jr@gmail.com

Constructor Summary
BeanConfig(Class<? extends Object> beanClass, String tableName)
          Creates a configuration for a bean represented by the given class.
 
Method Summary
<E> BeanConfig
abstractInstance(E abstractProperty, Class<? extends E> clazz)
          Configures a class that should be used instead of property type to create instances through Class.newInstance() method.
 BeanConfig abstractInstance(String abstractProperty, Class<? extends Object> clazz)
          Configures a class that should be used instead of property type to create instances through Class.newInstance() method.
 BeanConfig addSequenceName(String seqNameInDb)
          Add the sequence name *in the database* that will be used for this field.
 BeanConfig field(Object propValueFromGetter, DBType<? extends Object> type)
           
 BeanConfig field(Object propValueFromGetter, String dbName, DBType<? extends Object> type)
           
 BeanConfig field(String name, DBType<? extends Object> type)
          Add a database field for the given property with the given database type.
 BeanConfig field(String name, String dbName, DBType<? extends Object> type)
          Add a database field for the given property with the given database type.
 Iterator<DBField> fields()
          Return all DBFields configured for this bean.
 Class<? extends Object> getAbstractProperty(String key)
           
 DBField getAutoIncrementField()
          Return an auto-increment field, if one was configured for this bean.
 Class<? extends Object> getBeanClass()
          Return the bean class.
 TriggerDispatcher getDispatcher()
           
 DBField getField(String name)
           
 int getNumberOfFields()
          Return the number of fields configured for this bean.
 int getNumberOfPKs()
           
 DBField getSequenceField()
          Return a sequence field, if one was configured for this bean.
 String getSequenceName()
          Returns the name of the sequence in the database.
 String getTableName()
          Return the table name where the bean properties are stored.
 boolean hasPK()
          Check whether the primary key was defined.
 BeanConfig pk(Object propValueFromGetter, DBType<? extends Object> type)
           
 BeanConfig pk(Object propValueFromGetter, String dbName, DBType<? extends Object> type)
           
 BeanConfig pk(String name, DBType<? extends Object> type)
          Add a bean property that is the primary key in the database.
 BeanConfig pk(String name, String dbName, DBType<? extends Object> type)
          Add a property that is the primary key in the database.
 Iterator<DBField> pks()
          Return an iterator with the DBFields for the PK configured for this bean.
 BeanConfig remove(Object propValueFromGetter)
           
 BeanConfig remove(String name)
           
 BeanConfig remove(TriggerListener trigger)
           
 BeanConfig seq(String seqNameInDb)
          Alias for method addSequence
 String toString()
           
 BeanConfig trigger(TriggerListener trigger)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeanConfig

public BeanConfig(Class<? extends Object> beanClass,
                  String tableName)
Creates a configuration for a bean represented by the given class.

Parameters:
beanClass - The bean klass
tableName - The database table where the bean properties will be stored.
Method Detail

getTableName

public String getTableName()
Return the table name where the bean properties are stored.

Returns:
The database table name.

getBeanClass

public Class<? extends Object> getBeanClass()
Return the bean class.

Returns:
The bean class.

addSequenceName

public BeanConfig addSequenceName(String seqNameInDb)
Add the sequence name *in the database* that will be used for this field. NOTE: A field of type SEQUENCE must have been defined before or an IllegalStateException is thrown.

Parameters:
seqNameInDb - the name of the sequence in the database
Returns:
this bean config

seq

public BeanConfig seq(String seqNameInDb)
Alias for method addSequence

Parameters:
seqNameInDb -
Returns:
this bean config

getSequenceName

public String getSequenceName()
Returns the name of the sequence in the database. NOTE: The name returned is the name of the sequence in the database.

Returns:
the name of the sequence in the database.

remove

public BeanConfig remove(String name)

remove

public BeanConfig remove(Object propValueFromGetter)

getField

public DBField getField(String name)

getAutoIncrementField

public DBField getAutoIncrementField()
Return an auto-increment field, if one was configured for this bean. Note: A bean can have only one auto-increment field configured for this bean. Attempting to configure more than one will throw an exception.

Returns:
the auto-increment field configured for this bean or null if it was not defined

getSequenceField

public DBField getSequenceField()
Return a sequence field, if one was configured for this bean. Note: A bean can have only one sequence field configured for this bean. Attempting to configure more than one will throw an exception.

Returns:
the sequence field configured for this bean or null if it was not defined

field

public BeanConfig field(String name,
                        DBType<? extends Object> type)
Add a database field for the given property with the given database type. It assumes that the property name is the SAME as the database column name. If they are different, use the other addField method.

Parameters:
name - The bean property name (same as the database column name)
type - The database type
Returns:
This BeanConfig (Fluent API)

field

public BeanConfig field(Object propValueFromGetter,
                        DBType<? extends Object> type)

field

public BeanConfig field(String name,
                        String dbName,
                        DBType<? extends Object> type)
Add a database field for the given property with the given database type.

Parameters:
name - The bean property name
dbName - The name of the database column holding this property
type - The database type
Returns:
This BeanConfig (Fluent API)

field

public BeanConfig field(Object propValueFromGetter,
                        String dbName,
                        DBType<? extends Object> type)

pk

public BeanConfig pk(String name,
                     DBType<? extends Object> type)
Add a bean property that is the primary key in the database. The column name is the same as the property bean name. If they are different use the other pk method. All beans must have a primary key and you can call this method multiple times to support composite primary keys.

Parameters:
name - The bean property name
type - The database type
Returns:
This BeanConfig (Fluent API)

pk

public BeanConfig pk(Object propValueFromGetter,
                     DBType<? extends Object> type)

pk

public BeanConfig pk(String name,
                     String dbName,
                     DBType<? extends Object> type)
Add a property that is the primary key in the database. All beans must have a primary key and you can call this method multiple times to support composite primary keys.

Parameters:
name - The bean property name
dbName - The name of the database column holding this property
type - The database type
Returns:
This BeanConfig (Fluent API)

pk

public BeanConfig pk(Object propValueFromGetter,
                     String dbName,
                     DBType<? extends Object> type)

getNumberOfFields

public int getNumberOfFields()
Return the number of fields configured for this bean. It includes the PK.

Returns:
The number of fields configured for this bean.

getNumberOfPKs

public int getNumberOfPKs()

toString

public String toString()
Overrides:
toString in class Object

fields

public Iterator<DBField> fields()
Return all DBFields configured for this bean. It includes the PK as well.

Returns:
An Iterator with all DBFields configured for this bean.

hasPK

public boolean hasPK()
Check whether the primary key was defined.

Returns:
true if a primary key was defined.

pks

public Iterator<DBField> pks()
Return an iterator with the DBFields for the PK configured for this bean. Note: A bean can have more than one property as its primary key, in that case it has a composite primary key.

Returns:
An iterator with the DBFields for the PK.

trigger

public BeanConfig trigger(TriggerListener trigger)

remove

public BeanConfig remove(TriggerListener trigger)

getDispatcher

public TriggerDispatcher getDispatcher()

abstractInstance

public BeanConfig abstractInstance(String abstractProperty,
                                   Class<? extends Object> clazz)
Configures a class that should be used instead of property type to create instances through Class.newInstance() method. It's useful when working with abstract objects

Parameters:
abstractProperty - - The property name
clazz - - The concrete class
Returns:
this

abstractInstance

public <E> BeanConfig abstractInstance(E abstractProperty,
                                       Class<? extends E> clazz)
Configures a class that should be used instead of property type to create instances through Class.newInstance() method. It's useful when working with abstract objects

Parameters:
abstractProperty - - The property name (through proxy)
clazz - - The concrete class
Returns:
this

getAbstractProperty

public Class<? extends Object> getAbstractProperty(String key)


Copyright © 2013. All Rights Reserved.