1 package in.co.daffodil.db.jdbc; 2 3 import java.sql.*; 4 import java.util.*; 5 import com.daffodilwoods.daffodildb.client.*; 6 import com.daffodilwoods.database.resource.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dml.DMLResult; 9 import com.daffodilwoods.daffodildb.server.serversystem._Connection; 10 import com.daffodilwoods.daffodildb.server.datadictionarysystem._ColumnCharacteristics; 11 12 34 public class DaffodilDBStatement 35 implements Statement { 36 37 int fetchSize; 38 int fetchDirection; 39 int resultSetType; 40 int resultSetConcurrency; 41 int resultSetHoldability; 42 int maxFieldSize; 43 int maxRows; 44 int queryTimeOut; 45 46 DaffodilDBConnection connection; 47 ArrayList batchList; 48 Object [] executeResult; 49 int currentResultIndex; 50 SQLWarning sqlWarnings; 51 int updateCount; 52 DaffodilDBResultSet resultSet; 53 boolean escapeProcessingEnabled; 54 Locale locale; 55 DMLResult dmlResult; 56 57 public DaffodilDBStatement(DaffodilDBConnection connection) throws 58 SQLException { 59 this(connection, 60 ResultSet.TYPE_FORWARD_ONLY, 61 ResultSet.CONCUR_READ_ONLY, 62 1 ); 63 } 64 65 public DaffodilDBStatement(DaffodilDBConnection connection, 66 int resultSetType, 67 int resultSetConcurrency) throws SQLException { 68 this(connection, 69 resultSetType, 70 resultSetConcurrency, 71 1 ); 72 } 73 74 public DaffodilDBStatement(DaffodilDBConnection connection, 75 int resultSetType, 76 int resultSetConcurrency, 77 int resultSetHoldability) throws SQLException { 78 locale = connection.getLocale(); 79 if (!connection.getMetaData().supportsResultSetType(resultSetType)) { 80 addWarning("DataBaseMetaData does not supports passed ResultSetType"); 81 resultSetType = ResultSet.TYPE_FORWARD_ONLY; 82 } 83 if (!connection.getMetaData().supportsResultSetConcurrency(resultSetType, 84 resultSetConcurrency)) { 85 addWarning("DataBaseMetaData does not supports passed Concurrency"); 86 resultSetConcurrency = ResultSet.CONCUR_READ_ONLY; 87 } 88 this.connection = connection; 89 this.resultSetType = resultSetType; 90 this.resultSetConcurrency = resultSetConcurrency; 91 this.resultSetHoldability = resultSetHoldability; 92 fetchDirection = ResultSet.FETCH_FORWARD; 93 escapeProcessingEnabled = true; 94 queryTimeOut = 0; 95 } 96 97 protected void writeToLog(String str) { 98 DaffodilDBConnection.println(str); 99 } 100 101 protected void writeToLog(String modifier,String str) { 102 DaffodilDBConnection.println(modifier,str); 103 } 104 105 117 118 public synchronized ResultSet executeQuery(String query) throws SQLException { 119 checkConnection(); 120 if (query == null || query.length() == 0) { 121 DException dex = new DException("DSE828", null); 122 throw dex.getSqlException(locale); 123 } 124 writeToLog("Query" , query); 125 createEnvironmentToExecute(true); 126 if (resultSet != null) { 127 resultSet.close(); 128 resultSet = null; 129 } 130 updateCount = -1; 131 132 String queryForDB = escapeProcessingEnabled ? connection.nativeSQL(query) : 133 query; 134 Object result[] = null; 135 try { 136 synchronized (connection) { 137 result = getRequiredObjectOfexecuteQuery( 138 connection.getServerConnection().executeQuery(queryForDB, 139 queryTimeOut, 140 resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ? 141 IteratorConstants.UPDATABLE : 142 IteratorConstants.NONSCROLLABLE), 143 resultSetConcurrency,maxRows); 144 } 145 } 146 catch (DException dse) { 147 throw dse.getSqlException(connection.getLocale()); 148 } 149 150 _RecordSetBuffer rsb = (_RecordSetBuffer) result[0]; 151 resultSet = new DaffodilDBResultSet(this); 152 resultSet.setRecordSetBuffer(rsb); 153 int oldResultSetCon = resultSetConcurrency; 154 resultSetConcurrency = result[1].hashCode(); 155 if(oldResultSetCon != resultSetConcurrency ){ 156 addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY "); 157 } 158 setResultSetAttributes(); 159 setRecordSetBufferAttributes(rsb); 160 resultSetConcurrency = oldResultSetCon; 161 return resultSet; 162 } 163 164 177 178 public synchronized int executeUpdate(String query) throws SQLException { 179 return executeUpdate(query, true); 180 } 181 182 207 208 public synchronized void close() throws SQLException { 209 if (resultSet != null) 210 synchronized( resultSet){ 211 resultSet.close(); 212 } 213 connection = null; 214 } 215 216 217 235 236 public synchronized int getMaxFieldSize() throws SQLException { 237 checkConnection(); 238 return maxFieldSize; 239 } 240 241 256 257 public synchronized void setMaxFieldSize(int max) throws SQLException { 258 checkConnection(); 259 if (max < 0) { 260 DException dex = new DException("DSE828", null); 261 throw dex.getSqlException(locale); 262 } 263 maxFieldSize = max; 264 } 265 266 281 282 public synchronized int getMaxRows() throws SQLException { 283 checkConnection(); 284 return maxRows; 285 } 286 287 298 299 public synchronized void setMaxRows(int max) throws SQLException { 300 checkConnection(); 301 if (max < 0) { 302 DException dex = new DException("DSE545", new Object [] {new Integer (max)}); 303 throw dex.getSqlException(locale); 304 } 305 maxRows = max; 306 } 307 308 322 323 public synchronized void setEscapeProcessing(boolean enable) throws SQLException { 324 checkConnection(); 325 escapeProcessingEnabled = enable; 326 } 327 328 338 339 public synchronized int getQueryTimeout() throws SQLException { 340 checkConnection(); 341 return queryTimeOut; 342 } 343 344 358 359 public synchronized void setQueryTimeout(int seconds) throws SQLException { 360 checkConnection(); 361 if (seconds < 0) { 362 DException dex = new DException("DSE832", 363 new Object [] {new Integer (seconds)}); 364 throw dex.getSqlException(locale); 365 } 366 queryTimeOut = seconds; 367 } 368 369 379 380 public synchronized void cancel() throws SQLException { 381 DException dex = new DException("DSE16", new Object [] {"cancel"}); 382 throw dex.getSqlException(locale); 383 } 384 385 405 406 public synchronized SQLWarning getWarnings() throws SQLException { 407 checkConnection(); 408 return sqlWarnings; 409 } 410 411 423 424 public synchronized void clearWarnings() throws SQLException { 425 checkConnection(); 426 sqlWarnings = null; 427 } 428 429 453 454 public synchronized void setCursorName(String name) throws SQLException { 455 checkConnection(); 456 DException dex = new DException("DSE16", new Object [] {"setCursorName"}); 457 throw dex.getSqlException(locale); 458 } 459 460 461 487 488 public synchronized boolean execute(String query) throws SQLException { 489 checkConnection(); 490 writeToLog(query); 491 if (query == null || query.length() == 0) { 492 DException dex = new DException("DSE828", null); 493 throw dex.getSqlException(locale); 494 } 495 createEnvironmentToExecute(true); 496 if (resultSet != null) { 497 resultSet.close(); 498 resultSet = null; 499 } 500 currentResultIndex = 0; 501 updateCount = -1; 502 503 String queryForDB = changeQueryForDB(query); 504 Object [] reqObject = null; 505 try { 506 synchronized (connection) { 507 executeResult = new Object [] { 508 connection.getServerConnection().execute(queryForDB, queryTimeOut, resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ? 509 IteratorConstants.UPDATABLE : 510 IteratorConstants.NONSCROLLABLE)}; 511 } 512 513 reqObject = getRequiredObjectOfexecute(executeResult[0], 514 resultSetConcurrency,maxRows); 515 executeResult[0] = reqObject[0]; 516 } 517 catch (DException dex) { 518 519 throw dex.getSqlException(connection.getLocale()); 520 } 521 522 if (executeResult[0] instanceof _RecordSetBuffer) { 523 _RecordSetBuffer rsb = (_RecordSetBuffer) executeResult[0]; 524 resultSet = new DaffodilDBResultSet(this); 525 resultSet.setRecordSetBuffer(rsb); 526 int oldResultSetCon = resultSetConcurrency; 527 resultSetConcurrency = reqObject[1].hashCode(); 528 if(oldResultSetCon != resultSetConcurrency ) 529 addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY " ) ; 530 setResultSetAttributes(); 531 setRecordSetBufferAttributes(rsb); 532 resultSetConcurrency = oldResultSetCon; 533 return true; 534 } 535 updateCount = executeResult[0].hashCode(); 536 updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount; 537 return false; 538 } 539 540 549 550 public synchronized ResultSet getResultSet() throws SQLException { 551 checkConnection(); 552 return resultSet; 553 } 554 555 565 566 public synchronized int getUpdateCount() throws SQLException { 567 checkConnection(); 568 return updateCount; 569 } 570 571 588 589 public synchronized boolean getMoreResults() throws SQLException { 590 checkConnection(); 591 currentResultIndex++; 592 if (executeResult != null && currentResultIndex < executeResult.length) { 593 if (resultSet != null) { 594 resultSet.close(); 595 resultSet = null; 596 } 597 updateCount = -1; 598 if (executeResult[currentResultIndex] instanceof _RecordSetBuffer) { 599 _RecordSetBuffer rsb = (_RecordSetBuffer) executeResult[ 600 currentResultIndex]; 601 resultSet = new DaffodilDBResultSet(this); 602 resultSet.setRecordSetBuffer(rsb); 603 setResultSetAttributes(); 604 setRecordSetBufferAttributes(rsb); 605 return true; 606 } 607 updateCount = executeResult[currentResultIndex].hashCode(); 608 updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount; 609 return false; 610 } 611 if (resultSet != null) { 612 resultSet.close(); 613 resultSet = null; 614 } 615 executeResult = null; 616 updateCount = -1; 617 return false; 618 } 619 620 621 643 644 public synchronized void setFetchDirection(int direction) throws SQLException { 645 checkConnection(); 646 if (direction == ResultSet.FETCH_FORWARD || 647 direction == ResultSet.FETCH_REVERSE || 648 direction == ResultSet.FETCH_UNKNOWN) 649 fetchDirection = direction; 650 else { 651 DException dex = new DException("DSE541", 652 new Object [] {new Integer (direction)}); 653 throw dex.getSqlException(locale); 654 } 655 } 656 657 671 672 public synchronized int getFetchDirection() throws SQLException { 673 checkConnection(); 674 return fetchDirection; 675 } 676 677 694 695 public synchronized void setFetchSize(int rows) throws SQLException { 696 checkConnection(); 697 if (rows < 0 || (getMaxRows() != 0 && rows > getMaxRows())) { 698 DException dex = new DException("DSE518", new Object [] {new Integer (rows)}); 699 throw dex.getSqlException(locale); 700 } 701 fetchSize = rows; 702 } 703 704 718 719 public synchronized int getFetchSize() throws SQLException { 720 checkConnection(); 721 return fetchSize; 722 } 723 724 733 734 public synchronized int getResultSetConcurrency() throws SQLException { 735 checkConnection(); 736 return resultSetConcurrency; 737 } 738 739 749 750 public synchronized int getResultSetType() throws SQLException { 751 checkConnection(); 752 return resultSetType; 753 } 754 755 769 770 public synchronized void addBatch(String sql) throws SQLException { 771 checkConnection(); 772 if (batchList == null) 773 batchList = new ArrayList(); 774 batchList.add(sql); 775 } 776 777 788 789 public synchronized void clearBatch() throws SQLException { 790 checkConnection(); 791 if (batchList != null && batchList.size() > 0) 792 batchList.clear(); 793 } 794 795 843 844 public synchronized int[] executeBatch() throws SQLException { 845 checkConnection(); 846 if (batchList == null) 847 return new int[0]; writeToLog("Processing : DaffodilDBStatement.executeBatch()"); 849 createEnvironmentToExecute(false); 850 int size = batchList.size(); 851 int[] abc = new int[size]; 852 Arrays.fill(abc, -3 ); 853 synchronized(connection){ 854 for (int i = 0; i < size; i++) { 855 try { 856 abc[i] = executeUpdate( (String ) batchList.get(i), false); 857 } 858 catch (SQLException E) { 859 clearBatch(); 860 throw new BatchUpdateException(E.getMessage(), E.getSQLState(), abc); 861 } 862 } 863 } 864 clearBatch(); 865 return abc; 866 } 867 868 875 876 public synchronized java.sql.Connection getConnection() throws SQLException { 877 checkConnection(); 878 return connection; 879 } 880 881 882 888 894 901 907 913 919 925 950 951 public synchronized boolean getMoreResults(int current) throws SQLException { 952 checkConnection(); 953 DException dex = new DException("DSE16", 954 new Object [] {"getMoreResults"}); 955 throw dex.getSqlException(locale); 956 } 957 958 969 970 public synchronized ResultSet getGeneratedKeys() throws SQLException { 971 if(dmlResult == null || !dmlResult.isInitialised){ 972 TempResultSet tempRs = new TempResultSet(new Object [0][0],new String [0]); 973 TempResultSetMetaData tempMetaData = new TempResultSetMetaData(new Object [0][20]); 974 tempRs.setType(ResultSet.TYPE_FORWARD_ONLY); 975 tempRs.setMetaData(tempMetaData); 976 return tempRs; 977 } 978 _ColumnCharacteristics cc = dmlResult.getColumnCharacteristics(); 979 TempResultSet tempRs = null; 980 try { 981 tempRs = new TempResultSet(dmlResult.getAutoIncrementValues(), cc.getColumnNames()); 982 } 983 catch (DException ex) { 984 throw ex.getSqlException(locale); 985 } 986 DaffodilDBResultSetMetaData rsmd = new DaffodilDBResultSetMetaData(connection); 987 rsmd.setColumnCharacteristics(cc); 988 tempRs.setType(ResultSet.TYPE_FORWARD_ONLY); 989 tempRs.setMetaData(rsmd); 990 return tempRs; 991 } 992 993 1015 1016 1017 public synchronized int executeUpdate(String sql, int autoGeneratedKeys) throws 1018 SQLException { 1019 if(autoGeneratedKeys == NO_GENERATED_KEYS) 1020 return executeUpdate(sql); 1021 writeToLog("Update" , sql + ", " + autoGeneratedKeys); 1022 return executeUpdate(sql,_Connection.AUTOGENERATEDKEYS,null); 1023 } 1024 1025 1043 1044 1045 public synchronized int executeUpdate(String sql, int columnIndexes[]) throws SQLException { 1046 checkConnection(); 1047 if(columnIndexes == null){ 1048 addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed"); 1049 return executeUpdate(sql); 1050 } 1051 int length = columnIndexes.length; 1052 String str = " ["; 1053 for (int i = 0; i < length; i++) 1054 str += (columnIndexes[i] + " "); 1055 writeToLog("Update" , sql + ", " + str); 1056 return executeUpdate(sql,_Connection.COLUMNINDEXES,columnIndexes); 1057 } 1058 1059 1076 1077 1078 public synchronized int executeUpdate(String sql, String columnNames[]) throws 1079 SQLException { 1080 checkConnection(); 1081 if(columnNames == null){ 1082 addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed"); 1083 return executeUpdate(sql); 1084 } 1085 int length = columnNames.length; 1086 String str = " ["; 1087 for (int i = 0; i < length; i++) 1088 str += (columnNames[i] + " "); 1089 writeToLog("Update" , sql + ", " + str); 1090 return executeUpdate(sql,_Connection.COLUMNNAMES,columnNames); 1091 } 1092 1093 1129 1130 1131 public synchronized boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 1132 if(autoGeneratedKeys == NO_GENERATED_KEYS) 1133 return execute(sql); 1134 checkConnection(); 1135 writeToLog(sql + ", " + autoGeneratedKeys); 1136 return execute(sql,_Connection.AUTOGENERATEDKEYS,null); 1137 } 1138 1139 1140 1175 1176 1177 public synchronized boolean execute(String sql, int columnIndexes[]) throws SQLException { 1178 checkConnection(); 1179 if(columnIndexes == null){ 1180 addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed"); 1181 return execute(sql); 1182 } 1183 int length = columnIndexes.length; 1184 String str = " ["; 1185 for (int i = 0; i < length; i++) 1186 str += (columnIndexes[i] + " "); 1187 writeToLog(sql + ", " + str); 1188 return execute(sql,_Connection.COLUMNINDEXES,columnIndexes); 1189 } 1190 1191 1227 1228 1229 public synchronized boolean execute(String sql, String columnNames[]) throws SQLException { 1230 checkConnection(); 1231 if(columnNames == null){ 1232 addWarning("NO Generated Keys will be retrived as, NO ColumnNames were passed"); 1233 return execute(sql); 1234 } 1235 int length = columnNames.length; 1236 String str = " ["; 1237 for (int i = 0; i < length; i++) 1238 str += (columnNames[i] + " "); 1239 writeToLog(sql + ", " + str); 1240 return execute(sql,_Connection.COLUMNNAMES,columnNames); 1241 } 1242 1243 1253 1254 public synchronized int getResultSetHoldability() throws SQLException { 1255 checkConnection(); 1256 DException dex = new DException("DSE16", 1257 new Object [] {"getResultSetHoldability"}); 1258 throw dex.getSqlException(locale); 1259 } 1260 1261 1262 1263 1269 1270 protected void checkConnection() throws SQLException { 1271 if (connection == null ) { 1272 DException dex = new DException("DSE940", null); 1273 throw dex.getSqlException(locale); 1274 } 1275 if (connection.isClosed()) { 1276 DException dex = new DException("DSE279", null); 1277 throw dex.getSqlException(locale); 1278 } 1279 } 1280 1281 protected void createEnvironmentToExecute(boolean clearBatch) throws 1282 SQLException { 1283 clearWarnings(); 1284 dmlResult = null; 1285 if (clearBatch) { 1286 if (batchList != null && batchList.size() > 0) { 1287 addWarning("Clearing batchList for createEnvironmentToExecute"); 1288 batchList.clear(); 1289 } 1290 } 1291 } 1292 1293 protected void setRecordSetBufferAttributes(_RecordSetBuffer rsb) { 1294 rsb.setMaxRows(maxRows); 1295 rsb.setMaxFieldSize(maxFieldSize); 1296 } 1297 1298 protected void setResultSetAttributes() throws SQLException { 1299 resultSet.setFetchDirection(fetchDirection); 1300 resultSet.setFetchSize(fetchSize); 1301 resultSet.setType(resultSetType); 1302 resultSet.setConcurreny(resultSetConcurrency); 1303 } 1304 1305 protected void addWarning(String warning) throws SQLException { 1306 if (sqlWarnings == null) { 1307 sqlWarnings = new SQLWarning(warning); 1308 return; 1309 } 1310 sqlWarnings.setNextWarning(new SQLWarning(warning)); 1311 } 1312 1313 protected void printRSB(_RecordSetBuffer rsb) throws SQLException { 1314 try { 1315 _RecordSetBufferIterator rsbi = rsb.getIterator(); 1316 if (rsbi.top()) { 1317 int count = rsb.getColumnCharacteristics().getColumnCount(); 1318 do { 1319 _Record r = rsbi.getRecord(); 1320 for (int j = 0; j < count; j++) { 1321 System.out.print(r.getColumnValue(j + 1) + "\t"); 1322 } 1323 } 1324 while (rsbi.next()); 1325 1326 } 1327 else 1328 ; 1330 } 1331 catch (DException ex) { 1332 throw ex.getSqlException(connection.locale); 1333 } 1334 } 1335 1336 protected String changeQueryForDB(String query) throws SQLException { 1337 query = changeForDropQuery(query); 1338 return escapeProcessingEnabled ? connection.nativeSQL(query) : query; 1339 } 1340 1341 public String changeForDropQuery(String query) throws SQLException { 1342 query = query.trim(); 1343 String toRepleace = "long bit varying"; 1344 int ndx = query.toLowerCase().indexOf(toRepleace); 1345 StringBuffer sb = new StringBuffer (query); 1346 if (ndx > -1) 1347 sb.replace(ndx, ndx + toRepleace.length(), "LONG VARBINARY"); 1348 query = sb.toString(); 1349 return query; 1350 } 1351 1352 protected static Object [] getRequiredObjectOfexecute(Object returnObject, 1353 int concurrency,int maxrows) throws 1354 DException, SQLException { 1355 if (returnObject instanceof _SelectIterator) 1356 return getRequiredObjectOfexecuteQuery(returnObject, concurrency,maxrows) ; 1357 return new Object [] {returnObject,new Integer (concurrency)}; 1358 } 1359 1360 private static Object [] getRequiredObjectOfexecuteQuery(Object returnObject, 1361 int concurrency,int maxRows) throws DException, SQLException { 1362 _SelectIterator retriever = (_SelectIterator) returnObject; 1363 if (concurrency == ResultSet.CONCUR_UPDATABLE && retriever.isUpdatable()) { 1364 RecordSetUpdateable rsb = new RecordSetUpdateable(); 1365 rsb.setSelectIterator(retriever); 1366 return new Object []{rsb,new Integer (ResultSet.CONCUR_UPDATABLE)}; 1367 } 1368 RecordSet rsb = new RecordSet(); 1369 rsb.setSelectIterator(retriever); 1370 return new Object []{rsb,new Integer (ResultSet.CONCUR_READ_ONLY)}; 1371 } 1372 1373 protected synchronized int executeUpdate(String query, boolean clearBatch) throws 1374 SQLException { 1375 checkConnection(); 1376 if (query == null || query.length() == 0) { 1377 DException dex = new DException("DSE828", null); 1378 throw dex.getSqlException(locale); 1379 } 1380 writeToLog("Update" , query); 1381 createEnvironmentToExecute(clearBatch); 1382 if (resultSet != null) { 1383 resultSet.close(); 1384 resultSet = null; 1385 } 1386 updateCount = -1; 1387 1388 String queryForDB = changeQueryForDB(query); 1389 Object result = null; 1390 try { 1391 synchronized (connection) { 1392 result = connection.getServerConnection().executeUpdate(queryForDB, 1393 queryTimeOut); 1394 1395 } 1396 } 1397 catch (DException dex) { 1398 throw dex.getSqlException(locale); 1399 } 1400 updateCount = result.hashCode(); 1401 updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount; 1402 return updateCount; 1403 } 1404 1405 private boolean execute(String query ,int paramType,Object param) throws SQLException{ 1406 if (query == null || query.length() == 0) { 1407 DException dex = new DException("DSE828", null); 1408 throw dex.getSqlException(locale); 1409 } 1410 createEnvironmentToExecute(true); 1411 if (resultSet != null) { 1412 resultSet.close(); 1413 resultSet = null; 1414 } 1415 currentResultIndex = 0; 1416 updateCount = -1; 1417 1418 String queryForDB = changeQueryForDB(query); 1419 Object [] reqObject = null; 1420 try { 1421 synchronized (connection) { 1422 executeResult = new Object [] { connection.getServerConnection().execute(queryForDB, queryTimeOut, resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ? 1423 IteratorConstants.UPDATABLE : 1424 IteratorConstants.NONSCROLLABLE,_Connection.EXECUTE, 1425 paramType,param)}; 1426 } 1427 reqObject = getRequiredObjectOfexecute(executeResult[0], 1428 resultSetConcurrency,maxRows); 1429 } 1430 catch (DException dex) { 1431 throw dex.getSqlException(connection.getLocale()); 1432 } 1433 1434 if (reqObject[0] instanceof _RecordSetBuffer) { 1435 executeResult[0] = reqObject[0]; 1436 _RecordSetBuffer rsb = (_RecordSetBuffer) reqObject[0]; 1437 resultSet = new DaffodilDBResultSet(this); 1438 resultSet.setRecordSetBuffer(rsb); 1439 int oldResultSetCon = resultSetConcurrency; 1440 resultSetConcurrency = reqObject[1].hashCode(); 1441 if(oldResultSetCon != resultSetConcurrency ) 1442 addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY " ) ; 1443 setResultSetAttributes(); 1444 setRecordSetBufferAttributes(rsb); 1445 resultSetConcurrency = oldResultSetCon; 1446 return true; 1447 } 1448 if(reqObject[0] instanceof DMLResult){ 1449 dmlResult = (DMLResult)reqObject[0]; 1450 executeResult[0] = new Integer (dmlResult.rowsEffected); 1451 }else{ 1452 executeResult[0] = reqObject[0]; 1453 } 1454 updateCount = executeResult[0].hashCode(); 1455 updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount; 1456 return false; 1457 } 1458 1459 private int executeUpdate(String query,int paramType ,Object parm) throws 1460 SQLException { 1461 checkConnection(); 1462 if (query == null || query.length() == 0) { 1463 DException dex = new DException("DSE828", null); 1464 throw dex.getSqlException(locale); 1465 } 1466 createEnvironmentToExecute(true); 1467 if (resultSet != null) { 1468 resultSet.close(); 1469 resultSet = null; 1470 } 1471 updateCount = -1; 1472 1473 String queryForDB = changeQueryForDB(query); 1474 Object result = null; 1475 try { 1476 synchronized (connection) { 1477 result = connection.getServerConnection().execute(queryForDB, 1478 queryTimeOut, IteratorConstants.NONSCROLLABLE, _Connection.EXECUTEUPDATE, paramType, parm); 1479 } 1480 if (result instanceof DMLResult) { 1481 dmlResult = (DMLResult) result; 1482 updateCount = dmlResult.rowsEffected; 1483 } 1484 else { 1485 updateCount = result.hashCode(); 1486 updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount; 1487 } 1488 } 1489 catch (DException dex) { 1490 throw dex.getSqlException(locale); 1491 } 1492 return updateCount; 1493 } 1494 1495 1496} 1497 | Popular Tags |