From Pickwiki
Jump to navigationJump to search

Back to JavaSource

Click here for TestMeInstructions

* A simple test program provided by William Terry at Southwest Eye Center
* to help me get started with [[UniObjects]].
* Changes made by Wendy Smoak at Arizona State University wendy.smoak@asu.edu
* Don't hesitate to ask if you need help getting started!

import asjava.uniobjects.*;
import asjava.uniclientlibs.*;

public class [[TestMe]] {
   public static void main(String args[]) {

      [[UniFile]] customerFile;
      [[UniString]] uString;

      [[UniJava]] uJava = new [[UniJava]]();
      System.out.println("Version number = " + uJava.get[[VersionNumber]]());
      System.out.println("Max Sessions   = " + uJava.get[[MaxSessions]]());
      System.out.println("Num Sessions   = " + uJava.get[[NumSessions]]());

      try {
         // every thing runs out of the [[UniSession]] instance.
         [[UniSession]] uSession = new [[UniSession]]();
         System.out.println("after openSession");

         System.out.println("Status = " + uSession.status());

         /[[/Set]] up variables.
	 /[[/You]] don't need the next line on [[UniData]], where you 
	 //cannot change the port number.  However, if you are
	 //on [[UniVerse]] and have changed the port number from the
	 //default value of 31438, then uncomment this line edit it 
	 //to contain your port number. 
	 //uSession.set[[HostPort]]("YOUR PORT HERE");
	 /[[/This]] is the place you go to type 'uv' or 'udt'
	 /[[/Example]]:  /usr/ud60/demo
         //you may not need this...
         //it might need to be 'uvcs' for [[UniVerse]] (??)
         /[[/Uncomment]] the next three lines and change the values
         //if you're using a proxy.
         /[[/Ignore]] the part of the UOJ manual that tries to convince
         //you that you need it.  Unless you're using applets,
         //chances are, you do NOT need the proxy.
         //uSession.set[[ProxyHost]]("PROXY HOST");
         //uSession.set[[ProxyToken]]("PROXY TOKEN(PASSWORD)");

         System.out.println ( "[[HostName]]: "+uSession.get[[HostName]]() );
         System.out.println ( "[[HostPort]]: "+uSession.get[[HostPort]]() );
         System.out.println ( "[[UserName]]: "+uSession.get[[UserName]]() );
         System.out.println ( "[[AccountPath]]: "+uSession.get[[AccountPath]]() );
         System.out.println ( "[[ConnectionString]]: "+uSession.get[[ConnectionString]]() );
         System.out.println ( "[[ProxyPort]]: "+uSession.get[[ProxyPort]]() );
         System.out.println ( "[[ProxyHost]]: "+uSession.get[[ProxyHost]]() );
         System.out.println ( "[[ProxyToken]]: "+uSession.get[[ProxyToken]]() );

         // lets connect to the database.

         /[[/This]] next section is file-structure specific.
         /[[/Change]] to one of your filenames if you're not using the demo account
         customerFile = uSession.open("CUSTOMER");
         System.out.println("CUSTOMER opened");
         System.out.println (customerFile.toString());
         /[[/Change]] this to a key in the file you specified
         String key = "25";
         uString = customerFile.read(key);

         /[[/Some]] examples of [[UniDynArray]] and read[[NamedField]]
         [[UniDynArray]] u[[DynArray]] = new [[UniDynArray]](uString);
         System.out.println("Customer Name = " +
               u[[DynArray]].extract(1) + "\n");
         String fieldName = "CITY";
         [[UniString]] fieldContents = customerFile.read[[NamedField]](key, fieldName);
         System.out.println(fieldName+": "+fieldContents);
         System.out.println("CUSTOMER closed");
         // did we connect?
         if (uSession.isActive()) 
            // lets disconnect from the database.

      } catch ([[UniSessionException]] e) {
         System.out.println("Error: " + e);
      catch ([[UniFileException]] e) {
         System.out.println("File Error: " + e);