2 import java
.sql
.Connection
;
3 import java
.sql
.SQLException
;
4 import java
.sql
.SQLWarning
;
5 import java
.sql
.DatabaseMetaData
;
6 import java
.sql
.Savepoint
;
7 import java
.sql
.Statement
;
8 import java
.sql
.PreparedStatement
;
9 import java
.sql
.CallableStatement
;
10 import java
.lang
.String
;
11 import java
.util
.LinkedList
;
12 import java
.util
.ListIterator
;
14 import java
.util
.Properties
;
17 import java
.sql
.NClob
;
19 import java
.sql
.SQLXML
;
20 import java
.sql
.Struct
;
21 import java
.sql
.Array
;
23 public final class JdbcSqlConnection
extends JSqlError
implements Connection
, JSqlErrorType
25 private boolean isClosed
;
26 private JSqlConnection jniConn
;
27 private LinkedList stmtList
;
28 private boolean autoCommit
= true; //TODO
29 private boolean transRunning
= false;
30 private int isoLevel
= 2; //->READ_COMMITTED
31 private boolean readOnly
= false;
33 public String hName
="localhost";
34 public int portNo
=5678;
35 public String url
= "jdbc:csql";
36 private JdbcSqlDatabaseMetaData dbmtd
;
37 public JSqlConnection
getConnection()
42 JdbcSqlConnection(int imode
,String hostname
,int portno
, String username
, String password
) throws SQLException
44 if( password
== null || username
== null ) throw getException(CSQL_AUTHEN_ERR
);
45 if (username
.length() > 64 || password
.length() > 64) throw getException(CSQL_AUTHEN_ERR
);
46 jniConn
= new JSqlConnection();
51 jniConn
.alloc(imode
,hostname
,portNo
);
53 int rv
= jniConn
.connect(username
, password
);
54 //int rv = jniConn.connect("root", "manager");
58 throw getException(CSQL_CON_REJECTED
);
61 rv
= jniConn
.beginTrans(isoLevel
);
64 throw getException(CSQL_TRANS_NOT_STARTED
);
67 stmtList
= new LinkedList();
70 protected void finalize ()
79 System
.out
.println( e
);
83 public void setUrl(String url
)
87 public String
getUrl() { return this.url
; }
88 public void close() throws SQLException
91 if(stmtList
.size() > 0)
94 ListIterator lstIter
= stmtList
.listIterator(0);
95 while(lstIter
.hasNext())
97 stmt
= (Statement
) lstIter
.next();
104 if( jniConn
.rollback() != 0 )
105 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
106 if(jniConn
.disconnect() != 0 )
107 throw getException(CSQL_NOT_DISCONNECT
);
113 public void commit() throws SQLException
115 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
116 if( jniConn
.commit() != 0 )
117 throw getException(CSQL_TRANS_NOT_COMMIT
);
118 if (jniConn
.beginTrans(isoLevel
) != 0)
119 throw getException(CSQL_TRANS_NOT_STARTED
);
123 public Statement
createStatement() throws SQLException
125 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
126 JdbcSqlStatement stmt
= new JdbcSqlStatement(this);
131 public boolean getAutoCommit()
136 public int getTransactionIsolation() throws SQLException
138 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
139 int level
= TRANSACTION_READ_COMMITTED
;
143 level
= TRANSACTION_READ_UNCOMMITTED
; break;
145 level
= TRANSACTION_READ_COMMITTED
; break;
147 level
= TRANSACTION_REPEATABLE_READ
; break;
149 throw getException(CSQL_INVALID_ISOLATION
);
154 public boolean isClosed() throws SQLException
159 public String
nativeSQL (String query
) throws SQLException
164 public PreparedStatement
prepareStatement(String query
) throws SQLException
166 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
167 JdbcSqlPreparedStatement stmt
= new JdbcSqlPreparedStatement(this);
168 stmt
.prepareInt(query
);
173 public void rollback() throws SQLException
175 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
176 if( jniConn
.rollback() != 0 )
177 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
178 if (jniConn
.beginTrans(isoLevel
) != 0)
179 throw getException(CSQL_TRANS_NOT_STARTED
);
183 public void setAutoCommit(boolean aCommit
) throws SQLException
186 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
187 autoCommit
= aCommit
;
190 public void setTransactionIsolation(int level
) throws SQLException
192 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
195 case TRANSACTION_READ_UNCOMMITTED
:
197 case TRANSACTION_READ_COMMITTED
:
199 case TRANSACTION_REPEATABLE_READ
:
201 case TRANSACTION_SERIALIZABLE
:
202 throw getException(CSQL_NOT_SUPPORTED
);
203 case TRANSACTION_NONE
:
205 throw getException(CSQL_INVALID_ISOLATION
);
209 /* public java.sql.Statement createAutoStatement() throws SQLException
211 throw getException(CSQL_NOT_SUPPORTED);
215 //Unsupported Methods
216 public void clearWarnings() throws SQLException
221 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
) throws SQLException
223 if (JSqlError
.isDebug
) System
.out
.println("createStatement called");
224 throw getException(CSQL_NOT_SUPPORTED
);
226 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
,
227 int resultSetHoldability
) throws SQLException
229 if (JSqlError
.isDebug
) System
.out
.println("createStatement called");
230 throw getException(CSQL_NOT_SUPPORTED
);
232 public String
getCatalog() throws SQLException
236 public int getHoldability() throws SQLException
238 if (JSqlError
.isDebug
) System
.out
.println("getHoldability called");
239 throw getException(CSQL_NOT_SUPPORTED
);
241 public DatabaseMetaData
getMetaData() throws SQLException
243 //System.out.println("In connection create Metadata");
246 dbmtd
= new JdbcSqlDatabaseMetaData(this);
250 public Map
getTypeMap() throws SQLException
252 if (JSqlError
.isDebug
) System
.out
.println("getTypeMap called");
253 throw getException(CSQL_NOT_SUPPORTED
);
255 public SQLWarning
getWarnings() throws SQLException
258 //if (JSqlError.isDebug) System.out.println("getWarnings called");
261 public boolean isReadOnly() throws SQLException
265 public CallableStatement
prepareCall(String query
) throws SQLException
267 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
268 JdbcSqlCallableStatement stmt
= new JdbcSqlCallableStatement(this);
269 stmt
.prepareProc(query
);
273 public CallableStatement
prepareCall(String query
, int resultSetType
,
274 int resultSetConcurrency
) throws SQLException
276 if (JSqlError
.isDebug
) System
.out
.println("prepareCall called");
277 throw getException(CSQL_NOT_SUPPORTED
);
279 public CallableStatement
prepareCall(String query
, int resultSetType
,
280 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
282 if (JSqlError
.isDebug
) System
.out
.println("prepareCall called");
283 throw getException(CSQL_NOT_SUPPORTED
);
285 public PreparedStatement
prepareStatement(String query
,
286 int autoGeneratedKeys
) throws SQLException
288 if (JSqlError
.isDebug
) System
.out
.println("prepareStatement called");
289 throw getException(CSQL_NOT_SUPPORTED
);
291 public PreparedStatement
prepareStatement(String query
,
292 int[] columnIndexes
) throws SQLException
294 if (JSqlError
.isDebug
) System
.out
.println("prepareStatement called");
295 throw getException(CSQL_NOT_SUPPORTED
);
297 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
298 int resultSetConcurrency
) throws SQLException
300 if (JSqlError
.isDebug
) System
.out
.println("prepareStatement called");
301 throw getException(CSQL_NOT_SUPPORTED
);
303 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
304 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
306 if (JSqlError
.isDebug
) System
.out
.println("prepareStatement called");
307 throw getException(CSQL_NOT_SUPPORTED
);
309 public PreparedStatement
prepareStatement(String query
,
310 String
[] columnNames
) throws SQLException
312 if (JSqlError
.isDebug
) System
.out
.println("prepareStatement called");
313 throw getException(CSQL_NOT_SUPPORTED
);
315 public void releaseSavepoint(Savepoint savepoint
) throws SQLException
317 if (JSqlError
.isDebug
) System
.out
.println("releaseSavepoint called");
318 throw getException(CSQL_NOT_SUPPORTED
);
320 public void rollback(Savepoint savepoint
) throws SQLException
322 if (JSqlError
.isDebug
) System
.out
.println("rollback called");
323 throw getException(CSQL_NOT_SUPPORTED
);
325 public void setCatalog(String catalog
) throws SQLException
327 if (JSqlError
.isDebug
) System
.out
.println("setCatalog called");
328 throw getException(CSQL_NOT_SUPPORTED
);
330 public void setHoldability(int holdability
) throws SQLException
332 if (JSqlError
.isDebug
) System
.out
.println("setHoldability called");
333 throw getException(CSQL_NOT_SUPPORTED
);
335 public void setReadOnly(boolean rOnly
) throws SQLException
339 public Savepoint
setSavepoint() throws SQLException
341 if (JSqlError
.isDebug
) System
.out
.println("setSavepoint called");
342 throw getException(CSQL_NOT_SUPPORTED
);
344 public Savepoint
setSavepoint(String query
) throws SQLException
346 if (JSqlError
.isDebug
) System
.out
.println("setSavepoint called");
347 throw getException(CSQL_NOT_SUPPORTED
);
349 public void setTypeMap(Map map
) throws SQLException
351 if (JSqlError
.isDebug
) System
.out
.println("setTypeMap called");
352 throw getException(CSQL_NOT_SUPPORTED
);
355 public Struct
createStruct(String typeName
, Object
[] attributes
)
358 if (JSqlError
.isDebug
) System
.out
.println("createStruct called");
359 throw getException(CSQL_NOT_SUPPORTED
);
361 public Array
createArrayOf(String typeName
, Object
[] elements
)
364 if (JSqlError
.isDebug
) System
.out
.println("createArrayOf called");
365 throw getException(CSQL_NOT_SUPPORTED
);
367 public Blob
createBlob() throws SQLException
369 if (JSqlError
.isDebug
) System
.out
.println("createBlob called");
370 throw getException(CSQL_NOT_SUPPORTED
);
372 public Clob
createClob() throws SQLException
374 if (JSqlError
.isDebug
) System
.out
.println("createClob called");
375 throw getException(CSQL_NOT_SUPPORTED
);
377 public NClob
createNClob() throws SQLException
379 if (JSqlError
.isDebug
) System
.out
.println("createNClob called");
380 throw getException(CSQL_NOT_SUPPORTED
);
382 public SQLXML
createSQLXML() throws SQLException
384 if (JSqlError
.isDebug
) System
.out
.println("createSQLXML called");
385 throw getException(CSQL_NOT_SUPPORTED
);
387 public Properties
getClientInfo() throws SQLException
389 if (JSqlError
.isDebug
) System
.out
.println("getClientInfo called");
390 throw getException(CSQL_NOT_SUPPORTED
);
392 public String
getClientInfo(String name
) throws SQLException
394 if (JSqlError
.isDebug
) System
.out
.println("getClientInfo called");
395 throw getException(CSQL_NOT_SUPPORTED
);
397 public void setClientInfo(String name
, String value
)
401 public void setClientInfo(Properties properties
)
403 if (JSqlError
.isDebug
) System
.out
.println("setClientInfo called");
406 public boolean isValid(int timeout
) throws SQLException
408 if (JSqlError
.isDebug
) System
.out
.println("isValid called");
409 throw getException(CSQL_NOT_SUPPORTED
);
411 public boolean isWrapperFor(Class ifact
) throws SQLException
413 if (JSqlError
.isDebug
) System
.out
.println("isWrapperFor called");
414 throw getException(CSQL_NOT_SUPPORTED
);
416 public Class
unwrap(Class iface
) throws SQLException
418 if (JSqlError
.isDebug
) System
.out
.println("unwrap called");
419 throw getException(CSQL_NOT_SUPPORTED
);