| java.lang.Object simpleorm.properties.SPropertyMap simpleorm.core.SRecordMeta
Method Summary | |
public String | allFieldsString() Returns a list of all the fields for debugging. | public SRecordInstance | create(Object keys) Same as findOrCreate(key) but asserts must be a new row.
Also sets the row Dirty so that it will actually be inserted even if no
other non-key fields are set.
It is assumed that the record is not in the database, you will
get an SQL exception if it already exists. | public SRecordInstance | createDetached() Create an SRecordInstance that will be initially detached. | public SRecordInstance | createDetached(Object key) createDetached() and then sets the key field(s). | public String | createTableSQL() Returns a CREATE TABLE... for this table. | public SRecordInstance | createWithGeneratedKey() Creates a new object with a newly generated key. | SFieldMeta[] | expandSelectList(SFieldMeta[] fields) Given a list of fields, add primary key fields and then replace
any reference fields with their foreign keys. | SFieldMeta[] | fieldList(long sqy_bitSet) Returns SFieldMetas to select given bitSet.
### This needs a careful review. | public SRecordInstance | find(Object keys) Same as findOrCreate(key) but returns null if not found
instead of createing a new record. | public SRecordInstance | findOrCreate(Object keys, long sqy_bitSet, SFieldMeta[] selectList) Searches first the cache and then the database for a record with
the primary key == keys . | public SRecordInstance | findOrCreate(Object keys) | public SRecordInstance | findOrCreate(Object keys, long sqy_bitSet) | public void | flushAndPurge() Flushes and Purges all record instances for this table. | public SFieldMeta | getField(String fieldName) Returns the field by SFIELD_NAME, or null if not found. | public SArrayList | getFieldNames() All the field names. | public SGenerator | getSGenerator() Returns the (one) generator for the one key of this SRecord. | public SRecordInstance | mustFind(Object keys) Same as find(key) but throws an exception if the record is not found. | public SQuery | newQuery(long sqy_bitSet, SFieldMeta[] selectList) Start a query using the query builder instead of raw SQL. | public SQuery | newQuery(long sqy_bitSet) | public SQuery | newQuery() | protected Object | readResolve() SRecordMeta is like a singleton, in that only one instance of SRecordMeta must
exist in the VM for a specific table. | public SPreparedStatement | select(String where, String orderBy, long sqy_bitSet, SFieldMeta[] selectList) Produce an SQL Query, prepare it, and return an
SPreparedStatement . | public SPreparedStatement | select(String where, String orderBy, long sqy_bitSet, SFieldMeta[] selectList, SPreparedStatement ps) Use this variant to add extra parameters between ps creation and
sql generation. | public SPreparedStatement | select(String where, String orderBy, long sqy_bitSet) | public SPreparedStatement | select(String where, String orderBy) | public String | toString() |
fieldMap | transient HashMap fieldMap(Code) | | Exactly the same elements as SFieldMetas, but keyed by field
names which default to column names or reference table names or
prefixes.
|
keySFieldMetas | transient SArrayList keySFieldMetas(Code) | | The Primary Key fields. Contains both foreign keys
(recursively) and sFieldReference.
|
sFieldMetas | transient SArrayList sFieldMetas(Code) | | The SFieldMetas within this record. This contains both the
foreign keys and then the sFieldReference, ie. it is totally
flattened.
|
sFieldNames | public transient SArrayList sFieldNames(Code) | | The names of fields store redundantly.
Only to be used within the debugger.
|
userClass | protected transient Class userClass(Code) | | The underlying java class for this object.
|
SRecordMeta | public SRecordMeta(Object userClass, String tableName, SPropertyValue[] pvalues)(Code) | | Create a new table/record definition.
Parameters: userClass - When a (@link #SRecordInstant} is created bySRecordMeta.findOrCreate, it is cast to this class which must extendSRecordInstant. It is normally unique for each SRecordMeta, butthat is not strictly required. Parameters: tableName - The name of the SQL table that will beassociated with this record. Parameters: pvalues - Arbitrary properties that can be associated withthis record. Rarely used. |
allFieldsString | public String allFieldsString()(Code) | | Returns a list of all the fields for debugging.
|
create | public SRecordInstance create(Object keys)(Code) | | Same as findOrCreate(key) but asserts must be a new row.
Also sets the row Dirty so that it will actually be inserted even if no
other non-key fields are set.
It is assumed that the record is not in the database, you will
get an SQL exception if it already exists. This saves a SELECT statement.
But if there is any doubt use findOrCreate instead and then check .isNewRow.
A check is also made that the row is not already in the cache, ie. two calls to
create with the same key will produce an exception.
See Also: SRecordMeta.findOrCreate(Object,long,SFieldMeta[]) |
createDetached | public SRecordInstance createDetached()(Code) | | Create an SRecordInstance that will be initially detached. All
key fields must be populated before attaching unless they are
generated keys. Objects created this way
must not not have existed in the database previously, or a unique
key violation exception is thrown by JDBC at flush() time.
A typical use of this method is by a thick-client application that
creates a record, and then passes it to the application server which, in turn,
will insert it into the database.
The primary key can be set either using the key parameter,
explicitly after this method using set*, just before it
is reattached and the database is thus available, or if it is
generated then it can be automatically created by the attach()
method.
SRecordInstance A newly created 'blank' record See Also: simpleorm.core.SRecordInstance.attach |
createTableSQL | public String createTableSQL()(Code) | | Returns a CREATE TABLE... for this table. Delegates
to the database driver.
|
createWithGeneratedKey | public SRecordInstance createWithGeneratedKey()(Code) | | Creates a new object with a newly generated key. Note that the
SELECT MAX method is used unless a database dependent
alternative is available (currently only for PostgreSQL).
SGENERATED_KEY .
Always creates a new empty record.
## This code is partially copied into SRecordInstance.attach() for
records created while detached.
|
expandSelectList | SFieldMeta[] expandSelectList(SFieldMeta[] fields)(Code) | | Given a list of fields, add primary key fields and then replace
any reference fields with their foreign keys. Normally one
works with references, but when queries are generated one needs
the ground columns.
|
fieldList | SFieldMeta[] fieldList(long sqy_bitSet)(Code) | | Returns SFieldMetas to select given bitSet.
### This needs a careful review.
|
findOrCreate | public SRecordInstance findOrCreate(Object keys, long sqy_bitSet, SFieldMeta[] selectList)(Code) | | Searches first the cache and then the database for a record with
the primary key == keys . If one is found returns
it, otherwise creates a new SRecordInstance prepopulated with
the primary key.
For multi valued concurrency databases such as Oracle and
PostgreSQL, the row is usually selected FOR UPDATE unless
SRecordMeta.SQY_READ_ONLY .
In either case
SRecordMeta.findOrCreate never schedules the
record to be updated or inserted. That happens when one makes
it dirty by setting a field value or perhaps
SRecordInstance.setDirty().
The selectList is usually defaulted based on the sqy_bitSet.
If the record has identifying foreign keys the keys
must contain referenced records, not the actual foreign keys.
The APIs have been carefully designed so that SQL queries can be
made lazily. Ie. just schedule the query to be performed the
first time a field value is referenced. This enables efficient
batching techniques. However, this implementation performs the
queries eagerly, ie. the SQL query is issued by this method.
This always finds or creates a record within the context of a
connection.
SRecordMeta.createDetached can be used to create a new
record while not attached.
See also the SQY_* constants.
See Also: SRecordMeta.find See Also: SRecordMeta.create |
getField | public SFieldMeta getField(String fieldName)(Code) | | Returns the field by SFIELD_NAME, or null if not found.
|
getFieldNames | public SArrayList getFieldNames()(Code) | | All the field names. use getField to look up the actual field.
See also SFIELD_MAP property etc.
|
getSGenerator | public SGenerator getSGenerator()(Code) | | Returns the (one) generator for the one key of this SRecord.
|
readResolve | protected Object readResolve() throws ObjectStreamException(Code) | | SRecordMeta is like a singleton, in that only one instance of SRecordMeta must
exist in the VM for a specific table. This is a special method used during
de-serialization to determine if the object de-serialized should be substituted.
This method is implemented to return the SRecordMeta object for the appropriate
user Class that already exists.
|
select | public SPreparedStatement select(String where, String orderBy, long sqy_bitSet, SFieldMeta[] selectList)(Code) | | Produce an SQL Query, prepare it, and return an
SPreparedStatement . See that class for an example of its use.
where and orderBy are SFieldMetas that
arecopied literally into the query. The SQY_* BitSets are defined
in SConstants.
(This delegates the actual query creation to the Driver class.)
|
|
|