| com.methodhead.persistable.Persistable
All known Subclasses: com.methodhead.shim.IncludeModule, com.methodhead.shim.NavModule, com.methodhead.shim.TextModule, com.methodhead.event.Event, com.methodhead.transfer.SiteExtension, com.methodhead.property.Property, com.methodhead.persistable.KeyedPersistable,
Persistable | public class Persistable extends BasicDynaBean (Code) | |
A base class for database-backed objects. Methods are
provided to simplify managing data in a database:
Persistable.saveNew saveNew() ,
Persistable.save save() ,
Persistable.loadload() ,
Persistable.loadAll loadAll() , and
Persistable.deleteAlldeleteAll() . Methods are also provided to box and unbox
primitive values.
Persistable subclasses BasicDynaBean
from the BeanUtils component of Jakarta
Commons. This makes any Persistable-based
object compatible with libraries that operate on
DynaBeans, such as Apache Struts.
As it is a DynaBean, DynaClass plays an
important role in a persistable's operation. Make sure the
persistable's dynaclass is defined appropriately:
-
The dynaclass's name should match the
table name in the database.
-
The dynaclass's dynaproperties should match the
corresponding column names and types in the table.
-
The dynaclass's newInstance() should
return an appropriate object.
|
Constructor Summary | |
public | Persistable(DynaClass dynaClass) |
Method Summary | |
public static void | deleteAll(DynaClass dynaClass, String whereClause) Deletes all persistables according to the specified whereClause. | public void | deleteAll(String whereClause) Deletes all persistables according to the specified whereClause. | public boolean | getBoolean(String property) Returns property, unboxing the value if necessary; false
is returned if the property has not been set. | public Date | getDate(String property) Returns property, unboxing the value if necessary. | public double | getDouble(String property) Returns property, unboxing the value if necessary; 0.0
is returned if the property has not been set. | public int | getInt(String property) Returns property, unboxing the value if necessary; returns 0 if
the property has not been set. | public static String | getSqlLiteral(String value) Returns a string literal suitable for use in a SQL statement by escaping
single quotes and then wrapping the string in single quotes. | public static String | getSqlLiteral(Boolean value) Returns a string literal suitable for use in a SQL statement, using
'1' for true and '0' for false. | public static String | getSqlLiteral(Date value) Returns a date literal suitable for use in a SQL statement by wrapping a
standard SQL date in single quotes. | protected String | getSqlLiteral(DynaProperty dynaProperty) Returns the value of dynaProperty in a form suitable for use in a
SQL statement. | public String | getString(String property) Returns property, unboxing the value if necessary. | public void | load(String whereClause) Loads the persistable according to the specified whereClause. | public static List | loadAll(DynaClass dynaClass, String whereClause, String orderByClause) Returns a list containing all persistables for the specified
WHERE and ORDER BY clauses. | public List | loadAll(String whereClause, String orderByClause) Returns a list containing all persistables for the specified
WHERE and ORDER BY clauses. | public void | save(String whereClause) Saves the persistable, by updating any rows to which the specified
whereClause clause applies. | public void | saveNew() Saves the persistable by inserting a new row. | public void | setAsObject(String property, Object value) Sets property by calling
Persistable.setAsString setAsString() with
value.toString(). | public void | setAsString(String property, String value)
Sets property to value, converting
value from a string to the appropriate type in a
sensible way. | public void | setBoolean(String property, boolean value) Sets property to value, boxing the value if necessary. | public void | setDate(String property, Date value) Sets property to value, boxing the value if necessary. | public void | setDouble(String property, double value) Sets property to value, boxing the value if necessary. | public void | setInt(String property, int value) Sets property to value, boxing the value if necessary. | protected static void | setProperty(DynaBean persistable, DynaProperty dynaProperty, ResultSet rs) Convenience method to set the dynaProperty of
persistable with the corresponding value from rs. | public void | setString(String property, String value) Sets property to value, boxing the value if necessary. |
Persistable | public Persistable(DynaClass dynaClass)(Code) | | |
deleteAll | public static void deleteAll(DynaClass dynaClass, String whereClause) throws PersistableException(Code) | | Deletes all persistables according to the specified whereClause.
whereClause should not include the WHERE keyword; if
whereClause is null, all persistables in the table are
deleted.
|
deleteAll | public void deleteAll(String whereClause) throws PersistableException(Code) | | Deletes all persistables according to the specified whereClause.
whereClause should not include the WHERE keyword; if
whereClause is null, all persistables in the table are
deleted.
|
getBoolean | public boolean getBoolean(String property)(Code) | | Returns property, unboxing the value if necessary; false
is returned if the property has not been set.
|
getDate | public Date getDate(String property)(Code) | | Returns property, unboxing the value if necessary.
|
getDouble | public double getDouble(String property)(Code) | | Returns property, unboxing the value if necessary; 0.0
is returned if the property has not been set.
|
getInt | public int getInt(String property)(Code) | | Returns property, unboxing the value if necessary; returns 0 if
the property has not been set.
|
getSqlLiteral | public static String getSqlLiteral(String value)(Code) | | Returns a string literal suitable for use in a SQL statement by escaping
single quotes and then wrapping the string in single quotes. For example,
"it's good to escape" becomes "'it''s good to escape'"
|
getSqlLiteral | public static String getSqlLiteral(Boolean value)(Code) | | Returns a string literal suitable for use in a SQL statement, using
'1' for true and '0' for false.
|
getSqlLiteral | public static String getSqlLiteral(Date value)(Code) | | Returns a date literal suitable for use in a SQL statement by wrapping a
standard SQL date in single quotes.
|
getSqlLiteral | protected String getSqlLiteral(DynaProperty dynaProperty)(Code) | | Returns the value of dynaProperty in a form suitable for use in a
SQL statement.
|
getString | public String getString(String property)(Code) | | Returns property, unboxing the value if necessary.
|
load | public void load(String whereClause)(Code) | | Loads the persistable according to the specified whereClause. If
no records match whereClause, an exception is thrown. If more
than one record matches, only the first is used.
|
loadAll | public static List loadAll(DynaClass dynaClass, String whereClause, String orderByClause)(Code) | | Returns a list containing all persistables for the specified
WHERE and ORDER BY clauses. whereClause should
not include the WHERE keyword; if whereClause is
null all persistables in the table are loaded. orderBy
should not contain the ORDER BY keywords; if
orderByClause is null persistables are sorted as
returned from the database.
|
loadAll | public List loadAll(String whereClause, String orderByClause)(Code) | | Returns a list containing all persistables for the specified
WHERE and ORDER BY clauses. whereClause should
not include the WHERE keyword; if whereClause is
null all persistables in the table are loaded. orderBy
should not contain the ORDER BY keywords; if
orderByClause is null persistables are sorted as
returned from the database.
|
save | public void save(String whereClause) throws PersistableException(Code) | | Saves the persistable, by updating any rows to which the specified
whereClause clause applies. whereClause should not
include the WHERE keyword; if whereClause is
null, all rows in the table are updated.
|
saveNew | public void saveNew()(Code) | | Saves the persistable by inserting a new row.
|
setAsString | public void setAsString(String property, String value)(Code) | |
Sets property to value, converting
value from a string to the appropriate type in a
sensible way.
-
Strings: simply value or "" if
value is null.
-
Integers: value if it can be successfully
parsed; 0 if value is null or an
empty string.
-
Booleans: true if value is
"true", "yes", or "on" (case insensitive),
false otherwise.
-
Doubles: value if it can be successfully
parsed; 0.0 if value is null or
an empty string.
-
Dates: value if it can be successfully parsed
by DateFormat.getDateInstance( DateFormat.SHORT )
(e.g., "2/20/03") or DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT ) (e.g., "2/20/03
8:20 PM"); the current date if value is
null or an empty string.
|
setBoolean | public void setBoolean(String property, boolean value)(Code) | | Sets property to value, boxing the value if necessary.
|
setDate | public void setDate(String property, Date value)(Code) | | Sets property to value, boxing the value if necessary.
|
setDouble | public void setDouble(String property, double value)(Code) | | Sets property to value, boxing the value if necessary.
|
setInt | public void setInt(String property, int value)(Code) | | Sets property to value, boxing the value if necessary.
|
setProperty | protected static void setProperty(DynaBean persistable, DynaProperty dynaProperty, ResultSet rs)(Code) | | Convenience method to set the dynaProperty of
persistable with the corresponding value from rs.
|
setString | public void setString(String property, String value)(Code) | | Sets property to value, boxing the value if necessary.
|
|
|