/* Richard A. DeVenezia * SUGI 29 - "Greetings from the Edge" * www.devenezia.com/papers */ public class GatewayAdapter { private static int maxNumberOfConnections = 5; private static Gateway gateway = null; private static Thread gatewayThread = null; static final ThreadGroup myThreadGroup = new ThreadGroup (getRootThreadGroup(), "GatewayAdapter"); /**/ GatewayAdapter () { if (gateway != null) return; gateway = new Gateway(maxNumberOfConnections); gatewayThread = new Thread (myThreadGroup, gateway, "Gateway"); System.out.println ("thread created"); gatewayThread.start(); System.out.println ("thread started"); } /**/ private static ThreadGroup getRootThreadGroup () { ThreadGroup root = null; root = Thread.currentThread().getThreadGroup().getParent(); while (root.getParent() != null) { root = root.getParent(); } return root; } /**/ String getThreadGroupName () { return myThreadGroup.getName(); } /**/ String getServiceThreadName () { return gatewayThread.getName(); } /**/ void end () { gateway.end(); gateway = null; } /**/ public int getConnectionHandle (String driverClass, String databaseURL, String username, String password) throws Exception { return gateway.getConnectionHandle (driverClass, databaseURL, username, password); } /**/ public int getStatementHandle (double cHandle, double updatable) throws Exception { return gateway.getStatementHandle ( (int) cHandle, (0 != updatable)); } /**/ public void closeConnectionHandle (double cHandle) throws Exception { gateway.closeConnectionHandle ( (int) cHandle); } /**/ public void closeStatementHandle (double sHandle) throws Exception { gateway.closeStatementHandle ( (int) sHandle); } /**/ public void closeResultSetHandle (double rHandle) throws Exception { gateway.closeResultSetHandle ( (int) rHandle); } /**/ public void executeUpdate (double sHandle, String sql) throws Exception { gateway.executeUpdate ( (int) sHandle, sql); } /**/ public int executeQuery (double sHandle, String sql) throws Exception { return gateway.executeQuery ( (int) sHandle, sql); } /**/ public boolean nextRow (double rHandle) throws Exception { return gateway.nextRow ( (int) rHandle); } /**/ public double getValue (double rHandle, double colNum) throws Exception { return gateway.getValue ( (int) rHandle, (int) colNum); } /**/ public String getText (double handle, double colNum) throws Exception { return gateway.getText ( (int) handle, (int) colNum); } /**/ public void setValue (double handle, double colNum, double value) throws Exception { gateway.setValue ( (int) handle, (int) colNum, value); } /**/ public void setText (double handle, double colNum, String text) throws Exception { gateway.setText ( (int) handle, (int) colNum, text); } /**/ public void insertRow (double handle) throws Exception { gateway.insertRow ( (int) handle); } /**/ public void moveToInsertRow (double handle) throws Exception { gateway.moveToInsertRow ( (int) handle); } /**/ public String getColumnName (double handle, double colNum) throws Exception { return gateway.getColumnName ( (int) handle, (int) colNum); } /** / public int getColumnType ( double handle, double colNum) throws Exception { return gateway.getColumnType ( (int) handle, (int) colNum); } /**/ public int getColumnCount (double handle) throws Exception { return gateway.getColumnCount ( (int) handle); } /**/ public int getColumnDisplaySize (double handle, double colNum) throws Exception { return gateway.getColumnDisplaySize ( (int) handle, (int) colNum); } /**/ public String getSasColumnType (double handle, double colNum) throws Exception { int type = gateway.getColumnType ( (int) handle, (int) colNum); switch (type) { case java.sql.Types.CHAR: return "C"; case java.sql.Types.VARCHAR: return "C"; case java.sql.Types.BIGINT: return "N"; case java.sql.Types.BINARY: return "N"; case java.sql.Types.BOOLEAN: return "N"; case java.sql.Types.DECIMAL: return "N"; case java.sql.Types.DOUBLE: return "N"; case java.sql.Types.FLOAT: return "N"; case java.sql.Types.INTEGER: return "N"; case java.sql.Types.NUMERIC: return "N"; case java.sql.Types.REAL: return "N"; case java.sql.Types.SMALLINT:return "N"; default: return "?"; } } /**/ /* String listall() { // http://javaalmanac.com/egs/java.lang/ListThreads.html String s = ""; try { ThreadGroup root = Thread.currentThread().getThreadGroup().getParent(); while (root.getParent() != null) { root = root.getParent(); } s = visit (root,0); } catch (Exception e) { s = e.toString(); } return s; } private static String repeat(String p, int count) { String s = ""; if (count >= 0) for (int i=0; i<=count; i++) { s += p; } return s; } public static String visit(ThreadGroup group, int level) { String thelist = repeat(".", level) + "group:"+group.getName() + " level=" + level+ "\n"; int numThreads = group.activeCount(); Thread[] threads = new Thread[numThreads*2]; numThreads = group.enumerate(threads, false); for (int i=0; i