| ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.hussam.database.sql.DatabaseRecordHome
public class DatabaseRecordHome
This resembles a Database Table. you can insert, remove, update and serach for records. You can extend this class to add more functionality. To select or try to find any record, make note that this class does not read null entries when trying to find. dont use the find method if you have null entries.!!
You can benefit from this class easily. Extend this class and override the create method to return a subclass of record, that has a your business functionalty. For example you can create a CustomerHome class that resembles a Customer Table in the database. and you can create a Customer class that extends Record that can be used to access the data and implement business logic.This object has its own Record Pool. So dont worry, you wont have duplicate Records generated from the same pool.
| Constructor Summary | |
|---|---|
DatabaseRecordHome(ConnectionPool pool, java.lang.String tableName) | |
DatabaseRecordHome(ConnectionPool pool, java.lang.String tableName, java.lang.String primaryKeyName) | |
DatabaseRecordHome(TablesDataSource source, ConnectionPool pool, java.lang.String tableName) | |
DatabaseRecordHome(TablesDataSource source, ConnectionPool pool, java.lang.String tableName, java.lang.String primaryKeyName) | |
| Method Summary | |
|---|---|
protected void | addRecordToMemory(Record record) adds this record to the memory of record pool. |
void | addRelation(java.lang.String foreignKey, RecordHome home) adds a relation between this RecordHome and another recordhome using an entryname in this recordhome. |
Record | build(java.sql.ResultSet result) Builds one record from this Result set. |
java.util.List<? extends Record> | buildAll(java.sql.ResultSet result) Returns all records in this result set. |
Record | create(java.util.Map<java.lang.String,java.lang.Object> entries) This is a method that creates a sepcific Record from map of entries. |
void | createTable() Creates the table if it was not created. |
java.util.List<? extends Record> | find(java.util.Map<java.lang.String,java.lang.Object> entries) Finds the records that meets the given conditions. |
java.lang.Object | generateKey() Generates an unused key. |
java.util.List<java.lang.String> | getColumnNames() Returns a List |
java.util.Map<java.lang.String,RecordHome> | getForeignKeys() Returns a map with String Keys and RecordHome values. |
java.lang.String | getName() Returns the name of this Factory or Home. |
static java.lang.String | getPrimaryKeyForTable(java.sql.Connection c, java.lang.String table) |
java.lang.String | getPrimaryKeyName() Returns the name of the primary key. |
java.util.Map<java.lang.String,java.lang.Object> | getSearchOptions() returns a map representing serach options. |
protected boolean | isInMemory(java.lang.Object key) Tests if this id is in memory. |
Record | load(java.lang.Object id) Loads a spicific Record from the database. |
protected Record | loadFromMemory(java.lang.Object key) |
void | remove(Record record) Removes this record from the RecordHome. |
void | save(Record record) inserts a spcific Record into the database. |
protected void | testForNull(Record r) |
java.lang.Object | toID(java.lang.Object o) If the object is a record, the method will return the ID of that record. |
java.lang.Object | toRecord(java.lang.String name, java.lang.Object o) If this object is a record, it will return the id of the record. |
java.lang.String | toString() |
void | update(Record record) Updates this record into the database. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DatabaseRecordHome(TablesDataSource source,
ConnectionPool pool,
java.lang.String tableName,
java.lang.String primaryKeyName)
throws java.sql.SQLExceptionsource - pool - tableName - primaryKeyName - java.sql.SQLException
public DatabaseRecordHome(TablesDataSource source,
ConnectionPool pool,
java.lang.String tableName)
throws java.sql.SQLExceptionsource - pool - tableName - java.sql.SQLException
public DatabaseRecordHome(ConnectionPool pool,
java.lang.String tableName,
java.lang.String primaryKeyName)
throws java.sql.SQLExceptionpool - tableName - primaryKeyName - java.sql.SQLException
public DatabaseRecordHome(ConnectionPool pool,
java.lang.String tableName)
throws java.sql.SQLExceptionpool - tableName - java.sql.SQLException| Method Detail |
|---|
public static java.lang.String getPrimaryKeyForTable(java.sql.Connection c,
java.lang.String table)
throws java.sql.SQLExceptionc - table - java.sql.SQLExceptionpublic java.lang.String getPrimaryKeyName()
RecordHomegetPrimaryKeyName in interface RecordHomepublic void addRelation(java.lang.String foreignKey, RecordHome home)
foreignKey - home - public java.util.Map<java.lang.String,RecordHome> getForeignKeys()
RecordHomegetForeignKeys in interface RecordHomepublic java.lang.String getName()
RecordHomegetName in interface RecordHome
public void createTable()
throws DatabaseExceptionRecordHomecreateTable in interface RecordHomeDatabaseExceptionpublic java.util.List<java.lang.String> getColumnNames()
RecordHomegetColumnNames in interface RecordHome
public java.lang.Object generateKey()
throws DatabaseExceptionRecordHomegenerateKey in interface RecordHomeDatabaseException
protected void testForNull(Record r)
throws DatabaseExceptionr - DatabaseException
public void save(Record record)
throws DatabaseExceptionRecordHomesave in interface RecordHomerecord - DatabaseException
public java.lang.Object toRecord(java.lang.String name,
java.lang.Object o)
throws DatabaseExceptiontoRecord in interface RecordHomename - o - DatabaseException
public java.lang.Object toID(java.lang.Object o)
throws DatabaseExceptionRecordHometoID in interface RecordHomeo - DatabaseException
public Record load(java.lang.Object id)
throws DatabaseExceptionRecordHomeload in interface RecordHomeid - DatabaseException
public void remove(Record record)
throws DatabaseExceptionRecordHomeremove in interface RecordHomerecord - DatabaseException
public Record build(java.sql.ResultSet result)
throws DatabaseExceptionresult - DatabaseException
public java.util.List<? extends Record> buildAll(java.sql.ResultSet result)
throws DatabaseExceptionresult - DatabaseExceptionprotected void addRecordToMemory(Record record)
record - protected boolean isInMemory(java.lang.Object key)
key - protected Record loadFromMemory(java.lang.Object key)
public void update(Record record)
throws DatabaseExceptionRecordHomeupdate in interface RecordHomerecord - DatabaseExceptionpublic java.util.Map<java.lang.String,java.lang.Object> getSearchOptions()
RecordHomemap.put("name", "Hussam"); After that you can search for records using this condition: List extends Record> list=home.find(map);
The list will contian all records that have name=Hussam
getSearchOptions in interface RecordHome
public java.util.List<? extends Record> find(java.util.Map<java.lang.String,java.lang.Object> entries)
throws DatabaseException
RecordHome
find in interface RecordHomeentries -
DatabaseException
public Record create(java.util.Map<java.lang.String,java.lang.Object> entries)
throws DatabaseException
RecordHome
create in interface RecordHomeentries -
DatabaseExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||