Java Doc for SRecordInstance.java in  » Database-ORM » SimpleORM » simpleorm » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » SimpleORM » simpleorm.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   simpleorm.core.SRecordInstance

All known Subclasses:   simpleorm.examples.Project,  simpleorm.simplewebapp.dbute.WRecordInstance,  simpleorm.examples.Employee,  simpleorm.examples.Department,
SRecordInstance
abstract public class SRecordInstance implements SSerializable(Code)
Each SRecordInstance represents an individual record in memory that either correspond to a row in the database or are a new record that has yet to be inserted.

RecordInstances are created by either SRecordMeta.findOrCreate findOrCreate or SResultSet.getRecord . The former selects a specific record by primary key, while the latter retrieves a record from a general query result set.

The main methods are get* and set* which get and set field values of the record. SRecordInstance.deleteRecord deletes a row.

No two RecordInstances can have the same primary key field values within the same connection. Attempts to retrieve the same row twice will simple return a pointer to an existing SRecordInstance. There is no relationship between RecordInstances in different connections -- all locking is done by the underlying database.

SRecordsInstances may also be SRecordInstance.detach ed from a connection and then subsequently SRecordInstance.attach ed to another connection. Optimistic locking is used.

### Serializable, but only naively. Should throw exception if one attempts to serialize an attached record, or references to purged records. When deserializing, should match meta data with current SRecordMeta. The following of links to referenced records should be manual and should be part of the serialization process and not the detachment process.


Inner Class :public static class BrokenOptimisticLockException extends SException

Field Summary
 bytebitSets
     INstance BitSet, one per field instance in fieldValues, in particular INS_DIRTY which indicates that the field has been modified.
 booleandeleted
     Need to delete at commit.
 booleandirty
     Is dirty and needs to be flushed.
protected  ObjectfieldValues
     The actual field values for this record instance.
 booleannewRow
     Set after findOrInsert() that does not find the row already in the database.
 Object[]optimisticFieldValues
     The copy of the fieldValues used for optimistic locking.
 booleanreadOnly
     True if queried read only.
transient  SConnectionsConnection
     The one connection to which this Instance is glued.
 intupdateListIndex
     -1: not in sConnection.updateList either because 1.
 booleanwasInCache
    

Constructor Summary
public  SRecordInstance()
     Should only be called by SimpleORM, but difficult to protect.

Method Summary
public  StringallFields()
     For debugging like toString(), but shows all the fields.
public  voidassertNewRow()
     Throws an excpetion if ! SRecordInstance.isNewRow .
public  voidassertNotNewRow()
    
public  SRecordInstanceattach()
     Attach a detached record to the current transaction.
public  Objectclone()
     Override Object.clone() to make copies of the internal fieldValues array.
public  voiddeleteRecord()
     Sets a flag to delete this record when the transaction is commited.
public  voiddetach(boolean nullRefs)
     Detach this instance from the current transactions.
public  voiddetach()
    
public  voiddirtyPurge()
     Removes this record from the cache but without flushing it.
public  booleanequals(Object key2)
     Determines whehter two SRecordInstances are for the same SRecordMeta and have the same primary key fields.

This is purely for the purpose of putting SRecordInstances in the SConnection.transactionCache.

public  voidflush()
     Flush this instance to the database.
public  voidflushAndPurge()
     Flushes this record instance to the database, removes it from the transaction cache, and then destroys the record so that it can no longer be used.
public  BigDecimalgetBigDecimal(SFieldMeta field)
     etc.
public  booleangetBoolean(SFieldMeta field)
     Casts getObject() to double iff a Number, see getString(). Returns false if null.
public  byte[]getBytes(SFieldMeta field)
     Casts getObject() to byte[].
public  java.sql.DategetDate(SFieldMeta field)
     etc.
public  doublegetDouble(SFieldMeta field)
     Casts getObject() to double iff a Number, see getString(). Returns 0 if null, following JDBC.
public  intgetInt(SFieldMeta field)
     Casts getObject() to int iff a Number, see getString(). Returns 0 if null, following JDBC.
