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

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.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 java.sql.*;
 
27
 
 
28
import cli.System.Data.*;
 
29
import cli.System.Data.Common.*;
 
30
import cli.System.Data.Odbc.*;
 
31
 
 
32
/**
 
33
 * This JDBC Driver is a wrapper to the ODBC.NET Data Provider.
 
34
 */
 
35
public class JdbcOdbcStatement implements Statement{
 
36
 
 
37
    private final JdbcOdbcConnection jdbcConn;
 
38
 
 
39
    protected final OdbcCommand command;
 
40
 
 
41
    private final int resultSetType;
 
42
    
 
43
    private final int resultSetConcurrency;
 
44
    
 
45
    private DbDataReader reader;
 
46
    
 
47
    private ResultSet rs;
 
48
    
 
49
    private int updateCount;
 
50
    
 
51
    private boolean isClosed;
 
52
    
 
53
    private ResultSet moreResults;
 
54
 
 
55
    public JdbcOdbcStatement(JdbcOdbcConnection jdbcConn, OdbcCommand command, int resultSetType, int resultSetConcurrency){
 
56
        this.jdbcConn = jdbcConn;
 
57
        this.command = command;
 
58
        this.resultSetType = resultSetType;
 
59
        this.resultSetConcurrency = resultSetConcurrency;
 
60
    }
 
61
 
 
62
 
 
63
    public void addBatch(String sql) throws SQLException{
 
64
        // TODO Auto-generated method stub
 
65
 
 
66
    }
 
67
 
 
68
 
 
69
    public void cancel() throws SQLException{
 
70
        try{
 
71
            command.Cancel();
 
72
        }catch(Throwable ex){
 
73
            throw JdbcOdbcUtils.createSQLException(ex);
 
74
        }
 
75
    }
 
76
 
 
77
 
 
78
    public void clearBatch() throws SQLException{
 
79
        // TODO Auto-generated method stub
 
80
 
 
81
    }
 
82
 
 
83
 
 
84
    public void clearWarnings() throws SQLException{
 
85
        // TODO Auto-generated method stub
 
86
 
 
87
    }
 
88
 
 
89
 
 
90
    public void close() throws SQLException{
 
91
        isClosed = true;
 
92
        if(rs != null){
 
93
            rs.close();
 
94
        }
 
95
        if(reader != null){
 
96
            reader.Close();
 
97
        }
 
98
        command.Dispose();
 
99
    }
 
100
 
 
101
 
 
102
    public boolean execute(String sql) throws SQLException{
 
103
        try{
 
104
            if(sql != null){
 
105
                command.set_CommandText(sql);
 
106
            }
 
107
            command.ExecuteNonQuery();
 
108
            return false;
 
109
        }catch(Throwable ex){
 
110
            throw JdbcOdbcUtils.createSQLException(ex);
 
111
        }
 
112
    }
 
113
 
 
114
 
 
115
    public boolean execute(String sql, int autoGeneratedKeys){
 
116
        throw new UnsupportedOperationException();
 
117
    }
 
118
 
 
119
 
 
120
    public boolean execute(String sql, int[] columnIndexes){
 
121
        throw new UnsupportedOperationException();
 
122
    }
 
123
 
 
124
 
 
125
    public boolean execute(String sql, String[] columnNames){
 
126
        throw new UnsupportedOperationException();
 
127
    }
 
128
 
 
129
 
 
130
    public int[] executeBatch() throws SQLException{
 
131
        // TODO Auto-generated method stub
 
132
        return null;
 
133
    }
 
134
 
 
135
 
 
136
    public ResultSet executeQuery(String sql) throws SQLException{
 
137
        try{
 
138
            if(sql != null){
 
139
                command.set_CommandText(sql);
 
140
            }
 
141
            if(resultSetConcurrency == ResultSet.CONCUR_UPDATABLE){
 
142
                rs = new JdbcOdbcUpdateableResultSet(command);
 
143
            }else{
 
144
                if(resultSetType == ResultSet.TYPE_FORWARD_ONLY){
 
145
                    reader = command.ExecuteReader();
 
146
                    rs = new JdbcOdbcResultSet(this, reader);
 
147
                }else{
 
148
                    OdbcDataAdapter da = new OdbcDataAdapter(command);
 
149
                    DataTable dt = new DataTable();
 
150
                    da.Fill(dt);
 
151
                    rs = new JdbcOdbcDTResultSet(dt);
 
152
                }
 
153
            }
 
154
            return rs;
 
155
        }catch(Throwable ex){
 
156
            throw JdbcOdbcUtils.createSQLException(ex);
 
157
        }
 
158
    }
 
159
 
 
160
 
 
161
    public int executeUpdate(String sql) throws SQLException{
 
162
        try{
 
163
            if(sql != null){
 
164
                command.set_CommandText(sql);
 
165
            }
 
166
            updateCount = command.ExecuteNonQuery();
 
167
            return updateCount;
 
168
        }catch(Throwable ex){
 
169
            throw JdbcOdbcUtils.createSQLException(ex);
 
170
        }
 
171
    }
 
172
 
 
173
 
 
174
    public int executeUpdate(String sql, int autoGeneratedKeys){
 
175
        throw new UnsupportedOperationException();
 
176
    }
 
177
 
 
178
 
 
179
    public int executeUpdate(String sql, int[] columnIndexes){
 
180
        throw new UnsupportedOperationException();
 
181
    }
 
182
 
 
183
 
 
184
    public int executeUpdate(String sql, String[] columnNames){
 
185
        throw new UnsupportedOperationException();
 
186
    }
 
187
 
 
188
 
 
189
    public Connection getConnection(){
 
190
        return jdbcConn;
 
191
    }
 
192
 
 
193
 
 
194
    public int getFetchDirection(){
 
195
        return ResultSet.FETCH_UNKNOWN;
 
196
    }
 
197
 
 
198
 
 
199
    public int getFetchSize(){
 
200
        return 0;
 
201
    }
 
202
 
 
203
 
 
204
    public ResultSet getGeneratedKeys(){
 
205
        throw new UnsupportedOperationException();
 
206
    }
 
207
 
 
208
 
 
209
    public int getMaxFieldSize() throws SQLException{
 
210
        // TODO Auto-generated method stub
 
211
        return 0;
 
212
    }
 
213
 
 
214
 
 
215
    public int getMaxRows() throws SQLException{
 
216
        // TODO Auto-generated method stub
 
217
        return 0;
 
218
    }
 
219
 
 
220
 
 
221
    public boolean getMoreResults() throws SQLException{
 
222
        try{
 
223
            if(moreResults != null){
 
224
                rs = moreResults;
 
225
                moreResults = null;
 
226
                return true;
 
227
            }
 
228
            boolean isNext = reader.NextResult();
 
229
            if(isNext){
 
230
                rs = new JdbcOdbcResultSet(this, reader);
 
231
                return true;
 
232
            }
 
233
            rs = null;
 
234
            return false;
 
235
        }catch(Throwable th){
 
236
            throw JdbcOdbcUtils.createSQLException(th);
 
237
        }
 
238
    }
 
239
 
 
240
 
 
241
    public boolean getMoreResults(int current) throws SQLException{
 
242
        // TODO Auto-generated method stub
 
243
        return false;
 
244
    }
 
245
 
 
246
 
 
247
    public int getQueryTimeout(){
 
248
        return command.get_CommandTimeout();
 
249
    }
 
250
 
 
251
 
 
252
    public ResultSet getResultSet(){
 
253
        return rs;
 
254
    }
 
255
 
 
256
 
 
257
    public int getResultSetConcurrency(){
 
258
        return resultSetConcurrency;
 
259
    }
 
260
 
 
261
 
 
262
    public int getResultSetHoldability() throws SQLException{
 
263
        // TODO Auto-generated method stub
 
264
        return 0;
 
265
    }
 
266
 
 
267
 
 
268
    public int getResultSetType(){
 
269
        return resultSetType;
 
270
    }
 
271
 
 
272
 
 
273
    public int getUpdateCount(){
 
274
        return updateCount;
 
275
    }
 
276
 
 
277
 
 
278
    public SQLWarning getWarnings() throws SQLException{
 
279
        // TODO Auto-generated method stub
 
280
        return null;
 
281
    }
 
282
 
 
283
 
 
284
    public boolean isClosed(){
 
285
        return isClosed;
 
286
    }
 
287
 
 
288
 
 
289
    public void setCursorName(String name) throws SQLException{
 
290
        // TODO Auto-generated method stub
 
291
 
 
292
    }
 
293
 
 
294
 
 
295
    public void setEscapeProcessing(boolean enable) throws SQLException{
 
296
        // TODO Auto-generated method stub
 
297
 
 
298
    }
 
299
 
 
300
 
 
301
    public void setFetchDirection(int direction){
 
302
        // ignore it
 
303
    }
 
304
 
 
305
 
 
306
    public void setFetchSize(int rows){
 
307
        // ignore it
 
308
    }
 
309
 
 
310
 
 
311
    public void setMaxFieldSize(int max) throws SQLException{
 
312
        // TODO Auto-generated method stub
 
313
 
 
314
    }
 
315
 
 
316
 
 
317
    public void setMaxRows(int max) throws SQLException{
 
318
        // TODO Auto-generated method stub
 
319
 
 
320
    }
 
321
 
 
322
 
 
323
    public boolean isPoolable(){
 
324
        return false;
 
325
    }
 
326
 
 
327
 
 
328
    public void setPoolable(boolean poolable) throws SQLException{
 
329
        // ignore it
 
330
    }
 
331
 
 
332
 
 
333
    public void setQueryTimeout(int seconds){
 
334
        command.set_CommandTimeout(seconds);
 
335
    }
 
336
 
 
337
 
 
338
    public boolean isWrapperFor(Class<?> iface){
 
339
        return iface.isAssignableFrom(this.getClass());
 
340
    }
 
341
 
 
342
 
 
343
    public <T>T unwrap(Class<T> iface) throws SQLException{
 
344
        if(isWrapperFor(iface)){
 
345
            return (T)this;
 
346
        }
 
347
        throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
 
348
    }
 
349
    
 
350
    /**
 
351
     * Close the DbDataReader if there are no more results.
 
352
     * This give some blocking free without calling close() explicit.
 
353
     * If there are more results then we need to save it.
 
354
     */
 
355
    void closeReaderIfPossible(){
 
356
        ResultSet currentRs = rs;
 
357
        boolean isMoreResults;
 
358
        try{
 
359
            isMoreResults = getMoreResults();
 
360
        }catch(SQLException ex){
 
361
            isMoreResults = false;
 
362
        }
 
363
        if(!isMoreResults){
 
364
            reader.Close(); //this give the ODBC cursor free
 
365
        }else{
 
366
            moreResults = rs;
 
367
        }
 
368
        rs = currentRs;
 
369
    }
 
370
 
 
371
 
 
372
    /**
 
373
     * {@inheritDoc}
 
374
     */
 
375
        public void closeOnCompletion() throws SQLException {
 
376
        }
 
377
 
 
378
 
 
379
    /**
 
380
     * {@inheritDoc}
 
381
     */
 
382
        public boolean isCloseOnCompletion() throws SQLException {
 
383
                return false;
 
384
        }
 
385
 
 
386
}