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