1 package com.daffodilwoods.daffodildb.php; 2 3 16 import java.rmi.*; 17 import java.util.*; 18 19 import com.daffodilwoods.daffodildb.client.*; 20 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 21 import com.daffodilwoods.daffodildb.server.serversystem.*; 22 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 23 import com.daffodilwoods.database.resource.*; 24 import com.daffodilwoods.rmi.*; 25 import com.daffodilwoods.rmi.interfaces.*; 26 import java.lang.reflect.Constructor ; 27 28 public class DDBHypertextPreprocessor { 29 30 public RecordSet resultSet; 31 private String otherQueryStatus; 32 HashMap serverMap; 33 final int GET_ERROR_MESSAGE = 1; 34 final int GET_ERROR_CODE = 2; 35 final int GET_WARNING = 3; 36 final int TXN_COMMIT = 11; 37 final int TXN_ROLLBACK = 12; 38 final int CLOSE_CONNECTION = 13; 39 final int TXN_AUTOCOMMIT_ON = 14; 40 final int TXN_AUTOCOMMIT_OFF = 15; 41 final int SET_AUTO_COMMIT = 16; 42 final int DML_STMT = 21; 43 final int DQL_STMT = 22; 44 final int OTHER_STMT = 23; 45 final int DDB_FETCH_FIRST = 500; 46 final int DDB_FETCH_NEXT = 501; 47 final int DUMMY = 0; 48 49 61 public Object daffodildb_connect(String server, int port, String databaseName, 62 String username, String password, 63 String create, 64 int currentSessionID 65 66 ) throws 67 Exception { 68 69 if (serverMap == null) 70 serverMap = new HashMap(); 71 String rmiString = "rmi://" + server + ":" + port + "/DaffodilDB"; 72 _Server serverSystem = getServerSystemRmi(rmiString); 73 Properties prop = new Properties(); 74 prop.setProperty("user", username); 75 prop.setProperty("password", password); 76 prop.setProperty("create", 77 create.trim().equalsIgnoreCase("true") ? "true" : 78 "false"); 79 _Connection con = serverSystem.getConnection(databaseName, prop); 80 con.setAutoCommit(true); 81 con.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); 82 return con; 83 84 } 85 86 private _Server getServerSystemRmi(String rmiUrl) throws Exception { 87 _Server rmiServer = (_Server) serverMap.get(rmiUrl); 88 if (rmiServer == null) { 89 Object rmiServerInterface = Naming.lookup(rmiUrl); 90 Constructor rmiServerConstructor = Class.forName("com.daffodilwoods.rmi.RmiServer").getConstructor(new Class []{_RmiServer.class}); 91 rmiServer = (_Server) rmiServerConstructor.newInstance(new Object []{rmiServerInterface}); 92 serverMap.put(rmiUrl,rmiServer); 93 } 94 return rmiServer; 95 } 96 97 98 public String daffodildb_getError(Object obj, int requiredTypeObject) { 99 Throwable th = (Throwable ) obj; 100 if (requiredTypeObject == GET_ERROR_MESSAGE) { 101 return th.getMessage(); 102 } 103 if (requiredTypeObject == GET_ERROR_CODE) { 104 if (th instanceof DException) { 105 return ( (DException) th).getSQLCode(); 106 } 107 if (requiredTypeObject == GET_WARNING) { 108 } 109 110 } 111 return "HY000"; 112 } 113 114 public String getString(Object rsbi, int index) throws Exception { 115 return ( (_RecordSetBufferIterator) rsbi).getColumnValue(index). 116 toString(); 117 } 118 119 public String getString(Object rs) throws Exception { 120 return rs.toString(); 121 } 122 123 public long getLong(Object rs, int index) throws Exception { 124 return ( (Long ) ( (RecordSet) rs).getIterator().getRecord().getColumnValue( 125 index)).longValue(); 126 } 127 128 public void daffodildb_ConnectionOperation(Object conObj, 129 int operationTobePerformed) throws 130 Exception { 131 _Connection con = ( (_Connection) conObj); 132 if (operationTobePerformed == TXN_COMMIT) 133 con.commit(); 134 if (operationTobePerformed == TXN_ROLLBACK) 135 con.rollback(); 136 if (operationTobePerformed == CLOSE_CONNECTION) 137 con.close(); 138 } 139 140 public Object [] daffodildb_executer(Object connectionObject, 141 String sqlstatement) throws Exception { 142 Object retObj = ( (_Connection) connectionObject).execute(sqlstatement, 0, 143 0); 144 if (retObj instanceof _SelectIterator) { 145 RecordSet rs = new RecordSet(); 146 rs.setSelectIterator( (_SelectIterator) retObj); 147 _RecordSetBufferIterator rsbi = rs.getIterator(); 148 int colCount = rsbi.getRecordSetBuffer().getColumnCharacteristics(). 149 getColumnCount(); 150 String columnNames[] = new String [colCount]; 151 Integer [] sqlTypes = new Integer [colCount]; 152 _ColumnCharacteristics cc = rsbi.getRecordSetBuffer(). 153 getColumnCharacteristics(); 154 for (int i = 0; i < colCount; i++) { 155 columnNames[i] = cc.getColumnName(i + 1); 156 sqlTypes[i] = new Integer (cc.getColumnType(i + 1)); 157 158 } 159 return new Object [] { 160 new Integer (DQL_STMT), rsbi, 161 new Integer (colCount), columnNames, sqlTypes}; 162 } 163 if (retObj instanceof Integer ) { 164 return new Object [] { 165 new Integer (DML_STMT), new Integer (retObj.hashCode())}; 166 } 167 else 168 169 return new Object [] { 170 new Integer (OTHER_STMT)}; 171 172 } 173 174 public long daffodildb_getColumnCount(Object rsb) throws Exception { 175 return (long) ( (_RecordSetBuffer) rsb).getColumnCharacteristics(). 176 getColumnCount(); 177 } 178 179 public String daffodildb_getColumnName(Object rsbi, int columnIndex) throws 180 Exception { 181 return ( (_RecordSetBufferIterator) rsbi).getRecordSetBuffer(). 182 getColumnCharacteristics().getColumnName( 183 columnIndex); 184 } 185 186 public int getSQLTypes(Object rsbi, int columnIndex) throws Exception { 187 return ( (_RecordSetBufferIterator) rsbi).getRecordSetBuffer(). 188 getColumnCharacteristics().getColumnType( 189 columnIndex); 190 } 191 192 public int getInt(Object obj) { 193 return obj.hashCode(); 194 } 195 196 public boolean iterator(Object obj, int recordPosition, int absolute) throws 197 Exception { 198 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator) obj; 199 if (absolute != DUMMY) { 200 if (absolute < 0) { 201 rsbi.bottom(); 202 for (int i = absolute; i > 0; i++) { 203 if (!rsbi.previous()) { 204 rsbi.top(); 205 return false; 206 } 207 } 208 return true; 209 } 210 else { 211 rsbi.top(); 212 for (int i = 0; i < absolute; i++) { 213 if (!rsbi.next()) { 214 rsbi.bottom(); 215 return false; 216 } 217 } 218 return true; 219 } 220 } 221 else if (recordPosition == DDB_FETCH_FIRST) { 222 return rsbi.top(); 223 } 224 else { 225 return rsbi.next(); 226 } 227 } 228 229 238 } 239 | Popular Tags |