edu.jhu.tmaj.beans
Class JBean

java.lang.Object
  extended by edu.jhu.tmaj.beans.JBean
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
AnimalExperimentBean, ArrayBlockBean, ArrayCoreBean, ArrayImageBean, ArraySlideBean, BlockBean, BlockOrSlideExchangeBean, BlockUsageAltBean, BlockUsageBean, BloodSampleBean, BloodUsageBean, CellLineBean, CellLineExperimentBean, DynamicJBean, IASessionBean, MachineSessionBean, MolecularSampleBean, MolecularUsageBean, NullBean, PaperBean, PatientBean, ProjectBean, ProtocolBean, ScanBean, SessionBean, SlideBean, TissueSampleBean, TissueUsageBean, UrineSampleBean, UrineUsageBean, UserBean

public abstract class JBean
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

Represents a database table that can be converted into a Swing JTable and edited. A JBean class represents a database table. An instance of a JBean represents one row in that table. Classes InputPanel3 and TableData4 allow a database table to be editted as a JTable. This class, the JBean class, fills in the information about the particular table. This class provides functionality that turns a database row into a Bean, as well as the reverse. In addition this class provides functionality that turns a JTable row into this bean, as well as the reverse. To Summarize: Database <--> Bean <--> Swing-Interface As you can see, data is read from the database, put into this JBean, and then put into a row in a JTable. When the user makes a change, data goes from a row in the JTable, into this JBean, and finally is written back to the database. Note: The JBean, InputPanel, and TableData classes are the most complicated classes in TMAJ.

See Also:
Serialized Form

Field Summary
protected  StaticMetaData staticMetaData
           
 
Constructor Summary
protected JBean(StaticMetaData staticMetaData)
          Constructs a JBean.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this Bean to another Bean by doing a case-insensitive compare using toString()
 void createFromResultSet(java.sql.ResultSet rs, java.util.Set<java.lang.String> columnNames)
          Creates this Bean from a row in the database.
 void createFromSwingMap(java.util.Map<DatabaseField,java.lang.Object> columnField_value)
          Creates this Bean from a row in a swing JTable.
 void delete()
          Deletes this Bean from the database.
 boolean equals(java.lang.Object obj)
          Returns true if this bean is equal to obj, that is, if the bean's classes and ids are the same.
 java.util.List<DatabaseField> getAllStaticColumnIdentifiers()
          Returns a List of all regular columnIdentifiers for this Bean.
protected  java.lang.String getBaseSQL(Search search)
          Returns the SQL for a Search without the WHERE Clause.
protected  JBean getBeanInDatabase()
           
protected  java.util.List<JBean> getBeanList(Search search)
          Returns a List of Beans from a Search.
 java.util.List<JBean> getBeanList(java.lang.String sql)
          Returns a List of Beans from a SQL statement.
(package private)  boolean getBooleanField(DatabaseField field)
          Gets the boolean value of a field whose type is TFieldType.BOOLEAN
static java.lang.Class getClassForType(DatabaseFieldType tFieldType)
           
protected  java.util.List<DatabaseField> getColumnIdentifiers(Search search, java.util.List<JBean> beanList)
          Returns a List of ColumnIdentifiers based on a Search and the list of Beans generated.
(package private) static java.util.Set<java.lang.String> getColumnNamesSet(java.sql.ResultSet rs)
          Returns a Set of lowercase column names contained in the ResultSet
protected  java.util.Date getDateField(DatabaseField field)
          Gets a Date value of a field who type is TField.DATE
static java.lang.Object getDefaultBeanObjectForType(DatabaseFieldType tFieldType)
           
static java.lang.Object getDefaultSwingObjectForType(DatabaseFieldType tFieldType)
           
protected  java.lang.Double getDoubleField(DatabaseField field)
          Gets the int value of a field whose type is TFieldType.DOUBLE
 java.util.List<PickListEnumeration> getEnumerations(DatabaseField field)
          Returns a List of Enumerations for a given field (column).
abstract  DatabaseField[] getFieldsArray()
          Returns an Array of TFields representing the columnnames of this bean.
 java.lang.Object getFieldValue(DatabaseField field)
          Gets the value of a field.
static java.util.Map<java.lang.Integer,JBean> getID_Bean_Map(java.util.List<JBean> beanList)
          Returns a Map with an Integer representing the JBean's primary key ID and the value representing the Bean record itself.
 java.lang.Integer getID()
          Gets the id of this bean
protected  java.lang.Integer getIntegerField(DatabaseField field)
          Gets the int value of a field whose type is TFieldType.INTEGER
abstract  JBean getNewInstance()
          Returns a new instance of this bean.
static java.lang.String getNonNullString(java.sql.ResultSet rs, java.lang.String fieldName)
          Returns the value of fieldName in rs, or "" if the value is null.
 DatabaseField getPrimaryKeyField()
          Returns the TField that is the Primary Key for the bean's table.
 java.lang.String getPrimaryKeyName()
          Gets the primary key name of the bean's table.
 SelectResponse getSelectResponse(Search search)
          Returns a SelectResponse containing a beanList and columnIdentifiers from a Search.
 java.lang.String getSQL(Search search)
          Returns a SELECT SQL statement given a Search.
 StaticMetaData getStaticMetaData()
          Gets the StaticMetaData of this bean.
protected  java.lang.String getStringField(DatabaseField field)
          Gets the String value of a field whose type is TFieldType.STRING
 java.util.Map<DatabaseField,java.lang.Object> getSwingHash()
          Gets a Map with the fields as the keys, and the swing-ready values as the Map's values.
protected  java.lang.Object getSwingToBeanObject(DatabaseField columnField, java.lang.Object oldValue)
          Gets the value for this bean from a Swing JTable cell.
abstract  DatabaseTable getTable()
           
 java.lang.String getTableName()
          Returns the name of the database table to which this bean refers.
protected  UserBean getUserBean()
          Returns the UserBean of the person reading and writing data to this bean.
(package private)  java.lang.String getWantedColumnsString(Search search)
          Returns a comma, delimited list of columnNames desired in a Search.
(package private)  java.util.List<DatabaseField> getWantedStaticColumnIdentifiers(Search search)
          Returns a List of the ColumnIdentifiers that are desired by the end-user's search.
protected static java.lang.String getWhereClause(Search search, JBean bean, java.lang.String additional)
          Returns the WHERE Clause of a SELECT statement given a Search.
 int hashCode()
          Returns the ID of this bean.
 void insert()
          Inserts the database row with the data in this Bean.
 boolean isEnumerated(DatabaseField field)
          Returns true if the column is enumerated (gives a comboBox of choices).
(package private)  void setBooleanField(DatabaseField field, java.lang.Boolean bool)
          Sets a field of type TFieldType.BOOLEAN
(package private)  void setDateField(DatabaseField field, java.util.Date date)
           
protected  void setDoubleField(DatabaseField field, java.lang.Double newValue)
          Sets a field of type TFieldType.DOUBLE
 void setID(int id)
          Sets the id of this bean.
protected  void setIntegerField(DatabaseField field, java.lang.Integer newValue)
          Sets a field of type TFieldType.INTEGER
(package private)  void setStringField(DatabaseField field, java.lang.String s)
          Sets a field of type TFieldType.STRING
 void setUserBean(UserBean u)
          Sets the User who is reading and writing information to this bean.
 java.lang.String toString()
          Returns the primary key name of the bean's table, along with the bean's ID.
 void update()
          Updates the database row with the data in this Bean.
 void verify()
          Overwritten by subclasses, this method may throw an exception before an insert() or update() is done if there is something wrong with the JBean.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

staticMetaData

protected final StaticMetaData staticMetaData
Constructor Detail

JBean

protected JBean(StaticMetaData staticMetaData)
Constructs a JBean. The staticMetaData gives info on which columns are enumerated.

Method Detail

getEnumerations

public java.util.List<PickListEnumeration> getEnumerations(DatabaseField field)
Returns a List of Enumerations for a given field (column).


isEnumerated

public boolean isEnumerated(DatabaseField field)
Returns true if the column is enumerated (gives a comboBox of choices).


getBooleanField

final boolean getBooleanField(DatabaseField field)
Gets the boolean value of a field whose type is TFieldType.BOOLEAN


getIntegerField

protected final java.lang.Integer getIntegerField(DatabaseField field)
Gets the int value of a field whose type is TFieldType.INTEGER


