package extjtech; import java.io.*; import java.math.*; import com.sssw.rt.util.*; // The ExtData class shows how you can access a SilverStream // server from an external Java client. It includes examples // of retrieving and updating rows of data from a SilverStream // server object. public class ExtData { // Instance variables for the SilverStream objects used // by the ExtData class. AgrServerSession session; AgrData appdata; // Constructor for the ExtData class. It does the following: // * Connects to a SilverStream server // * Accesses the appropriate data // * Performs a requested operation on that data (including // retrieval and/or update) // // It takes 4 arguments: // 1 SilverStream server host // myserver // 2 SilverStream db & data source object // mydb:com.myorg.data.dsoMyPassthru // 3 Operation to perform // costupdate // 4 Value to use in the operation // 2 public ExtData(String s3serverhost, String s3dsolocation, String operation, String opvalue) { try { // Initialize the SilverStream runtime environment. Do // this if you need to specify a login handler for the // SilverStream server to call back when it requires user // authentication. (The login handler is a class that you // code and instantiate.) AgRuntime.init(new LoginHandler()); // Connect to the appropriate SilverStream server. This // establishes a server session (represented by an instance // of AgrServerSession). // // The following example connects via HTTP. In this case, // you wouldn't use RMI-IIOP (the connectRMI method), // because it doesn't support DSO access. session = AgRuntime.connect(s3serverhost); // Create an instance of AgrData (to represent the cache of // data you want to work with). appdata = new AgrData(); // Initialize the AgrData by passing it the AgrServerSession. appdata.init(session); // Specify the data source for the AgrData. In this case, // it is a pass-through DSO. appdata.setDataSource(s3dsolocation); // Invoke the DSO to get the data for the AgrData. appdata.invokeQuery(null); // Perform the requested operation (if supported). if (operation.equals("list")) { // Call the listRows() method of the ExtData class to // display the rows that the DSO put in the AgrData. listRows(); } else if (operation.equals("costupdate")) { // Call the raiseCost() method of the ExtData class to // get the "Cost per lb" column value in each AgrData // row and update it by a specified percentage. raiseCost(opvalue); // For demonstration purposes (to prove that the update // worked), execute a new query against the DSO to // refresh the AgrData with the updated rows from the // data source. (In your own applications, you may want // to keep using the rows you already have cached locally // and avoid extra queries such as this.) appdata.query(null); // Call the listRows() method of the ExtData class to // display the updated rows from the AgrData. listRows(); } else { // Notify user if the request can't be performed. System.out.println( "The requested operation:\n " + operation + "\n" + "is not supported. Please try again."); } } catch (Exception e) { System.out.println("Application error in ExtData"); e.printStackTrace(); System.exit(0); } finally { // When all done, close the SilverStream server session. session.close(); } } // This method displays all of the rows and columns from // the current cache (AgrData). void listRows() { try { // Go to the first row of the AgrData. boolean found = appdata.gotoFirst(); // Loop through the rows of the AgrData. while (found) { System.out.println(">>>Table row>>>"); // Loop through the columns (properties) of the // current row. For each column, display its name // and value. for (int i = 0; i < appdata.getPropertyCount(); i++) { System.out.println( appdata.getPropertyName(i) + ": " + String.valueOf(appdata.getProperty(i))); } // Go to the next row of the AgrData. found = appdata.gotoNext(); } System.out.println("<<