uk.ac.ic.doc.automed.reps
Class Transformation

java.lang.Object
  |
  +--uk.ac.ic.doc.automed.reps.Transformation
All Implemented Interfaces:
java.lang.Comparable

public class Transformation
extends java.lang.Object
implements java.lang.Comparable

The Transformation class

Author:
Michael Boyd (mboyd@doc.ic.ac.uk), Nerissa Tong (nnyt98@doc.ic.ac.uk)

Field Summary
static int ACTION_ADD
          Transformation action "add"
static int ACTION_CONTRACT
          Transformation action "contract"
static int ACTION_DELETE
          Transformation action "delete"
static int ACTION_EXTEND
          Transformation action "extend"
static int ACTION_IDENT
          Transformation action "ident"
static int ACTION_MAXIMUM
           
static int ACTION_MINIMUM
           
static int ACTION_RENAME
          Transformation action "rename"
 
Constructor Summary
protected Transformation(int action, int fromOBID, int toOBID, int fromSID, int toSID, java.lang.String function, java.lang.String constraint, boolean addToMap)
          Instantiates a transformation.
 
Method Summary
 int compareTo(java.lang.Object o)
           
static Transformation createAddTransformation(Schema fromSchema, Construct toObjectConstructType, java.lang.Object[] toObject, java.lang.String function, java.lang.String constraint)
          Creates a new ADD transformation.
static Transformation createAddTransformation(Schema fromSchema, Construct toObjectConstructType, java.lang.Object[] toObject, java.lang.String function, java.lang.String constraint, java.lang.String newSchemaName)
          Creates an ADD transformation.
static Transformation createContractTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.String function, java.lang.String constraint)
          Creates an CONTRACT transformation.
static Transformation createContractTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.String newSchemaName, java.lang.String function, java.lang.String constraint)
          Creates an CONTRACT transformation.
static Transformation createDeleteTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.String function, java.lang.String constraint)
          Creates a DELETE transformation.
static Transformation createDeleteTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.String function, java.lang.String constraint, java.lang.String newSchemaName)
          Creates a DELETE transformation.
static Transformation createExtendTransformation(Schema fromSchema, Construct toObjectConstructType, java.lang.Object[] toObject, java.lang.String function, java.lang.String constraint)
          Creates an EXTEND transformation.
static Transformation createExtendTransformation(Schema fromSchema, Construct toObjectConstructType, java.lang.Object[] toObject, java.lang.String newSchemaName, java.lang.String function, java.lang.String constraint)
          Creates an EXTEND transformation.
static Transformation[] createIdentTransformations(Schema fromSchema, Schema toSchema, java.lang.String function, java.lang.String constraint)
          Creates an IDENT transformation.
static Transformation createRenameTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.Object[] toObject)
          Creates a RENAME transformation.
static Transformation createRenameTransformation(Schema fromSchema, SchemaObject fromObject, java.lang.Object[] toObject, java.lang.String newSchemaName)
          Creates a RENAME transformation.
protected  Transformation duplicateTransformation(Schema fromSchema)
          Creates a duplicate of the transformation.
 int getActionFrom(Schema s)
          Returns the action of the transformation.
 int getActionTo(Schema s)
          Returns the action of the transformation.
 SchemaObject[] getAllReferencedSchemaObjects()
          Returns all the schema objects referenced in a transformation, including those referenced in its query.
The result of this method is the union of the results returned by the methods getReferencedSchemaObjects() and getReferencedSchemaObjectsInQuery().
static java.util.List getAllTrans()
           
 Schema getCommonSchema(Transformation t)
           
 java.lang.String getConstraint()
          Returns the constraint associated with the transformation.
protected  int getFromOBID()
          Returns the schema object identifier (OBID) of the input of the transformaiton (fromObject).
