00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.driver;
00026
00027 import java.io.IOException;
00028 import java.net.Socket;
00029 import java.sql.ResultSet;
00030 import java.sql.SQLException;
00031 import java.sql.SQLWarning;
00032 import java.sql.Savepoint;
00033 import java.util.ArrayList;
00034 import java.util.Hashtable;
00035 import java.util.Properties;
00036
00037 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException;
00038 import org.objectweb.cjdbc.common.sql.AbstractRequest;
00039 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
00040 import org.objectweb.cjdbc.common.sql.NotImplementedException;
00041 import org.objectweb.cjdbc.common.sql.SelectRequest;
00042 import org.objectweb.cjdbc.common.sql.StoredProcedure;
00043 import org.objectweb.cjdbc.common.sql.filters.AbstractBlobFilter;
00044 import org.objectweb.cjdbc.common.sql.filters.HexaBlobFilter;
00045 import org.objectweb.cjdbc.common.stream.CJDBCInputStream;
00046 import org.objectweb.cjdbc.common.stream.CJDBCOutputStream;
00047 import org.objectweb.cjdbc.common.util.Constants;
00048 import org.objectweb.cjdbc.driver.protocol.CommandCompleted;
00049 import org.objectweb.cjdbc.driver.protocol.Commands;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 public class Connection implements java.sql.Connection
00068 {
00069
00070
00071
00072 protected boolean autoCommit = true;
00073
00074
00075 protected boolean isClosed = false;
00076
00077
00078 protected boolean readOnly = false;
00079
00080
00081 boolean writeExecutedInTransaction = false;
00082
00083
00084 protected int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED;
00085
00086
00087 protected long transactionId = 0;
00088
00089
00090 protected boolean needSqlSkeleton = false;
00091
00092
00093 protected SQLWarning firstWarning = null;
00094
00095
00096 protected DatabaseMetaData metaData = null;
00097
00098
00099 protected Driver driver = null;
00100
00101
00102 protected String url = null;
00103
00104
00105 protected String vdbUser = null;
00106 protected String vdbPassword = null;
00107
00108
00109 protected Socket socket;
00110
00111
00112 protected CJDBCInputStream socketInput;
00113
00114
00115 protected CJDBCOutputStream socketOutput;
00116
00117 private int reconnectRetries = 0;
00118
00119
00120 private static final int MAX_RECONNECT_ATTEMPTS = 2;
00121
00122 private AbstractBlobFilter blobFilter;
00123
00124
00125 protected boolean escapeBackslash = true;
00126 protected boolean escapeSingleQuote = true;
00127
00128
00129 protected boolean driverProcessed = true;
00130
00131
00132 public static final String TAG_MARKER = "!%";
00133
00134 public static final String TAG_MARKER_ESCAPE = TAG_MARKER + ";";
00135
00136 public static final String START_PARAM_TAG = "<" + TAG_MARKER;
00137
00138 public static final String END_PARAM_TAG = "|" + TAG_MARKER + ">";
00139
00140
00141 protected String preparedStatementBooleanTrue = "'1'";
00142 protected String preparedStatementBooleanFalse = "'0'";
00143
00144 protected String escapeChar = "\'";
00145
00146 protected static final String LINE_SEPARATOR = System
00147 .getProperty("line.separator");
00148
00149 private boolean closeSocketOnGC = true;
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 public Connection()
00160 {
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 public Connection(Driver driver, Socket socket, CJDBCInputStream in,
00178 CJDBCOutputStream out, String url, String userName, String password,
00179 boolean sqlSkeletonNeeded, AbstractBlobFilter filter)
00180 {
00181 this.driver = driver;
00182 this.socket = socket;
00183 this.socketInput = in;
00184 this.socketOutput = out;
00185 this.url = url;
00186 this.vdbUser = userName;
00187 this.vdbPassword = password;
00188 this.needSqlSkeleton = sqlSkeletonNeeded;
00189 this.blobFilter = filter;
00190 }
00191
00192
00193
00194
00195 protected void finalize() throws Throwable
00196 {
00197 if (this.closeSocketOnGC)
00198 {
00199 Throwable t = null;
00200 try
00201 {
00202 rollback();
00203 }
00204 catch (Exception e)
00205 {
00206 t = e;
00207 }
00208 try
00209 {
00210 close();
00211 }
00212 catch (Exception e)
00213 {
00214 t = e;
00215 }
00216
00217 if (t != null)
00218 {
00219 throw t;
00220 }
00221
00222 }
00223 super.finalize();
00224 }
00225
00226
00227
00228
00229
00230
00231 public String getURL()
00232 {
00233 return url;
00234 }
00235
00236
00237
00238
00239
00240
00241 public String getUserName()
00242 {
00243 return vdbUser;
00244 }
00245
00246
00247
00248
00249
00250
00251 public String getPassword()
00252 {
00253 return vdbPassword;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262 public String getConnectedController()
00263 {
00264 if (socket == null)
00265 return null;
00266 else
00267 return socket.getInetAddress().getHostName() + ":" + socket.getPort();
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 public void clearWarnings() throws SQLException
00282 {
00283 firstWarning = null;
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293 public void close() throws SQLException
00294 {
00295
00296
00297 synchronized (this)
00298 {
00299 if (isClosed)
00300 return;
00301 else
00302 isClosed = true;
00303 }
00304
00305 try
00306 {
00307 autoCommit = true;
00308 readOnly = false;
00309 socketOutput.writeInt(Commands.Reset);
00310 socketOutput.flush();
00311 }
00312 catch (Exception e)
00313 {
00314 throw new SQLException("Error while closing the connection: " + e);
00315 }
00316
00317 synchronized (driver.pendingConnectionClosing)
00318 {
00319 if (!driver.connectionClosingThreadisAlive)
00320 {
00321 ConnectionClosingThread t = new ConnectionClosingThread(driver);
00322 t.start();
00323 }
00324
00325 driver.pendingConnectionClosing.add(this);
00326 }
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 public void commit() throws SQLException
00341 {
00342 if (autoCommit)
00343 throw new SQLException("Trying to commit a connection in autocommit mode");
00344
00345 if (driver == null)
00346 throw new SQLException("No driver to send the commit request");
00347 try
00348 {
00349 socketOutput.writeInt(Commands.Commit);
00350 socketOutput.flush();
00351
00352 Object r = socketInput.readObject();
00353 writeExecutedInTransaction = false;
00354 if (r instanceof Long)
00355 transactionId = ((Long) r).longValue();
00356 else
00357 throw new SQLException(
00358 "Error occured while trying to start transaction after commit on C-JDBC Controller ("
00359 + r + ")");
00360 }
00361 catch (Exception e)
00362 {
00363 throw new SQLException("Error occured while commit of transaction '"
00364 + transactionId + "' was processed by C-JDBC Controller (" + e + ")");
00365 }
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 public java.sql.Statement createStatement() throws SQLException
00379 {
00380 return new Statement(this);
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 public java.sql.Statement createStatement(int resultSetType,
00394 int resultSetConcurrency) throws SQLException
00395 {
00396 Statement s = new Statement(this);
00397 s.setResultSetType(resultSetType);
00398 s.setResultSetConcurrency(resultSetConcurrency);
00399 return s;
00400 }
00401
00402
00403
00404
00405
00406
00407
00408
00409 public boolean getAutoCommit() throws SQLException
00410 {
00411 return this.autoCommit;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 public java.sql.DatabaseMetaData getMetaData() throws SQLException
00424 {
00425 if (metaData == null)
00426 {
00427 metaData = new DatabaseMetaData(this);
00428 }
00429 return metaData;
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439 public String getCatalog() throws SQLException
00440 {
00441 if (driver == null)
00442 throw new SQLException("No driver to get the catalog.");
00443 try
00444 {
00445 socketOutput.writeInt(Commands.ConnectionGetCatalog);
00446 socketOutput.flush();
00447
00448 Object rs = socketInput.readObject();
00449 if (rs instanceof String)
00450 {
00451 return (String) rs;
00452 }
00453 else if (rs instanceof SQLException)
00454 throw (SQLException) rs;
00455 else
00456 throw new SQLException("Connection.getCatalog: Unexpected response ("
00457 + rs + ")");
00458 }
00459 catch (Exception e)
00460 {
00461 throw new SQLException(
00462 "Connection.getCatalog: Error occured while request was processed by C-JDBC Controller ("
00463 + e + ")");
00464 }
00465 }
00466
00467
00468
00469
00470
00471
00472
00473 public ResultSet getCatalogs() throws SQLException
00474 {
00475
00476 if (driver == null)
00477 throw new SQLException("No driver to get the catalogs.");
00478 try
00479 {
00480 socketOutput.writeInt(Commands.ConnectionGetCatalogs);
00481 socketOutput.flush();
00482
00483 Object rs = socketInput.readObject();
00484 if (rs instanceof ResultSet)
00485 return (ResultSet) rs;
00486 else if (rs instanceof SQLException)
00487 throw (SQLException) rs;
00488 else
00489 throw new SQLException("Connection.getCatalogs: Unexpected response ("
00490 + rs + ")");
00491 }
00492 catch (Exception e)
00493 {
00494 throw new SQLException(
00495 "Connection.getCatalogs: Error occured while request was processed by C-JDBC Controller ("
00496 + e + ")");
00497 }
00498 }
00499
00500 protected java.sql.ResultSet getProcedures(String catalog,
00501 String schemaPattern, String procedureNamePattern) throws SQLException
00502 {
00503 if (driver == null)
00504 throw new SQLException("No driver to get the tables.");
00505 try
00506 {
00507 socketOutput.writeInt(Commands.DatabaseMetaDataGetProcedures);
00508 socketOutput.writeUTF(catalog);
00509 socketOutput.writeUTF(schemaPattern);
00510 socketOutput.writeUTF(procedureNamePattern);
00511 socketOutput.flush();
00512
00513 Object rs = socketInput.readObject();
00514 if (rs instanceof ResultSet)
00515 return (ResultSet) rs;
00516 else if (rs instanceof SQLException)
00517 throw (SQLException) rs;
00518 else
00519 throw new SQLException(
00520 "Connection.getProcedures: Unexpected response (" + rs + ")");
00521 }
00522 catch (Exception e)
00523 {
00524 throw new SQLException(
00525 "Connection.getProcedures: Error occured while request was processed by C-JDBC Controller ("
00526 + e + ")");
00527 }
00528 }
00529
00530 protected java.sql.ResultSet getProcedureColumns(String catalog,
00531 String schemaPattern, String procedureNamePattern,
00532 String columnNamePattern) throws SQLException
00533 {
00534 if (driver == null)
00535 throw new SQLException("No driver to get the tables.");
00536 try
00537 {
00538 socketOutput.writeInt(Commands.DatabaseMetaDataGetProcedureColumns);
00539 socketOutput.writeUTF(catalog);
00540 socketOutput.writeUTF(schemaPattern);
00541 socketOutput.writeUTF(procedureNamePattern);
00542 socketOutput.writeUTF(columnNamePattern);
00543 socketOutput.flush();
00544
00545 Object rs = socketInput.readObject();
00546 if (rs instanceof ResultSet)
00547 return (ResultSet) rs;
00548 else if (rs instanceof SQLException)
00549 throw (SQLException) rs;
00550 else
00551 throw new SQLException(
00552 "Connection.getProcedureColumns: Unexpected response (" + rs + ")");
00553 }
00554 catch (Exception e)
00555 {
00556 throw new SQLException(
00557 "Connection.getProcedureColumns: Error occured while request was processed by C-JDBC Controller ("
00558 + e + ")");
00559 }
00560 }
00561
00562
00563
00564
00565
00566
00567
00568 public int getTransactionIsolation() throws SQLException
00569 {
00570 return isolationLevel;
00571 }
00572
00573
00574
00575
00576
00577
00578
00579 public java.util.Map getTypeMap() throws SQLException
00580 {
00581 throw new NotImplementedException("getTypeMap()");
00582 }
00583
00584
00585
00586
00587
00588
00589
00590
00591 public SQLWarning getWarnings() throws SQLException
00592 {
00593 return firstWarning;
00594 }
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 public boolean isClosed() throws SQLException
00605 {
00606 return isClosed;
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 public boolean isReadOnly() throws SQLException
00618 {
00619 return readOnly;
00620 }
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 public String nativeSQL(String query) throws SQLException
00632 {
00633 return query;
00634 }
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644 public java.sql.CallableStatement prepareCall(String sql) throws SQLException
00645 {
00646 return prepareCall(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
00647 java.sql.ResultSet.CONCUR_READ_ONLY);
00648 }
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 public java.sql.CallableStatement prepareCall(String sql, int resultSetType,
00660 int resultSetConcurrency) throws SQLException
00661 {
00662 CallableStatement c = new CallableStatement(this, sql);
00663 c.setResultSetType(resultSetType);
00664 c.setResultSetConcurrency(resultSetConcurrency);
00665 return c;
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 public java.sql.PreparedStatement prepareStatement(String sql)
00680 throws SQLException
00681 {
00682 return new PreparedStatement(this, sql);
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 public java.sql.PreparedStatement prepareStatement(String sql,
00697 int resultSetType, int resultSetConcurrency) throws SQLException
00698 {
00699 PreparedStatement s = new PreparedStatement(this, sql);
00700 s.setResultSetType(resultSetType);
00701 s.setResultSetConcurrency(resultSetConcurrency);
00702 return s;
00703 }
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 public void rollback() throws SQLException
00715 {
00716 if (autoCommit)
00717 throw new SQLException(
00718 "Trying to rollback a connection in autocommit mode");
00719
00720 if (driver == null)
00721 throw new SQLException("No driver to send the rollback request");
00722
00723 try
00724 {
00725 socketOutput.writeInt(Commands.Rollback);
00726 socketOutput.flush();
00727
00728 writeExecutedInTransaction = false;
00729 Object r = socketInput.readObject();
00730 if (r instanceof Long)
00731 transactionId = ((Long) r).longValue();
00732 else
00733 throw new SQLException(
00734 "Error occured while trying to start transaction after rollback on C-JDBC Controller ("
00735 + r + ")");
00736 }
00737 catch (Exception e)
00738 {
00739 throw new SQLException("Error occured while rollback of transaction '"
00740 + transactionId + "' was processed by C-JDBC Controller (" + e + ")");
00741 }
00742 }
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 public void setAutoCommit(boolean autoCommit) throws SQLException
00763 {
00764 if (this.autoCommit == autoCommit)
00765 return;
00766
00767 this.autoCommit = autoCommit;
00768 if (driver == null)
00769 throw new SQLException("No driver to get a transaction id");
00770
00771 if (autoCommit)
00772 {
00773 transactionId = 0;
00774 try
00775 {
00776 socketOutput.writeInt(Commands.SetAutoCommit);
00777 socketOutput.flush();
00778 Object r = socketInput.readObject();
00779 writeExecutedInTransaction = false;
00780 if (r instanceof Boolean || ((Boolean) r).booleanValue())
00781 return;
00782 else
00783 throw new SQLException(
00784 "Error occured while trying to change autocommit value on C-JDBC Controller ("
00785 + r + ")");
00786 }
00787 catch (Exception e)
00788 {
00789 throw new SQLException(
00790 "Error occured while trying to change autocommit value on C-JDBC Controller ("
00791 + e + ")");
00792 }
00793 }
00794 else
00795 {
00796
00797 try
00798 {
00799 socketOutput.writeInt(Commands.Begin);
00800 socketOutput.flush();
00801 Object r = socketInput.readObject();
00802 if (r instanceof Long)
00803 transactionId = ((Long) r).longValue();
00804 else
00805 throw new SQLException(
00806 "Error occured while trying to start transaction on C-JDBC Controller ("
00807 + r + ")");
00808 this.autoCommit = false;
00809 }
00810 catch (Exception e)
00811 {
00812 throw new SQLException(
00813 "Error occured while trying to start transaction on C-JDBC Controller ("
00814 + e + ")");
00815 }
00816 }
00817 }
00818
00819
00820
00821
00822
00823
00824
00825 public void setCatalog(String catalog) throws SQLException
00826 {
00827 if (catalog == null)
00828 throw new SQLException("Invalid Catalog");
00829 Hashtable properties = driver.parseURL(url);
00830 properties.put(Driver.DATABASE_PROPERTY, catalog);
00831 url = driver.getUrlFromProperties(properties);
00832
00833 if (driver == null)
00834 throw new SQLException("No driver to set the catalog.");
00835 try
00836 {
00837 socketOutput.writeInt(Commands.ConnectionSetCatalog);
00838 socketOutput.writeUTF(catalog);
00839 socketOutput.flush();
00840
00841 Object rs = socketInput.readObject();
00842 if (rs instanceof Boolean)
00843 {
00844 if (((Boolean) rs).booleanValue() == false)
00845 throw new SQLException("Invalid Catalog");
00846 }
00847 else
00848 throw new SQLException("Connection.setCatalog: Unexpected response ("
00849 + rs + ")");
00850 }
00851 catch (Exception e)
00852 {
00853 throw new SQLException(
00854 "Connection.setCatalog: Error occured while request was processed by C-JDBC Controller ("
00855 + e + ")");
00856 }
00857 }
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870 public void setReadOnly(boolean readOnly) throws SQLException
00871 {
00872 if ((autoCommit == false) && writeExecutedInTransaction)
00873 throw new SQLException(
00874 "setReadOnly cannot be called in a transaction that has executed write requests.");
00875
00876 this.readOnly = readOnly;
00877 }
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 public void setTransactionIsolation(int level) throws SQLException
00892 {
00893 isolationLevel = level;
00894 }
00895
00896
00897
00898
00899
00900
00901
00902 public void setTypeMap(java.util.Map map) throws SQLException
00903 {
00904 throw new NotImplementedException("setTypeMap()");
00905 }
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 protected void setConnectionParametersOnRequest(AbstractRequest request)
00917 {
00918 request.setIsAutoCommit(autoCommit);
00919 request.setIsReadOnly(readOnly);
00920 request.setDriverProcessed(driverProcessed);
00921 }
00922
00923
00924
00925
00926
00927
00928
00929
00930 protected java.sql.ResultSet execReadRequest(SelectRequest request)
00931 throws SQLException
00932 {
00933 if (driver == null)
00934 throw new SQLException("No driver to send the request '"
00935 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH) + "'");
00936 try
00937 {
00938 setConnectionParametersOnRequest(request);
00939 socketOutput.writeInt(Commands.ExecReadRequest);
00940 readRequestOnStream(request);
00941 socketOutput.flush();
00942
00943 Object in = socketInput.readObject();
00944 if (in instanceof NoMoreBackendException)
00945 {
00946 try
00947 {
00948
00949 if (driver.getControllerConfig().size() == 1)
00950 throw (SQLException) in;
00951 else
00952 {
00953
00954
00955 reconnect();
00956 return execReadRequest(request);
00957 }
00958 }
00959 catch (SQLException e1)
00960 {
00961
00962 in = e1;
00963 }
00964 }
00965 if (in instanceof IOException)
00966 {
00967 reconnect();
00968 return execReadRequest(request);
00969 }
00970 else if (in instanceof SQLException)
00971 {
00972 throw (SQLException) in;
00973 }
00974 else if (in instanceof Field[])
00975 {
00976 Field[] fields = (Field[]) in;
00977 ArrayList data = null;
00978 boolean hasMoreData;
00979 String cursorName = null;
00980 try
00981 {
00982 data = (ArrayList) socketInput.readObject();
00983 hasMoreData = socketInput.readBoolean();
00984 if (hasMoreData)
00985 cursorName = socketInput.readUTF();
00986 }
00987 catch (IOException e)
00988 {
00989 reconnect();
00990 return execReadRequest(request);
00991 }
00992 catch (Exception e1)
00993 {
00994 throw new SQLException(
00995 "Connection.execReadRequest: Unexpected response (" + e1
00996 + ") for request "
00997 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
00998 }
00999 return new org.objectweb.cjdbc.driver.DriverResultSet(fields, data,
01000 hasMoreData, cursorName);
01001 }
01002 else
01003 {
01004 throw new SQLException(
01005 "Connection.execReadRequest: Unexpected response (" + in
01006 + ") for request "
01007 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01008 }
01009
01010 }
01011 catch (RuntimeException e)
01012 {
01013 e.printStackTrace();
01014 throw new SQLException(
01015 "Connection.execReadRequest: Error occured while request '"
01016 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01017 + "' was processed by C-JDBC Controller (" + e + ")");
01018 }
01019 catch (IOException e)
01020 {
01021 try
01022 {
01023 reconnect();
01024 return execReadRequest(request);
01025 }
01026 catch (SQLException e1)
01027 {
01028 throw new SQLException("Connection lost while executing request '"
01029 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01030 + "' and automatic reconnect failed (" + e1 + ")");
01031 }
01032 }
01033 catch (ClassNotFoundException e)
01034 {
01035 e.printStackTrace();
01036 throw new SQLException(
01037 "Connection.execReadRequest: Unexpected response (" + e
01038 + ") for request "
01039 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01040 }
01041 }
01042
01043 private void reconnect() throws SQLException
01044 {
01045
01046 try
01047 {
01048 this.socket.close();
01049 }
01050 catch (IOException ignore)
01051 {
01052 }
01053 try
01054 {
01055 this.socketInput.close();
01056 }
01057 catch (IOException ignore)
01058 {
01059 }
01060 try
01061 {
01062 this.socketOutput.close();
01063 }
01064 catch (IOException ignore)
01065 {
01066 }
01067 synchronized (driver.pendingConnectionClosing)
01068 {
01069 if (driver.pendingConnectionClosing.remove(this))
01070 System.out.println("Warning! Closed call before reconnect");
01071 }
01072
01073
01074 reconnectRetries++;
01075 if (reconnectRetries > MAX_RECONNECT_ATTEMPTS)
01076 {
01077 reconnectRetries = 0;
01078 throw new SQLException("Aborting after " + MAX_RECONNECT_ATTEMPTS
01079 + " attemps.");
01080 }
01081 Properties prop = new Properties();
01082 prop.setProperty(Driver.USER_PROPERTY, vdbUser);
01083 prop.setProperty(Driver.PASSWORD_PROPERTY, vdbPassword);
01084 Connection c = (Connection) driver.connect(url, prop);
01085 c.setCloseSocketOnGC(false);
01086 this.socket = c.socket;
01087 this.socketInput = c.socketInput;
01088 this.socketOutput = c.socketOutput;
01089 this.isClosed = false;
01090 try
01091 {
01092 socketOutput.writeInt(Commands.RestoreConnectionState);
01093 socketOutput.writeBoolean(autoCommit);
01094 if (!autoCommit)
01095 socketOutput.writeLong(transactionId);
01096 }
01097 catch (IOException e)
01098 {
01099 throw new SQLException("Failed to reconnect to controller (" + e + ")");
01100 }
01101 reconnectRetries = 0;
01102 }
01103
01104
01105
01106
01107
01108
01109 protected void setCloseSocketOnGC(boolean closeSocketOnGC)
01110 {
01111 this.closeSocketOnGC = closeSocketOnGC;
01112 }
01113
01114
01115
01116
01117
01118
01119
01120
01121 protected int execWriteRequest(AbstractWriteRequest request)
01122 throws SQLException
01123 {
01124 if (driver == null)
01125 throw new SQLException("No driver to send the request '"
01126 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH) + "'");
01127 try
01128 {
01129 setConnectionParametersOnRequest(request);
01130 socketOutput.writeInt(Commands.ExecWriteRequest);
01131 writeRequestOnStream(request, false);
01132 socketOutput.flush();
01133
01134 Object r = socketInput.readObject();
01135 if (r instanceof Integer)
01136 return ((Integer) r).intValue();
01137 else if (r instanceof SQLException)
01138 throw (SQLException) r;
01139 else
01140 throw new SQLException(
01141 "Connection.execWriteRequest: Unexpected response (" + r
01142 + ") for request "
01143 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01144 }
01145 catch (SQLException e)
01146 {
01147 throw e;
01148 }
01149 catch (IOException e)
01150 {
01151 try
01152 {
01153 reconnect();
01154 return execWriteRequest(request);
01155 }
01156 catch (SQLException e1)
01157 {
01158 throw new SQLException("Connection lost while executing request'"
01159 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01160 + "' and automatic reconnect failed (" + e1 + ")");
01161 }
01162 }
01163 catch (Exception e)
01164 {
01165 throw new SQLException("execWriteRequest: Error occured while request '"
01166 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01167 + "' was processed by C-JDBC Controller (" + e + ")");
01168 }
01169 }
01170
01171
01172
01173
01174
01175
01176
01177
01178 private void readRequestOnStream(SelectRequest request) throws IOException
01179 {
01180
01181 socketOutput.writeUTF(request.getSQL());
01182 socketOutput.writeBoolean(request.getEscapeProcessing());
01183 socketOutput.writeUTF(LINE_SEPARATOR);
01184 socketOutput.writeInt(request.getTimeout());
01185 socketOutput.writeBoolean(request.isAutoCommit());
01186 socketOutput.writeBoolean(request.isDriverProcessed());
01187 socketOutput.writeInt(request.getMaxRows());
01188 socketOutput.writeInt(request.getFetchSize());
01189 String cursor = request.getCursorName();
01190 if (cursor != null)
01191 {
01192 socketOutput.writeBoolean(true);
01193 socketOutput.writeUTF(cursor);
01194 }
01195 else
01196 socketOutput.writeBoolean(false);
01197
01198
01199 if (needSqlSkeleton || !request.isDriverProcessed())
01200 {
01201 String skeleton = request.getSqlSkeleton();
01202 if (skeleton != null)
01203 {
01204 socketOutput.writeBoolean(true);
01205 socketOutput.writeUTF(skeleton);
01206 }
01207 else
01208 socketOutput.writeBoolean(false);
01209 }
01210
01211 }
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221 private void procedureOnStream(StoredProcedure proc, boolean isRead)
01222 throws IOException
01223 {
01224 if (!isRead)
01225 writeExecutedInTransaction = true;
01226
01227
01228 socketOutput.writeUTF(proc.getSQL());
01229 socketOutput.writeBoolean(proc.getEscapeProcessing());
01230 socketOutput.writeUTF(LINE_SEPARATOR);
01231 socketOutput.writeInt(proc.getTimeout());
01232 socketOutput.writeBoolean(proc.isAutoCommit());
01233 socketOutput.writeBoolean(proc.isDriverProcessed());
01234 if (isRead)
01235 {
01236 socketOutput.writeInt(proc.getMaxRows());
01237 socketOutput.writeInt(proc.getFetchSize());
01238 }
01239
01240
01241 if (needSqlSkeleton || !proc.isDriverProcessed())
01242 {
01243 String skeleton = proc.getSqlSkeleton();
01244 if (skeleton != null)
01245 {
01246 socketOutput.writeBoolean(true);
01247 socketOutput.writeUTF(skeleton);
01248 }
01249 else
01250 socketOutput.writeBoolean(false);
01251 }
01252
01253 }
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264 private void writeRequestOnStream(AbstractWriteRequest request,
01265 boolean withKeys) throws IOException
01266 {
01267 if (!autoCommit)
01268 writeExecutedInTransaction = true;
01269
01270
01271 boolean isCreate = request.isCreate();
01272 boolean isDelete = request.isDelete();
01273 boolean isDrop = request.isDrop();
01274 boolean isInsert = request.isInsert();
01275 boolean isUpdate = request.isUpdate();
01276 boolean isAlter = request.isAlter();
01277 int requestType = -1;
01278 if (isCreate)
01279 requestType = Commands.CreateRequest;
01280 else if (isDelete)
01281 requestType = Commands.DeleteRequest;
01282 else if (isDrop)
01283 requestType = Commands.DropRequest;
01284 else if (isInsert)
01285 requestType = Commands.InsertRequest;
01286 else if (isUpdate)
01287 requestType = Commands.UpdateRequest;
01288 else if (isAlter)
01289 requestType = Commands.AlterRequest;
01290
01291 socketOutput.writeInt(requestType);
01292 socketOutput.writeUTF(request.getSQL());
01293 socketOutput.writeBoolean(request.getEscapeProcessing());
01294 socketOutput.writeUTF(LINE_SEPARATOR);
01295 socketOutput.writeInt(request.getTimeout());
01296 socketOutput.writeBoolean(request.isAutoCommit());
01297 socketOutput.writeBoolean(request.isDriverProcessed());
01298 if (withKeys)
01299 {
01300 socketOutput.writeInt(request.getMaxRows());
01301 socketOutput.writeInt(request.getFetchSize());
01302 }
01303
01304
01305
01306 if (needSqlSkeleton || !request.isDriverProcessed())
01307 {
01308 String skeleton = request.getSqlSkeleton();
01309 if (skeleton != null)
01310 {
01311 socketOutput.writeBoolean(true);
01312 socketOutput.writeUTF(skeleton);
01313 }
01314 else
01315 socketOutput.writeBoolean(false);
01316 }
01317
01318 }
01319
01320
01321
01322
01323
01324
01325
01326
01327 protected ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
01328 throws SQLException
01329 {
01330 if (driver == null)
01331 throw new SQLException("No driver to send the request '"
01332 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH) + "'");
01333 try
01334 {
01335 setConnectionParametersOnRequest(request);
01336 socketOutput.writeInt(Commands.ExecWriteRequestWithKeys);
01337 writeRequestOnStream(request, true);
01338 socketOutput.flush();
01339
01340 Object in = socketInput.readObject();
01341 if (in instanceof SQLException)
01342 throw (SQLException) in;
01343 else if (in instanceof Field[])
01344 {
01345 Field[] fields = (Field[]) in;
01346 ArrayList data = null;
01347 boolean hasMoreData;
01348 String cursorName = null;
01349 try
01350 {
01351 data = (ArrayList) socketInput.readObject();
01352 hasMoreData = socketInput.readBoolean();
01353 if (hasMoreData)
01354 cursorName = socketInput.readUTF();
01355 }
01356 catch (Exception e1)
01357 {
01358 throw new SQLException(
01359 "Connection.execWriteRequestWithKeys: Unexpected response (" + e1
01360 + ") for request "
01361 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01362 }
01363 return new org.objectweb.cjdbc.driver.DriverResultSet(fields, data,
01364 hasMoreData, cursorName);
01365 }
01366 else
01367 throw new SQLException(
01368 "Connection.execWriteRequestWithKeys: Unexpected response (" + in
01369 + ") for request "
01370 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01371 }
01372 catch (Exception e)
01373 {
01374 throw new SQLException(
01375 "execWriteRequestWithKeys: Error occured while request '"
01376 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01377 + "' was processed by C-JDBC Controller (" + e + ")");
01378 }
01379 }
01380
01381
01382
01383
01384
01385
01386
01387
01388 public ResultSet execReadStoredProcedure(StoredProcedure proc)
01389 throws SQLException
01390 {
01391 if (driver == null)
01392 throw new SQLException("No driver to send the request '"
01393 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH) + "'");
01394 try
01395 {
01396 setConnectionParametersOnRequest(proc);
01397 socketOutput.writeInt(Commands.ExecReadStoredProcedure);
01398 procedureOnStream(proc, true);
01399 socketOutput.flush();
01400
01401 Object in = socketInput.readObject();
01402 if (in instanceof SQLException)
01403 throw (SQLException) in;
01404 else if (in instanceof Field[])
01405 {
01406 Field[] fields = (Field[]) in;
01407 ArrayList data = null;
01408 boolean hasMoreData;
01409 String cursorName = null;
01410 try
01411 {
01412 data = (ArrayList) socketInput.readObject();
01413 hasMoreData = socketInput.readBoolean();
01414 if (hasMoreData)
01415 cursorName = socketInput.readUTF();
01416 }
01417 catch (Exception e1)
01418 {
01419 throw new SQLException(
01420 "Connection.execReadStoredProcedure: Unexpected response (" + e1
01421 + ") for request "
01422 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01423 }
01424 return new org.objectweb.cjdbc.driver.DriverResultSet(fields, data,
01425 hasMoreData, cursorName);
01426 }
01427 else
01428 throw new SQLException(
01429 "Connection.execReadStoredProcedure: Unexpected response (" + in
01430 + ") for request "
01431 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01432 }
01433 catch (RuntimeException e)
01434 {
01435 throw new SQLException(
01436 "Connection.execReadStoredProcedure: Error occured while request '"
01437 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01438 + "' was processed by C-JDBC Controller (" + e + ")");
01439 }
01440 catch (IOException e)
01441 {
01442 try
01443 {
01444 reconnect();
01445 return execReadStoredProcedure(proc);
01446 }
01447 catch (SQLException e1)
01448 {
01449 throw new SQLException("Connection lost while executing request'"
01450 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01451 + "' and automatic reconnect failed (" + e1 + ")");
01452 }
01453 }
01454 catch (ClassNotFoundException e)
01455 {
01456 throw new SQLException(
01457 "Connection.execReadStoredProcedure: Unexpected response (" + e
01458 + ") for request "
01459 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01460 }
01461 }
01462
01463
01464
01465
01466
01467
01468
01469
01470 protected int execWriteStoredProcedure(StoredProcedure proc)
01471 throws SQLException
01472 {
01473 if (driver == null)
01474 throw new SQLException("No driver to send the request '"
01475 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH) + "'");
01476 try
01477 {
01478 setConnectionParametersOnRequest(proc);
01479 socketOutput.writeInt(Commands.ExecWriteStoredProcedure);
01480 procedureOnStream(proc, false);
01481 socketOutput.flush();
01482
01483 Object r = socketInput.readObject();
01484 if (r instanceof Integer)
01485 return ((Integer) r).intValue();
01486 else if (r instanceof SQLException)
01487 throw (SQLException) r;
01488 else
01489 throw new SQLException(
01490 "Connection.execWriteStoredProcedure: Unexpected response (" + r
01491 + ") for request "
01492 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH));
01493 }
01494 catch (Exception e)
01495 {
01496 throw new SQLException(
01497 "execWriteStoredProcedure: Error occured while request '"
01498 + proc.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
01499 + "' was processed by C-JDBC Controller (" + e + ")");
01500 }
01501 }
01502
01503 protected ResultSet getColumns(String catalog, String schemaPattern,
01504 String tableNamePattern, String columnNamePattern) throws SQLException
01505 {
01506 if (driver == null)
01507 throw new SQLException("No driver to get the tables.");
01508 try
01509 {
01510 socketOutput.writeInt(Commands.DatabaseMetaDataGetColumns);
01511 socketOutput.writeUTF(catalog);
01512 socketOutput.writeUTF(schemaPattern);
01513 socketOutput.writeUTF(tableNamePattern);
01514 socketOutput.writeUTF(columnNamePattern);
01515 socketOutput.flush();
01516
01517 Object rs = socketInput.readObject();
01518 if (rs == null)
01519 return null;
01520 if (rs instanceof ResultSet)
01521 return (ResultSet) rs;
01522 else if (rs instanceof SQLException)
01523 throw (SQLException) rs;
01524 else
01525 throw new SQLException("Connection.getColumns: Unexpected response ("
01526 + rs + ")");
01527 }
01528 catch (Exception e)
01529 {
01530 throw new SQLException(
01531 "Connection.getColumns: Error occured while request was processed by C-JDBC Controller ("
01532 + e + ")");
01533 }
01534 }
01535
01536
01537
01538
01539 protected ResultSet getPrimaryKeys(String catalog, String schemaPattern,
01540 String tableNamePattern) throws SQLException
01541 {
01542 if (driver == null)
01543 throw new SQLException("No driver to get the tables.");
01544 try
01545 {
01546 socketOutput.writeInt(Commands.DatabaseMetaDataGetPrimaryKeys);
01547 socketOutput.writeUTF(catalog);
01548 socketOutput.writeUTF(schemaPattern);
01549 socketOutput.writeUTF(tableNamePattern);
01550 socketOutput.flush();
01551
01552 Object rs = socketInput.readObject();
01553 if (rs == null)
01554 return null;
01555 if (rs instanceof ResultSet)
01556 return (ResultSet) rs;
01557 else if (rs instanceof SQLException)
01558 throw (SQLException) rs;
01559 else
01560 throw new SQLException(
01561 "Connection.getPrimaryKeys: Unexpected response (" + rs + ")");
01562 }
01563 catch (Exception e)
01564 {
01565 throw new SQLException(
01566 "Connection.getPrimaryKeys: Error occured while request was processed by C-JDBC Controller ("
01567 + e + ")");
01568 }
01569 }
01570
01571
01572
01573
01574
01575 protected ResultSet getTables(String catalog, String schemaPattern,
01576 String tableNamePattern, String[] types) throws SQLException
01577 {
01578 if (driver == null)
01579 throw new SQLException("No driver to get the tables.");
01580 try
01581 {
01582 socketOutput.writeInt(Commands.DatabaseMetaDataGetTables);
01583 socketOutput.writeUTF(catalog);
01584 socketOutput.writeUTF(schemaPattern);
01585 socketOutput.writeUTF(tableNamePattern);
01586 socketOutput.writeObject(types);
01587 socketOutput.flush();
01588
01589 Object rs = socketInput.readObject();
01590 if (rs == null)
01591 return null;
01592 if (rs instanceof ResultSet)
01593 return (ResultSet) rs;
01594 else if (rs instanceof SQLException)
01595 throw (SQLException) rs;
01596 else
01597 throw new SQLException("Connection.getTables: Unexpected response ("
01598 + rs + ")");
01599 }
01600 catch (Exception e)
01601 {
01602 throw new SQLException(
01603 "Connection.getTables: Error occured while request was processed by C-JDBC Controller ("
01604 + e + ")");
01605 }
01606 }
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616 public Object getStaticMetadata(String key) throws SQLException
01617 {
01618 try
01619 {
01620 socketOutput.writeInt(Commands.DatabaseStaticMetadata);
01621 socketOutput.writeUTF(key);
01622 socketOutput.flush();
01623
01624 Object s = socketInput.readObject();
01625 if (s instanceof SQLException)
01626 throw (SQLException) s;
01627 else
01628 return s;
01629 }
01630 catch (Exception e)
01631 {
01632 throw new SQLException(
01633 "Connection.getStaticMetadata: Error occured while request was processed by C-JDBC Controller ("
01634 + e + ")");
01635 }
01636
01637 }
01638
01639
01640
01641
01642
01643
01644
01645 public String getControllerVersionNumber() throws SQLException
01646 {
01647 try
01648 {
01649 socketOutput.writeInt(Commands.GetControllerVersionNumber);
01650 socketOutput.flush();
01651
01652 Object s = socketInput.readObject();
01653 if (s instanceof String)
01654 return (String) s;
01655 else
01656 throw new SQLException(
01657 "Connection.getControllerVersionNumber: Unexpected response (" + s
01658 + ")");
01659 }
01660 catch (Exception e)
01661 {
01662 throw new SQLException(
01663 "Connection.getControllerVersionNumber: Error occured while request was processed by C-JDBC Controller ("
01664 + e + ")");
01665 }
01666 }
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684 public void setHoldability(int holdability) throws SQLException
01685 {
01686 throw new NotImplementedException("setHoldability");
01687 }
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701 public int getHoldability() throws SQLException
01702 {
01703 throw new NotImplementedException("getHoldability");
01704 }
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717 public Savepoint setSavepoint() throws SQLException
01718 {
01719 throw new NotImplementedException("setSavepoint");
01720 }
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734 public Savepoint setSavepoint(String name) throws SQLException
01735 {
01736 throw new NotImplementedException("setSavepoint");
01737 }
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754 public void rollback(Savepoint savepoint) throws SQLException
01755 {
01756 throw new NotImplementedException("rollback");
01757 }
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770 public void releaseSavepoint(Savepoint savepoint) throws SQLException
01771 {
01772 throw new NotImplementedException("releaseSavepoint");
01773 }
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803 public java.sql.Statement createStatement(int resultSetType,
01804 int resultSetConcurrency, int resultSetHoldability) throws SQLException
01805 {
01806 throw new NotImplementedException("createStatement");
01807 }
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840 public java.sql.PreparedStatement prepareStatement(String sql,
01841 int resultSetType, int resultSetConcurrency, int resultSetHoldability)
01842 throws SQLException
01843 {
01844 throw new NotImplementedException("prepareStatement");
01845 }
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876 public java.sql.CallableStatement prepareCall(String sql, int resultSetType,
01877 int resultSetConcurrency, int resultSetHoldability) throws SQLException
01878 {
01879 throw new NotImplementedException("prepareCall");
01880 }
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916 public java.sql.PreparedStatement prepareStatement(String sql,
01917 int autoGeneratedKeys) throws SQLException
01918 {
01919 PreparedStatement ps = new PreparedStatement(this, sql);
01920 ps.setGeneratedKeysFlag(autoGeneratedKeys);
01921 return ps;
01922 }
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958 public java.sql.PreparedStatement prepareStatement(String sql,
01959 int columnIndexes[]) throws SQLException
01960 {
01961 throw new NotImplementedException("prepareStatement");
01962 }
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998 public java.sql.PreparedStatement prepareStatement(String sql,
01999 String columnNames[]) throws SQLException
02000 {
02001 throw new NotImplementedException("prepareStatement");
02002 }
02003
02004
02005
02006
02007
02008
02009 public AbstractBlobFilter getBlobFilter()
02010 {
02011 if (blobFilter == null)
02012 blobFilter = new HexaBlobFilter();
02013 return blobFilter;
02014 }
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024 public ResultSet getTableTypes() throws SQLException
02025 {
02026 if (driver == null)
02027 throw new SQLException("No driver to get the table types.");
02028 try
02029 {
02030 socketOutput.writeInt(Commands.DatabaseMetaDataGetTableTypes);
02031 socketOutput.flush();
02032
02033 Object rs = socketInput.readObject();
02034 if (rs == null)
02035 return null;
02036 if (rs instanceof ResultSet)
02037 return (ResultSet) rs;
02038 else if (rs instanceof SQLException)
02039 throw (SQLException) rs;
02040 else
02041 throw new SQLException(
02042 "Connection.getTableTypes: Unexpected response (" + rs + ")");
02043 }
02044 catch (Exception e)
02045 {
02046 throw new SQLException(
02047 "Connection.getTableTypes: Error occured while request was processed by C-JDBC Controller ("
02048 + e + ")");
02049 }
02050 }
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068 public ResultSet getTablePrivileges(String catalog, String schemaPattern,
02069 String tableNamePattern) throws SQLException
02070 {
02071 if (driver == null)
02072 throw new SQLException("No driver to get the table privileges.");
02073 try
02074 {
02075 socketOutput.writeInt(Commands.DatabaseMetaDataGetTablePrivileges);
02076 socketOutput.writeUTF(catalog);
02077 socketOutput.writeUTF(schemaPattern);
02078 socketOutput.writeUTF(tableNamePattern);
02079 socketOutput.flush();
02080
02081 Object rs = socketInput.readObject();
02082 if (rs == null)
02083 return null;
02084 if (rs instanceof ResultSet)
02085 return (ResultSet) rs;
02086 else if (rs instanceof SQLException)
02087 throw (SQLException) rs;
02088 else
02089 throw new SQLException(
02090 "Connection.getTablePrivileges: Unexpected response (" + rs + ")");
02091 }
02092 catch (Exception e)
02093 {
02094 throw new SQLException(
02095 "Connection.getTablePrivileges: Error occured while request was processed by C-JDBC Controller ("
02096 + e + ")");
02097 }
02098 }
02099
02100
02101
02102
02103 public ResultSet getSchemas() throws SQLException
02104 {
02105 if (driver == null)
02106 throw new SQLException("No driver to get the schemas.");
02107 try
02108 {
02109 socketOutput.writeInt(Commands.DatabaseMetaDataGetSchemas);
02110 socketOutput.flush();
02111
02112 Object rs = socketInput.readObject();
02113 if (rs == null)
02114 return null;
02115 if (rs instanceof ResultSet)
02116 return (ResultSet) rs;
02117 else if (rs instanceof SQLException)
02118 throw (SQLException) rs;
02119 else
02120 throw new SQLException("Connection.getSchemas: Unexpected response ("
02121 + rs + ")");
02122 }
02123 catch (Exception e)
02124 {
02125 throw new SQLException(
02126 "Connection.getSchemas: Error occured while request was processed by C-JDBC Controller ("
02127 + e + ")");
02128 }
02129 }
02130
02131
02132
02133
02134 public String getDatabaseProductName() throws SQLException
02135 {
02136 try
02137 {
02138 socketOutput.writeInt(Commands.DatabaseMetaDataGetDatabaseProductName);
02139 socketOutput.flush();
02140
02141 Object s = socketInput.readObject();
02142 if (s instanceof String)
02143 return (String) s;
02144 else
02145 throw new SQLException(
02146 "Connection.GetDatabaseProductName: Unexpected response (" + s
02147 + ")");
02148 }
02149 catch (Exception e)
02150 {
02151 throw new SQLException(
02152 "Connection.getDatabaseProductName: Error occured while request was processed by C-JDBC Controller ("
02153 + e + ")");
02154 }
02155 }
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165 public void fetchNextData(String cursorName, int fetchSize,
02166 DriverResultSet drsToUpdate) throws SQLException
02167 {
02168 try
02169 {
02170 socketOutput.writeInt(Commands.FetchNextResultSetRows);
02171 socketOutput.writeUTF(cursorName);
02172 socketOutput.writeInt(fetchSize);
02173 socketOutput.flush();
02174
02175 Object data = socketInput.readObject();
02176 if (data instanceof ArrayList)
02177 {
02178 boolean hasMoreData = socketInput.readBoolean();
02179 drsToUpdate.setData((ArrayList) data);
02180 drsToUpdate.setHasMoreData(hasMoreData);
02181 }
02182 else if (data instanceof SQLException)
02183 throw (SQLException) data;
02184 else
02185 throw new SQLException(
02186 "Connection.fetchNextData: Unexpected response (" + data + ")");
02187 }
02188 catch (Exception e)
02189 {
02190 throw new SQLException(
02191 "Connection.fetchNextData: Error occured while request was processed by C-JDBC Controller ("
02192 + e + ")");
02193 }
02194 }
02195
02196
02197
02198
02199
02200
02201
02202 public void closeRemoteResultSet(String cursorName) throws SQLException
02203 {
02204 try
02205 {
02206 socketOutput.writeInt(Commands.CloseRemoteResultSet);
02207 socketOutput.writeUTF(cursorName);
02208 socketOutput.flush();
02209
02210 Object data = socketInput.readObject();
02211 if (data instanceof CommandCompleted)
02212 return;
02213 else if (data instanceof SQLException)
02214 throw (SQLException) data;
02215 else
02216 throw new SQLException(
02217 "Connection.closeRemoteResultSet: Unexpected response (" + data
02218 + ")");
02219 }
02220 catch (Exception e)
02221 {
02222 throw new SQLException(
02223 "Connection.closeRemoteResultSet: Error occured while request was processed by C-JDBC Controller ("
02224 + e + ")");
02225 }
02226 }
02227
02228
02229
02230
02231
02232
02233 public String getPreparedStatementBooleanFalse()
02234 {
02235 return preparedStatementBooleanFalse;
02236 }
02237
02238
02239
02240
02241
02242
02243 public void setPreparedStatementBooleanFalse(String booleanFalse)
02244 {
02245 this.preparedStatementBooleanFalse = booleanFalse;
02246 }
02247
02248
02249
02250
02251
02252
02253 public String getPreparedStatementBooleanTrue()
02254 {
02255 return preparedStatementBooleanTrue;
02256 }
02257
02258
02259
02260
02261
02262
02263 public void setPreparedStatementBooleanTrue(String booleanTrue)
02264 {
02265 this.preparedStatementBooleanTrue = booleanTrue;
02266 }
02267
02268
02269
02270
02271
02272
02273 public boolean isEscapeBackslash()
02274 {
02275 return escapeBackslash;
02276 }
02277
02278
02279
02280
02281
02282
02283 public void setEscapeBackslash(boolean escapeBackslash)
02284 {
02285 this.escapeBackslash = escapeBackslash;
02286 }
02287
02288
02289
02290
02291
02292
02293 public boolean isEscapeSingleQuote()
02294 {
02295 return escapeSingleQuote;
02296 }
02297
02298
02299
02300
02301
02302
02303 public void setEscapeSingleQuote(boolean escapeSingleQuote)
02304 {
02305 this.escapeSingleQuote = escapeSingleQuote;
02306 }
02307
02308
02309
02310
02311
02312
02313
02314 public void setDriverProcessed(boolean processedByDriver)
02315 {
02316 this.driverProcessed = processedByDriver;
02317 }
02318
02319
02320
02321
02322
02323
02324 public boolean isDriverProcessed()
02325 {
02326 return driverProcessed;
02327 }
02328
02329
02330
02331
02332
02333
02334 public void setEscapeChar(String escapeChar)
02335 {
02336 this.escapeChar = escapeChar;
02337 }
02338
02339
02340
02341
02342 public String getEscapeChar()
02343 {
02344 return escapeChar;
02345 }
02346 }