JRelix System Developer Guide

Aldat Lab,School of Computer Science,McGill University, Montreal

 

Table of contents:

1.  Introduction.. 1

1.1   Relational Algebra. 1

1.2   Domain Algebra. 1

 

2.  System Architecture. 3

 

3.  JavaCC... 5

3.1   Backus-Naur Form for the Parser 5

3.2   JavaCC tutorial 5

3.3   JavaCC in jRelix system.. 5

3.3.1   Install JavaCC on linux/unix: 5

3.3.2  Regenerate Parser files: 6

 

4.   JRelix Storage. 7

4.1   Relation Table. 7

4.2   Domain Table. 7

4.3   RelationDomain Table. 8

4.4   Expression Table. 8

 

5.  JRelix Class. 10

5.1   JRelix System Class Map. 10

5.1.1   Front-end. 10

5.1.2    Database Engine. 10

5.1.3   DataBase Maintainer 12

5.1.4   Distribute Database. 12

5.2   Java Class Analyst 12

5.3   Relationship among classes. 39

 

6.   Conclusion.. 50

 

Reference. 51

 

APPENDIX    JavaCC Tutorial. Error! Bookmark not defined.

 


1.  Introduction

This developer guide is summarized from Professor Tim Merret’s papers and all Aldat lab students M.Sc. theses and projects. It is a guide for coming students as well as for jRelix system maintenance.

 

The relational model for representing data was proposed by Codd [Cod70] in early seventies. The relational model, unlike other data models, has a rigorous mathematical definition. However, it has since then been recognized for its simplicity, uniformity, data independence, integrity and evolvability [Ger75].

 

At McGill, we established generalizations to the relational algebra and created the domain algebra, in order to provide a better basis for a programming language. These extensions also led to a better query language. We studied information system requirements and concluded that the extended algebra is sufficient for all the applications we had envisaged. We called this work the Aldat Project, standing for the algebraic approach to data. [MerWeb]

 

JRelix, a relational database programming language in Unix, was developed based DBMS at the Aldat lab of School of Computer Science, McGill. JRelix system was classified into three parts: relation algebra, domain algebra and computation [Yua98]. It’s an interpreted language written in Java language. In the relational model, information is represented in table format. Each row is called a tuple and the label of a column is called attribute. A set of values in a column is called a domain. JRelix is based on an algebraic data manipulation language proposed by Merrett [Mer77]. JRelix mainly deals with two kinds of data: relations and domains and two kinds of operations: relational algebra and domain algebra.

 

1.1   Relational Algebra

JRelix supports relational algebra operations:

 

1.2   Domain Algebra

JRelix supports domain algebra operations:

 

In jRelix, there are two kinds of attributes, “actual attributes” and “virtual attributes”. Attributes created by declaring primitive data type and ADT (Abstract Data Type) are called “actual attributes”. Attributes created by expressing the attributes as domain algebra operations on existing attributes are called “virtual attributes”. “Virtual attributes” means no actual values associated with them. The value of virtual attributes is actualized in a jRelix statement.

 

The most important is that jRelix system is a nested relation model. The nested relational model allows abstract data types to be defined for domains, and allows operations to be defined on them.

 

Top>>

 


2.  System Architecture

The jRelix system is a database system composed of three conceptual modules: a front-end processor, a database engine and a database manager.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Top>>


3.  JavaCC

Java Compiler Compiler (JavaCC) is an important generator tool in jRelix system. JavaCC is a parser generator. It provides a Java language extension for specifying a programming language’s grammar. It is used to specify the grammar of input stream.

 

The jRelix parser is created by using JavaCC with a Backus-Naur form. The jRelix parser reads the command-line input. Then, it analyzes the command syntax. If it is wrong, a message is displayed. If it is correct, it translates the command in order to build a syntax tree.

3.1   Backus-Naur Form for the Parser

The convention of the BNF definition is shown as followed,

Form

Meaning

<SYMBOL>

“SYMBOL”

S1 | S2

(SYMBOL)?

(SYMBOL)*

(SYMBOLS)

SYMBOL is a definition of token and must be substituted

SYMBOL is reserved word or symbol and must be typed as it is

Either S1 or S2 can be used

SYMBOL is optional

SYMBOL may appear zero or more times

Grouping SYMBOLS as one unit for high precedence

 

There are five token definitions:

3.2   JavaCC tutorial

This JavaCC tutorial is from web site: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-cooltools.html , by Oliver Enseling. The appendix shows the free document downloaded from the website.

3.3   JavaCC in jRelix system

3.3.1   Install JavaCC on linux/unix:

There are three steps to install JavaCC on linux/unix:

1. unzip JCC.zip

2. locate the file JavaCC0_6_1.class inside JCC and run this class to install

3. set path appropriately

3.3.2  Regenerate Parser files:

There are six steps to regenerate parser file after modification:

1. make sure you have these two java source files:Node.java and SimpleNode.java

2. enter command: jjtree Parser.jjt

3. enter command: javacc Parser.jj

4. enter command: jjdoc Parser.jj > Parser.html

5. remove ParseError.java

6. copy all *.java files into your the directory which contains all other java files for jRelix

 

NB: All modifications are made only to Parser.jjt. Don’t modify in Parser.java!


 

Top>>

 

4.   JRelix Storage  

JRelix storage format is the file on the hard disk. The information of all relations and domains in jRelix system is split into several system files: .rel, .dom, .rd, .expr, .comp and .surrogate. JRelix maintains three basic system tables on disk: domain table (.dom), relation table (.rel) and Relation-Domain table (.rd). 

 

4.1   Relation Table

The relation table information is stored permanently in a disk file named “.rel”. The storage fomat is:

Item

Type

Description

name

string

relation name

rvc

integer

type(RELATION,VIEW or COMPUTATION)

numtuples

integer

the number of tuples in this relation

numattrs

integer

the number of attributes in this relation

numsortattrs

integer

the number of sorted attributes

 

Information on all relations in the database is also maintained by a hash-table in memory, with relation names as hash keys. The structure format is:

 

Item

Type

Description

name

string

relation name

rvc

integer

type(RELATION,VIEW or COMPUTATION)

numtuples

integer

the number of tuples in this relation

numattrs

integer

the number of attributes in this relation

numsortattrs

integer

the number of sorted attributes

tree

SimplyNode

syntax tree root if it is a view

domain

Domain[]

Array of domain objects

data

Object[]

pointer to relation data

capacity

int

capacity of the array of column

 

As you can see from the above structure format tables, the items in file .rel are part of the items in memory.

 

4.2   Domain Table

The domain table information is stored permanently in a disk file named “.dom”. The storage fomat is:

Item

Type

Description

name

string

domain name

type

integer

domain type

numref

integer

the number of relations that reference this domain

 

Type in domain is BOOLEAN, SHORT, INTEGER, LONG, FLOAT, DOUBLE, STRING, TEXT, STMT, EXPR, IDLIST or COMP.

 

Information on all domains in the database is also maintained by a hash-table in memory, with domain names as hash keys. The structure format is:

 

Item

Type

Description

name

string

domain name

type

integer

domain type

tree

SimpleNode

the syntax tree if it’s a virtual domain, otherwise null

numref

integer

the number of relations that reference this domain

 

As you can see from the above structure format tables, the items in file .dom are part of the items in memory.

 

4.3   RelationDomain Table

Information that links the relations with the domains on which they are defined is maintained by RelationDomain table. This kind of information is stored permanently in a disk file named “.rd”. The structure format is:

Item

Type

Description

relName

string

relation name

domName

string

domain name

position

integer

the position of this domain in current relation

 

 

4.4   Expression Table

The definitions of virtual domain and views are represented by expression syntax trees. For example,  “let x be b+c;”, where x is a virtual domain, the expression tree is :

Oval: Dec
Oval: b Oval: c
 

 

 

 

 

 

 


Information about all expression syntax trees is stored in disk file “.expr”. When jRelix system is running, a temporary hash-table is used by ExprTable calss to store expression trees.


Top>>

 

5.  JRelix Class

There are many java classes in jRelix system. This part will analyze them in detailed.

5.1   JRelix System Class Map

In jRelix system, there are three parts: a front-end processor, a database engine and a database manager. ( See Section 2: System Architecture)

5.1.1   Front-end

Name                                      Description

  1. JRelix                                       Main Program
  2. JRelixlnputStream                  Extends BlocklnputStream
  3. JRelixParser                             Extends Parser
  4. Parser*                                    Language Parser
  5. ParserTokenManager*            Supports Parser
  6. ParserConstants*                    Supports Parser
  7. ParserTreeConstants*             Supports Parser
  8. ParseException*                     Supports Parser
  9. ParseError                                Supports Parser
  10. ASClLCharStream*                Supports Parser
  11. Token*                                    Supports Parser
  12. TokenMgrError*                      Supports Parser   
  13. Node*                                     Syntax Tree Node Structure
  14. SimpleNode                             Enhanced Node Structure   
  15. Interpreter                                Interprets Syntax Trees   
  16. PrettyPrint                                Formats Display Output    
  17. Constants                                 Operation Constants       
  18. InterpretError                           Supports Interpreter      
  19. Global                                      Global Variables/Methods  

Files with “*” are machine generated; developer cannot modify them directly.

5.1.2    Database Engine

Name                                      Description

  1. Constants                                 Operation Constants
  2. InterpretError                           Supports Interpreter
  3. Global                                      Global Variables/Methods
  4. Relation                                    Implements Relational Algebra    
  5. RelTable                                   Supports Relation Lookup  
  6. RelInfo                                     Extends IDInfo for Relation 
  7. Domain                                    Implements Domain Algebra 
  8. DomTable                    Supports Domain Lookup  
  9. DomInfo                                   Extends IDInfo for Domain
  10. Actualizer                                 Implements Virtual Domain Actualization
  11. Actualizer76                             Supplements Actualizer
  12. Environment                             System Environment
  13. SemanticChecker                    Semantic Check of User Input
  14. SemanticCheckError               Supports Semantic Check
  15. TypeConstants                         Data Type Constants
  16. Surrogate                                 Surrogate Values
  17. Utility                                       Various Utilities
  18. NREnvironment                        Nested Relations Environment
  19. NRInfo                                     Extends IDInfo for Nested Environment
  20. Computation                             Implements Computation
  21. CompBlock                  Supports Computation
  22. CompTable                              Supports Computation
  23. IDInfo                                      Stores Variable Information
  24. LocalInfo                                  Extends IDInfo for Local Variables
  25. ParamInfo                                Extends IDInfo for Parameters
  26. StateInfo                                  Extends StateInfo_2002 for States
  27. StateInfo_2002                        Supplements StateInfo, Extends IDInfo for States
  28. EvalExpr                                  Evaluation of Expressions
  29. Gedit**                                    GIS Editor Related Classes
  30. AddLayersDialog                     Supports GIS 
  31. CvDraw                                   Supports GIS
  32. Legend                                     Supports GIS
  33. TriggerNode                             Supports Active Database
  34. CTrigger                                   Supports Active Database
  35. number                                     Implements Numerical Data Type
  36. ExprEntry                                 Entry for .expr System File
  37. ExprTable                                Supports .expr Maintenance
  38. CastToBool                              Cast to Boolean value
  39. CastToBoolByte                       Cast to Byte value
  40. CastToDouble                          Cast to Double value
  41. CastToFloat                             Cast to Float value
  42. CastToLong                             Cast to Long value
  43. CastToInt                                 Cast to Integer value
  44. CastToShort                             Cast to Short value
  45. CastToNum                             Cast to “number”
  46. CastToStrn                               Cast to String value

 

Gedit** means all the classes named begin with “Gedit”.

5.1.3   DataBase Maintainer

Name                                            Description

1.   ExprEntry                                 Entry for .expr System File

  1. ExprTable                                Supports .expr Maintenance
  2. BlocklnputStream                   Disk Input Operations
  3. BlockOutputStream                Disk Output Operations

 

5.1.4   Distribute Database

This part is for distribute database in jRelix.

Name                                            Description

1.   aldatpClient                              Client side

  1. aldatpHandler                           handle client and server
  2. aldarpServer                             server side
  3. aldatpTld                                 
  4. aldatpUtility                  utilities for distribute database

 

5.2   Java Class Analyst

This part will analyze lots of important java classes in alphabet.

 

5.2.1        Actualizer class

In jRelix, a virtual attribute is actualized with a tuple-by-tuple approach. The actualized class handles the actualization of virtual attributes. First, the class constructor involves a series of validity checks such as type and loop-declaration. Then, after the validity checks are passed, all virtual attributes will be actualized. There are some important methods: Actualizer(),buildTree() and actualize() (starred in the following list).

public class Actualizer extends Actualizer76 {

    //debugging

    private static boolean DEBUG = false;

    private static boolean debug_oct_5 = false;

    private static boolean debug_oct_52 = false;

    private static boolean debug_nov_24 = false;

    private static boolean debug_dec_14 = false;

   

    public static final int ACC_RESET = 100; // from sungsoo

    public static final int ACC_BYPASS= 200; // from sungsoo

    public static final int ACC_ACCUM = 300; // from sungsoo

   

    private Environment env;

    Hashtable relhtbl = null;

    private NREnvironment NRenv;

   

    private static final long startTime = System.currentTimeMillis();

    private Relation srcrel;      // source relation.

    private Relation destrel;     // destination relation.

    private Domain[] destdoms;    // destination domains.

    private Vector virdoms;       // vector for virtual domains (Domain object).

    private Vector actdoms;       // vector for actual domains (Domain obj).

    private Vector alldoms;       // vector for all domains involved.

    private Hashtable vvtree;

    private int fdomcounter = 0;  // temp domain counter for RED & EQUIV.

   

    // Transient varibles.

    private int currow;           // the row# currently passing.

    private Vector curpath;       // Vector for detecting recursive definition.

    private Hashtable vertdom;    // domains containing red or equiv operations.

    private int vertlevel = 0;    // current let of vertical operations.

    private int maxvertlevel = 0;

   

    private boolean nt = false; // new technology for nested domain actualization.

    public static Interpreter interpreter; // nt will use interpreter routines.

    private Vector nestdoms;      // vector for nested domains.

    private Hashtable nesthashs;  // each nested domain has a hashtable.

    private Vector tempnames;

   

    private Vector dom_tempnames;

   

    private Domain[] origDoms = null; // holds the orignal domains passed to ctor

    private Hashtable origTreeTable = null; // holds the original tree of a virtual dom

 

*   Actualizer(Domain[] doms, Relation srcrel, Environment env)    throws InterpretError{} //constructor

    private void Actualizer_old(Domain[] doms, Relation srcrel, Environment env) throws InterpretError {}

    private byte actBoolCell(SimpleNode node) throws InterpretError{} //Actualize a boolean-typed cell

    private byte actBoolCell_old(SimpleNode node) throws InterpretError { }   //handle the case of DC, DK

    private double actDoubleCell(SimpleNode node) throws InterpretError { } //Actualize a double-typed cell.

    private number actNumCell(SimpleNode node) throws InterpretError { } //Actualize a numeric-typed cell

    private int actIntCell(SimpleNode node) throws InterpretError { } // ctualize a integer-typed cell.

    private long actCompCell(SimpleNode node) throws InterpretError {} // Actualize a COMP  cell

    private long actLongCell(SimpleNode node) throws InterpretError { } //Actualize a long-typed cell.

    private Relation actRelCell(SimpleNode node, Vector dnames, Vector rname,Vector rindx, Hashtable relhtbl, String tname0, String tname1) throws InterpretError { } //Actualize an IDLIST-typed cell

    private String actStrCell(SimpleNode node) throws InterpretError { } //Actualize a string-typed cell.

    private long actUniCell(SimpleNode node) throws InterpretError {} // Actualize a string-typed cell

*   public Relation actualize() throws InterpretError { } // Actualize the virtual domains

    private void restoreTree() { }// restore the original virtual domain trees

    private void actualizeEquiv(Domain dom) throws InterpretError { } //Actualize the EQUIV-typed virtual domains.

    private void actualizeNestedDom(SimpleNode jnode, Hashtable htable, Hashtable relhtbl) throws InterpretError {}   // Actualize a nested domain

    private void actualizeNestedEquivDom(SimpleNode jnode, Hashtable htable, Hashtable relhtbl) throws InterpretError { } //Actualize a nested domain (equivalence)

    private void actualizeNestedJoinDom(SimpleNode jnode, Hashtable htable, Hashtable relhtbl) throws InterpretError { } //Actualize a nested domain (join operations)

private void actualizeNestedPrjSelDom(SimpleNode jnode, Hashtable htable, Hashtable relhtbl) throws InterpretError { }//Actualize a nested domain (project operation)

    private void actualizeNestedRedDom(SimpleNode jnode, Hashtable htable, Hashtable relhtbl) throws InterpretError {  }  //  Actualize a nested domain (reduction) using

    private void actualizing(Domain[] doms, int type) throws InterpretError { }//Actualize the virtual domains (including RED virtual domain).

    private Relation evalQTSelector(Object[] data, int numtuples) throws InterpretError { } //for QT evaluation

    private void qtCountValue(int current,Object[] data,Domain d,int i,Vector v)  throws InterpretError { }

    private int qtFindBrkPos(int previous,int current,Object[] data, Domain[] doms) throws InterpretError { }

    public static final long age(){} // Display current age in mili-seconds

    private void buildExpressionList(SimpleNode n) throws InterpretError { } // Build expand the tree for expression list.

    private Domain Contains(Vector allD, Domain d) { } // get the domain in allD

*  private int buildTree(SimpleNode node)   throws InterpretError { }// Building the actulization tree

     public void cleanup() {}

     public void cleanup_old() {}

     private void compareTwoRows(Relation rel) throws InterpretError { }

    private int equivSubrel(Relation destrel, int[] vals) { }

    private void fillSurrogate(Relation rel, long ref, long sur) { }

    private Domain getDom(String name) { }

    private Relation getMiniSet(Relation srcr, Domain[] srcdoms) throws InterpretError { }

    public Relation getRel(){} //Return an un-named memory-version relation

    public Relation getRel(String relname)  throws InterpretError { } Return a named/disk-saved relation.

    private void preProcIDListDom(SimpleNode node, Vector doms, Vector rname,Vector rindx) throws InterpretError { } //self-recursive method to process an entire virtual IDList domain.

    private Relation processIDListDom(SimpleNode node, Hashtable htable, boolean flag)throws InterpretError { } //hold the intermediate relations

    private int processRedNode(SimpleNode node, SimpleNode n, int j)  throws InterpretError{ }

    private void resetNodeBits(SimpleNode node)  throws InterpretError {} // Reset the value of node.bits