public  longgetLong(SFieldMeta field)
     Casts getObject() to long iff a Number, see getString(). Returns 0 if null, following JDBC.
abstract public  SRecordMetagetMeta()
     This must be defined in every user record's definition to access the SRecord which provides the meta data for this instance.
public  ObjectgetObject(SFieldMeta field)
     Returns the field's value as a Java Object.
public  ObjectgetObject(SFieldReference field, long sqy_flags)
     For references only.
public  SRecordInstancegetReference(SFieldReference field, long sqy_flags)
     Gets a record referenced by this.field.
public  SRecordInstancegetReference(SFieldReference field)
    
public  ObjectgetReferenceNoQuery(SFieldReference field)
     Same as getReference, except that if the referenced record is not already in the cache then it will simply return Boolean.FALSE. Particularily useful for detached records where it is not possible to do such a query.

If the underlying scalar key values are null, then this always null because there is no record to retrieve.

protected  SRecordInstancegetReferenceWhileDetached(SFieldReference reference, Object[] keys)
     This method is called if the record is detached, and a request is made for a reference that has not also been detached.
public  StringgetString(SFieldMeta field)
     Gets the value of field cast to a String, trimed of trailing spaces.
public  java.sql.TimegetTime(SFieldMeta field)
     etc.
public  java.sql.TimestampgetTimestamp(SFieldMeta field)
     etc.
public  inthashCode()
     See equals().
 voidincompleteDestroy()
     Destroys this instance so that it can no longer be used.
public  booleanisAttached()
     True if this instance is attached to the current begun transaction.
public  booleanisDeleted()
    
public  booleanisDirty()
     True iff this record is dirty but not yet flushed to the database.
public  booleanisDirty(SFieldMeta field)
     Tests whether just field is dirty.
public  booleanisEmpty(SFieldMeta field)
     True if field is the empty value.
