org.alfresco.util.schemacomp.model
Class AbstractDbObject

java.lang.Object
  extended by org.alfresco.util.schemacomp.model.AbstractDbObject
All Implemented Interfaces:
DbObject
Direct Known Subclasses:
AbstractDbObjectTest.AnotherConcreteDbObject, AbstractDbObjectTest.ConcreteDbObject, Column, DbPropertyTest.MyDbObject, DefaultComparisonUtilsTest.DatabaseObject, DefaultComparisonUtilsTest.DbObjectWithCollection, ForeignKey, Index, PrimaryKey, Schema, Sequence, Table

public abstract class AbstractDbObject
extends java.lang.Object
implements DbObject

Useful base class for many, if not all the DbObject implementations.


Field Summary
protected  ComparisonUtils comparisonUtils
           
 
Constructor Summary
AbstractDbObject(DbObject parent, java.lang.String name)
          Instantiate, giving the object a parent and a name.
 
Method Summary
 void diff(DbObject right, DiffContext ctx, Result.Strength strength)
          Provides an implementation of DbObject#diff(DbObject, Results).
protected  void doDiff(DbObject right, DiffContext ctx, Result.Strength strength)
          Override this method to provide subclass specific diffing logic.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getName()
          All items can be asked for their name, but it may be null.
 Result.Strength getNameStrength()
           
 DbObject getParent()
          Get the parent object for which this object is a child.
 java.lang.String getTypeName()
          Type name, e.g.
 java.util.List getValidators()
          Retrieve the list of validators associated with this database object.
 int hashCode()
           
 boolean sameAs(DbObject other)
          Are the two DbObjects logically the same? For example two Index objects may have different names, but are the same index as they both index the same columns for the same table.
 void setComparisonUtils(ComparisonUtils comparisonUtils)
          If a ComparisonUtils other than the default is required, then this setter can be used.
 void setName(java.lang.String name)
           
 void setNameStrength(Result.Strength nameStrength)
           
 void setParent(DbObject parent)
          Sets the parent object.
 void setValidators(java.util.List validators)
          Set/override the validators associated with this database object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.alfresco.util.schemacomp.model.DbObject
accept
 

Field Detail

comparisonUtils

protected ComparisonUtils comparisonUtils
Constructor Detail

AbstractDbObject

public AbstractDbObject(DbObject parent,
                        java.lang.String name)
Instantiate, giving the object a parent and a name.

Parameters:
parent -
name -
Method Detail

getName

public java.lang.String getName()
Description copied from interface: DbObject
All items can be asked for their name, but it may be null.

Specified by:
getName in interface DbObject
Returns:
the name

setName

public void setName(java.lang.String name)
Parameters:
name - the name to set

getNameStrength

public Result.Strength getNameStrength()
Returns:
the nameStrength

setNameStrength

public void setNameStrength(Result.Strength nameStrength)
Parameters:
nameStrength - the nameStrength to set

sameAs

public boolean sameAs(DbObject other)
Description copied from interface: DbObject
Are the two DbObjects logically the same? For example two Index objects may have different names, but are the same index as they both index the same columns for the same table.

If two objects a and b have the same logical identity, it does not mean that a.equals(b) == true. The two objects may well have differences and will be flagged as such by the schema comparison tool. When a.sameAs(b) == true it makes it easier to show the differences as related, i.e. a and b are different rather than, a is only in the 'left' tree and b is only in the 'right' tree.

Specified by:
sameAs in interface DbObject
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

diff

public void diff(DbObject right,
                 DiffContext ctx,
                 Result.Strength strength)
Provides an implementation of DbObject#diff(DbObject, Results). The template method #doDiff(DbObject, Results) provides the subclass specific diffing logic, whilst this method handles the workflow required in most cases: set the path's prefix that will be used to explain where differences occur; compare the name fields of the two objects; delegate to the subclass specific diffing (if any); remove the last path addition ready for the next object to perform its diff correctly.

Specified by:
diff in interface DbObject
Parameters:
right - The object to compare against.
ctx - The DiffContext

getParent

public DbObject getParent()
Description copied from interface: DbObject
Get the parent object for which this object is a child. If this is the root object then null should be returned.

Specified by:
getParent in interface DbObject
Returns:
Parent reference or null

setParent

public void setParent(DbObject parent)
Description copied from interface: DbObject
Sets the parent object.

Specified by:
setParent in interface DbObject
See Also:
DbObject.getParent()

doDiff

protected void doDiff(DbObject right,
                      DiffContext ctx,
                      Result.Strength strength)
Override this method to provide subclass specific diffing logic.

Parameters:
right -
differences -
strength -

setComparisonUtils

public void setComparisonUtils(ComparisonUtils comparisonUtils)
If a ComparisonUtils other than the default is required, then this setter can be used. Useful for testing, where a mock can be injected.

Parameters:
comparisonUtils - the comparisonUtils to set

getValidators

public java.util.List getValidators()
Description copied from interface: DbObject
Retrieve the list of validators associated with this database object.

Specified by:
getValidators in interface DbObject
Returns:
DbValidator List
See Also:
DbValidator

setValidators

public void setValidators(java.util.List validators)
Description copied from interface: DbObject
Set/override the validators associated with this database object.

Specified by:
setValidators in interface DbObject
Parameters:
validators - the validators to set

getTypeName

public java.lang.String getTypeName()
Description copied from interface: DbObject
Type name, e.g. "column", "foreign key"

Specified by:
getTypeName in interface DbObject
Returns:
String


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.