~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009, 2011 Volker Berlin (i-net software)
 
3
 
 
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.
 
7
 
 
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:
 
11
 
 
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.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
 */
 
24
package sun.jdbc.odbc;
 
25
 
 
26
import cli.System.Data.*;
 
27
import cli.System.Data.Common.*;
 
28
import cli.System.Data.Odbc.*;
 
29
 
 
30
import java.sql.*;
 
31
import java.util.Map;
 
32
import java.util.Properties;
 
33
import java.util.concurrent.Executor;
 
34
 
 
35
/**
 
36
 * This JDBC Driver is a wrapper to the ODBC.NET Data Provider
 
37
 */
 
38
public class JdbcOdbcConnection implements Connection{
 
39
 
 
40
    private final OdbcConnection netConn;
 
41
 
 
42
    private DbTransaction transaction;
 
43
 
 
44
    private int isolation = TRANSACTION_READ_COMMITTED;
 
45
 
 
46
 
 
47
    JdbcOdbcConnection(String connectString, Properties info) throws SQLException{
 
48
        try{
 
49
            boolean isDSN = connectString.indexOf('=') < 0;
 
50
            StringBuilder connStr = new StringBuilder();
 
51
            if(isDSN){
 
52
                connStr.append("DSN=");
 
53
            }
 
54
            connStr.append(connectString);
 
55
 
 
56
            String uid = info.getProperty("user");
 
57
            String pwd = info.getProperty("password");
 
58
 
 
59
            if(uid != null){
 
60
                connStr.append(";UID=").append(uid);
 
61
            }
 
62
            if(pwd != null){
 
63
                connStr.append(";PWD=").append(pwd);
 
64
            }
 
65
 
 
66
            netConn = new OdbcConnection(connStr.toString());
 
67
 
 
68
            netConn.Open();
 
69
        }catch(Throwable th){
 
70
            throw JdbcOdbcUtils.createSQLException(th);
 
71
        }
 
72
    }
 
73
 
 
74
 
 
75
    @Override
 
76
        public void clearWarnings() throws SQLException{
 
77
        // TODO Auto-generated method stub
 
78
 
 
79
    }
 
80
 
 
81
 
 
82
    @Override
 
83
        public void close() throws SQLException{
 
84
        try{
 
85
            netConn.Close();
 
86
        }catch(Throwable ex){
 
87
            throw JdbcOdbcUtils.createSQLException(ex);
 
88
        }
 
89
    }
 
90
 
 
91
 
 
92
    @Override
 
93
        public Array createArrayOf(String typeName, Object[] elements){
 
94
        throw new UnsupportedOperationException();
 
95
    }
 
96
 
 
97
 
 
98
    @Override
 
99
        public Blob createBlob(){
 
100
        throw new UnsupportedOperationException();
 
101
    }
 
102
 
 
103
 
 
104
    @Override
 
105
        public Clob createClob(){
 
106
        throw new UnsupportedOperationException();
 
107
    }
 
108
 
 
109
 
 
110
    @Override
 
111
        public NClob createNClob(){
 
112
        throw new UnsupportedOperationException();
 
113
    }
 
114
 
 
115
 
 
116
    @Override
 
117
        public SQLXML createSQLXML(){
 
118
        throw new UnsupportedOperationException();
 
119
    }
 
120
 
 
121
 
 
122
    @Override
 
123
        public Statement createStatement() throws SQLException{
 
124
        return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
125
    }
 
126
 
 
127
 
 
128
    @Override
 
129
        public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException{
 
130
        try{
 
131
            return new JdbcOdbcStatement(this, netConn.CreateCommand(), resultSetType, resultSetConcurrency);
 
132
        }catch(Throwable ex){
 
133
            throw JdbcOdbcUtils.createSQLException(ex);
 
134
        }
 
135
    }
 
136
 
 
137
 
 
138
    @Override
 
139
        public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability){
 
140
        throw new UnsupportedOperationException();
 
141
    }
 
142
 
 
143
 
 
144
    @Override
 
145
        public Struct createStruct(String typeName, Object[] attributes){
 
146
        throw new UnsupportedOperationException();
 
147
    }
 
148
 
 
149
 
 
150
    @Override
 