getDoubleField

protected final java.lang.Double getDoubleField(DatabaseField field)
Gets the int value of a field whose type is TFieldType.DOUBLE


getStringField

protected final java.lang.String getStringField(DatabaseField field)
Gets the String value of a field whose type is TFieldType.STRING


getDateField

protected final java.util.Date getDateField(DatabaseField field)
Gets a Date value of a field who type is TField.DATE


getFieldValue

public final java.lang.Object getFieldValue(DatabaseField field)
Gets the value of a field. If the field does not have a value, the default (or "null") value for the field's type is used. Generally, these "default values", such as "" into null, get turned into NULL when put into the database, and are displayed as blank in a JTable.


setUserBean

public final void setUserBean(UserBean u)
Sets the User who is reading and writing information to this bean.


getUserBean

protected final UserBean getUserBean()
Returns the UserBean of the person reading and writing data to this bean.


setIntegerField

protected final void setIntegerField(DatabaseField field,
                                     java.lang.Integer newValue)
Sets a field of type TFieldType.INTEGER


setDoubleField

protected final void setDoubleField(DatabaseField field,
                                    java.lang.Double newValue)
Sets a field of type TFieldType.DOUBLE


setStringField

final void setStringField(DatabaseField field,
                          java.lang.String s)
Sets a field of type TFieldType.STRING


setBooleanField

final void setBooleanField(DatabaseField field,
                           java.lang.Boolean bool)
Sets a field of type TFieldType.BOOLEAN


setDateField

final void setDateField(DatabaseField field,
                        java.util.Date date)

getSwingHash

public java.util.Map<DatabaseField,java.lang.Object> getSwingHash()
Gets a Map with the fields as the keys, and the swing-ready values as the Map's values. Summary: Bean->Swing This function is used to convert this bean into a row of a JTable. For example, if a field has a "default-null" value, this function makes sure that field shows up as blank in the JTable.


createFromSwingMap

public void createFromSwingMap(java.util.Map<DatabaseField,java.lang.Object> columnField_value)
Creates this Bean from a row in a swing JTable. Summary: Swing->Bean

Parameters:
columnField_value - A map where the keys are the columns in the Swing table, and the values are the data the user put in.

createFromResultSet

public final void createFromResultSet(java.sql.ResultSet rs,
                                      java.util.Set<java.lang.String> columnNames)
                               throws java.sql.SQLException
Creates this Bean from a row in the database. Summary: Database->Bean

Parameters:
rs - a ResultSet pointing to a row in the database table
columnNames - the column names in the resultset to get.
Throws:
java.sql.SQLException

update

public void update()
            throws java.sql.SQLException
Updates the database row with the data in this Bean. Summary: Bean->Database

Throws:
java.sql.SQLException

insert

public void insert()
            throws java.sql.SQLException
Inserts the database row with the data in this Bean. Summary: Bean->Database

Throws:
java.sql.SQLException

getSwingToBeanObject

protected java.lang.Object getSwingToBeanObject(DatabaseField columnField,
                                                java.lang.Object oldValue)
Gets the value for this bean from a Swing JTable cell. Numbers have to be parsed to get from a String to an Integer or Double. (JTables represent any user-editted value in the table-cell as a String.) EnumeratedValues are turned into Integers.


getID

public final java.lang.Integer getID()
Gets the id of this bean


setID

public final void setID(int id)
Sets the id of this bean.


delete

public void delete()
            throws java.sql.SQLException
Deletes this Bean from the database.

Throws:
java.sql.SQLException

getAllStaticColumnIdentifiers

public final java.util.List<DatabaseField> getAllStaticColumnIdentifiers()
Returns a List of all regular columnIdentifiers for this Bean. (This does not include the DynamicColumnIdentifiers of DynamicBeans.)


getWantedStaticColumnIdentifiers

final java.util.List<DatabaseField> getWantedStaticColumnIdentifiers(Search search)
Returns a List of the ColumnIdentifiers that are desired by the end-user's search.


getColumnIdentifiers

protected java.util.List<DatabaseField> getColumnIdentifiers(Search search,
                                                             java.util.List<JBean> beanList)
Returns a List of ColumnIdentifiers based on a Search and the list of Beans generated.


getSelectResponse

public final SelectResponse getSelectResponse(Search search)
                                       throws java.sql.SQLException
Returns a SelectResponse containing a beanList and columnIdentifiers from a Search.

Throws:
java.sql.SQLException

getBeanList

public final java.util.List<JBean> getBeanList(java.lang.String sql)
                                        throws java.sql.SQLException
Returns a List of Beans from a SQL statement.

Throws:
java.sql.SQLException

getBeanList

protected java.util.List<JBean> getBeanList(Search search)
                                     throws java.sql.SQLException
Returns a List of Beans from a Search.

Throws:
java.sql.SQLException

getColumnNamesSet

static final java.util.Set<java.lang.String> getColumnNamesSet(java.sql.ResultSet rs)
                                                        throws java.sql.SQLException
Returns a Set of lowercase column names contained in the ResultSet

Throws:
java.sql.SQLException

getPrimaryKeyField

public final DatabaseField getPrimaryKeyField()
Returns the TField that is the Primary Key for the bean's table. By convention, this is the first element of the TFields array.


getPrimaryKeyName

public final java.lang.String getPrimaryKeyName()
Gets the primary key name of the bean's table. Example=ProjectID


getTableName

public final java.lang.String getTableName()
Returns the name of the database table to which this bean refers.


getNewInstance

public abstract JBean getNewInstance()
Returns a new instance of this bean.


getFieldsArray

public abstract DatabaseField[] getFieldsArray()
Returns an Array of TFields representing the columnnames of this bean.


getBaseSQL

protected final java.lang.String getBaseSQL(Search search)
Returns the SQL for a Search without the WHERE Clause. Example: SELECT Col1,Col2,Col3 FROM TableName


getSQL

public java.lang.String getSQL(Search search)
Returns a SELECT SQL statement given a Search.


getWantedColumnsString

final java.lang.String getWantedColumnsString(Search search)
Returns a comma, delimited list of columnNames desired in a Search. This is eventually put into a SELECT SQL statement.


getWhereClause

protected static java.lang.String getWhereClause(Search search,
                                                 JBean bean,
                                                 java.lang.String additional)
Returns the WHERE Clause of a SELECT statement given a Search.


getID_Bean_Map

public static java.util.Map<java.lang.Integer,JBean> getID_Bean_Map(java.util.List<JBean> beanList)
Returns a Map with an Integer representing the JBean's primary key ID and the value representing the Bean record itself. (Also used in TissueDiagnosisBean.)


getNonNullString

public static java.lang.String getNonNullString(java.sql.ResultSet rs,
                                                java.lang.String fieldName)
                                         throws java.sql.SQLException
Returns the value of fieldName in rs, or "" if the value is null.

Throws:
java.sql.SQLException

compareTo

public int compareTo(java.lang.Object o)
Compares this Bean to another Bean by doing a case-insensitive compare using toString()

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Returns the primary key name of the bean's table, along with the bean's ID. Example: ProjectID#5

Overrides:
toString in class java.lang.Object

hashCode

public final int hashCode()
Returns the ID of this bean.

Overrides:
hashCode in class java.lang.Object

equals

public final boolean equals(java.lang.Object obj)
Returns true if this bean is equal to obj, that is, if the bean's classes and ids are the same.

Overrides:
equals in class java.lang.Object

verify

public void verify()
            throws java.sql.SQLException
Overwritten by subclasses, this method may throw an exception before an insert() or update() is done if there is something wrong with the JBean.

Throws:
java.sql.SQLException

getStaticMetaData

public final StaticMetaData getStaticMetaData()
Gets the StaticMetaData of this bean. The staticMetaData contains information on which columns are enumerated, and if so, what their enumeration values are. Static means non-dynamic, so StaticMetaData does not have any information about the enumerations of dynamic columns.


getBeanInDatabase

protected JBean getBeanInDatabase()
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

getTable

public abstract DatabaseTable getTable()

getDefaultSwingObjectForType

public static java.lang.Object getDefaultSwingObjectForType(DatabaseFieldType tFieldType)

getDefaultBeanObjectForType

public static java.lang.Object getDefaultBeanObjectForType(DatabaseFieldType tFieldType)

getClassForType

public static java.lang.Class getClassForType(DatabaseFieldType tFieldType)