Chris Pollett > Students >
An

    ( Print View )

    [Bio]

    [Project Blog]

    [CS297Proposal]

    [Del1]

    [CS297ProposalB]

    [Del2]

    [Del3]

    [Del4]

    [CS297Report-PDF]

    [CS298Proposal]

    [CS298Report-PDF]

    [CS298Presentation-PDF]

    [Source code-ZIP]

                          

























Source Code of the Native Database

Description:

In this deliverable, we implement our database design using JAVA. Reader can refer to Deliverable 3 for the architectural design.

The following is the source code for a logical leaf node. It contains a leaf id, page number in which it resides, and the actual data:

public ThLeave(long id, int pagenum, String dat)
 {
   iD = id;
   pageNum = pagenum;
   data = dat;
 }

Below is the logical Group node. It contain a node id, an attribute
which can be null, and a list of children in the ArrayList:

public class ThGroup implements IthNode
{
  public long nodeId;
  public ThAttributeNode attribute;
  public ArrayList children;

Here is the structure of a document. It contains a reference to the
database subsystem where global states of the database is kept,
the documentís name, the logical pointer to the root of the XML
documentís tree, and the physical page that will be flushed to disk when the page is full:

public class ThXMLDoc
{

  ThSystem subsys;
  public String name = null;
  public ThGroup root; //logical tree root
  public ThPage rootPage;

}

A database can contain 0 to n documents (if storage is enough).
Following is the structure of a database. Its name is created from the
DML file. The hash table contains the XML documents create in this database:

