EVEDemo.SWEEP
Class Relation

java.lang.Object
  |
  +--EVEDemo.SWEEP.Element
        |
        +--EVEDemo.SWEEP.StampedElement
              |
              +--EVEDemo.SWEEP.Relation
Direct Known Subclasses:
ViewDefinition

public class Relation
extends StampedElement
implements java.io.Serializable, java.lang.Cloneable

This is a class represent a Relational Database Table. We can create it from: 1. null 2. ResultSet from JDBC 3. File created by write() method We can following operations on it: 1. Join 2. Plus 3. Minus 4. Projection 5. delColumn Tuple Format: (values)[number] e.g. (5,6)[3] means we have three duplicate (5,6) tuples.

See Also:
Serialized Form

Field Summary
(package private)  java.lang.String alias
          Alias of this Relation.
(package private) static int objnum
          debug variable to trace how many relation object created.
(package private)  RelationExtent theExtent
           
(package private)  java.lang.String theName
           
(package private)  RelationSchema theSchema
           
 
Fields inherited from class EVEDemo.SWEEP.StampedElement
id, TimeStamp
 
Constructor Summary
private Relation()
           
  Relation(java.io.FileInputStream fin)
           
  Relation(java.sql.ResultSet rs, java.lang.String newName)
          this is a constructor of Relation from result set.
  Relation(java.sql.ResultSet rs, java.lang.String newName, Relation localrel, java.lang.String sign)
          This constructor will create a Relation from Resultset.
  Relation(java.sql.ResultSet rs, java.lang.String newName, java.lang.String sign)
          This constructor will create a Relation from Resultset.
  Relation(java.sql.ResultSet rs, java.lang.String newName, java.lang.String sign1, java.lang.String sign2)
          This constructor will create a Relation from Resultset.
  Relation(java.lang.String newName)
           
 
Method Summary
 java.lang.Object clone()
           
 java.lang.String createTableSQL()
           
 java.lang.String createTableSQL(java.lang.String sign)
          This function will create a table with sign field.
 void delCol(java.lang.String colName)
          Delete one column from the Relation
 void finalize()
           
 java.lang.String getAlias()
           
 int getCardinality()
           
 java.lang.String getCommon(Relation theRelation)
           
 RelationExtent getExtent()
           
 java.lang.String getName()
           
 RelationSchema getSchema()
          get Schema of this Relation.
 void initIterator()
          Cooperate with moreTuple and InsertTupleSQL, TupleSQL.
 void insertTuple(Tuple newTuple)
           
 int insertTupleSQL(java.lang.StringBuffer Query)
          Cooperate with moreTuple and initIterator.
 int insertTupleSQL(java.lang.StringBuffer Query, java.lang.String sign)
          Cooperate with moreTuple and initIterator.
 Relation join(Relation sndRelation)
          This method will join two relations and return the result.
 Relation joinVirtual(Relation sndRelation)
          This method will join two relations and return the result.
 Relation joinVirtualOn(Relation sndRelation, java.util.Hashtable JCAttrs)
          This method will join two relations and return the result.
private  java.lang.String makeConditions(java.lang.StringBuffer tupleValues)
          This function will generate the conditions from Relation Schema and the Tuple This function should be only used by method: insertTupleSQL().
 Relation minus(Relation sndRelation)
           
 boolean moreTuple()
          Cooperate with initIterator and InsertTupleSQL, TupleSQL.
 Relation plus(Relation sndRelation)
           
 void projectOn(Relation Rel)
          Do Project Operation.
 void rename(java.lang.String newName)
          Give this Relation a new name
 void setAlias(java.lang.String newname)
           
 void setExtent(RelationExtent newExtent)
          This function set the new extent of this relation.
 void setName(java.lang.String newName)
          Set New name for this relation.
 void setSchema(RelationSchema newSchema)
           
 java.lang.String toString()
          Convert Relation to String
 int updateTupleSQL(java.lang.StringBuffer Query)
          Cooperate with moreTuple and initIterator.
 void write(java.io.FileOutputStream fout)
           
 
Methods inherited from class EVEDemo.SWEEP.StampedElement
getTimeStamp, OlderThan, setTimeStamp
 
Methods inherited from class java.lang.Object
, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

theName

java.lang.String theName

alias

java.lang.String alias
Alias of this Relation. It used for Join Condition to keep track of Where this Relation comes from.

theSchema

RelationSchema theSchema

theExtent

RelationExtent theExtent

objnum

static int objnum
debug variable to trace how many relation object created.
Constructor Detail

Relation

private Relation()

Relation

public Relation(java.sql.ResultSet rs,
                java.lang.String newName)
         throws java.lang.Exception
