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
 BeanConfig addSequenceName(String seqNameInDb)
          Add the sequence name *in the database* that will be used for this field.
 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.
 DBField getAutoIncrementField()
          Return an auto-increment field, if one was configured for this bean.
 Class<? extends Object> getBeanClass()
          Return the bean class.
 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(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 seq(String seqNameInDb)
          Alias for method addSequence
 String toString()
           
 
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.

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(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)

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(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)

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.


Copyright © 2012. All Rights Reserved.