a83f1f16b939fa0b9f4030d153352e1935d00b11
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / opendaylight / controller / md / sal / dom / xsql / jdbc / JDBCStatement.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
10
11 import java.io.InputStream;
12 import java.io.Reader;
13 import java.math.BigDecimal;
14 import java.net.URL;
15 import java.sql.Array;
16 import java.sql.Blob;
17 import java.sql.Clob;
18 import java.sql.Connection;
19 import java.sql.Date;
20 import java.sql.NClob;
21 import java.sql.ParameterMetaData;
22 import java.sql.PreparedStatement;
23 import java.sql.Ref;
24 import java.sql.ResultSet;
25 import java.sql.ResultSetMetaData;
26 import java.sql.RowId;
27 import java.sql.SQLException;
28 import java.sql.SQLWarning;
29 import java.sql.SQLXML;
30 import java.sql.Time;
31 import java.sql.Timestamp;
32 import java.util.ArrayList;
33 import java.util.Calendar;
34 import java.util.Map;
35 import java.util.concurrent.ConcurrentHashMap;
36
37 public class JDBCStatement implements PreparedStatement {
38     private JDBCResultSet rs = null;
39     private transient JDBCConnection connection = null;
40     private static Map<Integer, JDBCResultSet> queries = new ConcurrentHashMap<Integer, JDBCResultSet>();
41     private String sql = null;
42
43     public JDBCStatement(JDBCConnection con,String _sql) {
44         this.connection = con;
45         this.sql = _sql;
46     }
47
48     public JDBCStatement(JDBCConnection con) {
49         this.connection = con;
50     }
51
52     public void setSQL(String _sql){
53         this.sql = _sql;
54     }
55
56     public JDBCStatement() {
57
58     }
59
60     public PreparedStatement getProxy() {
61         return this;
62         /*
63         return (PreparedStatement) Proxy.newProxyInstance(this.getClass()
64                 .getClassLoader(), new Class[] { PreparedStatement.class },
65                 new JDBCProxy(this));
66                 */
67     }
68
69     public static JDBCResultSet getQuery(int id) {
70         return queries.get(id);
71     }
72
73     public static JDBCResultSet removeQuery(int id) {
74         return queries.remove(id);
75     }
76
77     @Override
78     public java.sql.ResultSet executeQuery(String _sql) throws SQLException {
79         rs = new JDBCResultSet(_sql);
80         queries.put(rs.getID(), rs);
81         synchronized (rs) {
82             this.connection.send(new JDBCCommand(rs,
83                     JDBCCommand.TYPE_EXECUTE_QUERY));
84             try {
85                 rs.wait();
86             } catch (Exception err) {
87             }
88             if (rs.getError() != null) {
89                 throw ((SQLException) rs.getError());
90             }
91         }
92         return rs.getProxy();
93     }
94
95     @Override
96     public boolean execute(String _sql) throws SQLException {
97         return true;
98     }
99
100     public void addRecord(ArrayList<?> hierarchy) {
101         rs.addRecord(hierarchy);
102     }
103
104     public int size() {
105         return rs.size();
106     }
107
108     public void setFinished(boolean b) {
109         this.rs.setFinished(b);
110     }
111
112     public JDBCResultSet getRS() {
113         return this.rs;
114     }
115
116     public ResultSet getResultSet() {
117         return this.rs;
118     }
119
120     @Override
121     public boolean isWrapperFor(Class<?> arg0) throws SQLException {
122         // TODO Auto-generated method stub
123         return false;
124     }
125
126     @Override
127     public <T> T unwrap(Class<T> arg0) throws SQLException {
128         // TODO Auto-generated method stub
129         return null;
130     }
131
132     @Override
133     public void addBatch(String sql) throws SQLException {
134         // TODO Auto-generated method stub
135
136     }
137
138     @Override
139     public void cancel() throws SQLException {
140         // TODO Auto-generated method stub
141
142     }
143
144     @Override
145     public void clearBatch() throws SQLException {
146         // TODO Auto-generated method stub
147
148     }
149
150     @Override
151     public void clearWarnings() throws SQLException {
152         // TODO Auto-generated method stub
153
154     }
155
156     @Override
157     public void close() throws SQLException {
158         // TODO Auto-generated method stub
159
160     }
161
162     @Override
163     public boolean execute(String sql, int autoGeneratedKeys)
164             throws SQLException {
165         // TODO Auto-generated method stub
166         return false;
167     }
168
169     @Override
170     public boolean execute(String sql, int[] columnIndexes) throws SQLException {
171         // TODO Auto-generated method stub
172         return false;
173     }
174
175     @Override
176     public boolean execute(String sql, String[] columnNames)
177             throws SQLException {
178         // TODO Auto-generated method stub
179         return false;
180     }
181
182     @Override
183     public int[] executeBatch() throws SQLException {
184         // TODO Auto-generated method stub
185         return null;
186     }
187
188     @Override
189     public int executeUpdate(String sql, int autoGeneratedKeys)
190             throws SQLException {
191         // TODO Auto-generated method stub
192         return 0;
193     }
194
195     @Override
196     public int executeUpdate(String sql, int[] columnIndexes)
197             throws SQLException {
198         // TODO Auto-generated method stub
199         return 0;
200     }
201
202     @Override
203     public int executeUpdate(String sql, String[] columnNames)
204             throws SQLException {
205         // TODO Auto-generated method stub
206         return 0;
207     }
208
209     @Override
210     public int executeUpdate(String sql) throws SQLException {
211         // TODO Auto-generated method stub
212         return 0;
213     }
214
215     @Override
216     public Connection getConnection() throws SQLException {
217         // TODO Auto-generated method stub
218         return null;
219     }
220
221     @Override
222     public int getFetchDirection() throws SQLException {
223         // TODO Auto-generated method stub
224         return 0;
225     }
226
227     @Override
228     public int getFetchSize() throws SQLException {
229         // TODO Auto-generated method stub
230         return 0;
231     }
232
233     @Override
234     public java.sql.ResultSet getGeneratedKeys() throws SQLException {
235         // TODO Auto-generated method stub
236         return null;
237     }
238
239     @Override
240     public int getMaxFieldSize() throws SQLException {
241         // TODO Auto-generated method stub
242         return 0;
243     }
244
245     @Override
246     public int getMaxRows() throws SQLException {
247         return 200;
248     }
249
250     @Override
251     public boolean getMoreResults() throws SQLException {
252         // TODO Auto-generated method stub
253         return false;
254     }
255
256     @Override
257     public boolean getMoreResults(int current) throws SQLException {
258         // TODO Auto-generated method stub
259         return false;
260     }
261
262     @Override
263     public int getQueryTimeout() throws SQLException {
264         // TODO Auto-generated method stub
265         return 0;
266     }
267
268     @Override
269     public int getResultSetConcurrency() throws SQLException {
270         // TODO Auto-generated method stub
271         return 0;
272     }
273
274     @Override
275     public int getResultSetHoldability() throws SQLException {
276         // TODO Auto-generated method stub
277         return 0;
278     }
279
280     @Override
281     public int getResultSetType() throws SQLException {
282         // TODO Auto-generated method stub
283         return 0;
284     }
285
286     @Override
287     public int getUpdateCount() throws SQLException {
288         // TODO Auto-generated method stub
289         return 0;
290     }
291
292     @Override
293     public SQLWarning getWarnings() throws SQLException {
294         // TODO Auto-generated method stub
295         return null;
296     }
297
298     @Override
299     public boolean isClosed() throws SQLException {
300         // TODO Auto-generated method stub
301         return false;
302     }
303
304     @Override
305     public boolean isPoolable() throws SQLException {
306         // TODO Auto-generated method stub
307         return false;
308     }
309
310     @Override
311     public void setCursorName(String name) throws SQLException {
312         // TODO Auto-generated method stub
313
314     }
315
316     @Override
317     public void setEscapeProcessing(boolean enable) throws SQLException {
318         // TODO Auto-generated method stub
319
320     }
321
322     @Override
323     public void setFetchDirection(int direction) throws SQLException {
324         // TODO Auto-generated method stub
325
326     }
327
328     @Override
329     public void setFetchSize(int rows) throws SQLException {
330         // TODO Auto-generated method stub
331
332     }
333
334     @Override
335     public void setMaxFieldSize(int max) throws SQLException {
336         // TODO Auto-generated method stub
337
338     }
339
340     @Override
341     public void setMaxRows(int max) throws SQLException {
342         // TODO Auto-generated method stub
343
344     }
345
346     @Override
347     public void setPoolable(boolean poolable) throws SQLException {
348         // TODO Auto-generated method stub
349
350     }
351
352     @Override
353     public void setQueryTimeout(int seconds) throws SQLException {
354         // TODO Auto-generated method stub
355
356     }
357
358     @Override
359     public void closeOnCompletion() throws SQLException {
360         // TODO Auto-generated method stub
361
362     }
363
364     @Override
365     public boolean isCloseOnCompletion() throws SQLException {
366         // TODO Auto-generated method stub
367         return false;
368     }
369
370     @Override
371     public ResultSet executeQuery() throws SQLException {
372         return this.executeQuery(this.sql);
373     }
374
375     @Override
376     public int executeUpdate() throws SQLException {
377         // TODO Auto-generated method stub
378         return 0;
379     }
380
381     @Override
382     public void setNull(int parameterIndex, int sqlType) throws SQLException {
383         // TODO Auto-generated method stub
384
385     }
386
387     @Override
388     public void setBoolean(int parameterIndex, boolean x) throws SQLException {
389         // TODO Auto-generated method stub
390
391     }
392
393     @Override
394     public void setByte(int parameterIndex, byte x) throws SQLException {
395         // TODO Auto-generated method stub
396
397     }
398
399     @Override
400     public void setShort(int parameterIndex, short x) throws SQLException {
401         // TODO Auto-generated method stub
402
403     }
404
405     @Override
406     public void setInt(int parameterIndex, int x) throws SQLException {
407         // TODO Auto-generated method stub
408
409     }
410
411     @Override
412     public void setLong(int parameterIndex, long x) throws SQLException {
413         // TODO Auto-generated method stub
414
415     }
416
417     @Override
418     public void setFloat(int parameterIndex, float x) throws SQLException {
419         // TODO Auto-generated method stub
420
421     }
422
423     @Override
424     public void setDouble(int parameterIndex, double x) throws SQLException {
425         // TODO Auto-generated method stub
426
427     }
428
429     @Override
430     public void setBigDecimal(int parameterIndex, BigDecimal x)
431             throws SQLException {
432         // TODO Auto-generated method stub
433
434     }
435
436     @Override
437     public void setString(int parameterIndex, String x) throws SQLException {
438         // TODO Auto-generated method stub
439
440     }
441
442     @Override
443     public void setBytes(int parameterIndex, byte[] x) throws SQLException {
444         // TODO Auto-generated method stub
445
446     }
447
448     @Override
449     public void setDate(int parameterIndex, Date x) throws SQLException {
450         // TODO Auto-generated method stub
451
452     }
453
454     @Override
455     public void setTime(int parameterIndex, Time x) throws SQLException {
456         // TODO Auto-generated method stub
457
458     }
459
460     @Override
461     public void setTimestamp(int parameterIndex, Timestamp x)
462             throws SQLException {
463         // TODO Auto-generated method stub
464
465     }
466
467     @Override
468     public void setAsciiStream(int parameterIndex, InputStream x, int length)
469             throws SQLException {
470         // TODO Auto-generated method stub
471
472     }
473
474     @Override
475     public void setUnicodeStream(int parameterIndex, InputStream x, int length)
476             throws SQLException {
477         // TODO Auto-generated method stub
478
479     }
480
481     @Override
482     public void setBinaryStream(int parameterIndex, InputStream x, int length)
483             throws SQLException {
484         // TODO Auto-generated method stub
485
486     }
487
488     @Override
489     public void clearParameters() throws SQLException {
490         // TODO Auto-generated method stub
491
492     }
493
494     @Override
495     public void setObject(int parameterIndex, Object x, int targetSqlType)
496             throws SQLException {
497         // TODO Auto-generated method stub
498
499     }
500
501     @Override
502     public void setObject(int parameterIndex, Object x) throws SQLException {
503         // TODO Auto-generated method stub
504     }
505
506     @Override
507     public boolean execute() throws SQLException {
508         // TODO Auto-generated method stub
509         return false;
510     }
511
512     @Override
513     public void addBatch() throws SQLException {
514         // TODO Auto-generated method stub
515
516     }
517
518     @Override
519     public void setCharacterStream(int parameterIndex, Reader reader, int length)
520             throws SQLException {
521         // TODO Auto-generated method stub
522
523     }
524
525     @Override
526     public void setRef(int parameterIndex, Ref x) throws SQLException {
527         // TODO Auto-generated method stub
528
529     }
530
531     @Override
532     public void setBlob(int parameterIndex, Blob x) throws SQLException {
533         // TODO Auto-generated method stub
534
535     }
536
537     @Override
538     public void setClob(int parameterIndex, Clob x) throws SQLException {
539         // TODO Auto-generated method stub
540
541     }
542
543     @Override
544     public void setArray(int parameterIndex, Array x) throws SQLException {
545         // TODO Auto-generated method stub
546
547     }
548
549     @Override
550     public ResultSetMetaData getMetaData() throws SQLException {
551         // TODO Auto-generated method stub
552         return null;
553     }
554
555     @Override
556     public void setDate(int parameterIndex, Date x, Calendar cal)
557             throws SQLException {
558         // TODO Auto-generated method stub
559
560     }
561
562     @Override
563     public void setTime(int parameterIndex, Time x, Calendar cal)
564             throws SQLException {
565         // TODO Auto-generated method stub
566
567     }
568
569     @Override
570     public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
571             throws SQLException {
572         // TODO Auto-generated method stub
573
574     }
575
576     @Override
577     public void setNull(int parameterIndex, int sqlType, String typeName)
578             throws SQLException {
579         // TODO Auto-generated method stub
580
581     }
582
583     @Override
584     public void setURL(int parameterIndex, URL x) throws SQLException {
585         // TODO Auto-generated method stub
586
587     }
588
589     @Override
590     public ParameterMetaData getParameterMetaData() throws SQLException {
591         // TODO Auto-generated method stub
592         return null;
593     }
594
595     @Override
596     public void setRowId(int parameterIndex, RowId x) throws SQLException {
597         // TODO Auto-generated method stub
598
599     }
600
601     @Override
602     public void setNString(int parameterIndex, String value)
603             throws SQLException {
604         // TODO Auto-generated method stub
605
606     }
607
608     @Override
609     public void setNCharacterStream(int parameterIndex, Reader value,
610             long length) throws SQLException {
611         // TODO Auto-generated method stub
612
613     }
614
615     @Override
616     public void setNClob(int parameterIndex, NClob value) throws SQLException {
617         // TODO Auto-generated method stub
618
619     }
620
621     @Override
622     public void setClob(int parameterIndex, Reader reader, long length)
623             throws SQLException {
624         // TODO Auto-generated method stub
625
626     }
627
628     @Override
629     public void setBlob(int parameterIndex, InputStream inputStream, long length)
630             throws SQLException {
631         // TODO Auto-generated method stub
632
633     }
634
635     @Override
636     public void setNClob(int parameterIndex, Reader reader, long length)
637             throws SQLException {
638         // TODO Auto-generated method stub
639
640     }
641
642     @Override
643     public void setSQLXML(int parameterIndex, SQLXML xmlObject)
644             throws SQLException {
645         // TODO Auto-generated method stub
646
647     }
648
649     @Override
650     public void setObject(int parameterIndex, Object x, int targetSqlType,
651             int scaleOrLength) throws SQLException {
652         // TODO Auto-generated method stub
653
654     }
655
656     @Override
657     public void setAsciiStream(int parameterIndex, InputStream x, long length)
658             throws SQLException {
659         // TODO Auto-generated method stub
660
661     }
662
663     @Override
664     public void setBinaryStream(int parameterIndex, InputStream x, long length)
665             throws SQLException {
666         // TODO Auto-generated method stub
667
668     }
669
670     @Override
671     public void setCharacterStream(int parameterIndex, Reader reader,
672             long length) throws SQLException {
673         // TODO Auto-generated method stub
674
675     }
676
677     @Override
678     public void setAsciiStream(int parameterIndex, InputStream x)
679             throws SQLException {
680         // TODO Auto-generated method stub
681
682     }
683
684     @Override
685     public void setBinaryStream(int parameterIndex, InputStream x)
686             throws SQLException {
687         // TODO Auto-generated method stub
688
689     }
690
691     @Override
692     public void setCharacterStream(int parameterIndex, Reader reader)
693             throws SQLException {
694         // TODO Auto-generated method stub
695
696     }
697
698     @Override
699     public void setNCharacterStream(int parameterIndex, Reader value)
700             throws SQLException {
701         // TODO Auto-generated method stub
702
703     }
704
705     @Override
706     public void setClob(int parameterIndex, Reader reader) throws SQLException {
707         // TODO Auto-generated method stub
708
709     }
710
711     @Override
712     public void setBlob(int parameterIndex, InputStream inputStream)
713             throws SQLException {
714         // TODO Auto-generated method stub
715
716     }
717
718     @Override
719     public void setNClob(int parameterIndex, Reader reader) throws SQLException {
720         // TODO Auto-generated method stub
721
722     }
723
724 }