151
        public void setAutoCommit(boolean autoCommit) throws SQLException{
 
152
        try{
 
153
            if(autoCommit && transaction != null){
 
154
                return; // no change
 
155
            }
 
156
            if(!autoCommit && transaction == null){
 
157
                return; // no change
 
158
            }
 
159
            int level;
 
160
            switch(isolation){
 
161
                case TRANSACTION_READ_COMMITTED:
 
162
                    level = IsolationLevel.ReadUncommitted;
 
163
                    break;
 
164
                case TRANSACTION_READ_UNCOMMITTED:
 
165
                    level = IsolationLevel.ReadCommitted;
 
166
                    break;
 
167
                case TRANSACTION_REPEATABLE_READ:
 
168
                    level = IsolationLevel.RepeatableRead;
 
169
                    break;
 
170
                case TRANSACTION_SERIALIZABLE:
 
171
                    level = IsolationLevel.Serializable;
 
172
                    break;
 
173
                default:
 
174
                    level = IsolationLevel.ReadCommitted;
 
175
            }
 
176
            if(autoCommit){
 
177
                transaction = netConn.BeginTransaction(IsolationLevel.wrap(level));
 
178
            }else{
 
179
                transaction.Commit();
 
180
                transaction = null;
 
181
            }
 
182
        }catch(Throwable ex){
 
183
            throw JdbcOdbcUtils.createSQLException(ex);
 
184
        }
 
185
    }
 
186
 
 
187
 
 
188
    @Override
 
189
        public boolean getAutoCommit(){
 
190
        return transaction != null;
 
191
    }
 
192
 
 
193
 
 
194
    @Override
 
195
        public void commit() throws SQLException{
 
196
        try{
 
197
            if(transaction == null){
 
198
                // auto commit == true
 
199
                return;
 
200
            }
 
201
            transaction.Commit();
 
202
            transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
 
203
        }catch(Throwable ex){
 
204
            throw JdbcOdbcUtils.createSQLException(ex);
 
205
        }
 
206
    }
 
207
 
 
208
 
 
209
    @Override
 
210
        public void rollback() throws SQLException{
 
211
        try{
 
212
            if(transaction == null){
 
213
                // auto commit == true
 
214
                return;
 
215
            }
 
216
            transaction.Rollback();
 
217
            transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
 
218
        }catch(Throwable ex){
 
219
            throw JdbcOdbcUtils.createSQLException(ex);
 
220
        }
 
221
    }
 
222
 
 
223
 
 
224
    @Override
 
225
        public void setTransactionIsolation(int level){
 
226
        isolation = level;
 
227
    }
 
228
 
 
229
 
 
230
    @Override
 
231
        public int getTransactionIsolation(){
 
232
        return isolation;
 
233
    }
 
234
 
 
235
 
 
236
    @Override
 
237
        public String getClientInfo(String name){
 
238
        throw new UnsupportedOperationException();
 
239
    }
 
240
 
 
241
 
 
242
    @Override
 
243
        public Properties getClientInfo(){
 
244
        throw new UnsupportedOperationException();
 
245
    }
 
246
 
 
247
 
 
248
    @Override
 
249
        public int getHoldability(){
 
250
        throw new UnsupportedOperationException();
 
251
    }
 
252
 
 
253
 
 
254
    @Override
 
255
        public DatabaseMetaData getMetaData(){
 
256
        return new JdbcOdbcDatabaseMetaData(this, netConn);
 
257
    }
 
258
 
 
259
 
 
260
    @Override
 
261
        public Map<String, Class<?>> getTypeMap(){
 
262
        throw new UnsupportedOperationException();
 
263
    }
 
264
 
 
265
 
 
266
    @Override
 
267
        public SQLWarning getWarnings() throws SQLException{
 
268
        // TODO Auto-generated method stub
 
269
        return null;
 
270
    }
 
271
 
 
272
 
 
273
    @Override
 
274
        public boolean isClosed() throws SQLException{
 
275
        return netConn.get_State().Value == ConnectionState.Closed;
 
276
    }
 
277
 
 
278
 
 
279
    @Override
 
280
        public boolean isReadOnly() throws SQLException{
 
281
        // TODO Auto-generated method stub
 
282
        return false;
 
283
    }
 
284
 
 
285
 
 
286
    @Override
 
287
        public boolean isValid(int timeout) throws SQLException{
 
288
        throw new UnsupportedOperationException();
 
289
    }
 
290
 
 
291
 
 
292
    @Override
 
293
        public String nativeSQL(String sql) throws SQLException{
 
294
        // TODO Auto-generated method stub
 
295
        return sql;
 
296
    }
 
297
 
 
298
 
 
299
    @Override
 
300
        public CallableStatement prepareCall(String sql) throws SQLException{
 
301
        return prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
302
    }
 
303
 
 
304
 
 
305
    @Override
 
306
        public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException{
 
307
        try{
 
308
            return new JdbcOdbcCallableStatement(this, netConn.CreateCommand(), sql, resultSetType,
 
309
                    resultSetConcurrency);
 
310
        }catch(Throwable th){
 
311
            throw JdbcOdbcUtils.createSQLException(th);
 
312
        }
 
313
    }
 
314
 
 
315
 
 
316
    @Override
 
317
        public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
 
318
            int resultSetHoldability){
 
319
        throw new UnsupportedOperationException();
 
320
    }
 
321
 
 
322
 
 
323
    @Override
 
324
        public PreparedStatement prepareStatement(String sql) throws SQLException{
 
325
        return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
326
    }
 
327
 
 
328
 
 
329
    @Override
 
