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 JSqlConnection
getConnection()
40 JdbcSqlConnection(int imode
,String hostname
,int portno
, String username
, String password
) throws SQLException
42 if( password
== null || username
== null ) throw getException(CSQL_AUTHEN_ERR
);
43 if (username
.length() > 64 || password
.length() > 64) throw getException(CSQL_AUTHEN_ERR
);
44 jniConn
= new JSqlConnection();
49 jniConn
.alloc(imode
,hostname
,portNo
);
51 int rv
= jniConn
.connect(username
, password
);
55 throw getException(CSQL_CON_REJECTED
);
58 rv
= jniConn
.beginTrans(isoLevel
);
61 throw getException(CSQL_TRANS_NOT_STARTED
);
63 stmtList
= new LinkedList();
66 protected void finalize ()
75 System
.out
.println( e
);
79 public void close() throws SQLException
82 if(stmtList
.size() > 0)
85 ListIterator lstIter
= stmtList
.listIterator(0);
86 while(lstIter
.hasNext())
88 stmt
= (Statement
) lstIter
.next();
95 if( jniConn
.rollback() != 0 )
96 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
97 if(jniConn
.disconnect() != 0 )
98 throw getException(CSQL_NOT_DISCONNECT
);
104 public void commit() throws SQLException
106 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
107 if( jniConn
.commit() != 0 )
108 throw getException(CSQL_TRANS_NOT_COMMIT
);
109 if (jniConn
.beginTrans(isoLevel
) != 0)
110 throw getException(CSQL_TRANS_NOT_STARTED
);
114 public Statement
createStatement() throws SQLException
116 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
117 JdbcSqlStatement stmt
= new JdbcSqlStatement(this);
122 public boolean getAutoCommit()
127 public int getTransactionIsolation() throws SQLException
129 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
130 int level
= TRANSACTION_READ_COMMITTED
;
134 level
= TRANSACTION_READ_UNCOMMITTED
; break;
136 level
= TRANSACTION_READ_COMMITTED
; break;
138 level
= TRANSACTION_REPEATABLE_READ
; break;
140 throw getException(CSQL_INVALID_ISOLATION
);
145 public boolean isClosed() throws SQLException
150 public String
nativeSQL (String query
) throws SQLException
155 public PreparedStatement
prepareStatement(String query
) throws SQLException
157 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
158 JdbcSqlPreparedStatement stmt
= new JdbcSqlPreparedStatement(this);
159 stmt
.prepareInt(query
);
164 public void rollback() throws SQLException
166 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
167 if( jniConn
.rollback() != 0 )
168 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
169 if (jniConn
.beginTrans(isoLevel
) != 0)
170 throw getException(CSQL_TRANS_NOT_STARTED
);
174 public void setAutoCommit(boolean aCommit
) throws SQLException
177 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
178 autoCommit
= aCommit
;
181 public void setTransactionIsolation(int level
) throws SQLException
183 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
186 case TRANSACTION_READ_UNCOMMITTED
:
188 case TRANSACTION_READ_COMMITTED
:
190 case TRANSACTION_REPEATABLE_READ
:
192 case TRANSACTION_SERIALIZABLE
:
193 throw getException(CSQL_NOT_SUPPORTED
);
194 case TRANSACTION_NONE
:
196 throw getException(CSQL_INVALID_ISOLATION
);
200 /* public java.sql.Statement createAutoStatement() throws SQLException
202 throw getException(CSQL_NOT_SUPPORTED);
206 //Unsupported Methods
207 public void clearWarnings() throws SQLException
209 throw getException(CSQL_NOT_SUPPORTED
);
211 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
)
214 throw getException(CSQL_NOT_SUPPORTED
);
216 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
,
217 int resultSetHoldability
) throws SQLException
219 throw getException(CSQL_NOT_SUPPORTED
);
221 public String
getCatalog() throws SQLException
223 throw getException(CSQL_NOT_SUPPORTED
);
225 public int getHoldability() throws SQLException
227 throw getException(CSQL_NOT_SUPPORTED
);
229 public DatabaseMetaData
getMetaData() throws SQLException
231 throw getException(CSQL_NOT_SUPPORTED
);
233 public Map
getTypeMap() throws SQLException
235 throw getException(CSQL_NOT_SUPPORTED
);
237 public SQLWarning
getWarnings() throws SQLException
239 throw getException(CSQL_NOT_SUPPORTED
);
241 public boolean isReadOnly() throws SQLException
243 throw getException(CSQL_NOT_SUPPORTED
);
245 public CallableStatement
prepareCall(String query
) throws SQLException
247 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
248 JdbcSqlCallableStatement stmt
= new JdbcSqlCallableStatement(this);
249 stmt
.prepareProc(query
);
253 public CallableStatement
prepareCall(String query
, int resultSetType
,
254 int resultSetConcurrency
) throws SQLException
256 throw getException(CSQL_NOT_SUPPORTED
);
258 public CallableStatement
prepareCall(String query
, int resultSetType
,
259 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
261 throw getException(CSQL_NOT_SUPPORTED
);
263 public PreparedStatement
prepareStatement(String query
,
264 int autoGeneratedKeys
) throws SQLException
266 throw getException(CSQL_NOT_SUPPORTED
);
268 public PreparedStatement
prepareStatement(String query
,
269 int[] columnIndexes
) throws SQLException
271 throw getException(CSQL_NOT_SUPPORTED
);
273 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
274 int resultSetConcurrency
) throws SQLException
276 throw getException(CSQL_NOT_SUPPORTED
);
278 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
279 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
281 throw getException(CSQL_NOT_SUPPORTED
);
283 public PreparedStatement
prepareStatement(String query
,
284 String
[] columnNames
) throws SQLException
286 throw getException(CSQL_NOT_SUPPORTED
);
288 public void releaseSavepoint(Savepoint savepoint
) throws SQLException
290 throw getException(CSQL_NOT_SUPPORTED
);
292 public void rollback(Savepoint savepoint
) throws SQLException
294 throw getException(CSQL_NOT_SUPPORTED
);
296 public void setCatalog(String catalog
) throws SQLException
298 throw getException(CSQL_NOT_SUPPORTED
);
300 public void setHoldability(int holdability
) throws SQLException
302 throw getException(CSQL_NOT_SUPPORTED
);
304 public void setReadOnly(boolean rOnly
) throws SQLException
306 throw getException(CSQL_NOT_SUPPORTED
);
308 public Savepoint
setSavepoint() throws SQLException
310 throw getException(CSQL_NOT_SUPPORTED
);
312 public Savepoint
setSavepoint(String query
) throws SQLException
314 throw getException(CSQL_NOT_SUPPORTED
);
316 public void setTypeMap(Map map
) throws SQLException
318 throw getException(CSQL_NOT_SUPPORTED
);
321 public Struct
createStruct(String typeName
, Object
[] attributes
)
324 throw getException(CSQL_NOT_SUPPORTED
);
326 public Array
createArrayOf(String typeName
, Object
[] elements
)
329 throw getException(CSQL_NOT_SUPPORTED
);
331 public Blob
createBlob() throws SQLException
333 throw getException(CSQL_NOT_SUPPORTED
);
335 public Clob
createClob() throws SQLException
337 throw getException(CSQL_NOT_SUPPORTED
);
339 public NClob
createNClob() throws SQLException
341 throw getException(CSQL_NOT_SUPPORTED
);
343 public SQLXML
createSQLXML() throws SQLException
345 throw getException(CSQL_NOT_SUPPORTED
);
347 public Properties
getClientInfo() throws SQLException
349 throw getException(CSQL_NOT_SUPPORTED
);
351 public String
getClientInfo(String name
) throws SQLException
353 throw getException(CSQL_NOT_SUPPORTED
);
355 public void setClientInfo(String name
, String value
)
359 public void setClientInfo(Properties properties
)
363 public boolean isValid(int timeout
) throws SQLException
365 throw getException(CSQL_NOT_SUPPORTED
);
367 public boolean isWrapperFor(Class ifact
) throws SQLException
369 throw getException(CSQL_NOT_SUPPORTED
);
371 public Class
unwrap(Class iface
) throws SQLException
373 throw getException(CSQL_NOT_SUPPORTED
);