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;
38 * To be removed in Nitrogen
41 public class JDBCStatement implements PreparedStatement {
42 private JDBCResultSet rs = null;
43 private transient JDBCConnection connection = null;
44 private static Map<Integer, JDBCResultSet> queries = new ConcurrentHashMap<>();
45 private String sql = null;
47 public JDBCStatement(JDBCConnection con,String _sql) {
48 this.connection = con;
52 public JDBCStatement(JDBCConnection con) {
53 this.connection = con;
56 public void setSQL(String _sql){
60 public JDBCStatement() {
64 public PreparedStatement getProxy() {
67 return (PreparedStatement) Proxy.newProxyInstance(this.getClass()
68 .getClassLoader(), new Class[] { PreparedStatement.class },
73 public static JDBCResultSet getQuery(int id) {
74 return queries.get(id);
77 public static JDBCResultSet removeQuery(int id) {
78 return queries.remove(id);
82 public java.sql.ResultSet executeQuery(String _sql) throws SQLException {
83 rs = new JDBCResultSet(_sql);
84 queries.put(rs.getID(), rs);
86 this.connection.send(new JDBCCommand(rs,
87 JDBCCommand.TYPE_EXECUTE_QUERY));
90 } catch (Exception err) {
92 if (rs.getError() != null) {
93 throw ((SQLException) rs.getError());
100 public boolean execute(String _sql) throws SQLException {
104 public void addRecord(ArrayList<?> hierarchy) {
105 rs.addRecord(hierarchy);
112 public void setFinished(boolean b) {
113 this.rs.setFinished(b);
116 public JDBCResultSet getRS() {
120 public ResultSet getResultSet() {
125 public boolean isWrapperFor(Class<?> arg0) throws SQLException {
126 // TODO Auto-generated method stub
131 public <T> T unwrap(Class<T> arg0) throws SQLException {
132 // TODO Auto-generated method stub
137 public void addBatch(String sql) throws SQLException {
138 // TODO Auto-generated method stub
143 public void cancel() throws SQLException {
144 // TODO Auto-generated method stub
149 public void clearBatch() throws SQLException {
150 // TODO Auto-generated method stub
155 public void clearWarnings() throws SQLException {
156 // TODO Auto-generated method stub
161 public void close() throws SQLException {
162 // TODO Auto-generated method stub
167 public boolean execute(String sql, int autoGeneratedKeys)
168 throws SQLException {
169 // TODO Auto-generated method stub
174 public boolean execute(String sql, int[] columnIndexes) throws SQLException {
175 // TODO Auto-generated method stub
180 public boolean execute(String sql, String[] columnNames)
181 throws SQLException {
182 // TODO Auto-generated method stub
187 public int[] executeBatch() throws SQLException {
188 // TODO Auto-generated method stub
193 public int executeUpdate(String sql, int autoGeneratedKeys)
194 throws SQLException {
195 // TODO Auto-generated method stub
200 public int executeUpdate(String sql, int[] columnIndexes)
201 throws SQLException {
202 // TODO Auto-generated method stub
207 public int executeUpdate(String sql, String[] columnNames)
208 throws SQLException {
209 // TODO Auto-generated method stub
214 public int executeUpdate(String sql) throws SQLException {
215 // TODO Auto-generated method stub
220 public Connection getConnection() throws SQLException {
221 // TODO Auto-generated method stub
226 public int getFetchDirection() throws SQLException {
227 // TODO Auto-generated method stub
232 public int getFetchSize() throws SQLException {
233 // TODO Auto-generated method stub
238 public java.sql.ResultSet getGeneratedKeys() throws SQLException {
239 // TODO Auto-generated method stub
244 public int getMaxFieldSize() throws SQLException {
245 // TODO Auto-generated method stub
250 public int getMaxRows() throws SQLException {
255 public boolean getMoreResults() throws SQLException {
256 // TODO Auto-generated method stub
261 public boolean getMoreResults(int current) throws SQLException {
262 // TODO Auto-generated method stub
267 public int getQueryTimeout() throws SQLException {
268 // TODO Auto-generated method stub
273 public int getResultSetConcurrency() throws SQLException {
274 // TODO Auto-generated method stub
279 public int getResultSetHoldability() throws SQLException {
280 // TODO Auto-generated method stub
285 public int getResultSetType() throws SQLException {
286 // TODO Auto-generated method stub
291 public int getUpdateCount() throws SQLException {
292 // TODO Auto-generated method stub
297 public SQLWarning getWarnings() throws SQLException {
298 // TODO Auto-generated method stub
303 public boolean isClosed() throws SQLException {
304 // TODO Auto-generated method stub
309 public boolean isPoolable() throws SQLException {
310 // TODO Auto-generated method stub
315 public void setCursorName(String name) throws SQLException {
316 // TODO Auto-generated method stub
321 public void setEscapeProcessing(boolean enable) throws SQLException {
322 // TODO Auto-generated method stub
327 public void setFetchDirection(int direction) throws SQLException {
328 // TODO Auto-generated method stub
333 public void setFetchSize(int rows) throws SQLException {
334 // TODO Auto-generated method stub
339 public void setMaxFieldSize(int max) throws SQLException {
340 // TODO Auto-generated method stub
345 public void setMaxRows(int max) throws SQLException {
346 // TODO Auto-generated method stub
351 public void setPoolable(boolean poolable) throws SQLException {
352 // TODO Auto-generated method stub
357 public void setQueryTimeout(int seconds) throws SQLException {
358 // TODO Auto-generated method stub
363 public void closeOnCompletion() throws SQLException {
364 // TODO Auto-generated method stub
369 public boolean isCloseOnCompletion() throws SQLException {
370 // TODO Auto-generated method stub
375 public ResultSet executeQuery() throws SQLException {
376 return this.executeQuery(this.sql);
380 public int executeUpdate() throws SQLException {
381 // TODO Auto-generated method stub
386 public void setNull(int parameterIndex, int sqlType) throws SQLException {
387 // TODO Auto-generated method stub
392 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
393 // TODO Auto-generated method stub
398 public void setByte(int parameterIndex, byte x) throws SQLException {
399 // TODO Auto-generated method stub
404 public void setShort(int parameterIndex, short x) throws SQLException {
405 // TODO Auto-generated method stub
410 public void setInt(int parameterIndex, int x) throws SQLException {
411 // TODO Auto-generated method stub
416 public void setLong(int parameterIndex, long x) throws SQLException {
417 // TODO Auto-generated method stub
422 public void setFloat(int parameterIndex, float x) throws SQLException {
423 // TODO Auto-generated method stub
428 public void setDouble(int parameterIndex, double x) throws SQLException {
429 // TODO Auto-generated method stub
434 public void setBigDecimal(int parameterIndex, BigDecimal x)
435 throws SQLException {
436 // TODO Auto-generated method stub
441 public void setString(int parameterIndex, String x) throws SQLException {
442 // TODO Auto-generated method stub
447 public void setBytes(int parameterIndex, byte[] x) throws SQLException {
448 // TODO Auto-generated method stub
453 public void setDate(int parameterIndex, Date x) throws SQLException {
454 // TODO Auto-generated method stub
459 public void setTime(int parameterIndex, Time x) throws SQLException {
460 // TODO Auto-generated method stub
465 public void setTimestamp(int parameterIndex, Timestamp x)
466 throws SQLException {
467 // TODO Auto-generated method stub
472 public void setAsciiStream(int parameterIndex, InputStream x, int length)
473 throws SQLException {
474 // TODO Auto-generated method stub
479 public void setUnicodeStream(int parameterIndex, InputStream x, int length)
480 throws SQLException {
481 // TODO Auto-generated method stub
486 public void setBinaryStream(int parameterIndex, InputStream x, int length)
487 throws SQLException {
488 // TODO Auto-generated method stub
493 public void clearParameters() throws SQLException {
494 // TODO Auto-generated method stub
499 public void setObject(int parameterIndex, Object x, int targetSqlType)
500 throws SQLException {
501 // TODO Auto-generated method stub
506 public void setObject(int parameterIndex, Object x) throws SQLException {
507 // TODO Auto-generated method stub
511 public boolean execute() throws SQLException {
512 // TODO Auto-generated method stub
517 public void addBatch() throws SQLException {
518 // TODO Auto-generated method stub
523 public void setCharacterStream(int parameterIndex, Reader reader, int length)
524 throws SQLException {
525 // TODO Auto-generated method stub
530 public void setRef(int parameterIndex, Ref x) throws SQLException {
531 // TODO Auto-generated method stub
536 public void setBlob(int parameterIndex, Blob x) throws SQLException {
537 // TODO Auto-generated method stub
542 public void setClob(int parameterIndex, Clob x) throws SQLException {
543 // TODO Auto-generated method stub
548 public void setArray(int parameterIndex, Array x) throws SQLException {
549 // TODO Auto-generated method stub
554 public ResultSetMetaData getMetaData() throws SQLException {
555 // TODO Auto-generated method stub
560 public void setDate(int parameterIndex, Date x, Calendar cal)
561 throws SQLException {
562 // TODO Auto-generated method stub
567 public void setTime(int parameterIndex, Time x, Calendar cal)
568 throws SQLException {
569 // TODO Auto-generated method stub
574 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
575 throws SQLException {
576 // TODO Auto-generated method stub
581 public void setNull(int parameterIndex, int sqlType, String typeName)
582 throws SQLException {
583 // TODO Auto-generated method stub
588 public void setURL(int parameterIndex, URL x) throws SQLException {
589 // TODO Auto-generated method stub
594 public ParameterMetaData getParameterMetaData() throws SQLException {
595 // TODO Auto-generated method stub
600 public void setRowId(int parameterIndex, RowId x) throws SQLException {
601 // TODO Auto-generated method stub
606 public void setNString(int parameterIndex, String value)
607 throws SQLException {
608 // TODO Auto-generated method stub
613 public void setNCharacterStream(int parameterIndex, Reader value,
614 long length) throws SQLException {
615 // TODO Auto-generated method stub
620 public void setNClob(int parameterIndex, NClob value) throws SQLException {
621 // TODO Auto-generated method stub
626 public void setClob(int parameterIndex, Reader reader, long length)
627 throws SQLException {
628 // TODO Auto-generated method stub
633 public void setBlob(int parameterIndex, InputStream inputStream, long length)
634 throws SQLException {
635 // TODO Auto-generated method stub
640 public void setNClob(int parameterIndex, Reader reader, long length)
641 throws SQLException {
642 // TODO Auto-generated method stub
647 public void setSQLXML(int parameterIndex, SQLXML xmlObject)
648 throws SQLException {
649 // TODO Auto-generated method stub
654 public void setObject(int parameterIndex, Object x, int targetSqlType,
655 int scaleOrLength) throws SQLException {
656 // TODO Auto-generated method stub
661 public void setAsciiStream(int parameterIndex, InputStream x, long length)
662 throws SQLException {
663 // TODO Auto-generated method stub
668 public void setBinaryStream(int parameterIndex, InputStream x, long length)
669 throws SQLException {
670 // TODO Auto-generated method stub
675 public void setCharacterStream(int parameterIndex, Reader reader,
676 long length) throws SQLException {
677 // TODO Auto-generated method stub
682 public void setAsciiStream(int parameterIndex, InputStream x)
683 throws SQLException {
684 // TODO Auto-generated method stub
689 public void setBinaryStream(int parameterIndex, InputStream x)
690 throws SQLException {
691 // TODO Auto-generated method stub
696 public void setCharacterStream(int parameterIndex, Reader reader)
697 throws SQLException {
698 // TODO Auto-generated method stub
703 public void setNCharacterStream(int parameterIndex, Reader value)
704 throws SQLException {
705 // TODO Auto-generated method stub
710 public void setClob(int parameterIndex, Reader reader) throws SQLException {
711 // TODO Auto-generated method stub
716 public void setBlob(int parameterIndex, InputStream inputStream)
717 throws SQLException {
718 // TODO Auto-generated method stub
723 public void setNClob(int parameterIndex, Reader reader) throws SQLException {
724 // TODO Auto-generated method stub