this is a constructor of Relation from result set.

Relation

public Relation(java.sql.ResultSet rs,
                java.lang.String newName,
                java.lang.String sign)
         throws java.lang.Exception
This constructor will create a Relation from Resultset. Important part here, is that this constructor will search for the "SWEEPSIGN" field. if it is 'p', means positive; if it is 'n', means negative.

Relation

public Relation(java.sql.ResultSet rs,
                java.lang.String newName,
                Relation localrel,
                java.lang.String sign)
         throws java.lang.Exception
This constructor will create a Relation from Resultset. Important part here, is that this constructor will search for the "SWEEPSIGN" field. if it is 'p', means positive; if it is 'n', means negative.

Relation

public Relation(java.sql.ResultSet rs,
                java.lang.String newName,
                java.lang.String sign1,
                java.lang.String sign2)
         throws java.lang.Exception
This constructor will create a Relation from Resultset. Important part here, is that this constructor will search for the "SWEEPSIGN1" field and "SWEEPSIGN2" field. if they are same, means positive; otherwise, means negative.

Relation

public Relation(java.lang.String newName)

Relation

public Relation(java.io.FileInputStream fin)
Method Detail

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

setExtent

public void setExtent(RelationExtent newExtent)
This function set the new extent of this relation. It should check the consistency of current schema and current extent, but I haven't implement it.

getAlias

public java.lang.String getAlias()

setAlias

public void setAlias(java.lang.String newname)

setSchema

public void setSchema(RelationSchema newSchema)

insertTuple

public void insertTuple(Tuple newTuple)
                 throws java.lang.Exception

createTableSQL

public java.lang.String createTableSQL()

createTableSQL

public java.lang.String createTableSQL(java.lang.String sign)
This function will create a table with sign field. e.g. "col1, col2" will be "SWEEPSIGN, col1, col2"

initIterator

public void initIterator()
Cooperate with moreTuple and InsertTupleSQL, TupleSQL.

moreTuple

public boolean moreTuple()
Cooperate with initIterator and InsertTupleSQL, TupleSQL.

updateTupleSQL

public int updateTupleSQL(java.lang.StringBuffer Query)
Cooperate with moreTuple and initIterator. This function is only used for Create Temporary Table in Oracle. So, this function will ASSUME all the QUERYNUMBER should be POSITIVE. if the QUERYNUMBER is negative, it will genereate "delete" query.

insertTupleSQL

public int insertTupleSQL(java.lang.StringBuffer Query)
Cooperate with moreTuple and initIterator. This function is only used for Create Temporary Table in Oracle. So, this function will ASSUME all the QUERYNUMBER should be POSITIVE. if the QUERYNUMBER is negative, it will genereate "delete" query.

insertTupleSQL

public int insertTupleSQL(java.lang.StringBuffer Query,
                          java.lang.String sign)
Cooperate with moreTuple and initIterator. This function is only used for Create Temporary Table in Oracle. So, this function will ASSUME all the QUERYNUMBER should be POSITIVE. if the QUERYNUMBER is negative, it will genereate "delete" query.

makeConditions

private java.lang.String makeConditions(java.lang.StringBuffer tupleValues)
                                 throws java.lang.Exception
This function will generate the conditions from Relation Schema and the Tuple This function should be only used by method: insertTupleSQL(). The input stringbuffer should fit in such format: value1,value2,value3

getName

public java.lang.String getName()

getCommon

public java.lang.String getCommon(Relation theRelation)

getExtent

public RelationExtent getExtent()

write

public void write(java.io.FileOutputStream fout)

minus

public Relation minus(Relation sndRelation)
               throws java.lang.Exception

plus

public Relation plus(Relation sndRelation)

join

public Relation join(Relation sndRelation)
This method will join two relations and return the result. It is assumed the second Relation is already in the database.

joinVirtual

public Relation joinVirtual(Relation sndRelation)
This method will join two relations and return the result. It is assumed both relation are not on the database.

joinVirtualOn

public Relation joinVirtualOn(Relation sndRelation,
                              java.util.Hashtable JCAttrs)
This method will join two relations and return the result. It is assumed both relation are not on the database.

getCardinality

public int getCardinality()

toString

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

rename

public void rename(java.lang.String newName)
Give this Relation a new name

projectOn

public void projectOn(Relation Rel)
               throws java.lang.Exception
Do Project Operation. Project will project this relation on specific relation's schema. Here the new Relation's schema must be a subset of this relation's schema.

getSchema

public RelationSchema getSchema()
get Schema of this Relation.

setName

public void setName(java.lang.String newName)
Set New name for this relation.

delCol

public void delCol(java.lang.String colName)
Delete one column from the Relation