    private SimpleNode IsInTree(SimpleNode node, int op_type) {} // contains this operator?

    private boolean actBoolRelCell(SimpleNode node, Vector vdom, Vector rname, Vector rindx, String tname0, String tname1)  throws InterpretError{ } // converted into a boolean value from a boolean compatible relation/IDLIST cell.

    private void actualizeParFun(Domain dom) throws InterpretError {} // Partial Functional Mapping Implementation

    private void actualizeFun(Domain dom) throws InterpretError {}

    private void AccumulateDom(SimpleNode node, int accum_type, int virtual_type) throws InterpretError { }

// Functional and Partial Functional mapping

    private void RedFunCallAccumNode(SimpleNode node, int nodeType, Object actValueObj) throws InterpretError { }//implementing function call in vertical domain algebra

    private Relation actRelCellWithNull(SimpleNode node, Vector dnames, Vector rname, Vector rindx, Hashtable relhtbl, String tname0, String tname1) throws InterpretError { //Actualize an IDLIST typed cell.

   private boolean actBoolRelCellWithNull(SimpleNode node, Vector vdom, Vector rname, Vector rindx, String tname0, String tname1) throws InterpretError { } // converted into a boolean value from a boolean compatible relation/IDLIST cell.

}

 

 

5.2.2   Actualizer76 class

This class is modified for adding some infomation to Actualizer for QT evaluation.

public class Actualizer76 implements Constants, TypeConstants

 {

   // Transient varibles for QT actualization.

   protected boolean qtActive = false, cond = false,projIsSth = false; // if(qtActive):  QT actualization is on

   protected int p,q;

   protected Domain curdom;

   protected Domain[] predList;

   protected SimpleNode qtCond;

   protected Vector intType, doubleType;  // intType: stores #, doubleType: stores "." and "%"

  //Constructor (Virtual)

  Actualizer76() throws InterpretError {}

 }

 

 

5.2.3    BlockInputStream class

This class is used to implement the block access the data on disk. The instances of this class are constructed with two arguments: disk file name and buffer size.

public class BlockInputStream extends DataInputStream implements TypeConstants{

   public BlockInputStream(String filename, int buffersize)   throws IOException, FileNotFoundException  {  }     

   public BlockInputStream(DataInputStream DIS) {  }

   public String readString(String s)  throws IOException {  }

   public String readText(String s)   throws IOException  {  }     

}

 

 

5.2.4    BlockOutputStream class

This class is used to implement the block access the data on disk. The instances of this class are constructed with two arguments: disk file name and buffer size.

public class BlockOutputStream extends DataOutputStream implements TypeConstants{

   public BlockOutputStream(String filename, int buffersize)   throws IOException   {   }     

   public void writeString(String s)   throws IOException{   }     

   public void writeText(String s)   throws IOException  {  }     

}

 

 

5.2.5   CompBlock class

This is a class to support “Computation class” for storing information about an "alt" block in a convenient way.

class CompBlock implements Constants, TypeConstants {

   //Debugging:

   private boolean DEBUG=false;

   public int blockType;           //Type of the block

   public SimpleNode[] statements; //Statements contained in the block

   public int numStatements;       //Number of statements in this block

   public SimpleNode blockTree;    //pointer to jjTree for this block

 

//addition by Yi Zheng July 8, 2002

   public boolean redop = false;  //true if can be used as associative commutative operator

   public boolean funop = false; // true if can be used as ordered operator

//end of addition by Yi Zheng July 8, 2002

 

   private final int INPUT = 0;

   private final int OUTPUT = 1;

 

   public CompBlock(SimpleNode block, Environment env, SimpleNode tree)   throws InterpretError, SemanticCheckError  {     }

   public void dump(int blocknumber)   {   }

   public void dump()  { }

   private void findBlockType(SimpleNode stmt, Environment env)   throws InterpretError { } //implements block algorithm on one stmt of the comp

   private void updateStatus(int newStat, SimpleNode node, Environment env)  throws InterpretError { }

}

 

 

 

5.2.6   CompTable class

This class CompTable is used to store computation objects that are in a column of some relation. A surrogate is used to identify the individual computations.

public class CompTable {

    private Hashtable table;

    public CompTable() { }

   public void addEntry(long surrogate, Computation comp){} //Add an entry to the table.

   public void addEntry(String name, Computation comp) { } //Add an entry to the table.

   public void addEntry(String fullName, Long surrogate) { } //Add an entry to the table.

   public void fillExprTable(Hashtable exprTable) {} // Fill the exprtable (a hashtable) before dumping the expressions

   public Computation lookup(long surrogate){}

   public long lookup(String fullName) {}// look up the surrogate value of a computation by its full name

   public Hashtable getCompTable() { }

}

 

5.2.7   Computation class

This class implements computation. There are sevral methods are explained as following:

 * The constructor handles a computation declaration.

 * Method applyIjoin() handles the application of the computation with a relation.

 * Method applySelect() handles the application of the computation with a select statement.

 *   -- applySelect(Relation rel,int currow ...) is overloaded for implementing accessor methods of ADT

 * Method applyInOut() handles a stand-alone computation call

 *   -- applyInOut(Relation rel, ...) is overloaded for implementing modifier methods of ADT

 * Method duplicate() returns a duplicate of this Computation

 * Method print() is overloaded for the pr command on computation

 * Method sc() is for the sc command

(Starred the above methods in the following list)

class Computation extends Relation implements Constants,TypeConstants {

   private boolean DEBUG=false;

   public Environment stateEnv;        //stateEnv stores all state vars in a user session for this computation

   public boolean isIjoin;//distinguish between Ijoin and Select invocation

   public String parentName = new String("");//record the environment in which this comp is defined

   public boolean TOP_LEVEL_INOUT=false;//to distinguish between top level invocation by in/out syntax

   public boolean UPDATE = false;//to distinguish between calls made from within UPDATE

   public CompBlock[] blocks;    // The "alt" blocks of the computation

   private Environment declEnv;  // Pointer to parent environment

   private Domain[] joinAttrs;  //The input attributes

   private Domain[] extraAttrs; //attrs that aren't part of calculation

   public static Interpreter interpreter;

 

*  public Computation(SimpleNode node, Environment declEnv)   throws InterpretError

*   public void print(int[] lens, boolean flag){}

*   public void sc(){}

*   public Relation applyIjoin(Relation rel, Domain[] domsc, Domain[] domsr, String filename, Environment callEnv)   throws InterpretError { }

*  public void applyInOut(SimpleNode node, String filename, Environment callEnv)throws InterpretError {}

*  public Relation applySelect(SimpleNode select, String filename,Environment callEnv)   throws InterpretError {}

*   public Relation applyInOut(Relation rel, SimpleNode node, Environment callEnv) throws InterpretError {} //nested

*   public Relation applySelect(Relation rel, int currow, SimpleNode select, String filename, Environment callEnv)  throws InterpretError {}

*  public Computation duplicate()   throws InterpretError { }

    private void reGenerateBlocks(SimpleNode tempTree)   throws InterpretError  {} //generate domains and blocks for this computation

    private boolean isReplaceable(IDInfo id) throws InterpretError{ }

    private void transformStmt(SimpleNode stmt, Environment env) throws InterpretError { }

    private void transformExpr(SimpleNode node, Environment env) throws InterpretError {}

    private void runSingleStmtInUpdate(Relation rel, SimpleNode stmt, Environment tempEnv, NREnvironment NRe) throws InterpretError {}

   private boolean constraintMode(Domain[] joinAttrs, Environment env) { } // Check if this computation is being run in constraint mode

   private Domain[] extraDomains(Domain[] doma, Domain[] domb) {}  // Return the domain array whose elements are those which are in domb but not in doma.

   private Domain[] extraDomains2(Domain[] doma, Domain[] domb, Hashtable tbl) {}

   private CompBlock findBlock(Domain[] joinAttrs, Environment env)   throws InterpretError {} // Decide which "alt" block to use this time around.

   private void initializeData(Relation rel, Environment env, Domain[] tempJoinAttrs) {} // Initialize the data array

   private Environment initializeEnvironment(SimpleNode node,   Environment env, Environment callEnv)   throws InterpretError {}

   private Relation makeRelation(String name, Environment env)  throws InterpretError {} //Make this computation into a relation on the current 'data'

    private Domain[] replaceJoinAttrs(Domain[] doms, Hashtable tbl) throws InterpretError {} // replace join attributes

    private void parseSelectConditional(SimpleNode node, Vector inputDoms, Environment env, Environment callEnv)   throws InterpretError {} // parses the conditional expression in the selector

   private int processCallParams(SimpleNode callParams, String prefix,      Environment env, Environment callEnv) throws InterpretError {} // put input call parameters into LocalInfo objects

   private void renameIDs(SimpleNode node, String prefix, Environment env)   throws InterpretError  {} // It renames the identifiers in the syntax tree

   private void run(CompBlock block, Environment env)   throws InterpretError {}

   private void renameParamsInTree(SimpleNode tree, Hashtable tbl) {}

   private void renameParamInTree(SimpleNode tree, String oldName, String newName)  { } // rename a single parameter

   private void runConstraint(CompBlock block, Environment env, Vector failRows) throws InterpretError {} // run constraint mode

   private Relation makeRelationConstraint(String name, Environment env, Vector failRows) throws InterpretError {} // update env.data to delete rows that failed constraint testing and make a relation of the final result

    private void runSingleStmtConstraint(SimpleNode stmt, Environment env, Vector failRows)   throws InterpretError {} //simplest cases are implemented

   private void runSingleStmt(SimpleNode stmt, Environment env)  throws InterpretError  {} //method called by run

   private Domain[] getHiddenDoms(Relation rel) {} //get the states in rel

}

 

 

 

5.2.8   Constants class

This abstract class is about all static constants in jRelix system.

5.2.9    CTrigger class

This class is about trigger determination.

class CTrigger {

                Relation oldp;       // the parts of relation will be updated

                Relation newp;     // the updated parts of relation

                Relation restp;      // the parts of relation won't be updated

                String     relname; // the name of relation to be updated

                CTrigger(Environment env) { } //constructor

                }

                CTrigger(String rlname) { } // constructor

}

 

 

 

5.2.10   Domain class

This class encapsulats a single entry in .dom system table. These entries are described in the documentation for the DomTable class.

public class Domain implements TypeConstants, Constants

{  public String name;    //name of this domain

   public int type;       //type of this domain

   public int numref;     //a reference count of the number of relations defined on this domain,

   public SimpleNode tree;//sytax tree if the domain is virtual, else null

   public int isStateDom = 0;//1 if this domain is declared as a state var of a computation

   public int isRedTemp = 0; //1 if this is a temporary representing a reduction used for level lifting    public int     

   public int isRedTempTop = 0; //1 if this is a temporary domain as in the following case: A <- [red ujoin of U] in R;

   public Domain () {}  // constructor

   public Domain(String name, int type, Domain[] domlist, Environment env)  throws InterpretError {} //constructor

   public Domain(String nm, int tp, int ref, SimpleNode nd) {} //constructor

   public Domain duplicate(Environment env) throws InterpretError {}

   public SimpleNode getTree() {} // Get the syntax tree for virtual domain.

}

 

5.2.11   DomTable class

This class stores and accesses .dom system relation in memory. Some information from the .rd system table is kept in class DomTable as well. This class also is the information describing what attributes each domain is defined on and for nested relations. The .dom system relation is as follows:  .dom (.name  .type  .numref)  where .name is for the domain, .type is the type of the domain: intg, strg, bool, or rel. and .numref   is number of reference .

public class DomTable implements TypeConstants, Constants{

   private boolean DEBUG=false;

   private static final int BUF_SIZE = 16 * 1024;

   private static final String DOM_NAME = ".dom";

   private static final String RD_NAME = ".rd";

   private Hashtable table; //storing all the domains.

   private RelTable reltable;

   private Environment env;

   public DomTable(Environment env, boolean load)  {} //Initialize the hash table, and load domain information from disk files .dom & .rd.

   public void addDom(Domain d) {} // Add a domain object to this domtable.

   public void dump(){ }Dump this domain table to .dom and .rd

   public void fillExprTable(Hashtable exprTable) {} // Fill the exprtable (a hashtable)

   public Domain getDom(String name){}

   public Vector getDoms(String domname){} Get the attributes that a domain is defined on

   public int getType(String name) throws InterpretError{} //the type of a domain.

   public Enumeration keys()

   private void load(){} //Load domain information from disk files(.dom).

   public boolean rmDom(String name){} // Delete a domain from the DomTable

   public void showDom(Domain doment) {} //Print the information for one domain.

   public void showTable(boolean flag){} // Print the domain table.

   public int getDomTableSize() // provide the size of the domTable

}

 

 

5.2.12   Environment class

This class implements a frame of an environment. It consists of entries of five different "kinds": PARAM, LOCAL, STATE, REL and DOM. These are subclasses of IDInfo which provide convenient storage for each of these, respectively.

 class Environment implements Constants, TypeConstants { 

   private boolean DEBUG=false;

   private Environment parent;   //Pointer to parent environment

   private NREnvironment NRenv;  //For use with domain algebra

   private Hashtable table;  //Table holding information about params, locals and states

   public RelTable reltable; //For holding local domains and relations

   public DomTable domtable;

   public Object[] data; //used in computation

   public int row;//used in computation

   public boolean constraint_mode = false;//added by Yi Zheng March 31, 2002

   public TriggerNode triggerroot;

 

   public Environment() {}

   public Environment(Environment parentEnv) {}

   public Environment(RelTable prel, DomTable pdom)  {}

   public Environment(Environment parent, Hashtable tbl, RelTable prel, DomTable pdom) {}

 

   public void setParent(Environment pEnv) {}

   public Environment getParent() {}

 

   public NREnvironment addNRFrame(Relation r) {}

   public void clear() {}

   public void dump(boolean dumpParent)   throws InterpretError {}

   public String[] getStateNamesLocal() {} //NEEDED BY COMPUTATIONS

   public IDInfo lookup(String name, boolean searchParent) {}

   public Domain lookupDom(String name, boolean searchParent) {}

   public ParamInfo lookupParam(String name) {}

   public NRInfo lookupNR(String name, boolean searchParent) {}

   public ParamInfo lookupParam(String name, boolean searchParent) {}

   public Relation lookupRel(String name, boolean searchParent)   throws InterpretError {}

   public Relation lookupNestedRel(String name, boolean searchParent)  throws InterpretError {}

   public Relation lookupNestedRel(String name, boolean searchParent, int rrow)  throws InterpretError {}

   public Relation lookupRelSurr(String name, boolean searchParent)   throws InterpretError {}

   public long getSurrogate(String name)   throws InterpretError {}

   public void setSurrogate(String name, long sur)   throws InterpretError {}

   public void purge() {}

   public void put(Domain d) {}

   public void put(String name, IDInfo id) {}

   public void put(String name, IDInfo id, boolean searchParent) {}  //method used to export inner computations to parent environment(s)

   public void put(Relation r)  throws InterpretError {}

   public void put2(Relation r, Environment envFound)   throws InterpretError { } //put the relation in the designated environment

   public void removeNRFrame() {}

   public void removeRel(String name, boolean searchParent) {}

   public void removeDom(String name, boolean searchParent) {}

   public void removeParam(String name) {}

   public Environment removeRel2(String name, boolean searchParent) {}

   public String opcodeToString(int opcode)    throws InterpretError {}// convert opcode to string to represent the prefix/action name in event handle

   public int stringToOpcode(String str)   throws InterpretError {} // convert string that represents the prefix/action name in event handle to opcode

  public String getEventName(SimpleNode node)   throws InterpretError  { } //to get an actual event name from a tree.

}

 

5.2.13   EvalExpr class

This class contains evaluators for expressions that should return one of the follwoing types:Boolean short, integer, long, float, double and string.

class EvalExpr implements Constants, TypeConstants {

    private static boolean DEBUG = false;

    public static boolean WEIZHONG = false;

   public static Interpreter interpreter; //In order to use evaluateTLExpression() in Interpreter class

   static Hashtable emptyht = new Hashtable();   //Empty hashtable needed as hack since evaluateTLExpression()

   public static boolean evalBooleanExpr(SimpleNode node, Environment env)  throws InterpretError {}

   public static double evalDoubleExpr(SimpleNode node, Environment env)   throws InterpretError {}

   public static float evalFloatExpr(SimpleNode node, Environment env)   throws InterpretError {}

   public static int evalIntExpr(SimpleNode node, Environment env)     throws InterpretError {} //the fix is to enhance StateInfo object with value holders

   public static int evalIntExpr_old(SimpleNode node, Environment env)   throws InterpretError {}

   public static number evalNumExpr(SimpleNode node, Environment env)   throws InterpretError {}

   public static long evalLongExpr(SimpleNode node, Environment env)   throws InterpretError {}

   public static short evalShortExpr(SimpleNode node, Environment env)   throws InterpretError {}

   public static String evalStringExpr(SimpleNode node, Environment env)  throws InterpretError {}

   public static Object evalObjectExpr(SimpleNode node, Environment env)   throws InterpretError {}// for in If case

}


5.2.14   ExprTable class

This class stores and accesses .expr system relation in memory.

public class ExprTable implements Constants, TypeConstants {

  private static final String EXPR_FILE_NAME = ".expr";

   private Environment env;

   private RelTable reltable;

   private DomTable domtable;

   private CompTable comptable;

   private Hashtable exprtable;    // expression table.

 

   public ExprTable(Environment env, CompTable comp)   throws InterpretError {}

   public void dump() {}   // Dump the expression information to disk file .expr.

   public void load()  {} throws InterpretError {}  // Load the expression information from .expr and .view.

   public void showTable(){}   // Print table information.

   public void showTable2(){  }//Orignial version: Print table information.

   public Hashtable getExprtable() { }

}

 

5.2.15  Global class

This class contains global attributes/methods for sharing.

class Global  implements TypeConstants, Constants{

  private static boolean DEBUG=false;

  public static Environment environment;  //global Environment

  public static CompTable comptable; // global Tables

  public static ExprTable exprtable;

  public static JRelixInputStream jin;  // the JRelixInputStream for the parser

  public static int status;  // the status of the current parser

  public static SimpleNode root;  // the root of the current JJTREE

  public static long interpretTime;  // the interpret time of the current JJTREE

  public static Stack aldatp_list;  // the aldatp servers invoked by this JRelix run

  public static int start_type; //0:stand-alone 1:server.

  public  static Stack availablePort ;// top level server stores the available reserved port number for the sub server.

  public  static Hashtable services ;// top level server 's dictionary: sub server's path and it's port number.

  public static int active_threads = 0; //the number of active threads

