UniObjectsTest
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 [email protected] * 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. uSession.set[[HostName]]("[[YOUR_HOST_NAME]]"); uSession.set[[UserName]]("[[YOUR_USER_NAME]]"); uSession.setPassword("[[YOUR_PASSWORD]]"); /[[/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 uSession.set[[AccountPath]]("/usr/ud60/demo"); //you may not need this... //it might need to be 'uvcs' for [[UniVerse]] (??) //uSession.set[[ConnectionString]]("udcs"); /[[/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[[ProxyPort]](1234); //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(); 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. uSession.connect(); System.out.println("Connected!"); /[[/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); System.out.println(uString); /[[/Some]] examples of [[UniDynArray]] and read[[NamedField]] [[UniDynArray]] u[[DynArray]] = new [[UniDynArray]](uString); System.out.println("Customer Name = " + u[[DynArray]].extract(1) + "\n"); System.out.println(); String fieldName = "CITY"; [[UniString]] fieldContents = customerFile.read[[NamedField]](key, fieldName); System.out.println(fieldName+": "+fieldContents); customerFile.close(); System.out.println("CUSTOMER closed"); // did we connect? if (uSession.isActive()) { // lets disconnect from the database. uSession.disconnect(); } System.out.println("Disconnected."); } catch ([[UniSessionException]] e) { System.out.println("Error: " + e); } catch ([[UniFileException]] e) { System.out.println("File Error: " + e); } } }