2
Copyright (C) 2009, 2011 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.jdbc.odbc;
26
import cli.System.Data.*;
27
import cli.System.Data.Common.*;
28
import cli.System.Data.Odbc.*;
32
import java.util.Properties;
33
import java.util.concurrent.Executor;
36
* This JDBC Driver is a wrapper to the ODBC.NET Data Provider
38
public class JdbcOdbcConnection implements Connection{
40
private final OdbcConnection netConn;
42
private DbTransaction transaction;
44
private int isolation = TRANSACTION_READ_COMMITTED;
47
JdbcOdbcConnection(String connectString, Properties info) throws SQLException{
49
boolean isDSN = connectString.indexOf('=') < 0;
50
StringBuilder connStr = new StringBuilder();
52
connStr.append("DSN=");
54
connStr.append(connectString);
56
String uid = info.getProperty("user");
57
String pwd = info.getProperty("password");
60
connStr.append(";UID=").append(uid);
63
connStr.append(";PWD=").append(pwd);
66
netConn = new OdbcConnection(connStr.toString());
70
throw JdbcOdbcUtils.createSQLException(th);
76
public void clearWarnings() throws SQLException{
77
// TODO Auto-generated method stub
83
public void close() throws SQLException{
87
throw JdbcOdbcUtils.createSQLException(ex);
93
public Array createArrayOf(String typeName, Object[] elements){
94
throw new UnsupportedOperationException();
99
public Blob createBlob(){
100
throw new UnsupportedOperationException();
105
public Clob createClob(){
106
throw new UnsupportedOperationException();
111
public NClob createNClob(){
112
throw new UnsupportedOperationException();
117
public SQLXML createSQLXML(){
118
throw new UnsupportedOperationException();
123
public Statement createStatement() throws SQLException{
124
return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
129
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException{
131
return new JdbcOdbcStatement(this, netConn.CreateCommand(), resultSetType, resultSetConcurrency);
132
}catch(Throwable ex){
133
throw JdbcOdbcUtils.createSQLException(ex);
139
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability){
140
throw new UnsupportedOperationException();
145
public Struct createStruct(String typeName, Object[] attributes){
146
throw new UnsupportedOperationException();
151
public void setAutoCommit(boolean autoCommit) throws SQLException{
153
if(autoCommit && transaction != null){
156
if(!autoCommit && transaction == null){
161
case TRANSACTION_READ_COMMITTED:
162
level = IsolationLevel.ReadUncommitted;
164
case TRANSACTION_READ_UNCOMMITTED:
165
level = IsolationLevel.ReadCommitted;
167
case TRANSACTION_REPEATABLE_READ:
168
level = IsolationLevel.RepeatableRead;
170
case TRANSACTION_SERIALIZABLE:
171
level = IsolationLevel.Serializable;
174
level = IsolationLevel.ReadCommitted;
177
transaction = netConn.BeginTransaction(IsolationLevel.wrap(level));
179
transaction.Commit();
182
}catch(Throwable ex){
183
throw JdbcOdbcUtils.createSQLException(ex);
189
public boolean getAutoCommit(){
190
return transaction != null;
195
public void commit() throws SQLException{
197
if(transaction == null){
198
// auto commit == true
201
transaction.Commit();
202
transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
203
}catch(Throwable ex){
204
throw JdbcOdbcUtils.createSQLException(ex);
210
public void rollback() throws SQLException{
212
if(transaction == null){
213
// auto commit == true
216
transaction.Rollback();
217
transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
218
}catch(Throwable ex){
219
throw JdbcOdbcUtils.createSQLException(ex);
225
public void setTransactionIsolation(int level){
231
public int getTransactionIsolation(){
237
public String getClientInfo(String name){
238
throw new UnsupportedOperationException();
243
public Properties getClientInfo(){
244
throw new UnsupportedOperationException();
249
public int getHoldability(){
250
throw new UnsupportedOperationException();
255
public DatabaseMetaData getMetaData(){
256
return new JdbcOdbcDatabaseMetaData(this, netConn);
261
public Map<String, Class<?>> getTypeMap(){
262
throw new UnsupportedOperationException();
267
public SQLWarning getWarnings() throws SQLException{
268
// TODO Auto-generated method stub
274
public boolean isClosed() throws SQLException{
275
return netConn.get_State().Value == ConnectionState.Closed;
280
public boolean isReadOnly() throws SQLException{
281
// TODO Auto-generated method stub
287
public boolean isValid(int timeout) throws SQLException{
288
throw new UnsupportedOperationException();
293
public String nativeSQL(String sql) throws SQLException{
294
// TODO Auto-generated method stub
300
public CallableStatement prepareCall(String sql) throws SQLException{
301
return prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
306
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException{
308
return new JdbcOdbcCallableStatement(this, netConn.CreateCommand(), sql, resultSetType,
309
resultSetConcurrency);
310
}catch(Throwable th){
311
throw JdbcOdbcUtils.createSQLException(th);
317
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
318
int resultSetHoldability){
319
throw new UnsupportedOperationException();
324
public PreparedStatement prepareStatement(String sql) throws SQLException{
325
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
330
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
333
return new JdbcOdbcPreparedStatement(this, netConn.CreateCommand(), sql, resultSetType,
334
resultSetConcurrency);
335
}catch(Throwable th){
336
throw JdbcOdbcUtils.createSQLException(th);
342
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
343
int resultSetHoldability){
344
throw new UnsupportedOperationException();
349
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys){
350
throw new UnsupportedOperationException();
355
public PreparedStatement prepareStatement(String sql, int[] columnIndexes){
356
throw new UnsupportedOperationException();
361
public PreparedStatement prepareStatement(String sql, String[] columnNames){
362
throw new UnsupportedOperationException();
367
public void releaseSavepoint(Savepoint savepoint){
368
throw new UnsupportedOperationException();
373
public void rollback(Savepoint savepoint){
374
throw new UnsupportedOperationException();
379
public void setCatalog(String catalog) throws SQLException{
381
netConn.ChangeDatabase(catalog);
382
}catch(Throwable th){
383
throw JdbcOdbcUtils.createSQLException(th);
389
public String getCatalog(){
390
return netConn.get_Database();
395
public void setClientInfo(String name, String value){
396
throw new UnsupportedOperationException();
401
public void setClientInfo(Properties properties){
402
throw new UnsupportedOperationException();
407
public void setHoldability(int holdability){
408
throw new UnsupportedOperationException();
413
public void setReadOnly(boolean readOnly) throws SQLException{
414
// TODO Auto-generated method stub
420
public Savepoint setSavepoint(){
421
throw new UnsupportedOperationException();
426
public Savepoint setSavepoint(String name){
427
throw new UnsupportedOperationException();
432
public void setTypeMap(Map<String, Class<?>> map){
433
throw new UnsupportedOperationException();
438
public boolean isWrapperFor(Class<?> iface){
439
return iface.isAssignableFrom(this.getClass());
444
public <T>T unwrap(Class<T> iface) throws SQLException{
445
if(isWrapperFor(iface)){
448
throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
455
public void setSchema(String schema) throws SQLException {
462
public String getSchema() throws SQLException {
470
public void abort(Executor executor) throws SQLException {
471
throw new SQLFeatureNotSupportedException();
478
public void setNetworkTimeout(Executor executor, int milliseconds)
479
throws SQLException {
480
throw new SQLFeatureNotSupportedException();
487
public int getNetworkTimeout() throws SQLException {
488
throw new SQLFeatureNotSupportedException();