sav.z
Class Base

java.lang.Object
  extended bysav.z.ClassNavigation
      extended bysav.z.Base

public class Base
extends ClassNavigation

Objects of this class help to navigate through the database without execution of Zigzag expressions. Each object in Zigzag database has some ID like the name:value. The name corresponds to Zigzag's class name. The value of each class object is unique for that class. The name may not be equal to value. It is best practice to represent a class name as word or word sequence, for example order number. Value usually is a number or symbols in quotes, for example 283.12 or 'Smit'. Nevertheless, name may have the same view as value, and value have the same view as name. Furthermore, the object's ID may consist of several levels like this name:name:value, for example root:3:15.

Really Zigzag database consists of the classes (named set) of objects related each other. One object may belong to the several relations, or tables, simultaneously. It occurs if represented tables have equal column name and values. Such Zigzag representation is important distinction from the table representation of the usual relational databases, where each table has its own data. Table for Zigzag is not real representation, but rather conditional method to represent relation between data objects kept in database independently.

Let's consider Zigzag data representation on the example. Look at the following Java/Zigzag fragment, which creates a "table" with employee key column.

  String script =
    "$readTable() <" +
    "employee; name;           department; salary \n" +
    "101;      'Adams Smith';  1;          50000 \n" +
    "102;      'Clark White';  1;          30000 \n" +
    "103;      'Jones Hunter'; 2;          60000 \n" +
    "104;      'Blake Dull';   3;          65000 \n" +
    "105;      'Sylvia Smith'; 1;          25000 \n" +
    "108;      'Albert Green'; 3;          40000 \n" +
    "109;      'Clark Ringer'; 2;          50000 \n" +
    ">;"
  ;
  Session ss = new Session();
  ss.modifyBase("CompanyX");
  ss.z(script);
 
Zigzag's $readTable() procedure is most comfortable method to link objects via a table (correspondent relation). Such table is virtual. It does not have a schema. The table name is employee, name of the primary key column. After execution of ss.z(script), the database contains 4 classes: employee, name, department, salary. The employee class is related with name, department and salary classes. We need remark, the class department has only three objects, department:1, department:2, department:3. Each department has link with several employees. Following fragment shows, how we can iterate through the departments and belonged them employees by means of the Base.
  ss.exploreBase("CompanyX");
  Base b = ss.base();
  int depCount = b.size("department");
  for (String dep = b.first("department"); dep != null; dep = b.next("department", dep)) {
    String emp = b.attrFirst("department:" + dep, "employee");
    while (emp != null) {
      ...
      emp = b.attrNext("department:" + dep, "employee", emp);
    }
  }
 
Based on such iteration, example below groups employees, their quantity and salary sum by the department.
  ss.exploreBase("CompanyX");
  Base b = ss.base();
  int depCount = b.size("department");
  int peopleCount[] = new int[depCount + 1];
  float salarySum[] = new float[depCount + 1];
  for (String dep = b.first("department"); dep != null; dep = b.next("department", dep)) {
    int depNumber = Integer.parseInt(dep);
    peopleCount[depNumber] = b.attrSize("department:" + dep, "employee");
    String emp = b.attrFirst("department:" + dep, "employee");
    while (emp != null) {
      String salary = b.attrValue("employee:" + emp, "salary");
      if (salarySum[depNumber] == 0.0)
        salarySum[depNumber] = Float.parseFloat(salary);
      else
        salarySum[depNumber] += Float.parseFloat(salary);
      emp = b.attrNext("department:" + dep, "employee", emp);
    }
  }
  System.out.println("department; people_count; salary_sum");
  for (int i = 1; i <= depCount; ++i) {
    if (peopleCount[i] == 0)
      continue;
    System.out.println(i + "; " +  peopleCount[i] + "; " + salarySum[i]);
  }
  b.close();
 

Since:
7.0
See Also:
Session.base(), ClassNavigation