  public ThDB(String dbName)
  {
    name = new String(dbName);
    docNames = new Hashtable();
    dbUp = true;
  }

The following is the structure for the Buffer Manager. It consists
of a hash table of pages in memory and it manages a free pages list.
Buffer Manager also maintains the least recently used ArrayList of page number.

public class ThBufferMgr implements Serializable{
  public static int pSn = 0;   //page serial number
  public Hashtable bufferPool = new Hashtable();  //pages in buffer pool
  public ArrayList freeList = new ArrayList();
  public ArrayList leastRecentlyUse = new ArrayList();
  public int totalPage = 20; //20 pages in the pool
}

Please refer to the Appendix for code details.


Following is the content of DML7.TXT:

CREATE DATABASE DB1DB;
CREATE XMLDOC XML1DOC IN DB1DB;

LOAD "c://an//cs297//xmldb//test1.xml"
     INTO XML1DOC;

printTree(XML1DOC);

//* add to the end of first element of /G[1], /G[2], ...
INSERT INTO XML1DOC PATH("/G/G[1]") VALUES("<L>392 Lily Ann Way,
                         San Jose CA 95111</L>",
                         "<L>(408)123-1234</L>");
INSERT INTO XML1DOC PATH("/G/G[2]") VALUES("<L>123 No Name St.,
                         San Jose CA 95112</L>",
                         "<L>(408)123-1234</L>"); COMMIT;
INSERT INTO XML1DOC PATH("/G/G[3]") VALUES("<L>234 Bernal,
                         San Jose CA 95012</L>");
INSERT INTO XML1DOC PATH("/G/G[4]") VALUES("<L>555 Bailey Road,
                         San Jose CA 94091</L>");

INSERT INTO XML1DOC PATH("/G/G[5]") VALUES("<L>1234 1st street,
                         San Francisco CA 95012</L>",
                    <L>(510)344-1010</L>");

INSERT INTO XML1DOC PATH("/G/G[6]") VALUES("<L>2234 2st street,
                         Santa Rosa CA 94323</L>",
                         <L>(808)463-1203</L>");

INSERT INTO XML1DOC PATH("/G/G[7]") VALUES("<L>3542 3st street,
                         Santa monica CA 95002</L>",
                    <L>(808)463-1203</L>");


//* comments

printTree(XML1DOC);

DELETE FROM XML1DOC WHERE PATH("/G/G[4]");
DELETE FROM XML1DOC WHERE PATH("/G/G/L[4]", "/G/G/L[3]");

printTree(XML1DOC);

UPDATE XML1DOC SET VALUE("<L>392 Pasilo dr., San Jose CA 95123</L>")
                   WHERE PATH("/G/G/L[2]");

printTree(XML1DOC);

SELECT "/G[*]" FROM XML1DOC;

DROP XMLDOC XML1DOC;
DROP DATABASE DB1DB;



Following is the snapshot of running the above testcase:

testExecuteDML7()
System starting up...
Constructing transactiontable...
Sub-system is up
Parsing DML...
Executing DML Plan
DB1DB created
XML1DOC added in DB1DB
openning file:  c://an//cs297//xmldb//test1.xml
Loading into XMLDoc...
Closing file:  c://an//cs297//xmldb//test1.xml
Printing Logical structure of XML Tree:  XML1DOC
 ID=00000001
   name=CS297
     id=123-45-6789
       Jane Eyre
       3.8
     id=234-56-7890
       Irene Hugh
       3.0
     id=345-67-8901
       Thomas Lee
       2.8
     id=456-78-9012
       Erica Nguyen
       3.1
     id=567-45-6789
       Rochester Thornfield
       2.8
     id=678-45-6789
       John Lyle
       3.2
     id=789-00-6789
       Robert Mulan
       3.2
Inserting into XMLDoc...
Inserting into XMLDoc...
Inserting into XMLDoc...
Inserting into XMLDoc...
Inserting into XMLDoc...
Inserting into XMLDoc...
Inserting into XMLDoc...
Printing Logical structure of XML Tree:  XML1DOC
 ID=00000001
   name=CS297
     id=123-45-6789
       Jane Eyre
       3.8
       392 Lily Ann Way, San Jose CA 95111
       (408)123-1234
     id=234-56-7890
       Irene Hugh
       3.0
       123 No Name St., San Jose CA 95112
       (408)123-1234
     id=345-67-8901
       Thomas Lee
       2.8
       234 Bernal, San Jose CA 95012
     id=456-78-9012
       Erica Nguyen
       3.1
       555 Bailey Road, San Jose CA 94091
     id=567-45-6789
       Rochester Thornfield
       2.8
       1234 1st street, San Francisco CA 95012
       (510)344-1010
     id=678-45-6789
       John Lyle
       3.2
       2234 2st street, Santa Rosa CA 94323
       (808)463-1203
     id=789-00-6789
       Robert Mulan
       3.2
       3542 3st street, Santa monica CA 95002
       (808)463-1203
Deleting from XMLDoc...
Deleting from XMLDoc...
Printing Logical structure of XML Tree:  XML1DOC
 ID=00000001
   name=CS297
     id=123-45-6789
       Jane Eyre
       3.8
       392 Lily Ann Way, San Jose CA 95111
       (408)123-1234
     id=234-56-7890
       Irene Hugh
       3.0
       123 No Name St., San Jose CA 95112
       (408)123-1234
     id=678-45-6789
       John Lyle
       3.2
       2234 2st street, Santa Rosa CA 94323
       (808)463-1203
     id=789-00-6789
       Robert Mulan
       3.2
       3542 3st street, Santa monica CA 95002
       (808)463-1203
Updating XML1DOC...
Printing Logical structure of XML Tree:  XML1DOC
 ID=00000001
   name=CS297
     id=123-45-6789
       Jane Eyre
       3.8
       392 Lily Ann Way, San Jose CA 95111
       (408)123-1234
     392 Pasilo dr., San Jose CA 95123
     id=678-45-6789
       John Lyle
       3.2
       2234 2st street, Santa Rosa CA 94323
       (808)463-1203
     id=789-00-6789
       Robert Mulan
       3.2
       3542 3st street, Santa monica CA 95002
       (808)463-1203
Selecting from XMLDoc: XML1DOC
   id=123-45-6789
     Jane Eyre
     3.8
     392 Lily Ann Way, San Jose CA 95111
     (408)123-1234
   id=678-45-6789
     John Lyle
     3.2
     2234 2st street, Santa Rosa CA 94323
     (808)463-1203
   id=789-00-6789
     Robert Mulan
     3.2
     3542 3st street, Santa monica CA 95002
     (808)463-1203
 name=CS297
   392 Pasilo dr., San Jose CA 95123
Time: 1.632
OK (5 tests)