330
        public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
 
331
            throws SQLException{
 
332
        try{
 
333
            return new JdbcOdbcPreparedStatement(this, netConn.CreateCommand(), sql, resultSetType,
 
334
                    resultSetConcurrency);
 
335
        }catch(Throwable th){
 
336
            throw JdbcOdbcUtils.createSQLException(th);
 
337
        }
 
338
    }
 
339
 
 
340
 
 
341
    @Override
 
342
        public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
 
343
            int resultSetHoldability){
 
344
        throw new UnsupportedOperationException();
 
345
    }
 
346
 
 
347
 
 
348
    @Override
 
349
        public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys){
 
350
        throw new UnsupportedOperationException();
 
351
    }
 
352
 
 
353
 
 
354
    @Override
 
355
        public PreparedStatement prepareStatement(String sql, int[] columnIndexes){
 
356
        throw new UnsupportedOperationException();
 
357
    }
 
358
 
 
359
 
 
360
    @Override
 
361
        public PreparedStatement prepareStatement(String sql, String[] columnNames){
 
362
        throw new UnsupportedOperationException();
 
363
    }
 
364
 
 
365
 
 
366
    @Override
 
367
        public void releaseSavepoint(Savepoint savepoint){
 
368
        throw new UnsupportedOperationException();
 
369
    }
 
370
 
 
371
 
 
372
    @Override
 
373
        public void rollback(Savepoint savepoint){
 
374
        throw new UnsupportedOperationException();
 
375
    }
 
376
 
 
377
 
 
378
    @Override
 
379
        public void setCatalog(String catalog) throws SQLException{
 
380
        try{
 
381
            netConn.ChangeDatabase(catalog);
 
382
        }catch(Throwable th){
 
383
            throw JdbcOdbcUtils.createSQLException(th);
 
384
        }
 
385
    }
 
386
 
 
387
 
 
388
    @Override
 
389
        public String getCatalog(){
 
390
        return netConn.get_Database();
 
391
    }
 
392
 
 
393
 
 
394
    @Override
 
395
        public void setClientInfo(String name, String value){
 
396
        throw new UnsupportedOperationException();
 
397
    }
 
398
 
 
399
 
 
400
    @Override
 
401
        public void setClientInfo(Properties properties){
 
402
        throw new UnsupportedOperationException();
 
403
    }
 
404
 
 
405
 
 
406
    @Override
 
407
        public void setHoldability(int holdability){
 
408
        throw new UnsupportedOperationException();
 
409
    }
 
410
 
 
411
 
 
412
    @Override
 
413
        public void setReadOnly(boolean readOnly) throws SQLException{
 
414
        // TODO Auto-generated method stub
 
415
 
 
416
    }
 
417
 
 
418
 
 
419
    @Override
 
420
        public Savepoint setSavepoint(){
 
421
        throw new UnsupportedOperationException();
 
422
    }
 
423
 
 
424
 
 
425
    @Override
 
426
        public Savepoint setSavepoint(String name){
 
427
        throw new UnsupportedOperationException();
 
428
    }
 
429
 
 
430
 
 
431
        @Override
 
432
        public void setTypeMap(Map<String, Class<?>> map){
 
433
        throw new UnsupportedOperationException();
 
434
    }
 
435
 
 
436
 
 
437
    @Override
 
438
        public boolean isWrapperFor(Class<?> iface){
 
439
        return iface.isAssignableFrom(this.getClass());
 
440
    }
 
441
 
 
442
 
 
443
    @Override
 
444
        public <T>T unwrap(Class<T> iface) throws SQLException{
 
445
        if(isWrapperFor(iface)){
 
446
            return (T)this;
 
447
        }
 
448
        throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
 
449
    }
 
450
 
 
451
 
 
452
    /**
 
453
     * {@inheritDoc}
 
454
     */
 
455
        public void setSchema(String schema) throws SQLException {
 
456
        }
 
457
 
 
458
 
 
459
    /**
 
460
     * {@inheritDoc}
 
461
     */
 
462
        public String getSchema() throws SQLException {
 
463
                return null;
 
464
        }
 
465
 
 
466
 
 
467
    /**
 
468
     * {@inheritDoc}
 
469
     */
 
470
        public void abort(Executor executor) throws SQLException {
 
471
                throw new SQLFeatureNotSupportedException();
 
472
        }
 
473
 
 
474
 
 
475
    /**
 
476
     * {@inheritDoc}
 
477
     */
 
478
        public void setNetworkTimeout(Executor executor, int milliseconds)
 
479
                        throws SQLException {
 
480
                throw new SQLFeatureNotSupportedException();
 
481
        }
 
482
 
 
483
 
 
484
    /**
 
485
     * {@inheritDoc}
 
486
     */
 
487
        public int getNetworkTimeout() throws SQLException {
 
488
                throw new SQLFeatureNotSupportedException();
 
489
        }
 
490
}