Method Summary
 java.lang.String absolutePath()
          Returns absolute path of the database file.
 java.lang.String[] attrArray(java.lang.String object, java.lang.String attribute)
          Returns array values of the attribute that object has.
 java.lang.String attrBack(java.lang.String object, java.lang.String attribute, java.lang.String value)
          Returns a back value before the value of the attribute that object has.
 java.lang.String attrFirst(java.lang.String object, java.lang.String attribute)
          Returns first value of the attribute that object has.
 java.lang.String attrLast(java.lang.String object, java.lang.String attribute)
          Returns last value of the attribute that object has.
 java.lang.String attrNext(java.lang.String object, java.lang.String attribute, java.lang.String value)
          Returns a next value after the value of the attribute that object has.
 int attrSize(java.lang.String object, java.lang.String attribute)
          Returns a size of the attribute values for the object.
 java.lang.String attrTerm(java.lang.String object, java.lang.String attribute)
          Returns one (first) non-quoted value of the attribute that object has.
 java.lang.String attrValue(java.lang.String object, java.lang.String attribute)
          Returns one (first) value of the attribute that object has.
 java.util.Vector attrValues(java.lang.String object, java.lang.String attribute)
          Returns Vector values of the attribute that object has.
 BaseExtension be()
          Returns BaseExtension representing functional extension of the Base.
 void close()
          Closes database, this Base represents.
 boolean hasAttr(java.lang.String object)
          Checks whether or not object has attribute.
 java.lang.String[] header(java.lang.String zclass)
          Returns the ordered attributes of table corresponding to zclass Zigzag class.
 int headerSize(java.lang.String zclass)
          Returns a header size of the table corresponding to zclass Zigzag class.
 boolean isModifiable()
          Checks whether database is modifiable or not.
 java.lang.String path()
          Returns database path.
 java.lang.String[] row(java.lang.String object)
          Defines a table row of the current object.
 java.lang.String[] row(java.lang.String object, java.lang.String[] header)
          Defines a table row of the current object with header.
 
Methods inherited from class sav.z.ClassNavigation
array, back, first, generalizeTo, has, hasNumber, isEmpty, last, next, nextArray, size, term, value, values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

path

public java.lang.String path()
Returns database path.

See Also:
absolutePath()

absolutePath

public java.lang.String absolutePath()
Returns absolute path of the database file.

See Also:
path()

be

public BaseExtension be()
Returns BaseExtension representing functional extension of the Base. The methods of the BaseExtension are specific and are not recomended to usual developer.

See Also:
BaseExtension

headerSize

public int headerSize(java.lang.String zclass)
               throws java.io.IOException
Returns a header size of the table corresponding to zclass Zigzag class.

Throws:
java.io.IOException
See Also:
header(String)

header

public java.lang.String[] header(java.lang.String zclass)
                          throws java.io.IOException
Returns the ordered attributes of table corresponding to zclass Zigzag class.

Throws:
java.io.IOException
See Also:
row(String, String[])

row

public java.lang.String[] row(java.lang.String object,
                              java.lang.String[] header)
                       throws java.io.IOException
Defines a table row of the current object with header. The object is presented by ID of the name:value or name:value:... form. Look at the following example printing the employee table.
  Session ss = new Session();
  ss.exploreBase("CompanyX");
  Base base = ss.base();
  String header[] = base.header("employee");
  for (int i = 0; i < header.length; ++i) {
    System.out.print(header[i] + "; ");
  }
  System.out.println();
  String row[];
  for (String emp = base.first("employee"); emp != null; emp = base.next("employee", emp)) {
    row = base.row("employee:" + emp);
    for (int i = 0; i < row.length; ++i) {
      System.out.print(row[i] + "; ");
    }
   System.out.println();
 }
 

Throws:
java.io.IOException
See Also:
header(String), ClassNavigation.first(String), ClassNavigation.next(String, String)

row

public java.lang.String[] row(java.lang.String object)
                       throws java.io.IOException
Defines a table row of the current object. The object is presented by ID of the name:value or name:value:... form.

Throws:
java.io.IOException
See Also:
row(String, String[])

attrValue

public java.lang.String attrValue(java.lang.String object,
                                  java.lang.String attribute)
                           throws java.io.IOException
Returns one (first) value of the attribute that object has. The object may be either "name" or "name:value" or more complex "name:...:value". The name before ':' is a name of Zigzag class. By the way the attribute is also a Zigzag class name of objects related with the given.

The following example creates department:1 (worker:programmer:'Smit'), namely department-worker relation between 1 and programmer:'Smit'. The value is programmer:'Smit'. The value1 is 'Smit'.

  Session ss = new Session();
  ss.modifyBase("CompanyX");
  ss.z("department:1 (worker:programmer:'Smit')");
  ss.exploreBase();
  Base base = ss.base();
  String value = base.attrValue("department:1", "worker");
  String value1 = base.attrValue("department:1", "worker:programmer");
  ss.close();
 

Throws:
java.io.IOException
See Also:
attrValue(String, String), attrTerm(String, String), attrValues(String, String), attrArray(String, String)

hasAttr

public boolean hasAttr(java.lang.String object)
                throws java.io.IOException
Checks whether or not object has attribute. The object may be either "name" or "name:value" or more complex "name:...:value".

Throws:
java.io.IOException
See Also:
attrValue(String, String)

attrValues

public java.util.Vector attrValues(java.lang.String object,
                                   java.lang.String attribute)
                            throws java.io.IOException
Returns Vector values of the attribute that object has. By default the category of returned values are complex.

Throws:
java.io.IOException
See Also:
attrValue(String, String)

attrSize

public int attrSize(java.lang.String object,
                    java.lang.String attribute)
             throws java.io.IOException
Returns a size of the attribute values for the object. By default the category of values is complex.

Throws:
java.io.IOException
See Also:
attrArray(String, String), attrValues(String, String)

attrArray

public java.lang.String[] attrArray(java.lang.String object,
                                    java.lang.String attribute)
                             throws java.io.IOException
Returns array values of the attribute that object has.

Throws:
java.io.IOException
See Also:
attrValues(String, String), attrValue(String, String)

attrTerm

public java.lang.String attrTerm(java.lang.String object,
                                 java.lang.String attribute)
                          throws java.io.IOException
Returns one (first) non-quoted value of the attribute that object has. The category of returned value is only simple. The following example creates department-worker relation between 1 and 'John':'Smit'. The attrTerm() in example returns simple John value (no 'John').
  Session ss = new Session();
  ss.modifyBase("CompanyX");
  ss.z("department:1 (worker:'John':'Smit')");
  ss.exploreBase();
  Base base = ss.base();
  String value = base.attrTerm("department:1", "worker");
  System.out.println(value);
  ss.close();
 

Throws:
java.io.IOException
See Also:
attrValue(String, String)

attrFirst

public java.lang.String attrFirst(java.lang.String object,
                                  java.lang.String attribute)
                           throws java.io.IOException
Returns first value of the attribute that object has. The object may be either "name" or "name:value" or more complex "name:...:value". All the values are ordered in ascendant sequence. This method is like attrValue().

Throws:
java.io.IOException
See Also:
attrValue(String, String), attrNext(String, String, String), attrLast(String, String)

attrNext

public java.lang.String attrNext(java.lang.String object,
                                 java.lang.String attribute,
                                 java.lang.String value)
                          throws java.io.IOException
Returns a next value after the value of the attribute that object has.

Throws:
java.io.IOException
See Also:
attrFirst(String, String)

attrLast

public java.lang.String attrLast(java.lang.String object,
                                 java.lang.String attribute)
                          throws java.io.IOException
Returns last value of the attribute that object has. The object may be either "name" or "name:value" or more complex "name:...:value".

Throws:
java.io.IOException
See Also:
attrFirst(String, String), attrBack(String, String, String)

attrBack

public java.lang.String attrBack(java.lang.String object,
                                 java.lang.String attribute,
                                 java.lang.String value)
                          throws java.io.IOException
Returns a back value before the value of the attribute that object has.

Throws:
java.io.IOException
See Also:
attrLast(String, String)

isModifiable

public boolean isModifiable()
Checks whether database is modifiable or not.

See Also:
Session.modifyBase(java.lang.String)

close

public void close()
           throws java.io.IOException
Closes database, this Base represents.

Throws:
java.io.IOException
See Also:
Session.openBase(java.lang.String), Session.exploreBase(java.lang.String), Session.modifyBase(java.lang.String)