  public static boolean permit_start = true ; //true: allow new threads be forked

  public  static Hashtable DataFileSet = new Hashtable(); //store the removed relation files' mode

  public  static Hashtable userHomes = new Hashtable(); //store user names and home directorys

  public static boolean debug = false;    //debug toggle, true for ON

  public static boolean batch = false;    //batch toggle, true for ON

  public static boolean expert = false;   //expert toggle, true for ON

  public static boolean time = false;     //time toggle, true for ON

  public static boolean trace = false;    //trace toggle, true for ON

  public static boolean ssd = false;

  public static boolean ssr = false;

 

  public static final InputStream instream = System.in;

  public static final PrintStream outstream = System.out;

  public static PrintStream traceoutstream = null;

 

  private static final String RD_NAME = ".rd";

  private static final int BUF_SIZE = 16 * 1024;

 

  static { }

  public static void beforeInterpret() {}// implements the action needed before the Interpret

  public static void afterInterpret() { }// implements the action needed after the parsed node is interpreted.

  public static void afterSRDInterpret() { } // implements the action needed after the parsed node is interpreted.

  public static void beforeParse() {} // implements the action needed before the user input is parsed.

  public static void afterParse(Environment env) {} throws InterpretError // implements the action after the user input

  public static void traverse(SimpleNode node) {}

  public static void cleanup(SimpleNode node) { }

  public static void switchNode(SimpleNode node) {}// implement using...change as alternative to change...using in updates

  public static  void filterFile (String source, String target)

  public static void exit(int status) {} // for distribute database to exit connection

  public static void quit(int status) { } //quit from jRelix

  public static void save() {} //save all information into disk

  private static void fillDomArray(Domain[] doms,String domname, int index, Environment env)throws InterpretError {}

  public static void flush() {}

  private static void init() throws InterpretError //added by Yi Zheng March 18, 2002

  private static void loadRDTable(Environment env) throws InterpretError{} // load the Relation/Domain (RD) tables from the files on disk

   private static void populateInitData(String relName, Environment env) throws InterpretError {} // populates .rel, .dom, .rd system relations at startup and stores them on to disk

   public static void print(String name) {}//This method print a String.

   public static void println(String name) {} println a String

   public static void print(Throwable e) {} // print a Throwable

   public static void println(Throwable e) { }// println a Throwable

   public static void printHead () { } //print the jRelix head.

   public static void processThrowable(Throwable e) {}

   public static void processThrowable(Throwable e, PrintStream out) {}

   public static int saveCompCode(Environment env) throws InterpretError {} // Save the user input text for the computation declaration if it is.

   public static void tracePrint(String name) {} // print a String to the OutputStream for the trace.

   public static void tracePrintln(String name) {} // println a String to the OutputStream for the trace.

}

 

5.2.16   IDInfo class

This abstract class is a structure that stores information about all the parameters and variables in a computation. This includes for each variable:

*what is its kind? (PARAM, LOCAL, STATE..)

                        * is it a local variable?

                        * if so, what is its current value?

                        *which column is the (local?)/state var or parameter in?

 

 public abstract class IDInfo implements TypeConstants {

     public int kind = RELIX_VOID;

     public int inoutStatus = RELIX_VOID; //used only by the block type algorithm when a computation is declared.

     public int type = RELIX_VOID;

      public IDInfo() {}

      abstract void dump();

}

 

5.2.17  Interpreter class

This class receives a syntax tree from parser class and dispatch function calls into the database. A single Interpreter object is instantiated and used throughout a user session of jRelix system. Several jRelix command functions such as help, quit, pr and etc are implemented in this class. It also provides methods that perform basic validity check.

 

public class Interpreter implements Constants, TypeConstants{

  private boolean DEBUG=false;

  private boolean DEBUG_09_22_2002 = false;

  public Environment env;   // the top level environment

  private CompTable comptable; // Relation system table

  private ExprTable exprtable;             // Expression system table

  private Parser parser;        // the parser

  private Stack instack;      //stack for old input streams

  private InputStream in;     //current parser input stream

  public static final String temp_name_prefix = "_temp_X9X_";

  private static final int MAX_TEMP_FILE = Integer.MAX_VALUE;

  private static int next_number = 0;

  private static final int MAX_INITIALIZE_SIZE = 10000;

  public Relation destrel = null;

  public int currow = -1;

 

  public Interpreter () { }

  private void assignLiteral(Relation rel, int i, int offset, SimpleNode node)  throws InterpretError{}

  private Vector CreateDAG(String relname, Environment env) throws InterpretError {}

  private void CreateData(Hashtable ht, String name, Environment env) throws InterpretError{}  // create data array for a relation and put the relaton into the hashtable

  private Hashtable CreateDataHashTable(String name, Environment env)    throws InterpretError {} // Create all relations and their data arrays and use hashtable to store all relations

  public static void deleteFile(String filename)  {}// delete a data file on disk

  private boolean equals(Relation rl, Relation rr)  throws InterpretError {}

  private Relation evaluateJoin(SimpleNode node, String filename, Hashtable htable, Environment env) throws InterpretError {}//evaluating the join specified in the node's tree.

  private Relation evaluateGedit(SimpleNode node,String filename, Hashtable htable, boolean flag, Environment env, Domain[] doms) throws InterpretError {}

  private Relation evaluateProject(SimpleNode node, String filename,   Hashtable htable, boolean flag, Environment env)    throws InterpretError{}

  private Relation evaluateQSelect(SimpleNode orgNode, String filename,   Hashtable htable, Environment env)       throws InterpretError {}

  private Vector qtEvaluateProj(SimpleNode node,Environment env, Vector allDoms) throws InterpretError{}

  private Vector qtEvaluateQuantDom(SimpleNode node,Environment env,Vector allDoms) throws InterpretError {}

  private Domain[] qtEvaluatePred(SimpleNode node,Environment env)  throws InterpretError {}

  private Vector qtEvaluateDomInQuant(SimpleNode node, Environment env,Vector alldoms) throws InterpretError {}

  private Relation evaluateSelect(SimpleNode node, String filename, Hashtable htable, Environment env) throws InterpretError {} //  Returns relation only with tuples selected by the selector as specified by the tree of node.

  public Relation evaluateTLExpression(SimpleNode node, String filename, Hashtable htable, Environment env)      throws InterpretError{} // evaluate Top Level expression, which results in a relation

  private Relation evaluateView(SimpleNode node, String filename,Hashtable htable, Environment env)  throws InterpretError {} // evaluate top level view and return the result relation

  private void executeAssignment(SimpleNode node, Environment env)  throws InterpretError {}

  public void executeCompCommand(SimpleNode node, Environment env)  throws InterpretError {}

  private void executeCommand(SimpleNode node, Environment env)   throws InterpretError {}

  private String getEveAtt(SimpleNode node, Environment env)  throws InterpretError {}

  private void executeCommand(SimpleNode node, Environment env, String rlname, int opc) throws InterpretError {} // overload the function to handle the different level's undo command in event handlers

  private int printTrigger(CTrigger trigger) throws InterpretError {}

  private int printAllTrigger(TriggerNode triggernode)  throws InterpretError {}

  public void executeCompDeclaration(SimpleNode node, Environment env) throws InterpretError  {}

  private void executeDeclaration(SimpleNode node, Environment env) throws InterpretError {}

  private void AddVirtDom2DomTable(SimpleNode node,  Environment env) throws InterpretError {}  // Original code for processing Virtual Domain declaration

  public void executeCompStatement(SimpleNode node, Environment env) throws InterpretError {}

  private void executeStatement(SimpleNode node, Environment env) throws InterpretError {}

  private int getIDCol(Relation r) throws InterpretError {} // to get the '.id' col position involved in assignment operation

  public static int CompareRelType(Relation left, Relation right)  throws InterpretError {} // compare the types of the two relations

  public static int CompareRelTypeComp(Relation left, Relation right)  throws InterpretError {} // used for comparison between two relations

  public int lookCompUpdate(SimpleNode node, Environment env, Relation prtmp, TriggerNode triggernode) throws InterpretError {}

  private int lookUpdate(SimpleNode node, Environment env, Relation prtmp, TriggerNode triggernode) throws InterpretError {}   // to produce the three parts relation of trigger for the certain update

  public int executeCompUpdate(SimpleNode root, SimpleNode node, Environment env)  throws InterpretError {}

  private int executeUpdate(SimpleNode root, SimpleNode node, Environment env)  throws InterpretError {}

  public void doCompTrigger(Environment env, TriggerNode triggernode, int searchchild) throws InterpretError {}

  private void doTrigger(Environment env, TriggerNode triggernode, int searchchild) throws InterpretError {} // use the env.trigger to produce the new updated relation

   private Domain[] ExpressionListToGeditDomains(SimpleNode node,Domain[] doms,int projectno) throws InterpretError {}

   private Domain[] ExpressionListToDomains(SimpleNode node) throws InterpretError {} // convert an ExpressionList node to an array of domains

   public Domain[] AttribsRel2DomList(Relation rel) throws InterpretError {}

   private Domain[] ExpressionListToDomains(SimpleNode node, Relation rel, Hashtable htable, Environment env) throws InterpretError {}

  private Domain[] ExpressionListToDomains(Domain[] node, Relation rel) throws InterpretError {} // adds hidden state domains from rel to the domains

  private Domain[] ExpressionListToDomains(SimpleNode node, Relation rel) throws InterpretError {}

   public Domain[] ExpressionListToDomains(SimpleNode node, Hashtable htable, Environment env)  throws InterpretError {}

   private Domain[] handleRedDomain(Domain[] domArray, SimpleNode node, Relation rel, Environment env) throws InterpretError {} // generate a temporary domain for red node that is intended for level lifting

   private void getDomsInCompList(SimpleNode node, Hashtable htable, Environment env) throws InterpretError {}

   private Relation getIDList(SimpleNode node, Environment env) throws InterpretError {} // Return a virtual relation

   private Relation getProjListRel(Relation rel, SimpleNode arrayList, Environment env)        throws InterpretError {} // returns a relation containing the domains to appear in the projection list

   private void help(String name)  throws InterpretError {}  // convert an IDList node to an array of domains

   private Domain[] IDListToDomains(SimpleNode node, Environment env)  throws InterpretError {}

   public long interpret(SimpleNode node, Environment env) throws InterpretError {}

   public long interpret(SimpleNode node, Environment env, String rlname, int opc) throws InterpretError {}  // overload the original interpret to handle the UNDO command

   private void lefthandUpdate(SimpleNode node, Environment env) throws InterpretError {}

   private void reverseView(SimpleNode node, Environment env) throws InterpretError {}

   public void distributedStmt(String rname,String lname,String URL, int op,Environment env) throws InterpretError {}

   private boolean isRecursiveView(SimpleNode node, String name,  Hashtable htable, Environment env) throws InterpretError {}   // check if there is self-reference in a view expression, the semantic

   public void traverse(SimpleNode node) {} // traverse and output the dump info to screen

   public void mainLoop(String args[]) { } // The main loop for the interpretation.

   public Domain newVirDomain(String name, SimpleNode node, Environment env) throws InterpretError {} // used for virtual domains.

   public static String nextTempName() // Return the a temporary file name for intermediate result in relational operation

   private void parse(String sp) {}

   private void RelationalDeclaration(SimpleNode node, Environment env) throws InterpretError {} // handle parsing of a relational declaration with optional initialization

   private long RelationalInitialization(SimpleNode node, Hashtable relsHT,String name, long surr,  int tupleNum) throws InterpretError  {} //   recursive routine to initialize a relation using the curly bracket syntax

   private void traverseNode(SimpleNode node, int flag, Environment env) throws InterpretError {} // Traverse the syntax tree of a virtual domain.

   private int traverseType(SimpleNode node, Environment env)  throws InterpretError {} // Get the actualized type

   private int executeEventH(String prefixname, SimpleNode enode, Environment env) throws InterpretError {}

   public boolean executeEventH( String actionname, Environment env)  throws InterpretError {}

   public boolean IsEmbody(String handAtt, String queAtt) {}

   public void RemoveTrigger(TriggerNode triggernode) {} // to clear up trigger

   public void printNode(SimpleNode Node) {}

   public  int executeRelixCommand(String commd){}

   public  void executeJRelixCommand(String commd)  {}

   public Relation getRelbyName(String name) throws InterpretError  {}

}

 

 

5.2.18   InterpretError class

This exception is thrown by method DBInterpreter.

 

5.2.19   JRelix class

This class is the entry of jRelix system. It contains “main”.

 

5.2.20   JrelixInputStream class

This class is to input in jRelix system.

class JRelixInputStream extends java.io.InputStream {

    protected java.io.InputStream in; // the underlying InputStream

    protected StringBuffer sb = null; // the StringBuffer holding input text

    protected boolean isFileInputStream; // flag indicating if the underlying InputStream is FileInputStream

    protected JRelixInputStream(java.io.InputStream in) {}

    public int available() throws java.io.IOException {}

    public void close() throws java.io.IOException {}

    public StringBuffer getText() {}

    public synchronized void mark(int readlimit) {} // Marks the current position in this input stream

    public boolean markSupported() {}

    public int read() throws java.io.IOException {}

    public int read(byte b[]) throws java.io.IOException {}

    public int read(byte b[], int off, int len) throws java.io.IOException {}

    public synchronized void reset() throws java.io.IOException {}

    public void resetIn(java.io.InputStream in) {} // Reset the underlying input stream.

    public void resetText() {} // This method resets/clears the StringBuffer holding the input text

    public long skip(long n) throws java.io.IOException {} // Skips over and discards bytes of data from the input stream.

}

 

 

5.2.21   JRelixParser class

This class is a class extends Parser class. This class wraps the Parser for better error message display.

 

class JRelixParser extends Parser {

    public JRelixParser(java.io.InputStream stream) {}

    public JRelixParser(ParserTokenManager tm) {}

    protected void token_error()  {}// overwrites the superclass method for better error message display.

}

 

 

5.2.22   LocalInfo class

This class extends IDInfo class for local information.

class LocalInfo extends IDInfo implements TypeConstants {

   public int intVal = 0;

   public long longVal = 0;

   public float floatVal = 0;

   public double doubleVal = 0;

   public String stringVal = "";

   public String nrVal = "";

    public number numberVal = new number("+000+0");

    public Relation relVal = null; //for storing IDLIST/COMP typed locals

    public LocalInfo(int type, Object val) {}

    public void dump(String name) {}

    public void dump() {}

}

 


5.2.23   NREnvironment class

This class is a frame for nested relation

public class NREnvironment implements TypeConstants {

   public int row;

   public Object[] data;

   private NREnvironment parent;

   private Environment env;

   private Hashtable table;

 

   public int callpreEventH;

   public int callpostEventH;

   public NREnvironment(Relation rel, NREnvironment parent, Environment env) {}

   public NREnvironment getParent() {}

   public NRInfo lookup(String name, boolean searchParent) {}

   public Relation lookupRel(String name)    throws InterpretError {}

   public Relation lookupNestedRel(String name, int rrow) throws InterpretError {}

   public Relation lookupRelSurr(String name)   throws InterpretError {}

   public Relation lookupRelSurr(String name, long surrogate)  throws InterpretError {}

   public long getSurrogate(String name)   throws InterpretError {}

   public void setSurrogate(String name, long sur)   throws InterpretError {}

}

 

5.2.23   NREnvironment class

This class extends IDInfo class for nested relation information.

class NRInfo extends IDInfo implements TypeConstants {

   public int type;

   public int index;

   public NREnvironment NRenv;       //pointer to the enclosing environment

   public NRInfo(int type,int index, NREnvironment NRenv) {}

   public void dump(String name) {}

   public void dump() {}

}

 

5.2.24   number class

This class a new data type class to represent numbers with unlimited precision.

 

5.2.25   ParamInfo class

This class extends IDInfo class for Parameter information.

class ParamInfo extends IDInfo implements TypeConstants {

   public int index;

   public Relation rel;            //also stores Computation passed as parameter

   public Environment env;       //pointer to the enclosing environment

    public ParamInfo(int type,int index) {}

    public void dump(String name) {}

    public void dump(){}

}

 

 

5.2.26   Parser class

This class is automatically generated. Don’t modify this class.

 

5.2.27   PrettyPrint class

This class gives a format to print data.

 

5.2.28   Relation class

Class Relation contains all the data/methods for a relation.

 

class Relation implements TypeConstants, Constants {

   public boolean DEBUG = false;

   protected Environment myEnv; //Pointer to the frame of the environment

   public String name;      // name of the relation

   public int active;       // state of the event handler, active = 0/1

   public int rvc;          // RELATION, VIEW or COMPUTATION

   public int numtuples;    // number of tuples

   public int numattrs;// number of attributes

   public int numsortattrs;      // number of sorted attributes

   public SimpleNode tree;   // reference to the root of AST

   public Domain[] domains;  // array of Domain objects

   public Object[] data; // array of columns, data of relation

   public int capacity;  // capacity of the array of column

   static final int BUFFERSIZE = 32768;   // 32K

   static final public boolean     isSigmaJoinImplemented = true;

 

   public Relation() {}

   public Relation(String name, Domain[] domains, int rvc, int tuples, int attributes, int sort, SimpleNode root, Environment env) {}

   public Relation(String name, Domain[] domains, int tuples, int attributes, int sort, Environment env) {}

   public Relation (Environment env)  {}

   public void append(Object[] dataArray, int tuples)  throws InterpretError  {} //appends some tuples in the data array to the relation

   public void appendInRAM(Relation relr, Relation rell) throws InterpretError {}// Append relation relr to relation rell, the duplicate is eliminated.

   public void appendInRAM2(Relation relr, Relation rell)  throws InterpretError {}   // Append relation relr to relation rell, the duplicate is NOT eliminated.

 

   public Relation assign(Domain[] domsr, String newname, Domain[] domsl)  throws InterpretError {} // Assign this relation to a new relation with newname

   public void assignAdd(Domain[] domsr, Relation rell, Domain[] domsl) throws InterpretError {} // Assign & add this relation to relation rell, note that relation rell

   private void buildHeap(int[] atypes, boolean[] flags)  throws InterpretError {}

   private int compareRelation(Relation rel) throws InterpretError {}  // compare this relation with relation rel

   public int compareTwoRows(Object[] datal, int m, Object[] datar, int n, int len, int[] types, boolean[] flags, Domain[] domsl, Domain[] domsr) throws InterpretError {}

   private int compareTwoStrings(String m, String n) {}  // compare two strings which are possibly dk and dc.

   public static Object[] createDataArray(Domain[] doms, int rows){}   // create the data array according to the domain array

   public void createDataArray(int rows) {}

   public Relation duplicate(boolean ifload)   throws InterpretError {}

   public Relation duplicateLoadAll()  throws InterpretError {} // Duplicate this relation as a working copy

   protected boolean existDuplicateDomain(Domain[] doms)   { }

   public void extract(long surrNo, Relation rel) {} // put the rows with corresponding surrogate number into a relation

   private int find(long[] surArray, long surr, int numtuples){} // find the one position of surr in array surArray

   public Relation getRelation(long surr)   throws InterpretError {}

   public Relation getRelwithSurr(long surr) throws InterpretError{}

   public Relation getRelExceptSurr(long surr, String relName)   throws InterpretError{}

   private void heapify(int n, int size, int[] atypes, boolean[] flags)   throws InterpretError {}

   public void heapSort(Domain[] doms, boolean[] flags)   throws InterpretError {} //for flat relation

   public int indexOfDomain(Domain dom) {} // find the index of domain dom in the domain array in this relation

   public void insert(long surrNo, Relation rel) throws InterpretError //Add a tuple into a nested relation using surrogate number

   private boolean isDkIn(Object[] dataArray, int index, int len, int[] types) {}   // check if dk exists

   public boolean isDomainIn(Domain dom) {} // check if domain dom is an element of the domain array of this relation

   public boolean isDomainIn(Domain dom, Domain[] dlist) {}  // check if one domain dom is in domain array dlist

   public boolean isDomainsIn(Domain[] doms) {}

   public boolean isDomainsIn(Domain[] doms, Domain[] dlist) {}

   public boolean isLoaded()

   public static String strRead(DataInputStream fin, int Type) throws IOException {} // read one field from input file fin.

   public static String strRead(BlockInputStream fin, int Type) throws IOException {} 

   public void load()  throws InterpretError {}   // load data from disk file

   public void load(boolean ifcheck)   throws InterpretError {}

   public void loadAll(Relation rel)   throws InterpretError {}

   public Relation mujoin(int opcode, Domain[] doml, Relation relr,Domain[] domr, String relname)   throws InterpretError {}

   public Domain[] mujoinType(int opcode, Domain[] doml, Relation relr, Domain[] domr)   throws InterpretError{}

   private void shuffleDoms(Domain[] dj, Domain[] toShuffle){} // rearrange domains in toShuffle

   public Relation pick(String relname)   throws InterpretError {} // Randomly pick one tuple

   public void print()   throws InterpretError {}   // print the relation onto an OutputStream

   public void print(int[] lens, boolean flag)   throws InterpretError {}

   public void project(Domain[] doms)   throws InterpretError {} // Project the relation

   public Relation project(Domain[] doms, String relname)  throws InterpretError {}

   public Relation renameTo(String newname) throws InterpretError {}

   public void save()  throws InterpretError {}    // save data onto disk file

   private void select(int index){}

   public Relation select(Domain dom, int num, String relname)   throws InterpretError {} //select rows

   public Relation select(Domain dom, String relname)   throws InterpretError {}

   public void setName(String name) {}

   public void setEnv(Environment newEnv)   { }

   public void sort(Domain[] doms)    throws InterpretError {}

   public void sort(Domain[] doms, boolean[] flags)   throws InterpretError {}

   public void swapColumns(Domain[] doms)  {} // swap the domain and data array

   public void swapTwoRows(int m, int n) {} // swap two rows indexed by m and n respectively

 

   public int[] toTypes(Domain[] doms) {}

   public int[] toTypes2(Domain[] doms) {}

   public void unload() {}   // unload the data

   public void unloadAll(Relation rel)   throws InterpretError {}// unload the data for relation rel and all the nested relations

   private void writeAttributes(BlockOutputStream bout, Object[] dataArray, int index, int[] types, boolean[] flags)   throws IOException {}  // write a tuple to BlockOutputStream

   private void writeDcAttributes(BlockOutputStream bout, int[] types, boolean[] flags, int offset)   throws IOException {} // write a dc's to BlockOutputStream

   public void printdata() throws InterpretError {}

   public Relation AttribsOf(String relname)  throws InterpretError {} // creates a relation

   public Domain[] sigmaJoinType(int opcode, Domain[] doml, Relation relr, Domain[] domr) throws InterpretError {}

   public Relation sigmaJoin(int opcode, Domain[] doml,Relation relr, Domain[] domr, String relname) throws InterpretError {}

   private Domain[] nonJoinDomains(Domain[] allDomains,Domain[] joinDomains)  {} //Returns a domain array whose elements are the grouping/non-join domains for sigma-join

   protected boolean isSigmaJoinTupleTrue(int sigmaJoinOpcode, boolean isSup, boolean isSub, boolean isSep) throws InterpretError {}

   public int compareTwoRowsWithDk(Object[] datal, int m, Object[] datar, int n,int len, int[] types, boolean[] flags, Domain[] domsl, Domain[] domsr) throws InterpretError {}

   public int compareTwoRowsWithDataOffset(Object[] datal, int m, Object[] datar, int n, int len, int[] types, boolean[] flags, Domain[] domsl, Domain[] domsr,int leftJoinDataOffset, int rightJoinDataOffset) throws InterpretError {}

    public void noloadprintdata() throws InterpretError {}

    public boolean isBoolCompatible()  {}

    public boolean boolCompatibleValue()   throws InterpretError {}

}

 

5.2.29   RelInfo class

It extends IDInfo class for relation information.

class RelInfo extends IDInfo implements TypeConstants {

    public Relation rel;

     public RelInfo(Relation rel)

    public void dump()

 }

 

5.2.30   RelTable class

This class stores and accesses .rel system relation in memory. The .rel system relation is as follows:

 .rel(.name   .numattribs   .numtuples   .vrc   .tree   .persistent)

 * .name                       identifier for the relation

 * .numattribs                number of attributes the relation is defined on

 * .numtuples                number of tuples in the relation

 * .vrc                          indicates whether this is a view, a relation or a comp

 * .tree                         root of syntax tree of code if virtual, NULL otherwise

 * .persistent                 boolean flag indicating if this relation is persistent

 

Some information from the .rd system table is kept in this RelTable class. This also includes the information describing what domains belong to each relation. The .rd system relation is as follows:

 .rd(.relname  .domname  .count  .dompos .sortrank)

 * .name                       identifier for the relation or domain

 * .attribute                   identifier for an attribute of the relation or domain

 * .drc                          indicates if this identifier is a domain, relation or a comp

 * .count                       number of different values of the domain in this relation

 * .dompos                   index of first byte of domain in the relation

 * .sortrank      position of domain in sort list

 

public class RelTable implements TypeConstants,Constants {

   private static final int    BUF_SIZE  = 16 * 1024;

   private static final String REL_NAME  = ".rel";

   private static final String RD_NAME   = ".rd";

   private static final String VIEW_NAME = ".view";

   private static final String COMP_NAME = ".comp";

   private Hashtable table; // A hash table storing all the relation entries.

   public RelTable(Environment env, boolean load) {}// Initialize the hash table, and load relation information

   private void addRel(String name, int numTuples, int numAttr,  int rvc, int sort, Environment env) {}

   public void addRel(Relation rel, boolean incNumRef) {}

   public void dump() {}

   public void fillExprTable(Hashtable exprTable) {} // Fill the exprtable

   public Relation getRel(String name) {}

    public void insertIDlist(String relname, Domain[] doms){ }Insert the idlist information from file .rd to RelTable.

    public void insertIDlist(String relname, Domain doment, int pos) {} // Insert the idlist information from file .rd to RelTable.

   private boolean isRel(String name){ }// Check if a relation exists.

   public Enumeration keys()

   public void load(Environment env) {}// Load the ascii system files .rel, and .comp into memory

   public void rmRel(String name){} // Delete a relation from the RelTable.

   public void showTable(boolean flag) {}

   public Hashtable getRelTable() {}

   public int getRelTableSize() {} // provide number of tuples in .rel

    public int getRDTableSize() {} // provide rdTable size

}

 

5.2.30      SemanticChecker class

The purpose of this class is to collect methods used for  checking the semantics of user code. These methods should all be public and static.

 

class SemanticChecker implements Constants {

   private static void SC_CompCommand(SimpleNode stmt, Environment env)  throws SemanticCheckError {}

   private static void SC_CompAssignment(SimpleNode stmt, Environment env)   throws SemanticCheckError {}

   private static void SC_CompDeclaration(SimpleNode stmt, Environment env)   throws SemanticCheckError {}

   private static void SC_CompStatement(SimpleNode stmt, Environment env)  throws SemanticCheckError {}

   private static void SC_CompUpdate(SimpleNode stmt, Environment env)  throws SemanticCheckError{}

   public static void SC_Computation(SimpleNode stmt, Environment env)  throws SemanticCheckError {} // check computations           

}

 

 

 

5.2.31   SemanticCheckError class

This class is an Exception for semantic checking.

public class SemanticCheckError extends Exception {

    public SemanticCheckError()

    public SemanticCheckError(String s)

}

 

 

5.2.31   SimpleNode class

A syntax tree is represented by simpleNode class. The syntax tree can be decomposed recursively from top down into a number of sub-trees, each of which represents a jRelix expression, statement or operator. At the extreme end of such decomposition are nodes. The following example shows a virtual domain declaration.

Example: jRelix virtual domain declaration:

    let a be b+c;

Oval: Dec
 

 

 

 

 

Oval: b Oval: c
 

 

 


The SimpleNode class describe a node in the syntax tree. Since a node contains references to both its children and its parent, it is possible to traverse a syntax tree (or part of it) in both ways. The information kept with a node object is frequently used by the Interpreter class and other classes. The SimpleNode class is therefore one of the most important classes in jRelix system.

 

public class SimpleNode implements Node, java.io.Serializable,Constants, TypeConstants{

  protected Node parent;

  protected java.util.Vector children;

  protected String identifier;

  protected Object info;

  protected int type;

  protected int opcode;

  protected String name;

  protected int bits;      //bits for order or existance of options

  protected java.util.Vector list;

  protected int active;   // active = 1/0, for event handler, on/off

  protected String url;

  public SimpleNode(String id) {}

  public void dump( PrintWriter out ) throws IOException {} dump the sub parser tree to a text file

  public void dump( PrintWriter out,String URL ,Environment env) throws IOException,InterpretError {}

   public SimpleNode updateChangeDump( PrintWriter out ) throws IOException {}

  public void dump(String prefix) {}

  public Object getInfo() { }

  public Object getObject() {}

  public boolean isBitSet(int pos) {}

  public void jjtAddChild(Node n) {}

  public void jjtAddChildAtHead(Node n) {}

  public void jjtClose() {}

  public static Node jjtCreate(String id) {}

  public static SimpleNode jjtCreateNode(String id, int type, int opcode, String name) {}

  public SimpleNode jjtDeepDuplicate() {}

  public SimpleNode jjtDuplicate(){ } // Duplicate a new node.

  public Node jjtGetChild(int i) {}

  public int jjtGetNumChildren() {}

  public Node jjtGetParent() {}

  public void jjtOpen() {}

  public Node jjtRemoveChild(int i) {}  // remove and return child indexed by i

  public void jjtReplace(SimpleNode n){

  public void jjtReplaceChild(int i, Node node) {}// replace a child with the one indexed as i in this node

  public void jjtSetParent(Node n) {}

  public void set(int t, int op) {}

  public void set(int t, int op, String s) {}

   public void set(String u,int t, int op) {}

   public void set(String u, int t, int op, String s) {}

   public void setBit(int pos) {}

  public void setInfo(Object i) {}

  public void setObject(java.lang.Object o) { }

  public String toString() {}

  public String toString(String prefix) {}

  public boolean hasDomain(String domName){}// Check if the name is in the virtual domain tree

}

 

5.2.32     StateInfo class

It is about State information.

class StateInfo extends StateInfo_2002 implements TypeConstants {

   public int index;

   public Relation rel;//REVISIT: this should go ??

   public Environment env;       //pointer to the enclosing environment

   public StateInfo(int type,int index) {}

    public void dump(String name){}

    public void dump(){}

}

 

 

5.2.33    StateInfo_2002 class

It extends IDInfo class about State information.

 

class StateInfo_2002 extends IDInfo implements TypeConstants {

   public int intVal = 0;

   public long longVal = 0;

   public float floatVal = 0;

   public double doubleVal = 0;

   public String stringVal = "";

   public Relation relVal = null; //for storing IDLIST typed states

   public number numberVal = new number("+000+0");

   public void setVal(int type, Object val) throws InterpretError {}

   public Object getVal(int type) throws InterpretError {}

    public void dump(int type) throws InterpretError {}

   public void dump() {}

}             

 

5.2.34   Surrogate class

This class implements the algorithm for loading and storing of surrogate value from and to disk. Surrogates are generated by the system. At first, jRelix system generates 0 to a surrogate. Then, when using it, jRelix system will increase the surrogate by one for next turn. They are all different for one database inorder to avoid conflict. We use long integers as surrogates. Since the largest long integer is about 9.2E+18, it will wrap after 292,471 years, assuming that the surrogates are generated at a speed of 1,000,000 per second. To ensure that the surrogates are uniquely defined over the lifetime of a database, we make it persistent by storing it on disk. Its value is loaded from the disk before using it. Before storing a relation that contains surrogates, we always dump the current value of the surrogate onto disk.

 

 

public final class Surrogate implements TypeConstants{

    private static final String fname = ".surrogate";

    private static long value = 1L; //Value of surrogate for successive use.

    static {}

   public static long next()

   public static void save() {} //* Save the surrogate value onto disk file .surrogate.

}

 

5.2.35   TriggerNode class

This class keeps the triggers for every update level.

 

public class TriggerNode implements Node, java.io.Serializable {

  protected Node parent;

  protected java.util.Vector children;

  protected String relname;  // the updated relation name

  public int opcode;  // the operate code on that relation

  protected CTrigger trigger;

  protected Environment env;

  public TriggerNode(String rlname, Environment env, Node p) {}

  public TriggerNode(String rlname, Environment env) {}

  public TriggerNode(Environment env) {}

  public TriggerNode(Environment env, TriggerNode p) {}

  private TriggerNode(String rlname, Environment env, CTrigger trigger) { } // for duplicating, inside used.

  public void jjtAddChild(Node n) {}

  public void jjtAddChildAtHead(Node n) {}

  public TriggerNode jjtDeepDuplicate() {} //duplicate a tree started with a certain node

  public TriggerNode jjtDuplicate(){} // Duplicate a new node.

  public Node jjtGetChild(int i) {}

  public int jjtGetNumChildren() {}

  public Node jjtGetParent() { }

  public void jjtOpen() {}

  public Node jjtRemoveChild(int i) { } // remove and return child indexed by i

  public void jjtSetParent(Node n) {}

  public String getName() {}

  public void setName(String rname) {}

  public TriggerNode getNode(String rname, int opc) {}

}

 

5.2.36   TypeConstants class

It is an abstract class to contain constants declaration.

 

5.2.37   Utility class

This class is a tool in jRelix system. It is similar with Global class.

 

public class Utility implements Constants, TypeConstants

    private static boolean DEBUG=false;

    public static boolean isNumeric(int type){ }

    private static boolean isBoolType(int type){}

    public static boolean isBoolOrIDListType(int type){}

    public static String type2String(int type){}

   public static int typeCheck(int[] typeArray, int opcode) throws InterpretError{} //Return resulting type of operation (optype).

   public static int typeConvert(int optype){} // Converse type in SimpleNode to relix type.

    public static String jRelixConstToString(int opcode) {}

    public static void dump(SimpleNode node, String prefix) {}

 

   public static void cleanUp(String fpattern) {} //removing temp files at exit

   public static boolean isPrimitiveType(int opcode) {}

   public static boolean domsCastCompatible(int typeLHS, int typeRHS) {}

}

 

 

 

5.3   Relationship among classes

5.3.1        JRelix system excution order:

 

Oval: end
 

 

 


5.3.2        Relation

implement:                             extend:                                 use:  

 

RelTable

 

Enviroment

SimpleNode

Domain

 

Relation

 
 

 

 

 

 

 


5.3.3        Domain

RelTable

Environment

 

DomTable

 

Domain

 

SimpleNode

 

 
 

 

 

 

 

 


5.3.4        Computation

 

SimpleNode

 

Enviroment

Interpreter

Domain

 
 

 

 


                                                            

 

Relation

 
 

 

 


5.3.5        Trigger

TriggerNode

 

CTrigger

 

Relation

 

Enviroment

 
 

 

 

 


5.3.6        Expression

EvalExpr

 

Interpreter

 

Enviroment

RelTable

DomTable

CompTable

 
 

 

 

 

 

 

 

 


5.3.7        ID information

TypeConstants

 

RelInfo

DomInfo

NRInfo

LocalInfo

ParamInfo

 
 

 

 

 

 

 

 


Top>>


6.   Conclusion

This guide is a general documentation for developer. From it, developer can get the whole system idea. But, if you want to improve the jRelix system, you should know the detail code where will give you the detail implementation and you can consult all project/ thesis document in Prof. Tim website: http://www.cs.mcgill.ca/~tim/cv/students.html.

 

Top>>


Reference

[Cod70]           E.F.Codd, A relational model of data for large shared data banks. Communications of the ACM, 13(6):377-387, 1970.

[DB612] T.H.Merrett, The Database System. http://www.cs.mcgill.ca/cs612/homepage.html

[Ger75]            R.Gerritsen. The Relational and Network Models of Database: Bridging the Gap, Second U.S.A. Japan Computer Conference, 1975.

[Kan01] Sung Soo Kang, Implementation of Functional Mapping in Nested Relation Algebra.

[JavaCC]         Oliver Enseling. JavaCC tutorial. http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-cooltools.html

[jRelix]             Aldat Lab, Computer Science, McGill University. JRelix system java code.

[Mer77]           T.H. Merrett, Relations as programming language elements. Information Processing Letters, 6(1): 29-33, 1977

[Mer84]           T.H.Merrett, Relational Information System. Reston Publishing Co., Restion, VA, 1984

[MerWeb]        T.H. Merrett, websit: http://www.cs.mcgill.ca/~tim/

[SDV02]          Sriram Sankar and Sreenivasa Viswanadha. JavaCC Grammar Repository. http://www.cobase.cs.ucla.edu/pub/javacc/

[Yua98]           Zhongxia Yuan, Java Implementation of the Domain algebra for Nested Relations.

[Wan02]          Zongyan Wang, Implementation of Distributed Data Processing in a Database Programming Language.

[Zhe02]            Yi Zheng, Abstract Data Types and Extended Domain Operations in a Nested Relational Algebra.