|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsav.z.Session
Is a central class executing Zigzag scripts. Session object provides connection with Zigzag database and variables. Via Session the Base, Variable, Printer and Status objects are created. Session is used to analyze and execute Zigzag Scripts. Session keeps Report and Warnings (Errors and Failures) as results of Zigzag Script execution. Session synchronizes execution. It is usual practice to associate one Session with one database and one user (or thread).
Following is a complete simple example of using Zigzag request and Zigzag description. If request has been unsuccessful, program initiates description. Description (or writing new relations) is easy, and Database schema is formed automatically.
import sav.z.*;
public class SessionDemo extends Session {
public static void main(String arg[]) {
SessionDemo ss = new SessionDemo("Users");
System.out.println("Requesting...");
String result = ss.request("User:ann1");
if (result.length() == 0) {
System.out.println("Describing...");
ss.describe("User:ann1", "Password:111111");
result = ss.request("User:ann1");
}
System.out.println(result);
}
SessionDemo(String dbPath) {
super();
z("$base \"" + dbPath + "\"");
}
String request(String object) {
String sQuery = "= " + object + ";";
z(sQuery);
String result = report();
return result;
}
public describe(String object, String attributes) {
String sUpdate = object + "(" + attributes + ");";
z(sUpdate);
}
}
One thread may service one or several Sessions.
One Session may provide connection with distinct databases
but only in a some sequence. To work with several distinct databases
simultaneously, a simple solution is to create several Sessions.
Following example illustrates the use of Zigzag variables ("$owner", "$user"), which values are got from diverse databases ("$base Owners", "$base Users"). Zigzag script selects equal value of "User" and "Owner" classes in the $user variable. Then $user objects are printed.
Session ss = new Session();
String script =
"= $base 'Owners';\n" +
"$owner = Owner/;\n" +
"= $base 'Users';\n" +
"$user = User/$owner;\n";
ss.z(script); //Forms values of $owner and $user variable
Variable users = ss.var("$user");
System.out.println("OWNER AND USER");
for (String user = users.first(); user != null; user = users.next())
System.out.println(user);
Databases may be opened as in modifiable so in non-modifiable mode. When a few Sessions (threads) perform connection with one database file, they will run faster if the databases have non-modifiable mode. Modifying session locks other sessions. In this case sessions work in asynchronous regime. The Sav Zigzag provides support of multi-connection from threads produced only by one JVM.
Script,
Warning,
Printer,
Status,
LineStatus| Field Summary |
| Fields inherited from interface sav.outfit.Lexis |
BASE, BRACE, BRACE_TERM, BRACKET, BRACKET_TERM, CATEGORY, COLON, COMMA, DECLARATION, DECLARED, DESCRIPTIVE, DEVS, DIVIDE, ELLIPSIS, EQUALITY, EXTRACTION, FILE, FILED, FUNCTION, INEQUALITY, INTERNAL, KEYS, LEFT_SLASH, MDERIVABLE, NONE, NUMBER, P1, P2, PARENTHESIS, PARENTHESIS_TERM, POINT, PROCEDURE, QUOTE, RANGE, REVERSE_SOLIDUS, SPACE, SPECIFICATION, STRING, TERMINATION, VARIABLE, VDERIVABLE, VERTICAL_LINE, WORD |
| Constructor Summary | |
Session()
Constructs a Session. |
|
Session(java.lang.String rootPath)
Constructs a Session with root directory path that will be concatenated to relative file name. |
|
| Method Summary | |
void |
analyse(Script scr)
Analyzes syntax of a Script within a Session context. |
Base |
base()
Constructs a Base object for the current Session's database. |
Base |
base(int category)
Constructs a Base object of the current Session's database for navigation through category values.
|
void |
clearBase()
Deletes the contents of Session's current database and sets up it as modifiable . |
void |
clearBase(java.lang.String path)
Deletes the contents of Session's path database
and sets up it as modifiable . |
void |
clearDataBaseStatus()
Clears Status used to determine a current Session's database. |
void |
clearDataLineStatus()
Clears LineStatus used to determine current line of a processed (read or printed) out data text. |
void |
clearErrors()
Clears list of Errors in a Session. |
void |
clearFailures()
Clears list of Failures in a Session. |
void |
clearMessagePrinter()
Clears Printer the Warning messages are prented via. |
void |
clearProcessStatus()
Clears process Status used to determine a current Session's process. |
void |
clearReportPrinter()
Clears current Printer used for reporting by Zigzag print procedure or Zigzag request statement. |
void |
clearScriptLine()
Clears a current Script line number. |
void |
clearScriptLineStatus()
Clears LineStatus used to determine a current line of a processed (executed or analyzed) Script. |
void |
clearWarnings()
Clears list of Warnings (Errors and Failures) in a Session. |
void |
close()
Completes session. |
void |
closeBase()
Closes the Session's current database. |
void |
closeBase(java.lang.String path)
Closes the Session's path database.
|
void |
closeBases()
Closes all the databases opened in this Session. |
void |
closeVar(java.lang.String name)
Closes Zigzag's variable. |
int |
countErrors()
Counts Errors of a Session. |
int |
countFailures()
Counts Failures of a Session. |
int |
countWarnings()
Counts Warnings of a Session. |
Statement |
curStatement()
Returns a current executed/analyzed Statement or Statement at that Session makes Exception. |
Error[] |
errors()
Returns array of Errors produced by Script analysis. |
void |
execute(Script scr)
Executes a Script within a Session context. |
Base |
exploreBase()
Sets up the Session's current database as readable. |
Base |
exploreBase(java.lang.String path)
Sets up the Session's path database as readable.
|
Failure[] |
failures()
Returns array of Failures produced by Script execution. |
Commutator |
getCommutator()
Returns Session's Commutator, which permits to interrupt current process. |
java.lang.Object |
getContext()
Returns context object. |
Status |
getDataBaseStatus()
Returns Status used to determine a current Session's database. |
LineStatus |
getDataLineStatus()
Returns LineStatus used to determine a current line of a processed (read or printed) out data text. |
Printer |
getMessagePrinter()
Returns Printer the Warning messages are printed via. |
Status |
getProcessStatus()
Returns process Status used to determine a current Session's process. |
Printer |
getReportPrinter()
Returns Printer used for reporting by Zigzag print procedure or Zigzag request statement. |
int |
getScriptLine()
Returns a current Script line number. |
LineStatus |
getScriptLineStatus()
Returns LineStatus used to determine a current line of a processed (executed or analyzed) Script. |
boolean |
hasErrors()
Tests to see if Session has Errors. |
boolean |
hasFailures()
Tests to see if Session has Failures. |
boolean |
hasWarnings()
Tests to see if Session has Warnings. |
void |
hideScriptStatus(boolean yes)
Hides statuses for z scripts: current process, and current line. |
void |
initSpec()
Initiates Zigzag specifications (default names of variables, procedures and others). |
boolean |
isEmptyLineReporting()
Checks the setting of EmptyLineReporting regime. |
boolean |
isErrExcepted()
Determines if ZException is produced in case of Error. |
boolean |
isFailExcepted()
Indicates whether the ZException will be in case of Failure. |
int |
login(User user)
Registers a user and determines User's access that
is defined in the current Session's database.
|
void |
modifyBase()
Sets up the Session's current database as modifiable . |
void |
modifyBase(java.lang.String path)
Sets up the Session's path database as modifiable.
|
void |
openBase()
Opens the Session's current database, if it was closed. |
void |
openBase(java.lang.String path)
Opens the Session's path database, if it was closed. |
java.lang.String |
report()
Returns string of the default report WStatus. |
java.lang.String |
rootPath()
Returns root directory path for databases with relative name. |
void |
setCommutator(Commutator comm)
Sets Commutator, which permits to interrupt current process. |
void |
setContext(java.lang.Object context)
Sets context object. |
void |
setDataBaseStatus(Status stDataBase)
Sets Status used to determine a current Session's database. |
void |
setDataLineStatus(LineStatus stDataLine)
Sets LineStatus used to determine a current line of a processed (read or printed) out data text. |
void |
setEmptyLineReporting(boolean emptyLineReporting)
Enables to print the ";" line when no object is printed. |
void |
setErrExcepted(boolean excepted)
Sets up ZException in case of Error. |
void |
setFailExcepted(boolean excepted)
Sets up ZException in case of Failure. |
void |
setMessagePrinter(Printer prtMessage)
Sets Printer the Warning messages are printed via. |
void |
setProcessStatus(Status stProcess)
Sets process Status used to determine a current Session's process. |
void |
setReportPrinter(Printer prtReport)
Sets Printer for reporting by Zigzag print procedure or Zigzag request statement. |
void |
setScriptLine(int number)
Sets up a current Script line number. |
void |
setScriptLineStatus(LineStatus stLine)
Sets LineStatus used to determine a current line of a processed (executed or analyzed) Script. |
User |
user()
Returns User, registered through the login(User). |
Variable |
var(java.lang.String name)
Returns a Variable object corresponding to Zigzag's variable. |
Variable |
var(java.lang.String name,
int category)
Returns a Variable object corresponding to Zigzag's variable for navigation through category values.
|
Warning[] |
warnings()
Returns array of Warnings, namely Errors or Failures, produced by Script analysis or execution. |
int |
z(java.lang.String text)
Executes a text of Zigzag script within a Session context.
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Session()
Session ss = new Session();
ss.z("= $base Users"); //opens non-modifiable "Users.ass" database
close()
public Session(java.lang.String rootPath)
throws java.io.IOException
Session ss = new Session("/MyDirectory");
ss.z("$base Users ="); //opens modifiable "/MyDirectory/Users.ass" database
rootPath(),
close()| Method Detail |
public java.lang.String rootPath()
Session(String)
public void initSpec()
throws java.io.IOException
ss.z("$var pr");
...
ss.initSpec();
java.io.IOExceptionpublic int z(java.lang.String text)
text of Zigzag script within a Session context.
Context is formed by Zigzag specifications
("$var, $base, $..."), Printers, Statuses.
If Warnings (Errors and Failures) are, the Session contents its.
Session ss;
String text;
...
if (ss.z(text) <= 0) {
Warning w[] = ss.warnings();
...
}
hasWarnings(),
report()public void analyse(Script scr)
Session ss; Script scr; ... ss.analyse(scr); if (scr.hasErrors()) ...
hasErrors(),
execute(sav.z.Script)public void execute(Script scr)
Session ss; Script scr; ... ss.execute(scr); if (scr.hasFailures()) ...
hasFailures(),
analyse(sav.z.Script)public java.lang.String report()
User and Name.
Session ss;
...
ss.z("$printTableRows(User:ann1, User, Name)");
String result = ss.report();
z(java.lang.String)public Warning[] warnings()
hasWarnings()public Error[] errors()
hasErrors()public Failure[] failures()
hasFailures()public boolean hasWarnings()
z(java.lang.String),
warnings()public boolean hasErrors()
analyse(sav.z.Script),
errors()public boolean hasFailures()
execute(sav.z.Script),
failures()public int countWarnings()
public int countErrors()
public int countFailures()
public void clearWarnings()
public void clearErrors()
public void clearFailures()
public Statement curStatement()
Exception.
public void setReportPrinter(Printer prtReport)
PrintWriter pw;
...
Printer prt = new WPrinter(pw);
ss.setReportPrinter(prt);
ss.z("= User:");
pw.close();
public Printer getReportPrinter()
Printer prt = ss.getReportPrinter();
prt.println("Report has been finished");
prt.flush();
public void clearReportPrinter()
...
ss.clearReportPrinter();
ss.z("= User:");
String result = ss.report();
public void setMessagePrinter(Printer prtMessage)
PrintWriter pw = new PrintWriter(new FileWriter("Messages.log"));
Printer prt = new WPrinter(pw);
ss.setMessagePrinter(prt);
...
pw.close();
if (ss.hasErrors())
System.out("See errors in Messages.log file");
public Printer getMessagePrinter()
public void clearMessagePrinter()
public void setProcessStatus(Status stProcess)
public Status getProcessStatus()
public void clearProcessStatus()
public void setScriptLineStatus(LineStatus stLine)
LineStatus ls = new ConsoleLineStatus(10);
ss.setScriptLineStatus(ls);
String text =
"User:ann1 (Name:Ann);\n" +
"User:dan (Name:Daniel);\n" +
...
;
ss.z(text);
public LineStatus getScriptLineStatus()
public void clearScriptLineStatus()
public void setDataLineStatus(LineStatus stDataLine)
LineStatus ls = new ConsoleLineStatus(1000);
ss.setDataLineStatus(ls);
String text =
"User; Name \n" +
"ann1; Ann \n" +
"dan ; Daniel\n" +
...
;
ss.z("$readTable()<\n" + text + ">");
public LineStatus getDataLineStatus()
public void clearDataLineStatus()
public void setDataBaseStatus(Status stDataBase)
public Status getDataBaseStatus()
public void clearDataBaseStatus()
public void setScriptLine(int number)
public int getScriptLine()
public void clearScriptLine()
public void setCommutator(Commutator comm)
public Commutator getCommutator()
public void close()
throws java.io.IOException
Session ss = new Session();
ss.exploreBase("Users");
ss.z("$x = a");
String x1[] = ss.var("$x").array();
ss.z("$x = b**");
String x2[] = ss.var("$x").array();
if (ss.hasErrors()) {
ss.close();
}
String x3[] = ss.var("$x").array();
Note: A Session resources are automatically released
in the course of garbage collection.
java.io.IOExceptionSession(),
Session(String),
closeBases()public void setContext(java.lang.Object context)
getContext()public java.lang.Object getContext()
setContext(java.lang.Object)public void hideScriptStatus(boolean yes)
public void openBase(java.lang.String path)
throws java.io.IOException
path database, if it was closed.
java.io.IOExceptionexploreBase(String),
modifyBase(String),
closeBase(String)
public void openBase()
throws java.io.IOException
java.io.IOExceptionopenBase(String),
exploreBase(),
modifyBase(),
closeBase()
public Base exploreBase(java.lang.String path)
throws java.io.IOException
path database as readable.
The database is not modifiable. Simultaneously other sessions
can read (use) the same database, but not modify.
This method together with modifyBase() is basic mechanism
for implementation of multithread and multi-user work in a server.
Session ss = new Session();
ss.exploreBase("Users");
ss.z("= User:ann1");
ss.z("= User:dan");
...
ss.closeBase();
Note: In place of exploreBase("Users") the Zigzag expression
ss.z("= $base Users") may be used. In this case
database will be closed at end of each successful Script execution,
so closeBase() is not needed.
path - pathname of a database
java.io.IOExceptionBase,
modifyBase(String),
closeBase(String)
public Base exploreBase()
throws java.io.IOException
java.io.IOExceptionexploreBase(String),
modifyBase(),
closeBase()
public void modifyBase(java.lang.String path)
throws java.io.IOException
path database as modifiable.
This method together with exploreBase() is basic mechanism
for implementation of multithread and multi-user work in a server.
Session ss = new Session();
ss.modifyBase("Users");
ss.z("User:ann1 =");
ss.z("User:dan =");
...
ss.closeBase();
Note: In place of modifyBase("Users") the Zigzag expression
ss.z("$base Users =") may be used. In this case
database will be closed at end of each successful Script execution,
so closeBase() is not needed.
path - pathname of a database
java.io.IOExceptionexploreBase(String),
closeBase(String)
public void modifyBase()
throws java.io.IOException
java.io.IOExceptionmodifyBase(String),
exploreBase(),
closeBase()
public void clearBase(java.lang.String path)
throws java.io.IOException
path database
and sets up it as modifiable .
java.io.IOExceptionexploreBase(String),
modifyBase(String),
closeBase(String)
public void clearBase()
throws java.io.IOException
java.io.IOExceptionclearBase(String),
exploreBase(),
modifyBase(),
closeBase()
public void closeBase()
throws java.io.IOException
Session ss = new Session();
ss.modifyBase("Users");
...
ss.closeBase();
Note: Closed database may be opened repeatedly.
java.io.IOExceptionexploreBase(),
exploreBase(String),
modifyBase(),
modifyBase(String),
openBase(),
openBase(String)
public void closeBase(java.lang.String path)
throws java.io.IOException
path database.
Session ss = new Session();
ss.modifyBase("Users");
ss.exploreBase("Owners");
...
ss.closeBase("Users");
...
Note: Closed database may be opened repeatedly.
java.io.IOExceptionexploreBase(),
exploreBase(String),
modifyBase(),
modifyBase(String),
openBase(),
openBase(String)
public void closeBases()
throws java.io.IOException
java.io.IOExceptioncloseBase()
public Variable var(java.lang.String name)
throws java.io.IOException
Session ss = new Session();
...
ss.z("$x = department/");
Variable x = ss.var("$x");
java.io.IOExceptioncloseVar(String),
Variable
public Variable var(java.lang.String name,
int category)
throws java.io.IOException
category values.
The category may be
PN.SIMPLE or PN.COMPLEX.
In example below the value is simple name department,
the value1 is department:'software support'
Session ss = new Session();
ss.z("$x = department:'software support'");
String value = ss.var("$x", PN.SIMPLE).value();
String value1 = ss.var("$x", PN.COMPLEX).value();
ss.close();
java.io.IOExceptioncloseVar(String),
Variable
public void closeVar(java.lang.String name)
throws java.io.IOException
x.clear() and x = null
enables to free memory before garbage collection by JVM.
Session ss = new Session();
...
ss.z("$x = department/");
Variable x = ss.var("$x");
Vector v = x.values();
ss.closeVar("$x");
x.clear();
x = null;
java.io.IOExceptionvar(String),
Variablepublic Base base()
Session ss = new Session();
ss.exploreBase("CompanyX");
...
Base base = ss.base();
Base,
exploreBase(java.lang.String),
modifyBase(java.lang.String)public Base base(int category)
category values.
The category may be
PN.SIMPLE or PN.COMPLEX.
In example below the value is simple name programmer,
the value1 is programmer:'Smit'.
Session ss = new Session();
ss.modifyBase("CompanyX");
ss.z("worker:programmer:'Smit' =;");
ss.exploreBase();
String value = ss.base(PN.SIMPLE).value("worker");
String value1 = ss.base(PN.COMPLEX).value("worker");
ss.close();
Base,
exploreBase(java.lang.String),
modifyBase(java.lang.String),
base()public void setEmptyLineReporting(boolean emptyLineReporting)
report()public boolean isEmptyLineReporting()
setEmptyLineReporting(boolean)public void setErrExcepted(boolean excepted)
Errorpublic boolean isErrExcepted()
Error,
setErrExcepted(boolean)public void setFailExcepted(boolean excepted)
Failurepublic boolean isFailExcepted()
Failure,
setFailExcepted(boolean)
public int login(User user)
throws java.io.IOException
user and determines User's access that
is defined in the current Session's database.
The User's access is defined as role via
database relation $User ($Password, $Role).
If database does not have such relation,
this method returns User.ADMIN access.
This method is intended for the advanced developers.
java.io.IOExceptionUser,
User.access()public User user()
User, registered through the login(User).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||