|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsav.z.ClassNavigation
sav.z.Base
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.
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 theString 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);
Base
.
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"); 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); } }
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();
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 |
public java.lang.String path()
absolutePath()
public java.lang.String absolutePath()
path()
public BaseExtension be()
BaseExtension
public int headerSize(java.lang.String zclass) throws java.io.IOException
zclass
Zigzag class.
java.io.IOException
header(String)
public java.lang.String[] header(java.lang.String zclass) throws java.io.IOException
zclass
Zigzag class.
java.io.IOException
row(String, String[])
public java.lang.String[] row(java.lang.String object, java.lang.String[] header) throws java.io.IOException
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(); }
java.io.IOException
header(String)
,
ClassNavigation.first(String)
,
ClassNavigation.next(String, String)
public java.lang.String[] row(java.lang.String object) throws java.io.IOException
row
of the current object
.
The object
is presented by ID of the name:value or
name:value:... form.
java.io.IOException
row(String, String[])
public java.lang.String attrValue(java.lang.String object, java.lang.String attribute) throws java.io.IOException
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();
java.io.IOException
attrValue(String, String)
,
attrTerm(String, String)
,
attrValues(String, String)
,
attrArray(String, String)
public boolean hasAttr(java.lang.String object) throws java.io.IOException
object
has attribute.
The object
may be either "name" or "name:value"
or more complex "name:...:value".
java.io.IOException
attrValue(String, String)
public java.util.Vector attrValues(java.lang.String object, java.lang.String attribute) throws java.io.IOException
attribute
that
object
has. By default the category of returned values
are complex.
java.io.IOException
attrValue(String, String)
public int attrSize(java.lang.String object, java.lang.String attribute) throws java.io.IOException
attribute
values
for the object
.
By default the category of values is complex.
java.io.IOException
attrArray(String, String)
,
attrValues(String, String)
public java.lang.String[] attrArray(java.lang.String object, java.lang.String attribute) throws java.io.IOException
attribute
that
object
has.
java.io.IOException
attrValues(String, String)
,
attrValue(String, String)
public java.lang.String attrTerm(java.lang.String object, java.lang.String attribute) throws java.io.IOException
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();
java.io.IOException
Name.toTerm(String)
,
attrValue(String, String)
public java.lang.String attrFirst(java.lang.String object, java.lang.String attribute) throws java.io.IOException
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().
java.io.IOException
attrValue(String, String)
,
attrNext(String, String, String)
,
attrLast(String, String)
public java.lang.String attrNext(java.lang.String object, java.lang.String attribute, java.lang.String value) throws java.io.IOException
value
of the
attribute
that object
has.
java.io.IOException
attrFirst(String, String)
public java.lang.String attrLast(java.lang.String object, java.lang.String attribute) throws java.io.IOException
attribute
that
object
has. The object
may be either
"name" or "name:value" or more complex "name:...:value".
java.io.IOException
attrFirst(String, String)
,
attrBack(String, String, String)
public java.lang.String attrBack(java.lang.String object, java.lang.String attribute, java.lang.String value) throws java.io.IOException
value
of the
attribute
that object
has.
java.io.IOException
attrLast(String, String)
public boolean isModifiable()
Session.modifyBase(java.lang.String)
public void close() throws java.io.IOException
java.io.IOException
Session.openBase(java.lang.String)
,
Session.exploreBase(java.lang.String)
,
Session.modifyBase(java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |