public interface DBObject extends Copyable, DynamicPropertySet
Table
, Column
etc.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMMENT
The comment property.
|
Modifier and Type | Method and Description |
---|---|
void |
addObjectListener(DBObjectListener list)
Attaches a listener to this object to listen for change events.
|
DBObject |
copyTo(DBObject target,
boolean temporaryCopy)
Copies the state of this object to another instance.
|
DBObject |
copyTo(DBObject target,
IDPolicy idPolicy)
Copies the state of this object to another instance.
|
java.lang.Object |
copyTo(java.lang.Object target)
Implementation of the Copyable interface that copies the state of this
DBObject to another instance.
|
boolean |
equals(java.lang.Object obj)
Returns true if this object is "equal" to the given object.
|
DBObject |
findOwnedObject(DBObjectID id)
Returns a child of this object that has the given ID.
|
DBObject |
findOwnedObject(DBObjectID id,
boolean strict)
Returns a child of this object that has the given ID.
|
DBObject |
findOwnedObject(java.lang.String type,
java.lang.String name)
Returns an object owned by this object with given name and type, if one
exists.
|
DBObjectID |
getID()
Retrieves the object ID associated with this object.
|
java.lang.String |
getName()
Retrieves the name of this object.
|
DBObject[] |
getOwnedObjects()
Returns the objects owned by this object.
|
DBObject[] |
getOwnedObjects(java.lang.String... type)
Returns the objects owned by this object of the given type.
|
DBObject |
getParent()
Returns the parent of this object, if one exists.
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Gets the property map that stores all the property information for this
object.
|
DBObjectID[] |
getReferenceIDs()
Returns all the IDs that this object has as properties that reference
other DBObjects.
|
java.lang.String |
getType()
Returns the type of this object.
|
int |
hashCode()
Returns a hashCode value for the object.
|
void |
removeObjectListener(DBObjectListener list)
Removes the given listener from the list of registered listeners for
this object.
|
boolean |
removeOwnedObject(DBObject child)
Removes the given child from this object.
|
boolean |
replaceReferenceIDs(java.util.Map<? extends DBObjectID,? extends DBObjectID> oldToNew)
Replaces any reference ids (e.g.
|
void |
setID(DBObjectID id)
Sets the object ID associated with this object.
|
void |
setName(java.lang.String name)
Sets the name of this object.
|
getProperty, getProperty, setProperties, setProperty
static final java.lang.String COMMENT
java.lang.Object copyTo(java.lang.Object target)
null
is specified for the
target, a new instance will be created.
The entire state of the object will be copied, with a few exceptions. In particular, any observers registered will NOT be copied. In cases where this instance contains child DBObjects, new instances of those children will be created, and the state copied to them. The copy will thus contain its own unique state; after making the copy, changing one instance will not cause any changes to occur to the copy. The properties will be copied; however, copies will not be made of the values referenced by the properties - thus, the copy will refer to the same instance as the original. Child objects that are copied will still point to the original parent; it is the responsibility of a copied parent to update the parent of copies of its children point to the copy of itself.
If the object, or any child object has an ID set, the equivalent object in
the copy will be given a TemporaryObjectID that does not reference back
to the original object. See copyTo(DBObject, boolean)
for
details.
copyTo
in interface Copyable
target
- The object to copy to. If target is null
, a new
instance will be created, and the state will be copied to that object.java.lang.ClassCastException
- if the target is not null and cannot
be downcast to the type represented by this object.copyTo(DBObject, boolean)
DBObject copyTo(DBObject target, boolean temporaryCopy)
null
is specified for the target, a new instance will be created.
The entire state of the object will be copied. In cases where this instance contains child DBObjects, new instances of those children will be created, and the state copied to them. The copy will thus contain its own unique state; after making the copy, changing one instance will not cause any changes to occur to the copy. The properties will be copied; however, copies will not be made of the values referenced by the properties - thus, the copy will refer to the same instance as the original.
The includeID parameter governs what happens to any ids (on this object, or on any children). If true a TemporaryObjectID will be assigned to the copy of any DBObject, that points back to the original object. If false a TemporaryObjectID will be assigned to the copy of any DBObject that already has an ID, but it will not point back to the original.
target
- The object to copy to. If target is null
, a new
instance will be created, and the state will be copied to that object.temporaryCopy
- Whether to include a TemporaryObjectID that points
back to the original for every object.java.lang.ClassCastException
- if the target is not null and cannot
be downcast to the type represented by this object.TemporaryObjectID
,
copyTo(java.lang.Object)
DBObject copyTo(DBObject target, IDPolicy idPolicy)
null
is specified for the target, a new instance will be created.
The entire state of the object will be copied. In cases where this instance contains child DBObjects, new instances of those children will be created, and the state copied to them. The copy will thus contain its own unique state; after making the copy, changing one instance will not cause any changes to occur to the copy. The properties will be copied; however, copies will not be made of the values referenced by the properties - thus, the copy will refer to the same instance as the original.
The idPolicy is used to control the IDs set on all objects in the copy.
target
- The object to copy to. If target is null
, a new
instance will be created, and the state will be copied to that object.idPolicy
- The policy for the IDs set in the copy.java.lang.ClassCastException
- if the target is not null and cannot
be downcast to the type represented by this object.TemporaryObjectID
,
copyTo(java.lang.Object)
,
copyTo(DBObject, boolean)
void setName(java.lang.String name)
name
- a string containing the new name for this object.java.lang.String getName()
DBObjectID getID()
void setID(DBObjectID id)
id
- the DBObjectID to be associated with this objectjava.lang.IllegalStateException
- if the ID is already setjava.lang.String getType()
DBObject[] getOwnedObjects()
If this object supports lazy loading, calling this will fully load the object.
This method should not return null - whether children are not supported on this object, or the object supports children and has none an empty array should be returned.
DBObject[] getOwnedObjects(java.lang.String... type)
If this object supports lazy loading, calling this will fully load the object.
This method should not return null - whether children are not supported on this object, or the object supports children and has none an empty array should be returned.
types
- the DBObject type(s) for the children to be returned
(e.g. Column.TYPE
)DBObject findOwnedObject(java.lang.String type, java.lang.String name)
The method does not recurse to look for children of children.
If this object supports lazy loading, calling this will fully load the object.
This will not find SchemaObjects in a Schema, as in the API the Schema -> SchemaObject relationship is not an owner -> owned object relationship.
type
- the DBObject type for the child to be returned
(e.g. Column.TYPE
)name
- the name of the DBObject to be returnedDBObject findOwnedObject(DBObjectID id)
This will do a strict comparison of the DBObjectIDs when searching.
The method does not recurse to look for children of children.
This will not find SchemaObjects in a Schema, as in the API the Schema -> SchemaObject relationship is not an owner -> owned object relationship.
id
- the id to look forfindOwnedObject(DBObjectID,boolean)
DBObject findOwnedObject(DBObjectID id, boolean strict)
Note: an unstrict comparison can be time consuming, only request it if you need it (i.e. you are searching using a DBObjectID that did not originate in this object's heirarchy).
The method does not recurse to look for children of children.
This will not find SchemaObjects in a Schema, as in the API the Schema -> SchemaObject relationship is not an owner -> owned object relationship.
id
- the id to look forstrict
- whether to stricly compare IDs or notDBObjectID.equals(DBObjectID,boolean)
boolean removeOwnedObject(DBObject child)
This will not remove SchemaObjects from a Schema, as in the API the Schema -> SchemaObject relationship is not an owner -> owned object relationship.
child
- a DBObject instance held as a property on this DBObject
that is to be removed.DBObject getParent()
DBObjectID[] getReferenceIDs()
If this object supports lazy loading, calling this will fully load the object.
Will not return null.
boolean replaceReferenceIDs(java.util.Map<? extends DBObjectID,? extends DBObjectID> oldToNew)
If this object supports lazy loading, calling this will fully load the object.
oldToNew
- key = old DBObjectID, value = new DBObjectIDvoid addObjectListener(DBObjectListener list)
list
- the listener to add to this objectvoid removeObjectListener(DBObjectListener list)
list
- the listener to removejava.util.Map<java.lang.String,java.lang.Object> getProperties()
getProperties
in interface DynamicPropertySet
boolean equals(java.lang.Object obj)
For this reason care should be taken putting DBObjects in to Collection or Map implementations, because any comparison using equals will be slow.
equals
in class java.lang.Object
obj
- the other object to compare for equality.DBObjectSet
,
DBObjectMap
int hashCode()
type
, as that is the only property of a DBObject that
is immutable.
Combined with the equals
implementation, this
means that lookup in a HashMap
will not be performant, and in
general DBObjects should not be put in a HashMap
,
HashSet
etc.
hashCode
in class java.lang.Object
DBObjectSet
,
DBObjectMap