protected  int getFromSID()
          Returns the schema identifier (SID) of the originating schema.
 java.lang.String getFunction()
          Returns the function of the transformation.
 Schema[] getOriginalSchemas()
           
 Schema getOtherSchema(Schema s)
          Returns the schemas of the transformation.
 SchemaObject[] getReferencedSchemaObjects()
          Returns all the schema objects referenced in a transformation.
 SchemaObject[] getReferencedSchemaObjectsInQuery()
          Returns all the schema objects referenced in the query of a transformation.
protected  Transformation getReverseTransformation()
          Returns the reverse transformation of the given transformation.
 SchemaObject getSchemaObject(Schema s)
          Returns the SchemaObject of the transformation.
 Schema[] getSchemas()
          Returns the schemas of the transformation.
protected  int getToOBID()
          Returns the schema object identifier (OBID) of the output of the transformaiton (toObject).
protected  int getToSID()
          Returns the schema identifier (SID) of the resultant schema.
protected static Transformation getTransformation(int fSID, int tSID)
          Returns the transformation between two given schemas.
static Transformation getTransformation(Schema fs, Schema ts)
          Returns the transformation between two given schemas.
static java.lang.Object[][] getTransformations()
           
static void importTransformations(java.io.InputStream is)
           
static void importTransformations(java.io.InputStream is, java.lang.String suffix)
           
protected  boolean isDependentOn(Transformation tran)
          Determines whether or not the transformation is dependent on another transformation.
protected  boolean isRedundant(Transformation tran)
          Determines whether or not the transformation and the given tran are redundant, e.g., two transformations are redundant if they transform the same schema object and their action is the opposite of the other (add/delete, extend/contract, etc.).
static Transformation read(java.io.InputStream is)
           
 void remove()
          Removes this Transformation from the repository.
static void removeTransformation(java.lang.String fromSchema, java.lang.String toSchema)
          Removes the transformation between two given schemas.
 void retract()
           
static void syncWithRepository()
           
 java.lang.String toString()
           
 void write()
           
 void write(java.io.OutputStream os)
           
 void write(java.io.PrintWriter pw)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTION_MINIMUM

public static final int ACTION_MINIMUM
See Also:
Constant Field Values

ACTION_ADD

public static final int ACTION_ADD
Transformation action "add"

See Also:
Constant Field Values

ACTION_DELETE

public static final int ACTION_DELETE
Transformation action "delete"

See Also:
Constant Field Values

ACTION_RENAME

public static final int ACTION_RENAME
Transformation action "rename"

See Also:
Constant Field Values

ACTION_EXTEND

public static final int ACTION_EXTEND
Transformation action "extend"

See Also:
Constant Field Values

ACTION_CONTRACT

public static final int ACTION_CONTRACT
Transformation action "contract"

See Also:
Constant Field Values

ACTION_IDENT

public static final int ACTION_IDENT
Transformation action "ident"

See Also:
Constant Field Values

ACTION_MAXIMUM

public static final int ACTION_MAXIMUM
See Also:
Constant Field Values
Constructor Detail

Transformation

protected Transformation(int action,
                         int fromOBID,
                         int toOBID,
                         int fromSID,
                         int toSID,
                         java.lang.String function,
                         java.lang.String constraint,
                         boolean addToMap)
Instantiates a transformation.

Parameters:
action - the action of the transformation.
fromOBID - the schema object identifier (OBID) of the fromObject of the transformation.
toOBID - the schema object identifier (OBID) of the toObject of the transformation.
fromSID - the schema identifier (SID) of the fromSchema of the transformation.
toSID - the schema identifier (SID) of the toSchema of the transformation.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
addToMap - set to true if the transformation is to be added to the transformation HashMap; false otherwise.
Method Detail

createAddTransformation

public static Transformation createAddTransformation(Schema fromSchema,
                                                     Construct toObjectConstructType,
                                                     java.lang.Object[] toObject,
                                                     java.lang.String function,
                                                     java.lang.String constraint)
                                              throws InconsistentException,
                                                     TypeMismatchException
Creates a new ADD transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
toObjectConstructType - the construct type (see Construct) of the resulting transformation object.
toObject - the scheme (in an Object array) that forms the output of the transformation.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createAddTransformation