public  booleanisNewRow()
     Often called after {SRecordMeta#findOrCreate} to determine whether a row was retrieved from the database (not a new row) or whether this record represents a new row that will be inserted when it is flushed.
public  booleanisNull(SFieldMeta field)
    
public  booleanisValid()
     True if the record has valid data, ie.
public  booleanisValid(SFieldMeta field)
     True if the field has been queried as part of the current transaction and so a get is valid.
 SArrayListkeyFieldMetas(boolean optimistic, Object[] keyMetaValues)
     Returns the list of fields that are used as part of the optimistic locking.
public  voidnullReferences()
     Null direct references from this record instance to other instances.
public  voidsetBigDecimal(SFieldMeta field, BigDecimal value)
    
public  voidsetBoolean(SFieldMeta field, boolean value)
    
public  voidsetBytes(SFieldMeta field, byte[] value)
    
public  voidsetDate(SFieldMeta field, java.util.Date value)
     See SRecordInstance.setTimestamp for discussion of Date parameter.
public  voidsetDirty()
     Sets this record to be dirty so that it will be updated in the database.
public  voidsetDouble(SFieldMeta field, double value)
    
public  voidsetEmpty(SFieldMeta field)
     Sets field to be empty, ie.
public  voidsetInt(SFieldMeta field, int value)
    
public  voidsetLong(SFieldMeta field, long value)
    
public  voidsetNull(SFieldMeta field)
    
public  voidsetObject(SFieldMeta field, Object value)
     Generic routine to set a fields value.
 voidsetOptimistic(boolean redo)
     Set this record to be locked Optimistically.
public  voidsetReference(SFieldReference field, SRecordInstance value)
    
public  voidsetString(SFieldMeta field, String value)
    
public  voidsetTime(SFieldMeta field, java.util.Date value)
     See SRecordInstance.setTimestamp for discussion of Date parameter.
public  voidsetTimestamp(SFieldMeta field, java.util.Date value)
     Note that value should normally be a java.sql.Timestamp (a subclass of java.util.Date).
public  StringtoString()
     toString just shows the Key field(s).
 StringtoStringDefault()
     Default behavior of toString().
public  voidvalidateField(SFieldMeta field, Object newValue)
     The main field validation method, this is specialized for records that need to perform field level validation.
public  voidvalidateRecord()
     The main record validation method, this is specialized for records that need to perform validation. Throw an SValidationException if not OK.

This is called just before a record would be flushed.

public  booleanwasInCache()
     Was in the cache before the most recent findOrCreate.

Field Detail
bitSets
byte bitSets(Code)
INstance BitSet, one per field instance in fieldValues, in particular INS_DIRTY which indicates that the field has been modified. Values are INS_*



deleted
boolean deleted(Code)
Need to delete at commit.



dirty
boolean dirty(Code)
Is dirty and needs to be flushed. But may not be in sConnection.updateList because the instance is detached.



fieldValues
protected Object fieldValues(Code)
The actual field values for this record instance. Null if destroyed. Elements null if retrieved data SQL Null.



newRow
boolean newRow(Code)
Set after findOrInsert() that does not find the row already in the database.



optimisticFieldValues
Object[] optimisticFieldValues(Code)
The copy of the fieldValues used for optimistic locking. null means not optimistically locked.



readOnly
boolean readOnly(Code)
True if queried read only. Ie. either selected FOR UPDATE, optimistically locked, or new and not read only.



sConnection
transient SConnection sConnection(Code)
The one connection to which this Instance is glued. Instances may never be shared across connections.



updateListIndex
int updateListIndex(Code)
-1: not in sConnection.updateList either because 1. not dirty or 2. not attached.



wasInCache
boolean wasInCache(Code)

See Also:   SRecordInstance.wasInCache()




Constructor Detail
SRecordInstance
public SRecordInstance()(Code)
Should only be called by SimpleORM, but difficult to protect.




Method Detail
allFields
public String allFields()(Code)
For debugging like toString(), but shows all the fields.



assertNewRow
public void assertNewRow()(Code)
Throws an excpetion if ! SRecordInstance.isNewRow . Handy, use often in your code to trap nasty errors.



assertNotNewRow
public void assertNotNewRow()(Code)

See Also:   SRecordInstance.assertNewRow
See Also:   



attach
public SRecordInstance attach()(Code)
Attach a detached record to the current transaction. A record with the same key must not already exist in this transaction, although this restriction may be relaxed later. Recursively attaches any referenced records.

Currently, the returned value is just this. However, a future version may allow the unattached record to be merged with an existing record, so one should always assume that the record may change identity during attachment.

Attaching the same record twice is OK.

If the record has a generated primary key then the key is generated as part of the attachement processing.




clone
public Object clone()(Code)
Override Object.clone() to make copies of the internal fieldValues array.

This method may only be used while the object is detached.




deleteRecord
public void deleteRecord()(Code)
Sets a flag to delete this record when the transaction is commited. The record is not removed from the transaction cache. Any future findOrCreate will thus return the deleted record but its fields may not be referenced. (isDeleted can be used to determine that the record has been deleted.)

The record is only deleted from the database when the transaction is committed or is flushed. Thus a transaction that nulls out references to a parent record and then deletes the parent record will not cause a referential integrity violation because the update order is preserved so that the updates will (normally) be performed before the deletes.

Note that for Optimistic locks only those fields that were retrieved are checked for locks.




detach
public void detach(boolean nullRefs)(Code)
Detach this instance from the current transactions. Sets optimistic locking if the record was updatable. ,p> If a future query in the same transaction retrieves a record with the same key then it will be a different instance. Ie. this really does detach the record from the transaction.

Nulls any references to records that have not already been detached so that they will not be serialized. The keys are kept so that the references can be reconstructed later. (This does NOT recursively detach any referenced records -- you have to explicitly detach all the records that you need.)

Set nullRefs to false to break instance indirect circular references, eg. if an Employee e manages someone that manages e. Very rarely needed. It is OK to detach a record twice.




detach
public void detach()(Code)
detach(true)



dirtyPurge
public void dirtyPurge()(Code)
Removes this record from the cache but without flushing it. Any changes to it will be lost. This might be useful if the record is being manually updated/deleted and you want to deliberately ignore any direct changes.

Dangerous, use with care.


See Also:   SRecordInstance.flushAndPurge




equals
public boolean equals(Object key2)(Code)
Determines whehter two SRecordInstances are for the same SRecordMeta and have the same primary key fields.

This is purely for the purpose of putting SRecordInstances in the SConnection.transactionCache. This is done as tc.put(SRecordInstance, SRecordInstance), ie the instance is used for both the key and the body. This avoids having to create a separate primary key object for each record instance.

It only foreign keys, not referenced SRecordInstances which may be null if the parent record has not been retrieved.




flush
public void flush()(Code)
Flush this instance to the database. Normally called by SConnection.flush() in reponse to commit but can also be called expicitly if the update order needs to be modified. This method does nothing unless the record is dirty.

## This should really utilize the new batching techniques if the JDBC driver supports them. This would substantially minimize the nr of round trips to the server.


See Also:   SConnection.flush




flushAndPurge
public void flushAndPurge()(Code)
Flushes this record instance to the database, removes it from the transaction cache, and then destroys the record so that it can no longer be used. Any future findOrCreate will requery the data base and produce a new record.

This is useful if one wants to do raw JDBC updates on the record, and be guaranteed not to have an inconsistent cache. (Where bulk updates can be used they are several times faster than updates made via the JVM -- see the benchmarks section in the white paper.)

Problems with the update order can generally be avoided by first flushing the entire connection.


See Also:   SRecordMeta.flushAndPurge
See Also:   SConnection.flushAndPurge
See Also:   SConnection.flush




getBigDecimal
public BigDecimal getBigDecimal(SFieldMeta field)(Code)
etc. for BigDecimal.



getBoolean
public boolean getBoolean(SFieldMeta field)(Code)
Casts getObject() to double iff a Number, see getString(). Returns false if null.



getBytes
public byte[] getBytes(SFieldMeta field)(Code)
Casts getObject() to byte[].



getDate
public java.sql.Date getDate(SFieldMeta field)(Code)
etc. for Date.



getDouble
public double getDouble(SFieldMeta field)(Code)
Casts getObject() to double iff a Number, see getString(). Returns 0 if null, following JDBC.



getInt
public int getInt(SFieldMeta field)(Code)
Casts getObject() to int iff a Number, see getString(). Returns 0 if null, following JDBC.



getLong
public long getLong(SFieldMeta field)(Code)
Casts getObject() to long iff a Number, see getString(). Returns 0 if null, following JDBC. Note that longs may not be accurately supported by the database -- see SFieldLong.



getMeta
abstract public SRecordMeta getMeta()(Code)
This must be defined in every user record's definition to access the SRecord which provides the meta data for this instance. It is normally defined as:-

  SRecord getMeta() { return meta; }; 

The actual meta variable is thus not Serialized, but it would not be anyway as it is usually static.




getObject
public Object getObject(SFieldMeta field)(Code)
Returns the field's value as a Java Object. Methods such as getString() dispach to this method but are generally more convenient because the cast the result to the correct type. This method in turn just dispaches to field.getFieldValue(), ie. it is the declaredtype of the SField that determines how the value is retrieved.




getObject
public Object getObject(SFieldReference field, long sqy_flags)(Code)
For references only.



getReference
public SRecordInstance getReference(SFieldReference field, long sqy_flags)(Code)
Gets a record referenced by this.field. does a lazy lookup if necessary.



getReference
public SRecordInstance getReference(SFieldReference field)(Code)



getReferenceNoQuery
public Object getReferenceNoQuery(SFieldReference field)(Code)
Same as getReference, except that if the referenced record is not already in the cache then it will simply return Boolean.FALSE. Particularily useful for detached records where it is not possible to do such a query.

If the underlying scalar key values are null, then this always null because there is no record to retrieve. It is only for a non-null, non-retrieved references that this returns FALSE.




getReferenceWhileDetached
protected SRecordInstance getReferenceWhileDetached(SFieldReference reference, Object[] keys)(Code)
This method is called if the record is detached, and a request is made for a reference that has not also been detached. This method gives you one last chance to return the referenced record before an exception is thrown.

By default, this method just returns null to indicate that no last-ditch effort is made to fetch missing references, so you must override it to do something more useful (i.e. fetch the reference from the database)

Warning: Note that because this record and the fetched reference are obtained in separate transactions, any consistency constraints between the two objects might not hold.
Parameters:
  reference - The reference that is being followed
Parameters:
  keys - Object[] keys for the reference, just as you would pass themto THE REFERENCED record's findOrCreate() SRecordInstance Return the fetched record, or null, if no attempt wasmade. NOTE: currently, this does not cover the awkward case where an attempt ISmade, but the value returned is NULL, anyway.




getString
public String getString(SFieldMeta field)(Code)
Gets the value of field cast to a String, trimed of trailing spaces. This is equivalent to getObject().toString().trimTrailingSpaces(). So the field type itself need not be SFieldString, but just something that can be cast to a String. Trailing spaces can be a problem with some databases and fileds declared CHAR.

Note that if you do not want trailing spaces trimmed, then just call getObject().toString() manually. (For CHAR fields, most dbs/jdbc drivers seem to trim, but this is highly inconsistent.)

## Trimming is an issue with CHAR style fields that pad with spaces. Currently we always read from database into the fields without trimming. The idea being to let the SimpleORM user get at the raw query result using getObject, whatever that raw result is.

Most DBs seem to trim for us. But some may not, and some may require the trailing spaces on queries. Certainly trailing spaces in the objects will upset the record cache, and there is some dubious code in SRecordFinder.retrieveRecord() to handle this.

I think that for CHAR fields we need to always trim at database read, and pad where needed. This should also be dispatched to DB handler. I think that Oracle gives grief. (Note that trim means trailing spaces, leading should be left alone.)

I have not done this because it would require testing on many datbases.




getTime
public java.sql.Time getTime(SFieldMeta field)(Code)
etc. for Time.



getTimestamp
public java.sql.Timestamp getTimestamp(SFieldMeta field)(Code)
etc. for Timestamp.



hashCode
public int hashCode()(Code)
See equals().



incompleteDestroy
void incompleteDestroy()(Code)
Destroys this instance so that it can no longer be used. Also nulls out variables so to reduce risk of memory leaks. Note that it does not remove the record from the transaction cache and update list -- it cannot be called on its own.



isAttached
public boolean isAttached()(Code)
True if this instance is attached to the current begun transaction. Exception if is attached but not to the current transaction or the current transaction has not begun.



isDeleted
public boolean isDeleted()(Code)



isDirty
public boolean isDirty()(Code)
True iff this record is dirty but not yet flushed to the database. May be both dirty and unattached.

A record is not dirty if a record has been flushed to the database but the transaction not committed.

## Should add wasEverDirty method for both record and fields for validation tests.




isDirty
public boolean isDirty(SFieldMeta field)(Code)
Tests whether just field is dirty.



isEmpty
public boolean isEmpty(SFieldMeta field)(Code)
True if field is the empty value. Currently just tests getObject() == null. But other options will be added later to allow "" to be treated as null.
See Also:   SRecordInstance.SMANDATORY



isNewRow
public boolean isNewRow()(Code)
Often called after {SRecordMeta#findOrCreate} to determine whether a row was retrieved from the database (not a new row) or whether this record represents a new row that will be inserted when it is flushed.



isNull
public boolean isNull(SFieldMeta field)(Code)



isValid
public boolean isValid()(Code)
True if the record has valid data, ie. it has not been destroyed. (This has nothing to do with validateRecord.)



isValid
public boolean isValid(SFieldMeta field)(Code)
True if the field has been queried as part of the current transaction and so a get is valid. Use this to guard validations if partial column queries are performed. See isDirty.



keyFieldMetas
SArrayList keyFieldMetas(boolean optimistic, Object[] keyMetaValues)(Code)
Returns the list of fields that are used as part of the optimistic locking. Includes Primary key fields, any valid fields that are dirty, but not references.



nullReferences
public void nullReferences()(Code)
Null direct references from this record instance to other instances. Leaves the actual scalar referencing key fields alone. May only be called on a detached object. This method was created for two reasons:
  1. Reduce communication burden when sending detached records from a client back to the server for processing
  2. Avoid problems when recursively attaching referenced records that we really did not want. attach() currently does not allow multiple attach'es of same record. Even though this reason may evenutually go away, the first reason will remain.



setBigDecimal
public void setBigDecimal(SFieldMeta field, BigDecimal value)(Code)



setBoolean
public void setBoolean(SFieldMeta field, boolean value)(Code)



setBytes
public void setBytes(SFieldMeta field, byte[] value)(Code)



setDate
public void setDate(SFieldMeta field, java.util.Date value)(Code)
See SRecordInstance.setTimestamp for discussion of Date parameter.



setDirty
public void setDirty()(Code)
Sets this record to be dirty so that it will be updated in the database. Normally done implicitly by setting a specific column. But may occasionally be useful after a findOrInsert() to add a record that contains nothing appart from its primary key.



setDouble
public void setDouble(SFieldMeta field, double value)(Code)



setEmpty
public void setEmpty(SFieldMeta field)(Code)
Sets field to be empty, ie. currently setObject(, null). But other options will be added later.
See Also:   SRecordInstance.SMANDATORY
See Also:   



setInt
public void setInt(SFieldMeta field, int value)(Code)



setLong
public void setLong(SFieldMeta field, long value)(Code)



setNull
public void setNull(SFieldMeta field)(Code)



setObject
public void setObject(SFieldMeta field, Object value)(Code)
Generic routine to set a fields value. Just dispaches to field.setFieldValue()




setOptimistic
void setOptimistic(boolean redo)(Code)
Set this record to be locked Optimistically. Assert that it is not dirty and copy the current value of all relevant fields. These can be compared with values stored in the database at flush time.

The copy is cheap because it is only copying pointers. However, if the optimisitic lock fails then an exception will be thrown. Mainly used for long lived transactions.




setReference
public void setReference(SFieldReference field, SRecordInstance value)(Code)



setString
public void setString(SFieldMeta field, String value)(Code)



setTime
public void setTime(SFieldMeta field, java.util.Date value)(Code)
See SRecordInstance.setTimestamp for discussion of Date parameter.



setTimestamp
public void setTimestamp(SFieldMeta field, java.util.Date value)(Code)
Note that value should normally be a java.sql.Timestamp (a subclass of java.util.Date). However, if it is a java.util.Date instead, then it will replaced by a new java.sql.Timestamp object before being set. This is convenient for people using java.util.Date as their main date type.



toString
public String toString()(Code)
toString just shows the Key field(s). It is meant to be consise, often used as part of longer messages.



toStringDefault
String toStringDefault()(Code)
Default behavior of toString(). This was split out from the toString() method to avoid infinite recursion if a subclass of SRecordInstance overrode toString() to use any of the get...() methods.



validateField
public void validateField(SFieldMeta field, Object newValue)(Code)
The main field validation method, this is specialized for records that need to perform field level validation. It is called each time a field is set a value, (now) including keys.

Throw an SValidationException if not OK. The value is not assigned, and the transaction can continue.

This is called after the value has been converted to its proper type, eg. from a String to a Double. (Which is why it is not a good place to also do conversions.)

This is called for key values as well. This is only for newly created records but is during the findOrCreate -- ie it is called even if the record is never made dirty and thus saved. See ADemo and ValidationTest for examples.




validateRecord
public void validateRecord()(Code)
The main record validation method, this is specialized for records that need to perform validation. Throw an SValidationException if not OK.

This is called just before a record would be flushed. Only dirty records are validated. If the validation fails then the record is not flushed. (It may also be called directly by the application to validate the record before it is flushed.)

Use this routine when a record may be in a temporarily invalid state, but which must be corrected before flushing. This is common when there is a more complex relationship between different fields that cannot be validated until all the fields have been assigned values.

If an exception is thrown then the condition will need to be corrected or the transaction will need to be rolled back.

See ADemo for an example.




wasInCache
public boolean wasInCache()(Code)
Was in the cache before the most recent findOrCreate. (Will always been in the cache after a findOrCreate.) Used to prevent two create()s for the same key. Also for unit tests.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.