public abstract class AbstractDBObject extends java.lang.Object implements DBObject
DBObject
interface.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractDBObject.ChildSupport |
protected class |
AbstractDBObject.ListenerSupport
Utility class for caching a list of DBObjectListeners and firing events to
them.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractDBObject()
Constructs a new instance.
|
protected |
AbstractDBObject(java.lang.String name)
Constructs a new instance with the specified name.
|
protected |
AbstractDBObject(java.lang.String name,
DBObjectID id)
Constructs a new instance with the specified name and id.
|
Modifier and Type | Method and Description |
---|---|
void |
addObjectListener(DBObjectListener list)
Attaches a listener to this object to listen for change events.
|
void |
addObjectListener(DBObjectListener list)
Deprecated.
|
void |
addObjectListener(SchemaObjectListener list)
Deprecated.
|
protected void |
changeParent(ChildDBObject oldChild,
ChildDBObject newChild)
Changes the parent by removing this object as the parent on the oldChild
and setting this object as the parent of the newChild.
|
protected int |
compareToImpl(AbstractDBObject target) |
protected <T> T |
copyObject(T value,
DBObject copy,
IDPolicy idPolicy)
Recursive function that can copy all objects supported as properties in the
API.
|
DBObject |
copyTo(DBObject target,
boolean temporaryCopy)
Copies the state of this object to another instance.
|
protected DBObject |
copyTo(DBObject target,
DBObject copyParent,
IDPolicy idPolicy)
Internal copy method used by the API to perform copy operations.
|
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.
|
protected void |
copyToImpl(AbstractDBObject copy,
DBObject copyParent,
IDPolicy idPolicy)
Implementation method for making a copy of this object.
|
boolean |
equals(java.lang.Object other)
Returns true if this object is "equal" to the given object.
|
protected boolean |
equalsImpl(AbstractDBObject other)
Equals implementation for testing equality with another AbstractDBObject.
|
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.
|
protected DBObject |
findOwnedObject(DBObjectID id,
boolean strict,
boolean deep)
Finds an owned object with the given ID, optionally recursing into the
owned object heirachy.
|
DBObject |
findOwnedObject(java.lang.String type,
java.lang.String name)
Final implementation uses getChildrenImpl( String type ) and searches
through the contained DBObjects by name.
|
<T extends DBObject> |
findParent(java.lang.Class<T> parentClass)
Looks in the parent heirachy of this object for an object of the given
class.
|
void |
fireObjectUpdated(DBObjectChange change) |
protected void |
firePropertyChanged(java.lang.String key,
java.lang.Object oldValue,
java.lang.Object newValue) |
protected AbstractDBObject.ChildSupport |
getChildSupport(java.lang.String propName) |
DBObjectID |
getID()
Retrieves the object ID associated with this object.
|
java.lang.String |
getName()
Retrieves the name of this object.
|
DBObject[] |
getOwnedObjects()
Final implementation calls getOwnedObjectsImpl with a null
argument for the type.
|
DBObject[] |
getOwnedObjects(java.lang.String... types)
Final implementation calls getOwnedObjectsImpl with the given
types.
|
protected void |
getOwnedObjectsImpl(java.util.Collection<DBObject> objs,
java.lang.String... types)
Used by all the final children methods.
|
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.
|
java.lang.Object |
getProperty(java.lang.String key)
Retrieves the value associated with a property.
|
java.lang.Object |
getProperty(java.lang.String key,
java.lang.Object defaultValue)
Retrieves the value associated with a property.
|
DBObjectID[] |
getReferenceIDs()
Final implementation that calls the internal getReferenceIDsImpl() method.
|
protected void |
getReferenceIDsImpl(java.util.Collection<DBObjectID> refs)
Used by the final getReferenceID() implementation.
|
int |
hashCode()
Returns a hashCode value for the object.
|
protected void |
includeOwnedObject(java.util.Collection<DBObject> objs,
DBObject obj,
java.lang.String... types) |
protected boolean |
includesType(DBObject obj,
java.lang.String... types)
Use to check the types parameter when implementing the getOwnedObjectsImpl
method.
|
protected boolean |
includesType(java.lang.String type,
java.lang.String... types)
Use to check the types parameter when implementing the getOwnedObjectsImpl
method.
|
void |
removeObjectListener(DBObjectListener list)
Removes the given listener from the list of registered listeners for
this object.
|
void |
removeObjectListener(DBObjectListener list)
Deprecated.
|
void |
removeObjectListener(SchemaObjectListener list)
Deprecated.
|
boolean |
removeOwnedObject(DBObject child)
Removes the given child from this object.
|
protected void |
removeThisAsParent(ChildDBObject child)
If the given child object has this object as a parent, this method will
remove the parent setting.
|
boolean |
replaceReferenceIDs(java.util.Map<? extends DBObjectID,? extends DBObjectID> idMap)
Override in subclasses to replace reference IDs as appropriate.
|
void |
setID(DBObjectID id)
Sets the object ID associated with this object.
|
void |
setName(java.lang.String name)
Sets the name of this object.
|
void |
setProperties(java.util.Map properties)
Sets the properties of this object to be those in the given Map.
|
void |
setProperty(java.lang.String key,
java.lang.Object value)
Sets the value for a property.
|
java.lang.String |
toString() |
protected AbstractDBObject()
protected AbstractDBObject(java.lang.String name)
name
- a string representing the name of this object.protected AbstractDBObject(java.lang.String name, DBObjectID id)
name
- a string representing the name of this object.id
- the id for this object.public final void addObjectListener(DBObjectListener list)
DBObject
addObjectListener
in interface DBObject
list
- the listener to add to this objectpublic final void removeObjectListener(DBObjectListener list)
DBObject
removeObjectListener
in interface DBObject
list
- the listener to removepublic final void fireObjectUpdated(DBObjectChange change)
@Deprecated public final void addObjectListener(DBObjectListener list)
@Deprecated public final void removeObjectListener(DBObjectListener list)
@Deprecated public final void removeObjectListener(SchemaObjectListener list)
@Deprecated public final void addObjectListener(SchemaObjectListener list)
public final java.lang.Object copyTo(java.lang.Object target)
DBObject
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 DBObject.copyTo(DBObject, boolean)
for
details.
copyTo
in interface DBObject
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.DBObject.copyTo(DBObject, boolean)
public final DBObject copyTo(DBObject target, boolean temporaryCopy)
DBObject
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.
copyTo
in interface DBObject
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.TemporaryObjectID
,
DBObject.copyTo(java.lang.Object)
public final DBObject copyTo(DBObject target, IDPolicy idPolicy)
DBObject
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.
copyTo
in interface DBObject
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.TemporaryObjectID
,
DBObject.copyTo(java.lang.Object)
,
DBObject.copyTo(DBObject, boolean)
protected final DBObject copyTo(DBObject target, DBObject copyParent, IDPolicy idPolicy)
This method does not fix internal reference ids on copy. That is done by
the calling DBObject.copyTo(DBObject, IDPolicy)
method.
DBObject.copyTo(java.lang.Object)
,
DBObject.copyTo(DBObject, boolean)
,
copyToImpl(oracle.javatools.db.AbstractDBObject, oracle.javatools.db.DBObject, oracle.javatools.db.IDPolicy)
protected void copyToImpl(AbstractDBObject copy, DBObject copyParent, IDPolicy idPolicy)
copy
- the copy being created of this objectcopyParent
- if this object is being copied underneath a parent, this
parameter is the copy of the parent of this object, which will therefore
need to be the parent of the copy of this object.idPolicy
- the policy for copying the object's ID.protected <T> T copyObject(T value, DBObject copy, IDPolicy idPolicy)
public final boolean equals(java.lang.Object other)
DBObject
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 interface DBObject
equals
in class java.lang.Object
other
- the other object to compare for equality.DBObjectSet
,
DBObjectMap
protected boolean equalsImpl(AbstractDBObject other)
protected int compareToImpl(AbstractDBObject target)
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
DBObject
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 interface DBObject
hashCode
in class java.lang.Object
DBObjectSet
,
DBObjectMap
public void setName(java.lang.String name)
DBObject
public java.lang.String getName()
DBObject
public final DBObject getParent()
DBObject
public final <T extends DBObject> T findParent(java.lang.Class<T> parentClass)
frag.findParent( SQLQuery.class )
on a
valid SQLFragment instance will return the SQLQuery in its heirachy (if
one exists).parentClass
- the type of parent object to look forpublic void setID(DBObjectID id)
DBObject
public final DBObjectID getID()
DBObject
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
DBObject
getProperties
in interface DBObject
getProperties
in interface DynamicPropertySet
public java.lang.Object getProperty(java.lang.String key)
DynamicPropertySet
getProperty
in interface DynamicPropertySet
key
- the property key for which a value is desired.
exists.null
value
if the property does not exist or is not set.public final java.lang.Object getProperty(java.lang.String key, java.lang.Object defaultValue)
DynamicPropertySet
getProperty
in interface DynamicPropertySet
key
- the property key for which a value is desired.defaultValue
- the value to return if no value currently
exists.public void setProperties(java.util.Map properties)
setProperties
in interface DynamicPropertySet
properties
- the new properties for this object.java.lang.ClassCastException
- if any key in the given Map isn't a String.public void setProperty(java.lang.String key, java.lang.Object value)
DynamicPropertySet
null
removes that property.setProperty
in interface DynamicPropertySet
key
- the property key to setvalue
- the value to setprotected final void firePropertyChanged(java.lang.String key, java.lang.Object oldValue, java.lang.Object newValue)
protected final void removeThisAsParent(ChildDBObject child)
protected final void changeParent(ChildDBObject oldChild, ChildDBObject newChild)
public final DBObject[] getOwnedObjects()
getOwnedObjects
in interface DBObject
getOwnedObjectsImpl(java.util.Collection<oracle.javatools.db.DBObject>, java.lang.String...)
,
DBObject.getOwnedObjects()
public final DBObject[] getOwnedObjects(java.lang.String... types)
getOwnedObjects
in interface DBObject
getOwnedObjectsImpl(java.util.Collection<oracle.javatools.db.DBObject>, java.lang.String...)
public final DBObject findOwnedObject(java.lang.String type, java.lang.String name)
findOwnedObject
in interface DBObject
type
- the DBObject type for the child to be returned
(e.g. Column.TYPE
)name
- the name of the DBObject to be returnedgetOwnedObjectsImpl(java.util.Collection<oracle.javatools.db.DBObject>, java.lang.String...)
,
DBObject.findOwnedObject(java.lang.String, java.lang.String)
public final DBObject findOwnedObject(DBObjectID id)
DBObject
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.
findOwnedObject
in interface DBObject
id
- the id to look forDBObject.findOwnedObject(DBObjectID,boolean)
public DBObject findOwnedObject(DBObjectID id, boolean strict)
DBObject
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.
findOwnedObject
in interface DBObject
id
- the id to look forstrict
- whether to stricly compare IDs or notDBObjectID.equals(DBObjectID,boolean)
protected final DBObject findOwnedObject(DBObjectID id, boolean strict, boolean deep)
id
- the object ID to look forstrict
- whether to do a strict comparison on the idsdeep
- whether to recurse further into owned objects' owned
objects (and so on)protected void getOwnedObjectsImpl(java.util.Collection<DBObject> objs, java.lang.String... types)
includesType
to check the types vararg.types
- a vararg of the type(s) to search forobjs
- a Collection of the apppropriate children.includesType(java.lang.String, java.lang.String...)
protected final void includeOwnedObject(java.util.Collection<DBObject> objs, DBObject obj, java.lang.String... types)
protected final boolean includesType(java.lang.String type, java.lang.String... types)
if ( includesType( Column.TYPE, types ) ) ...
type
- the type we're interested intypes
- the types parameter passed to getOwnedObjectsImplprotected final boolean includesType(DBObject obj, java.lang.String... types)
if ( includesType( column, types ) ) ...
obj
- the object to test whether we should includetypes
- the types parameter passed to getOwnedObjectsImplpublic boolean removeOwnedObject(DBObject child)
DBObject
This will not remove SchemaObjects from a Schema, as in the API the Schema -> SchemaObject relationship is not an owner -> owned object relationship.
removeOwnedObject
in interface DBObject
child
- a DBObject instance held as a property on this DBObject
that is to be removed.public final DBObjectID[] getReferenceIDs()
getReferenceIDs
in interface DBObject
getReferenceIDsImpl(java.util.Collection<oracle.javatools.db.DBObjectID>)
,
DBObject.getReferenceIDs()
protected void getReferenceIDsImpl(java.util.Collection<DBObjectID> refs)
refs
- the collection of ids this object referencespublic boolean replaceReferenceIDs(java.util.Map<? extends DBObjectID,? extends DBObjectID> idMap)
replaceReferenceIDs
in interface DBObject
idMap
- key = old DBObjectID, value = new DBObjectIDprotected final AbstractDBObject.ChildSupport getChildSupport(java.lang.String propName)