2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
11 import java.io.InputStream;
12 import java.io.Reader;
13 import java.math.BigDecimal;
15 import java.sql.Array;
18 import java.sql.Connection;
20 import java.sql.NClob;
21 import java.sql.ParameterMetaData;
22 import java.sql.PreparedStatement;
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;
31 import java.sql.Timestamp;
32 import java.util.ArrayList;
33 import java.util.Calendar;
35 import java.util.concurrent.ConcurrentHashMap;
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;
43 public JDBCStatement(JDBCConnection con,String _sql) {
44 this.connection = con;
48 public JDBCStatement(JDBCConnection con) {
49 this.connection = con;
52 public void setSQL(String _sql){
56 public JDBCStatement() {
60 public PreparedStatement getProxy() {
63 return (PreparedStatement) Proxy.newProxyInstance(this.getClass()
64 .getClassLoader(), new Class[] { PreparedStatement.class },
69 public static JDBCResultSet getQuery(int id) {
70 return queries.get(id);
73 public static JDBCResultSet removeQuery(int id) {
74 return queries.remove(id);
78 public java.sql.ResultSet executeQuery(String _sql) throws SQLException {
79 rs = new JDBCResultSet(_sql);
80 queries.put(rs.getID(), rs);
82 this.connection.send(new JDBCCommand(rs,
83 JDBCCommand.TYPE_EXECUTE_QUERY));
86 } catch (Exception err) {
88 if (rs.getError() != null) {
89 throw ((SQLException) rs.getError());
96 public boolean execute(String _sql) throws SQLException {
100 public void addRecord(ArrayList<?> hierarchy) {
101 rs.addRecord(hierarchy);
108 public void setFinished(boolean b) {
109 this.rs.setFinished(b);
112 public JDBCResultSet getRS() {
116 public ResultSet getResultSet() {
121 public boolean isWrapperFor(Class<?> arg0) throws SQLException {
122 // TODO Auto-generated method stub
127 public <T> T unwrap(Class<T> arg0) throws SQLException {
128 // TODO Auto-generated method stub
133 public void addBatch(String sql) throws SQLException {
134 // TODO Auto-generated method stub
139 public void cancel() throws SQLException {
140 // TODO Auto-generated method stub
145 public void clearBatch() throws SQLException {
146 // TODO Auto-generated method stub
151 public void clearWarnings() throws SQLException {
152 // TODO Auto-generated method stub
157 public void close() throws SQLException {
158 // TODO Auto-generated method stub
163 public boolean execute(String sql, int autoGeneratedKeys)
164 throws SQLException {
165 // TODO Auto-generated method stub
170 public boolean execute(String sql, int[] columnIndexes) throws SQLException {
171 // TODO Auto-generated method stub
176 public boolean execute(String sql, String[] columnNames)
177 throws SQLException {
178 // TODO Auto-generated method stub
183 public int[] executeBatch() throws SQLException {
184 // TODO Auto-generated method stub
189 public int executeUpdate(String sql, int autoGeneratedKeys)
190 throws SQLException {
191 // TODO Auto-generated method stub
196 public int executeUpdate(String sql, int[] columnIndexes)
197 throws SQLException {
198 // TODO Auto-generated method stub
203 public int executeUpdate(String sql, String[] columnNames)
204 throws SQLException {
205 // TODO Auto-generated method stub
210 public int executeUpdate(String sql) throws SQLException {
211 // TODO Auto-generated method stub
216 public Connection getConnection() throws SQLException {
217 // TODO Auto-generated method stub
222 public int getFetchDirection() throws SQLException {
223 // TODO Auto-generated method stub
228 public int getFetchSize() throws SQLException {
229 // TODO Auto-generated method stub
234 public java.sql.ResultSet getGeneratedKeys() throws SQLException {
235 // TODO Auto-generated method stub
240 public int getMaxFieldSize() throws SQLException {
241 // TODO Auto-generated method stub
246 public int getMaxRows() throws SQLException {
251 public boolean getMoreResults() throws SQLException {
252 // TODO Auto-generated method stub
257 public boolean getMoreResults(int current) throws SQLException {
258 // TODO Auto-generated method stub
263 public int getQueryTimeout() throws SQLException {
264 // TODO Auto-generated method stub
269 public int getResultSetConcurrency() throws SQLException {
270 // TODO Auto-generated method stub
275 public int getResultSetHoldability() throws SQLException {
276 // TODO Auto-generated method stub
281 public int getResultSetType() throws SQLException {
282 // TODO Auto-generated method stub
287 public int getUpdateCount() throws SQLException {
288 // TODO Auto-generated method stub
293 public SQLWarning getWarnings() throws SQLException {
294 // TODO Auto-generated method stub
299 public boolean isClosed() throws SQLException {
300 // TODO Auto-generated method stub
305 public boolean isPoolable() throws SQLException {
306 // TODO Auto-generated method stub
311 public void setCursorName(String name) throws SQLException {
312 // TODO Auto-generated method stub
317 public void setEscapeProcessing(boolean enable) throws SQLException {
318 // TODO Auto-generated method stub
323 public void setFetchDirection(int direction) throws SQLException {
324 // TODO Auto-generated method stub
329 public void setFetchSize(int rows) throws SQLException {
330 // TODO Auto-generated method stub
335 public void setMaxFieldSize(int max) throws SQLException {
336 // TODO Auto-generated method stub
341 public void setMaxRows(int max) throws SQLException {
342 // TODO Auto-generated method stub
347 public void setPoolable(boolean poolable) throws SQLException {
348 // TODO Auto-generated method stub
353 public void setQueryTimeout(int seconds) throws SQLException {
354 // TODO Auto-generated method stub
359 public void closeOnCompletion() throws SQLException {
360 // TODO Auto-generated method stub
365 public boolean isCloseOnCompletion() throws SQLException {
366 // TODO Auto-generated method stub
371 public ResultSet executeQuery() throws SQLException {
372 return this.executeQuery(this.sql);
376 public int executeUpdate() throws SQLException {
377 // TODO Auto-generated method stub
382 public void setNull(int parameterIndex, int sqlType) throws SQLException {
383 // TODO Auto-generated method stub
388 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
389 // TODO Auto-generated method stub
394 public void setByte(int parameterIndex, byte x) throws SQLException {
395 // TODO Auto-generated method stub
400 public void setShort(int parameterIndex, short x) throws SQLException {
401 // TODO Auto-generated method stub
406 public void setInt(int parameterIndex, int x) throws SQLException {
407 // TODO Auto-generated method stub
412 public void setLong(int parameterIndex, long x) throws SQLException {
413 // TODO Auto-generated method stub
418 public void setFloat(int parameterIndex, float x) throws SQLException {
419 // TODO Auto-generated method stub
424 public void setDouble(int parameterIndex, double x) throws SQLException {
425 // TODO Auto-generated method stub
430 public void setBigDecimal(int parameterIndex, BigDecimal x)
431 throws SQLException {
432 // TODO Auto-generated method stub
437 public void setString(int parameterIndex, String x) throws SQLException {
438 // TODO Auto-generated method stub
443 public void setBytes(int parameterIndex, byte[] x) throws SQLException {
444 // TODO Auto-generated method stub
449 public void setDate(int parameterIndex, Date x) throws SQLException {
450 // TODO Auto-generated method stub
455 public void setTime(int parameterIndex, Time x) throws SQLException {
456 // TODO Auto-generated method stub
461 public void setTimestamp(int parameterIndex, Timestamp x)
462 throws SQLException {
463 // TODO Auto-generated method stub
468 public void setAsciiStream(int parameterIndex, InputStream x, int length)
469 throws SQLException {
470 // TODO Auto-generated method stub
475 public void setUnicodeStream(int parameterIndex, InputStream x, int length)
476 throws SQLException {
477 // TODO Auto-generated method stub
482 public void setBinaryStream(int parameterIndex, InputStream x, int length)
483 throws SQLException {
484 // TODO Auto-generated method stub
489 public void clearParameters() throws SQLException {
490 // TODO Auto-generated method stub
495 public void setObject(int parameterIndex, Object x, int targetSqlType)
496 throws SQLException {
497 // TODO Auto-generated method stub
502 public void setObject(int parameterIndex, Object x) throws SQLException {
503 // TODO Auto-generated method stub
507 public boolean execute() throws SQLException {
508 // TODO Auto-generated method stub
513 public void addBatch() throws SQLException {
514 // TODO Auto-generated method stub
519 public void setCharacterStream(int parameterIndex, Reader reader, int length)
520 throws SQLException {
521 // TODO Auto-generated method stub
526 public void setRef(int parameterIndex, Ref x) throws SQLException {
527 // TODO Auto-generated method stub
532 public void setBlob(int parameterIndex, Blob x) throws SQLException {
533 // TODO Auto-generated method stub
538 public void setClob(int parameterIndex, Clob x) throws SQLException {
539 // TODO Auto-generated method stub
544 public void setArray(int parameterIndex, Array x) throws SQLException {
545 // TODO Auto-generated method stub
550 public ResultSetMetaData getMetaData() throws SQLException {
551 // TODO Auto-generated method stub
556 public void setDate(int parameterIndex, Date x, Calendar cal)
557 throws SQLException {
558 // TODO Auto-generated method stub
563 public void setTime(int parameterIndex, Time x, Calendar cal)
564 throws SQLException {
565 // TODO Auto-generated method stub
570 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
571 throws SQLException {
572 // TODO Auto-generated method stub
577 public void setNull(int parameterIndex, int sqlType, String typeName)
578 throws SQLException {
579 // TODO Auto-generated method stub
584 public void setURL(int parameterIndex, URL x) throws SQLException {
585 // TODO Auto-generated method stub
590 public ParameterMetaData getParameterMetaData() throws SQLException {
591 // TODO Auto-generated method stub
596 public void setRowId(int parameterIndex, RowId x) throws SQLException {
597 // TODO Auto-generated method stub
602 public void setNString(int parameterIndex, String value)
603 throws SQLException {
604 // TODO Auto-generated method stub
609 public void setNCharacterStream(int parameterIndex, Reader value,
610 long length) throws SQLException {
611 // TODO Auto-generated method stub
616 public void setNClob(int parameterIndex, NClob value) throws SQLException {
617 // TODO Auto-generated method stub
622 public void setClob(int parameterIndex, Reader reader, long length)
623 throws SQLException {
624 // TODO Auto-generated method stub
629 public void setBlob(int parameterIndex, InputStream inputStream, long length)
630 throws SQLException {
631 // TODO Auto-generated method stub
636 public void setNClob(int parameterIndex, Reader reader, long length)
637 throws SQLException {
638 // TODO Auto-generated method stub
643 public void setSQLXML(int parameterIndex, SQLXML xmlObject)
644 throws SQLException {
645 // TODO Auto-generated method stub
650 public void setObject(int parameterIndex, Object x, int targetSqlType,
651 int scaleOrLength) throws SQLException {
652 // TODO Auto-generated method stub
657 public void setAsciiStream(int parameterIndex, InputStream x, long length)
658 throws SQLException {
659 // TODO Auto-generated method stub
664 public void setBinaryStream(int parameterIndex, InputStream x, long length)
665 throws SQLException {
666 // TODO Auto-generated method stub
671 public void setCharacterStream(int parameterIndex, Reader reader,
672 long length) throws SQLException {
673 // TODO Auto-generated method stub
678 public void setAsciiStream(int parameterIndex, InputStream x)
679 throws SQLException {
680 // TODO Auto-generated method stub
685 public void setBinaryStream(int parameterIndex, InputStream x)
686 throws SQLException {
687 // TODO Auto-generated method stub
692 public void setCharacterStream(int parameterIndex, Reader reader)
693 throws SQLException {
694 // TODO Auto-generated method stub
699 public void setNCharacterStream(int parameterIndex, Reader value)
700 throws SQLException {
701 // TODO Auto-generated method stub
706 public void setClob(int parameterIndex, Reader reader) throws SQLException {
707 // TODO Auto-generated method stub
712 public void setBlob(int parameterIndex, InputStream inputStream)
713 throws SQLException {
714 // TODO Auto-generated method stub
719 public void setNClob(int parameterIndex, Reader reader) throws SQLException {
720 // TODO Auto-generated method stub