package hero.hook; import hero.interfaces.*; import hero.util.HeroHookException; import java.net.URL; import java.sql.*; import java.util.*; public class myHookOnReady implements hero.hook.NodeHookI { public String getMetadata() {return Constants.Nd.ONREADY;} public void onReady(Object b,BnNodeLocal n) throws HeroHookException { String url1 = "jdbc:postgresql://morpork.keogh.net.au:5432/Jonas_users"; String query1 = "SELECT branch FROM jiapuser WHERE name = "; String url2 = "jdbc:postgresql://localhost:5432/Lucid"; String query2 = "SELECT \"CustomerName\" FROM \"CustomersByBranch\" INNER JOIN \"CustomerDetails\" USING (\"CustomerName\") WHERE \"ValidBranch\" = "; String branch = ""; try { Class.forName ("org.postgresql.Driver"); DriverManager.setLogStream(System.out); Connection con = DriverManager.getConnection (url1, "jonas", "thewhale"); Statement stmt = con.createStatement (); String nodeName = n.getName(); BnProjectLocal project = n.getBnProject(); String prjName = project.getName(); /* Getting an instance of the ProjectSession API */ ProjectSessionHome prjhome = (ProjectSessionHome)ProjectSessionUtil.getHome(); ProjectSession prjSession = prjhome.create(); /* Referring to the current workflow instance */ prjSession.initProject(prjName); String userName = prjSession.getNodeExecutor(nodeName); System.out.println("userName =" + "p.keogh"); ResultSet rs = stmt.executeQuery (query1 + "\'" + userName + "\'"); while (rs.next()) { branch = rs.getString("branch"); System.out.println("branch=" + branch); } prjSession.setNodeProperty(nodeName,"Branch",branch); rs.close(); stmt.close(); con.close(); con = DriverManager.getConnection (url2, "jonas", "thewhale"); stmt = con.createStatement (); rs = stmt.executeQuery (query2 + "\'" + branch + "\'"); Collection customerList = new ArrayList(); while (rs.next()) { String cust = rs.getString("CustomerName"); customerList.add(cust); System.out.println("CustomerName=" + cust); } prjSession.setNodePropertyPossibleValues(nodeName,"CustomerName",customerList); rs.close(); stmt.close(); con.close(); } catch (SQLException ex) { // A SQLException was generated. Catch it and // display the error information. Note that there // could be multiple error objects chained // together System.out.println ("\n*** SQLException caught ***\n"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } } catch (java.lang.Exception ex) { // Got some other type of exception. Dump it. ex.printStackTrace (); } } //------------------------------------------------------------------- // checkForWarning // Checks for and displays warnings. Returns true if a warning // existed //------------------------------------------------------------------- private static boolean checkForWarning (SQLWarning warn) throws SQLException { boolean rc = false; // If a SQLWarning object was given, display the // warning messages. Note that there could be // multiple warnings chained together if (warn != null) { System.out.println ("\n *** Warning ***\n"); rc = true; while (warn != null) { System.out.println ("SQLState: " + warn.getSQLState ()); System.out.println ("Message: " + warn.getMessage ()); System.out.println ("Vendor: " + warn.getErrorCode ()); System.out.println (""); warn = warn.getNextWarning (); } } return rc; } // Other events public void beforeStart(Object b,BnNodeLocal n) throws HeroHookException {} public void afterStart(Object b,BnNodeLocal n) throws HeroHookException {} public void beforeTerminate(Object b,BnNodeLocal n) throws HeroHookException {} public void afterTerminate(Object b,BnNodeLocal n) throws HeroHookException {} public void onCancel(Object b,BnNodeLocal n) throws HeroHookException {} public void anticipate(Object b,BnNodeLocal n) throws HeroHookException {} public void onDeadline(Object b,BnNodeLocal n) throws HeroHookException {} }