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;
34 public JSqlConnection
getConnection()
39 JdbcSqlConnection(int imode
, String username
, String password
) throws SQLException
41 if( password
== null || username
== null ) throw getException(CSQL_AUTHEN_ERR
);
42 if (username
.length() > 64 || password
.length() > 64) throw getException(CSQL_AUTHEN_ERR
);
43 jniConn
= new JSqlConnection();
46 int rv
= jniConn
.connect(username
, password
);
50 throw getException(CSQL_CON_REJECTED
);
53 rv
= jniConn
.beginTrans(isoLevel
);
56 throw getException(CSQL_TRANS_NOT_STARTED
);
58 stmtList
= new LinkedList();
61 protected void finalize ()
70 System
.out
.println( e
);
74 public void close() throws SQLException
77 if(stmtList
.size() > 0)
80 ListIterator lstIter
= stmtList
.listIterator(0);
81 while(lstIter
.hasNext())
83 stmt
= (Statement
) lstIter
.next();
90 if( jniConn
.rollback() != 0 )
91 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
92 if(jniConn
.disconnect() != 0 )
93 throw getException(CSQL_NOT_DISCONNECT
);
99 public void commit() throws SQLException
101 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
102 if( jniConn
.commit() != 0 )
103 throw getException(CSQL_TRANS_NOT_COMMIT
);
104 if (jniConn
.beginTrans(isoLevel
) != 0)
105 throw getException(CSQL_TRANS_NOT_STARTED
);
109 public Statement
createStatement() throws SQLException
111 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
112 JdbcSqlStatement stmt
= new JdbcSqlStatement(this);
117 public boolean getAutoCommit()
122 public int getTransactionIsolation() throws SQLException
124 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
125 int level
= TRANSACTION_READ_COMMITTED
;
129 level
= TRANSACTION_READ_UNCOMMITTED
; break;
131 level
= TRANSACTION_READ_COMMITTED
; break;
133 level
= TRANSACTION_REPEATABLE_READ
; break;
135 throw getException(CSQL_INVALID_ISOLATION
);
140 public boolean isClosed() throws SQLException
145 public String
nativeSQL (String query
) throws SQLException
150 public PreparedStatement
prepareStatement(String query
) throws SQLException
152 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
153 JdbcSqlPreparedStatement stmt
= new JdbcSqlPreparedStatement(this);
154 stmt
.prepareInt(query
);
159 public void rollback() throws SQLException
161 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
162 if( jniConn
.rollback() != 0 )
163 throw getException(CSQL_TRANS_NOT_ROLLBACK
);
164 if (jniConn
.beginTrans(isoLevel
) != 0)
165 throw getException(CSQL_TRANS_NOT_STARTED
);
169 public void setAutoCommit(boolean aCommit
) throws SQLException
172 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
173 autoCommit
= aCommit
;
176 public void setTransactionIsolation(int level
) throws SQLException
178 if(isClosed
) throw getException(CSQL_INVALID_STATE
);
181 case TRANSACTION_READ_UNCOMMITTED
:
183 case TRANSACTION_READ_COMMITTED
:
185 case TRANSACTION_REPEATABLE_READ
:
187 case TRANSACTION_SERIALIZABLE
:
188 throw getException(CSQL_NOT_SUPPORTED
);
189 case TRANSACTION_NONE
:
191 throw getException(CSQL_INVALID_ISOLATION
);
195 /* public java.sql.Statement createAutoStatement() throws SQLException
197 throw getException(CSQL_NOT_SUPPORTED);
201 //Unsupported Methods
202 public void clearWarnings() throws SQLException
204 throw getException(CSQL_NOT_SUPPORTED
);
206 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
)
209 throw getException(CSQL_NOT_SUPPORTED
);
211 public Statement
createStatement(int resultSetType
, int resultSetConcurrency
,
212 int resultSetHoldability
) throws SQLException
214 throw getException(CSQL_NOT_SUPPORTED
);
216 public String
getCatalog() throws SQLException
218 throw getException(CSQL_NOT_SUPPORTED
);
220 public int getHoldability() throws SQLException
222 throw getException(CSQL_NOT_SUPPORTED
);
224 public DatabaseMetaData
getMetaData() throws SQLException
226 throw getException(CSQL_NOT_SUPPORTED
);
228 public Map
getTypeMap() throws SQLException
230 throw getException(CSQL_NOT_SUPPORTED
);
232 public SQLWarning
getWarnings() throws SQLException
234 throw getException(CSQL_NOT_SUPPORTED
);
236 public boolean isReadOnly() throws SQLException
238 throw getException(CSQL_NOT_SUPPORTED
);
240 public CallableStatement
prepareCall(String query
) throws SQLException
242 throw getException(CSQL_NOT_SUPPORTED
);
244 public CallableStatement
prepareCall(String query
, int resultSetType
,
245 int resultSetConcurrency
) throws SQLException
247 throw getException(CSQL_NOT_SUPPORTED
);
249 public CallableStatement
prepareCall(String query
, int resultSetType
,
250 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
252 throw getException(CSQL_NOT_SUPPORTED
);
254 public PreparedStatement
prepareStatement(String query
,
255 int autoGeneratedKeys
) throws SQLException
257 throw getException(CSQL_NOT_SUPPORTED
);
259 public PreparedStatement
prepareStatement(String query
,
260 int[] columnIndexes
) throws SQLException
262 throw getException(CSQL_NOT_SUPPORTED
);
264 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
265 int resultSetConcurrency
) throws SQLException
267 throw getException(CSQL_NOT_SUPPORTED
);
269 public PreparedStatement
prepareStatement( String query
, int resultSetType
,
270 int resultSetConcurrency
, int resultSetHoldability
) throws SQLException
272 throw getException(CSQL_NOT_SUPPORTED
);
274 public PreparedStatement
prepareStatement(String query
,
275 String
[] columnNames
) throws SQLException
277 throw getException(CSQL_NOT_SUPPORTED
);
279 public void releaseSavepoint(Savepoint savepoint
) throws SQLException
281 throw getException(CSQL_NOT_SUPPORTED
);
283 public void rollback(Savepoint savepoint
) throws SQLException
285 throw getException(CSQL_NOT_SUPPORTED
);
287 public void setCatalog(String catalog
) throws SQLException
289 throw getException(CSQL_NOT_SUPPORTED
);
291 public void setHoldability(int holdability
) throws SQLException
293 throw getException(CSQL_NOT_SUPPORTED
);
295 public void setReadOnly(boolean rOnly
) throws SQLException
297 throw getException(CSQL_NOT_SUPPORTED
);
299 public Savepoint
setSavepoint() throws SQLException
301 throw getException(CSQL_NOT_SUPPORTED
);
303 public Savepoint
setSavepoint(String query
) throws SQLException
305 throw getException(CSQL_NOT_SUPPORTED
);
307 public void setTypeMap(Map map
) throws SQLException
309 throw getException(CSQL_NOT_SUPPORTED
);
312 public Struct
createStruct(String typeName
, Object
[] attributes
)
315 throw getException(CSQL_NOT_SUPPORTED
);
317 public Array
createArrayOf(String typeName
, Object
[] elements
)
320 throw getException(CSQL_NOT_SUPPORTED
);
322 public Blob
createBlob() throws SQLException
324 throw getException(CSQL_NOT_SUPPORTED
);
326 public Clob
createClob() throws SQLException
328 throw getException(CSQL_NOT_SUPPORTED
);
330 public NClob
createNClob() throws SQLException
332 throw getException(CSQL_NOT_SUPPORTED
);
334 public SQLXML
createSQLXML() throws SQLException
336 throw getException(CSQL_NOT_SUPPORTED
);
338 public Properties
getClientInfo() throws SQLException
340 throw getException(CSQL_NOT_SUPPORTED
);
342 public String
getClientInfo(String name
) throws SQLException
344 throw getException(CSQL_NOT_SUPPORTED
);
346 public void setClientInfo(String name
, String value
)
350 public void setClientInfo(Properties properties
)
354 public boolean isValid(int timeout
) throws SQLException
356 throw getException(CSQL_NOT_SUPPORTED
);
358 public boolean isWrapperFor(Class ifact
) throws SQLException
360 throw getException(CSQL_NOT_SUPPORTED
);
362 public Class
unwrap(Class iface
) throws SQLException
364 throw getException(CSQL_NOT_SUPPORTED
);