1 package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
3 import java.io.InputStream;
5 import java.math.BigDecimal;
10 import java.sql.Connection;
12 import java.sql.NClob;
13 import java.sql.ParameterMetaData;
14 import java.sql.PreparedStatement;
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;
23 import java.sql.Timestamp;
24 import java.util.ArrayList;
25 import java.util.Calendar;
27 import java.util.concurrent.ConcurrentHashMap;
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;
35 public JDBCStatement(JDBCConnection con,String _sql) {
36 this.connection = con;
40 public JDBCStatement(JDBCConnection con) {
41 this.connection = con;
44 public void setSQL(String _sql){
48 public JDBCStatement() {
52 public PreparedStatement getProxy() {
55 return (PreparedStatement) Proxy.newProxyInstance(this.getClass()
56 .getClassLoader(), new Class[] { PreparedStatement.class },
61 public static JDBCResultSet getQuery(int id) {
62 return queries.get(id);
65 public static JDBCResultSet removeQuery(int id) {
66 return queries.remove(id);
70 public java.sql.ResultSet executeQuery(String _sql) throws SQLException {
71 rs = new JDBCResultSet(_sql);
72 queries.put(rs.getID(), rs);
74 this.connection.send(new JDBCCommand(rs,
75 JDBCCommand.TYPE_EXECUTE_QUERY));
78 } catch (Exception err) {
80 if (rs.getError() != null) {
81 throw ((SQLException) rs.getError());
88 public boolean execute(String _sql) throws SQLException {
92 public void addRecord(ArrayList<?> hierarchy) {
93 rs.addRecord(hierarchy);
100 public void setFinished(boolean b) {
101 this.rs.setFinished(b);
104 public JDBCResultSet getRS() {
108 public ResultSet getResultSet() {
113 public boolean isWrapperFor(Class<?> arg0) throws SQLException {
114 // TODO Auto-generated method stub
119 public <T> T unwrap(Class<T> arg0) throws SQLException {
120 // TODO Auto-generated method stub
125 public void addBatch(String sql) throws SQLException {
126 // TODO Auto-generated method stub
131 public void cancel() throws SQLException {
132 // TODO Auto-generated method stub
137 public void clearBatch() throws SQLException {
138 // TODO Auto-generated method stub
143 public void clearWarnings() throws SQLException {
144 // TODO Auto-generated method stub
149 public void close() throws SQLException {
150 // TODO Auto-generated method stub
155 public boolean execute(String sql, int autoGeneratedKeys)
156 throws SQLException {
157 // TODO Auto-generated method stub
162 public boolean execute(String sql, int[] columnIndexes) throws SQLException {
163 // TODO Auto-generated method stub
168 public boolean execute(String sql, String[] columnNames)
169 throws SQLException {
170 // TODO Auto-generated method stub
175 public int[] executeBatch() throws SQLException {
176 // TODO Auto-generated method stub
181 public int executeUpdate(String sql, int autoGeneratedKeys)
182 throws SQLException {
183 // TODO Auto-generated method stub
188 public int executeUpdate(String sql, int[] columnIndexes)
189 throws SQLException {
190 // TODO Auto-generated method stub
195 public int executeUpdate(String sql, String[] columnNames)
196 throws SQLException {
197 // TODO Auto-generated method stub
202 public int executeUpdate(String sql) throws SQLException {
203 // TODO Auto-generated method stub
208 public Connection getConnection() throws SQLException {
209 // TODO Auto-generated method stub
214 public int getFetchDirection() throws SQLException {
215 // TODO Auto-generated method stub
220 public int getFetchSize() throws SQLException {
221 // TODO Auto-generated method stub
226 public java.sql.ResultSet getGeneratedKeys() throws SQLException {
227 // TODO Auto-generated method stub
232 public int getMaxFieldSize() throws SQLException {
233 // TODO Auto-generated method stub
238 public int getMaxRows() throws SQLException {
243 public boolean getMoreResults() throws SQLException {
244 // TODO Auto-generated method stub
249 public boolean getMoreResults(int current) throws SQLException {
250 // TODO Auto-generated method stub
255 public int getQueryTimeout() throws SQLException {
256 // TODO Auto-generated method stub
261 public int getResultSetConcurrency() throws SQLException {
262 // TODO Auto-generated method stub
267 public int getResultSetHoldability() throws SQLException {
268 // TODO Auto-generated method stub
273 public int getResultSetType() throws SQLException {
274 // TODO Auto-generated method stub
279 public int getUpdateCount() throws SQLException {
280 // TODO Auto-generated method stub
285 public SQLWarning getWarnings() throws SQLException {
286 // TODO Auto-generated method stub
291 public boolean isClosed() throws SQLException {
292 // TODO Auto-generated method stub
297 public boolean isPoolable() throws SQLException {
298 // TODO Auto-generated method stub
303 public void setCursorName(String name) throws SQLException {
304 // TODO Auto-generated method stub
309 public void setEscapeProcessing(boolean enable) throws SQLException {
310 // TODO Auto-generated method stub
315 public void setFetchDirection(int direction) throws SQLException {
316 // TODO Auto-generated method stub
321 public void setFetchSize(int rows) throws SQLException {
322 // TODO Auto-generated method stub
327 public void setMaxFieldSize(int max) throws SQLException {
328 // TODO Auto-generated method stub
333 public void setMaxRows(int max) throws SQLException {
334 // TODO Auto-generated method stub
339 public void setPoolable(boolean poolable) throws SQLException {
340 // TODO Auto-generated method stub
345 public void setQueryTimeout(int seconds) throws SQLException {
346 // TODO Auto-generated method stub
351 public void closeOnCompletion() throws SQLException {
352 // TODO Auto-generated method stub
357 public boolean isCloseOnCompletion() throws SQLException {
358 // TODO Auto-generated method stub
363 public ResultSet executeQuery() throws SQLException {
364 return this.executeQuery(this.sql);
368 public int executeUpdate() throws SQLException {
369 // TODO Auto-generated method stub
374 public void setNull(int parameterIndex, int sqlType) throws SQLException {
375 // TODO Auto-generated method stub
380 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
381 // TODO Auto-generated method stub
386 public void setByte(int parameterIndex, byte x) throws SQLException {
387 // TODO Auto-generated method stub
392 public void setShort(int parameterIndex, short x) throws SQLException {
393 // TODO Auto-generated method stub
398 public void setInt(int parameterIndex, int x) throws SQLException {
399 // TODO Auto-generated method stub
404 public void setLong(int parameterIndex, long x) throws SQLException {
405 // TODO Auto-generated method stub
410 public void setFloat(int parameterIndex, float x) throws SQLException {
411 // TODO Auto-generated method stub
416 public void setDouble(int parameterIndex, double x) throws SQLException {
417 // TODO Auto-generated method stub
422 public void setBigDecimal(int parameterIndex, BigDecimal x)
423 throws SQLException {
424 // TODO Auto-generated method stub
429 public void setString(int parameterIndex, String x) throws SQLException {
430 // TODO Auto-generated method stub
435 public void setBytes(int parameterIndex, byte[] x) throws SQLException {
436 // TODO Auto-generated method stub
441 public void setDate(int parameterIndex, Date x) throws SQLException {
442 // TODO Auto-generated method stub
447 public void setTime(int parameterIndex, Time x) throws SQLException {
448 // TODO Auto-generated method stub
453 public void setTimestamp(int parameterIndex, Timestamp x)
454 throws SQLException {
455 // TODO Auto-generated method stub
460 public void setAsciiStream(int parameterIndex, InputStream x, int length)
461 throws SQLException {
462 // TODO Auto-generated method stub
467 public void setUnicodeStream(int parameterIndex, InputStream x, int length)
468 throws SQLException {
469 // TODO Auto-generated method stub
474 public void setBinaryStream(int parameterIndex, InputStream x, int length)
475 throws SQLException {
476 // TODO Auto-generated method stub
481 public void clearParameters() throws SQLException {
482 // TODO Auto-generated method stub
487 public void setObject(int parameterIndex, Object x, int targetSqlType)
488 throws SQLException {
489 // TODO Auto-generated method stub
494 public void setObject(int parameterIndex, Object x) throws SQLException {
495 // TODO Auto-generated method stub
499 public boolean execute() throws SQLException {
500 // TODO Auto-generated method stub
505 public void addBatch() throws SQLException {
506 // TODO Auto-generated method stub
511 public void setCharacterStream(int parameterIndex, Reader reader, int length)
512 throws SQLException {
513 // TODO Auto-generated method stub
518 public void setRef(int parameterIndex, Ref x) throws SQLException {
519 // TODO Auto-generated method stub
524 public void setBlob(int parameterIndex, Blob x) throws SQLException {
525 // TODO Auto-generated method stub
530 public void setClob(int parameterIndex, Clob x) throws SQLException {
531 // TODO Auto-generated method stub
536 public void setArray(int parameterIndex, Array x) throws SQLException {
537 // TODO Auto-generated method stub
542 public ResultSetMetaData getMetaData() throws SQLException {
543 // TODO Auto-generated method stub
548 public void setDate(int parameterIndex, Date x, Calendar cal)
549 throws SQLException {
550 // TODO Auto-generated method stub
555 public void setTime(int parameterIndex, Time x, Calendar cal)
556 throws SQLException {
557 // TODO Auto-generated method stub
562 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
563 throws SQLException {
564 // TODO Auto-generated method stub
569 public void setNull(int parameterIndex, int sqlType, String typeName)
570 throws SQLException {
571 // TODO Auto-generated method stub
576 public void setURL(int parameterIndex, URL x) throws SQLException {
577 // TODO Auto-generated method stub
582 public ParameterMetaData getParameterMetaData() throws SQLException {
583 // TODO Auto-generated method stub
588 public void setRowId(int parameterIndex, RowId x) throws SQLException {
589 // TODO Auto-generated method stub
594 public void setNString(int parameterIndex, String value)
595 throws SQLException {
596 // TODO Auto-generated method stub
601 public void setNCharacterStream(int parameterIndex, Reader value,
602 long length) throws SQLException {
603 // TODO Auto-generated method stub
608 public void setNClob(int parameterIndex, NClob value) throws SQLException {
609 // TODO Auto-generated method stub
614 public void setClob(int parameterIndex, Reader reader, long length)
615 throws SQLException {
616 // TODO Auto-generated method stub
621 public void setBlob(int parameterIndex, InputStream inputStream, long length)
622 throws SQLException {
623 // TODO Auto-generated method stub
628 public void setNClob(int parameterIndex, Reader reader, long length)
629 throws SQLException {
630 // TODO Auto-generated method stub
635 public void setSQLXML(int parameterIndex, SQLXML xmlObject)
636 throws SQLException {
637 // TODO Auto-generated method stub
642 public void setObject(int parameterIndex, Object x, int targetSqlType,
643 int scaleOrLength) throws SQLException {
644 // TODO Auto-generated method stub
649 public void setAsciiStream(int parameterIndex, InputStream x, long length)
650 throws SQLException {
651 // TODO Auto-generated method stub
656 public void setBinaryStream(int parameterIndex, InputStream x, long length)
657 throws SQLException {
658 // TODO Auto-generated method stub
663 public void setCharacterStream(int parameterIndex, Reader reader,
664 long length) throws SQLException {
665 // TODO Auto-generated method stub
670 public void setAsciiStream(int parameterIndex, InputStream x)
671 throws SQLException {
672 // TODO Auto-generated method stub
677 public void setBinaryStream(int parameterIndex, InputStream x)
678 throws SQLException {
679 // TODO Auto-generated method stub
684 public void setCharacterStream(int parameterIndex, Reader reader)
685 throws SQLException {
686 // TODO Auto-generated method stub
691 public void setNCharacterStream(int parameterIndex, Reader value)
692 throws SQLException {
693 // TODO Auto-generated method stub
698 public void setClob(int parameterIndex, Reader reader) throws SQLException {
699 // TODO Auto-generated method stub
704 public void setBlob(int parameterIndex, InputStream inputStream)
705 throws SQLException {
706 // TODO Auto-generated method stub
711 public void setNClob(int parameterIndex, Reader reader) throws SQLException {
712 // TODO Auto-generated method stub