public static Transformation createAddTransformation(Schema fromSchema,
                                                     Construct toObjectConstructType,
                                                     java.lang.Object[] toObject,
                                                     java.lang.String function,
                                                     java.lang.String constraint,
                                                     java.lang.String newSchemaName)
                                              throws InconsistentException,
                                                     TypeMismatchException
Creates an ADD transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
toObjectConstructType - the construct type (see Construct) of the resulting transformation object.
toObject - the scheme (in an Object array) that forms the output of the transformation.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
newSchemaName - the name of the resultant schema.
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createDeleteTransformation

public static Transformation createDeleteTransformation(Schema fromSchema,
                                                        SchemaObject fromObject,
                                                        java.lang.String function,
                                                        java.lang.String constraint)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates a DELETE transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be deleted in the transformation. Note that this schema object must belong to the given fromSchema.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createDeleteTransformation

public static Transformation createDeleteTransformation(Schema fromSchema,
                                                        SchemaObject fromObject,
                                                        java.lang.String function,
                                                        java.lang.String constraint,
                                                        java.lang.String newSchemaName)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates a DELETE transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be deleted in the transformation. Note that this schema object must belong to the given fromSchema.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
newSchemaName - the name of the resultant schema.
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createRenameTransformation

public static Transformation createRenameTransformation(Schema fromSchema,
                                                        SchemaObject fromObject,
                                                        java.lang.Object[] toObject)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates a RENAME transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be renamed in the transformation. Note that this schema object must belong to the given fromSchema.
toObject - the scheme (in an Object array) that forms the output of the transformation. (The construct type of toObject must be the same as the fromObject).
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createRenameTransformation

public static Transformation createRenameTransformation(Schema fromSchema,
                                                        SchemaObject fromObject,
                                                        java.lang.Object[] toObject,
                                                        java.lang.String newSchemaName)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates a RENAME transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be renamed in the transformation. Note that this schema object must belong to the given fromSchema.
toObject - the scheme (in an Object array) that forms the output of the transformation. (The construct type of toObject must be the same as the fromObject).
newSchemaName - the name of the resultant schema.
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createExtendTransformation

public static Transformation createExtendTransformation(Schema fromSchema,
                                                        Construct toObjectConstructType,
                                                        java.lang.Object[] toObject,
                                                        java.lang.String function,
                                                        java.lang.String constraint)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates an EXTEND transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
toObjectConstructType - the construct type (see Construct) of the resulting transformation object.
toObject - the scheme (in an Object array) that forms the output of the transformation.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createExtendTransformation

public static Transformation createExtendTransformation(Schema fromSchema,
                                                        Construct toObjectConstructType,
                                                        java.lang.Object[] toObject,
                                                        java.lang.String newSchemaName,
                                                        java.lang.String function,
                                                        java.lang.String constraint)
                                                 throws InconsistentException,
                                                        TypeMismatchException
Creates an EXTEND transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
toObjectConstructType - the construct type (see Construct) of the resulting transformation object.
toObject - the scheme (in an Object array) that forms the output of the transformation.
newSchemaName - the name of the resultant schema.
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createContractTransformation

public static Transformation createContractTransformation(Schema fromSchema,
                                                          SchemaObject fromObject,
                                                          java.lang.String function,
                                                          java.lang.String constraint)
                                                   throws TypeMismatchException
Creates an CONTRACT transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be contracted in the transformation. Note that this schema object must belong to the given fromSchema.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createContractTransformation

public static Transformation createContractTransformation(Schema fromSchema,
                                                          SchemaObject fromObject,
                                                          java.lang.String newSchemaName,
                                                          java.lang.String function,
                                                          java.lang.String constraint)
                                                   throws InconsistentException,
                                                          TypeMismatchException
Creates an CONTRACT transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
fromObject - the SchemaObject to be contracted in the transformation. Note that this schema object must belong to the given fromSchema.
newSchemaName - the name of the resultant schema.
Returns:
the Transformation object.
Throws:
InconsistentException
TypeMismatchException

createIdentTransformations

public static Transformation[] createIdentTransformations(Schema fromSchema,
                                                          Schema toSchema,
                                                          java.lang.String function,
                                                          java.lang.String constraint)
                                                   throws InconsistentException,
                                                          IntegrityException,
                                                          SchemasNotIdenticalException
Creates an IDENT transformation.

Parameters:
fromSchema - the originating Schema of the transformation.
toSchema - the resultant Schema of the transformation.
function - the query that expresses the extent of the construct being transformed.
constraint - the constraint associated with the transformation (if any).
Returns:
an array of Transformation objects.
Throws:
InconsistentException
IntegrityException
SchemasNotIdenticalException

getTransformation

protected static Transformation getTransformation(int fSID,
                                                  int tSID)
                                           throws InconsistentException
Returns the transformation between two given schemas.

Parameters:
fSID - the schema identifier (SID) of the originating schema.
tSID - the schema identifier (SID) of the resultant schema.
Returns:
the transformation between two given schemas.
Throws:
InconsistentException

getTransformation

public static Transformation getTransformation(Schema fs,
                                               Schema ts)
                                        throws InconsistentException,
                                               IntegrityException
Returns the transformation between two given schemas.

Parameters:
fs - the Schema of the originating schema.
ts - the Schema of the resultant schema.
Returns:
the transformation between two given schemas.
Throws:
InconsistentException
IntegrityException

removeTransformation

public static void removeTransformation(java.lang.String fromSchema,
                                        java.lang.String toSchema)
                                 throws NotFoundException,
                                        IntegrityException
Removes the transformation between two given schemas.

Parameters:
fromSchema - the name of the originating schema.
toSchema - the name of the resultant schema.
Throws:
NotFoundException - if either of the two named schemas do not exist
IntegrityException

remove

public void remove()
            throws IntegrityException
Removes this Transformation from the repository. Clearly, once called, this Transformation object instance should not be used again.

IntegrityException

retract

public void retract()

getActionFrom

public int getActionFrom(Schema s)
                  throws InconsistentException,
                         IntegrityException
Returns the action of the transformation.

Returns:
the action of the transformation.
InconsistentException
IntegrityException

getActionTo

public int getActionTo(Schema s)
                throws InconsistentException,
                       IntegrityException
Returns the action of the transformation.

Returns:
the action of the transformation.
InconsistentException
IntegrityException

getSchemaObject

public SchemaObject getSchemaObject(Schema s)
                             throws InconsistentException,
                                    IntegrityException
Returns the SchemaObject of the transformation.

Parameters:
s - the schema in which the transformation object exists as a result of applying the transformation.
Returns:
the SchemaObject of the transformation.
Throws:
InconsistentException
IntegrityException

getSchemas

public Schema[] getSchemas()
Returns the schemas of the transformation.

Returns:
the schemas of the transformation.

getOtherSchema

public Schema getOtherSchema(Schema s)
                      throws IntegrityException
Returns the schemas of the transformation.

Parameters:
s - one of the schemas associated with the transformation.
Returns:
the schemas of the transformation.
Throws:
InconsistentException
IntegrityException

getFromSID

protected int getFromSID()
Returns the schema identifier (SID) of the originating schema.

Returns:
the schema identifier (SID) of the originating schema.

getToSID

protected int getToSID()
Returns the schema identifier (SID) of the resultant schema.

Returns:
the schema identifier (SID) of the resultant schema.

getFromOBID

protected int getFromOBID()
Returns the schema object identifier (OBID) of the input of the transformaiton (fromObject).

Returns:
the schema object identifier (OBID) of the input of the transformaiton (fromObject).

getToOBID

protected int getToOBID()
Returns the schema object identifier (OBID) of the output of the transformaiton (toObject).

Returns:
the schema object identifier (OBID) of the output of the transformaiton (toObject).

getFunction

public java.lang.String getFunction()
Returns the function of the transformation.

Returns:
the function of the transformation.

getConstraint

public java.lang.String getConstraint()
Returns the constraint associated with the transformation.

Returns:
the constraint associated with the transformation.

getReverseTransformation

protected Transformation getReverseTransformation()
Returns the reverse transformation of the given transformation.

Returns:
the reverse transformation of the given transformation.

isDependentOn

protected boolean isDependentOn(Transformation tran)
                         throws InconsistentException,
                                IntegrityException
Determines whether or not the transformation is dependent on another transformation. If the transformation object appears anywhere in the scheme of the given transformation's object, this method will return true.

Parameters:
tran - the Transformation whose transformation object is to be compared.
Returns:
true if the transformation is dependent on the given Transformation; false otherwise.
Throws:
InconsistentException
IntegrityException

isRedundant

protected boolean isRedundant(Transformation tran)
                       throws InconsistentException,
                              IntegrityException
Determines whether or not the transformation and the given tran are redundant, e.g., two transformations are redundant if they transform the same schema object and their action is the opposite of the other (add/delete, extend/contract, etc.).

Parameters:
tran - the Transformation whose transformation object and action are to be compared.
Returns:
true if the transformation and the given Transformation are redundant; false otherwise.
InconsistentException
IntegrityException

toString

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

syncWithRepository

public static void syncWithRepository()
                               throws InconsistentException
InconsistentException

getReferencedSchemaObjects

public SchemaObject[] getReferencedSchemaObjects()
Returns all the schema objects referenced in a transformation.

Returns:
an array of SchemaObject instances that are referenced in the transformation.

getReferencedSchemaObjectsInQuery

public SchemaObject[] getReferencedSchemaObjectsInQuery()
Returns all the schema objects referenced in the query of a transformation.

Returns:
an array of SchemaObject instances that are referenced in the query of the transformation.

getAllReferencedSchemaObjects

public SchemaObject[] getAllReferencedSchemaObjects()
Returns all the schema objects referenced in a transformation, including those referenced in its query.
The result of this method is the union of the results returned by the methods getReferencedSchemaObjects() and getReferencedSchemaObjectsInQuery().

Returns:
an array of SchemaObject instances that are referenced in the transformation, plus the SchemaObject instances referenced in its query.

duplicateTransformation

protected Transformation duplicateTransformation(Schema fromSchema)
                                          throws InconsistentException,
                                                 IntegrityException
Creates a duplicate of the transformation. A new intentional schema and entries in the STR will be created.

Parameters:
fromSchema - the originating Schema of the transformation.
Returns:
a duplicate of the transformation with the given fromSchema.
InconsistentException
IntegrityException

getTransformations

public static java.lang.Object[][] getTransformations()
                                               throws InconsistentException
InconsistentException

importTransformations

public static void importTransformations(java.io.InputStream is)
                                  throws java.io.IOException,
                                         AutoRepException,
                                         UnexpectedTokenException,
                                         AutoMedException,
                                         java.sql.SQLException
java.io.IOException
AutoRepException
UnexpectedTokenException
AutoMedException
java.sql.SQLException

importTransformations

public static void importTransformations(java.io.InputStream is,
                                         java.lang.String suffix)
                                  throws java.io.IOException,
                                         AutoRepException,
                                         UnexpectedTokenException,
                                         AutoMedException,
                                         java.sql.SQLException
java.io.IOException
AutoRepException
UnexpectedTokenException
AutoMedException
java.sql.SQLException

read

public static Transformation read(java.io.InputStream is)
                           throws java.io.IOException,
                                  AutoRepException,
                                  UnexpectedTokenException,
                                  AutoMedException,
                                  java.sql.SQLException
java.io.IOException
AutoRepException
UnexpectedTokenException
AutoMedException
java.sql.SQLException

write

public void write()

write

public void write(java.io.OutputStream os)

write

public void write(java.io.PrintWriter pw)

getOriginalSchemas

public Schema[] getOriginalSchemas()

getAllTrans

public static java.util.List getAllTrans()

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

getCommonSchema

public Schema getCommonSchema(Transformation t)