|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--DBWeb.EntityModel
An EntityModel describes the relationship between an Entity and a table or tables in a database. The baseTable should identify the table each of whose rows corresponds to a single Entity. In addition, DetailModels can identify additional tables that hold 1-n relationships to these Entities. When an Entity is retrieved from the database, such details are used to populate multi-valued associations in the Entity with data from these details. EntityModels are mostly used when retrieving information for update. For display only, it may be more convenient simply to construct a complex SQL expression that retrieves all the needed data, and to code explicitly further retrieval expressions to get the details.
Field Summary | |
boolean[] |
asDate
|
boolean |
asName
|
java.lang.String |
baseTable
|
java.lang.String |
condition
|
java.util.ArrayList |
details
|
java.lang.String |
fieldNames
|
java.util.ArrayList |
fieldNamesA
|
java.lang.String |
keyName
|
Constructor Summary | |
EntityModel(java.lang.String mainSpec)
|
|
EntityModel(java.lang.String mainSpec,
java.lang.String[] detailSpecs)
Creates a new instance of EntityModel, from a compact form. |
|
EntityModel(java.lang.String table,
java.lang.String key,
java.lang.String fields,
java.lang.String cond)
Creates a new instance of EntityModel |
Method Summary | |
void |
addDetail(DetailModel dm)
|
void |
addDetail(java.lang.String table,
java.lang.String key,
java.lang.String field)
|
void |
addDetail(java.lang.String table,
java.lang.String key,
java.lang.String field,
java.lang.String name)
Adds a detail relationship to an EntityModel. |
java.lang.String |
toSql()
|
java.lang.String |
toSql(java.lang.String id)
Creates a SQL query that retrieves the modeled Entity identified by key id. |
java.lang.String |
toSqlDelete(Entity b)
|
java.lang.String |
toSqlInsert(Entity b)
Creates a SQL query that inserts the modeled Entity. |
java.lang.String |
toSqlUpdate(Entity b)
Creates a SQL command that updates the modeled Entity. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public java.lang.String baseTable
public java.lang.String keyName
public java.lang.String fieldNames
public java.util.ArrayList fieldNamesA
public java.lang.String condition
public boolean asName
public boolean[] asDate
public java.util.ArrayList details
Constructor Detail |
public EntityModel(java.lang.String mainSpec, java.lang.String[] detailSpecs) throws java.text.ParseException
mainSpec
- String specifying the table name and list of fields
that hold data about the entity. The format is
table:key:f1,f2,...fn:cond
table is the sql table holding the base information
key is the primary key field
f1,f2,...fn are the other fields (should not include key)
The cond, if any, must be proper SQL for the conditon.
Omit : if none.
If the table is followed by =n, the Entity retrieved is treated
as an EnglishName and fields fullname and fullFNF are added,
for the last-name-first full name, and first-name-first.
If any field name is followed by =d, it is treated as a date,
and converted to the required SQL form of date before being
stored or updated.detailSpecs
- String[] specifying the detail models. Each has form:
table: key: field: name: c1=v1,c2=v2,...ck=vk
where table holds the editable 1-n relationship,
key is its key field,
field is the field whose values are to be retrieved,
name is the property of the main object having field as its
multiple values
Unlike for the baseTable, detailSpecs normally specify indices into
other tables, not names or dates; hence no =n, =d support.public EntityModel(java.lang.String mainSpec) throws java.text.ParseException
public EntityModel(java.lang.String table, java.lang.String key, java.lang.String fields, java.lang.String cond) throws java.text.ParseException
table
- String naming the base table.key
- String naming the field in table that holds the primary key.fields
- String naming the fields of the table to retrieve as
single-valued associations with the field name. These are
separated by commas. This should NOT include the key.cond
- String holding a WHERE condition that is added to the SQL.Method Detail |
public void addDetail(java.lang.String table, java.lang.String key, java.lang.String field, java.lang.String name)
table
- String holding the name of the 1-n relationship table.key
- String holding field name in table that is the foreign key
identifying the base Entity.field
- String holding the field name whose values are to become
associated with this field name as multiple values in the
Entity.name
- String holding the name with which to associate these
retrived values, if field is not appropriate.public void addDetail(java.lang.String table, java.lang.String key, java.lang.String field)
public void addDetail(DetailModel dm)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toSql(java.lang.String id)
id
- String holding the key.
public java.lang.String toSql()
public java.lang.String toSqlInsert(Entity b)
b
- Entity to be inserted.
public java.lang.String toSqlDelete(Entity b)
public java.lang.String toSqlUpdate(Entity b)
b
- Entity to be updated.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |