|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.starhope.appius.util.ManagedReferenceHolder
org.starhope.appius.util.BaseDatum
public class BaseDatum
Another way to register a Managed Object to the Data Manager is with the setBinding call. This call does not return a Managed Reference, but instead binds the Managed Object to the string passed in with it to the call. Once a Managed Object has a name bound to it, the Managed Object may be retrieved by passing the same name to the getBinding call. Note that name bindings must be distinct. For each unique string used as a name binding by an application, there can be one and only one Managed Object bound.
Field Summary | |
---|---|
private static com.sun.sgs.app.ManagedReference<com.sun.sgs.app.util.ScalableHashMap<Class<? extends BaseDatum>,com.sun.sgs.app.ManagedReference<? extends BaseDatum>>> |
classCache
This is the cache of all objects of a given class, used by some stuff to make some other stuff happy. |
protected String |
database_id
This is either the database ID value of this object in the database; or, if it's less than zero, it's a flag that means that the contents of the object have not been instantiated from the database and have not been flushed to the database. |
private static long |
serialVersionUID
|
Constructor Summary | |
---|---|
BaseDatum()
Instantiate a "null object," with no data. |
Method Summary | |
---|---|
void |
changed()
This method should be called from all setters who wish to force an immediate (attempt at) flush of the contents to the database. |
protected void |
commitToDatabase()
This method performs the actual flush of data to the database. |
void |
delete()
Remove an object from the pool |
boolean |
equals(BaseDatum other)
Compare two BaseDatum-derived objects |
void |
flush()
Saves the object's state to the database, using either INSERT or UPDATE as appropriate. |
protected static BaseDatum |
get(Class<? extends BaseDatum> klass,
org.json.JSONObject object)
Instantiate a BaseDatum-derived object based upon JSON data |
protected static BaseDatum |
get(Class<? extends BaseDatum> klass,
String id)
Loads a database record into this object. |
String |
getID()
Get the database ID value for this object. |
protected String[] |
getUniqueBoundName()
|
void |
readExternal(ObjectInput in)
|
org.json.JSONObject |
refJSON(com.sun.sgs.app.ManagedReference<? extends BaseDatum> reference)
|
void |
set(org.json.JSONObject o)
This method will attempt to set the data contents of this object to the values derived from the JSON object being passed-in. |
protected void |
setID(String id)
|
static String |
sqlDateTime(Date dateTime)
|
org.json.JSONObject |
toJSON()
This returns a copy of the object's data cast into a JSON form. |
void |
writeExternal(ObjectOutput out)
|
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder |
---|
deref, setRef |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static com.sun.sgs.app.ManagedReference<com.sun.sgs.app.util.ScalableHashMap<Class<? extends BaseDatum>,com.sun.sgs.app.ManagedReference<? extends BaseDatum>>> classCache
private static final long serialVersionUID
protected String database_id
Constructor Detail |
---|
public BaseDatum()
Method Detail |
---|
public static String sqlDateTime(Date dateTime)
dateTime
- The java.util.Date to be formatted
protected static BaseDatum get(Class<? extends BaseDatum> klass, org.json.JSONObject object) throws RuntimeException, NotFoundException, org.json.JSONException
klass
- the subclass to which the resultant object is
believed to belongobject
- the JSON object describing the desired object
NotFoundException
- if the object has an ID value, and is
not found in the database with that ID
RuntimeException
- if there's a severe problem, such as bad
JSON data or numbers out of range
org.json.JSONException
- if the JSON data is badly-formedprotected static BaseDatum get(Class<? extends BaseDatum> klass, String id) throws RuntimeException, NotFoundException
Loads a database record into this object.
Instantiate a certain item by looking it up in the database based upon the ID column in the database table.
This method attempts to either find a copy of the given object ID in core, or (if one is not found), create a new one and load its contents from the database.
klass
- The subclass of BaseDatum to which the resultant
object belongsid
- The ID number. Note that, while we use
a Java "long" type to hold this, the actual valid range is
that of an INT UNSIGNED, that is, from 0 to 2**32
- 1. Since Java doesn't have unsigned types, we have to
use a long to contain all possible values.
RuntimeException
- if something really nasty were to happen
NotFoundException
- if the given value doesn't return a
result set (i.e. if the ID supplied is not found in the
database)public void changed()
public void delete()
public boolean equals(BaseDatum other)
other
- The other object
public void flush()
Saves the object's state to the database, using either INSERT or UPDATE as appropriate. The database will not be changed if the object's this.changed flag is "false."
This method does not propagate exceptions due to bad data. If you want to catch them, yourself, call the underlying commitToDatabase method, instead.
To simply confirm whether the database was updated, without concerning yourself with the details, you can also just check the changed flag, which will be cleared upon success.
public String getID()
flush()
to the database; this is so that
newly-instantiated objects can get their AUTO_INCREMENT database
ID value assigned by being INSERT:ed for the first time.
If that fails, this will throw up a DataException, on the
assumption that there's some problem with internal data
consistency causing this problem.
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Externalizable.readExternal(java.io.ObjectInput)
public org.json.JSONObject refJSON(com.sun.sgs.app.ManagedReference<? extends BaseDatum> reference)
reference
- a ManagedReference to a BaseDatum-derived class
public void set(org.json.JSONObject o)
CastsToJSON
set
in interface CastsToJSON
o
- The JSON object containing a the new data for this
object.CastsToJSON.set(org.json.JSONObject)
public org.json.JSONObject toJSON()
CastsToJSON
toJSON
in interface CastsToJSON
CastsToJSON.toJSON()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
Externalizable.writeExternal(java.io.ObjectOutput)
protected void commitToDatabase()
This method performs the actual flush of data to the database. It ignores the state of the changed flag, and propagates exceptions to the caller.
Generally, users will call "flush," but this method is available to child classes for their use.
Note that what we actually do here, in our post-SQL Darkstar
existence, is bind the data object to the names returned by
getUniqueBoundName()
.
protected String[] getUniqueBoundName()
protected void setID(String id)
id
- the database ID for this object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |