Introduction of XSQL
[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.sql.Connection;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
6 import java.sql.SQLWarning;
7 import java.sql.Statement;
8 import java.util.ArrayList;
9 import java.util.Map;
10 import java.util.concurrent.ConcurrentHashMap;
11
12 public class JDBCStatement implements Statement {
13     private JDBCResultSet rs = null;
14     private transient JDBCConnection connection = null;
15     private static Map<Integer, JDBCResultSet> queries =
16         new ConcurrentHashMap<Integer, JDBCResultSet>();
17
18     public JDBCStatement(JDBCConnection con) {
19         this.connection = con;
20     }
21
22     public JDBCStatement() {
23
24     }
25
26     public static JDBCResultSet getQuery(int id) {
27         return queries.get(id);
28     }
29
30     public static JDBCResultSet removeQuery(int id) {
31         return queries.remove(id);
32     }
33
34     @Override
35     public java.sql.ResultSet executeQuery(String _sql) throws SQLException {
36         rs = new JDBCResultSet(_sql);
37         queries.put(rs.getID(), rs);
38         synchronized (rs) {
39             this.connection
40                 .send(new JDBCCommand(rs, JDBCCommand.TYPE_EXECUTE_QUERY));
41             try {
42                 rs.wait();
43             } catch (Exception err) {
44             }
45             if (rs.getError() != null) {
46                 throw ((SQLException) rs.getError());
47             }
48         }
49         return rs;
50     }
51
52     @Override
53     public boolean execute(String _sql) throws SQLException {
54         return true;
55     }
56
57     public void addRecord(ArrayList hierarchy) {
58         rs.addRecord(hierarchy);
59     }
60
61     public int size() {
62         return rs.size();
63     }
64
65     public void setFinished(boolean b) {
66         this.rs.setFinished(b);
67     }
68
69     public JDBCResultSet getRS() {
70         return this.rs;
71     }
72
73     public ResultSet getResultSet() {
74         return this.rs;
75     }
76
77     @Override
78     public boolean isWrapperFor(Class<?> arg0) throws SQLException {
79         // TODO Auto-generated method stub
80         return false;
81     }
82
83     @Override
84     public <T> T unwrap(Class<T> arg0) throws SQLException {
85         // TODO Auto-generated method stub
86         return null;
87     }
88
89     @Override
90     public void addBatch(String sql) throws SQLException {
91         // TODO Auto-generated method stub
92
93     }
94
95     @Override
96     public void cancel() throws SQLException {
97         // TODO Auto-generated method stub
98
99     }
100
101     @Override
102     public void clearBatch() throws SQLException {
103         // TODO Auto-generated method stub
104
105     }
106
107     @Override
108     public void clearWarnings() throws SQLException {
109         // TODO Auto-generated method stub
110
111     }
112
113     @Override
114     public void close() throws SQLException {
115         // TODO Auto-generated method stub
116
117     }
118
119     @Override
120     public boolean execute(String sql, int autoGeneratedKeys)
121         throws SQLException {
122         // TODO Auto-generated method stub
123         return false;
124     }
125
126     @Override
127     public boolean execute(String sql, int[] columnIndexes)
128         throws SQLException {
129         // TODO Auto-generated method stub
130         return false;
131     }
132
133     @Override
134     public boolean execute(String sql, String[] columnNames)
135         throws SQLException {
136         // TODO Auto-generated method stub
137         return false;
138     }
139
140     @Override
141     public int[] executeBatch() throws SQLException {
142         // TODO Auto-generated method stub
143         return null;
144     }
145
146     @Override
147     public int executeUpdate(String sql, int autoGeneratedKeys)
148         throws SQLException {
149         // TODO Auto-generated method stub
150         return 0;
151     }
152
153     @Override
154     public int executeUpdate(String sql, int[] columnIndexes)
155         throws SQLException {
156         // TODO Auto-generated method stub
157         return 0;
158     }
159
160     @Override
161     public int executeUpdate(String sql, String[] columnNames)
162         throws SQLException {
163         // TODO Auto-generated method stub
164         return 0;
165     }
166
167     @Override
168     public int executeUpdate(String sql) throws SQLException {
169         // TODO Auto-generated method stub
170         return 0;
171     }
172
173     @Override
174     public Connection getConnection() throws SQLException {
175         // TODO Auto-generated method stub
176         return null;
177     }
178
179     @Override
180     public int getFetchDirection() throws SQLException {
181         // TODO Auto-generated method stub
182         return 0;
183     }
184
185     @Override
186     public int getFetchSize() throws SQLException {
187         // TODO Auto-generated method stub
188         return 0;
189     }
190
191     @Override
192     public java.sql.ResultSet getGeneratedKeys() throws SQLException {
193         // TODO Auto-generated method stub
194         return null;
195     }
196
197     @Override
198     public int getMaxFieldSize() throws SQLException {
199         // TODO Auto-generated method stub
200         return 0;
201     }
202
203     @Override
204     public int getMaxRows() throws SQLException {
205         // TODO Auto-generated method stub
206         return 0;
207     }
208
209     @Override
210     public boolean getMoreResults() throws SQLException {
211         // TODO Auto-generated method stub
212         return false;
213     }
214
215     @Override
216     public boolean getMoreResults(int current) throws SQLException {
217         // TODO Auto-generated method stub
218         return false;
219     }
220
221     @Override
222     public int getQueryTimeout() throws SQLException {
223         // TODO Auto-generated method stub
224         return 0;
225     }
226
227     @Override
228     public int getResultSetConcurrency() throws SQLException {
229         // TODO Auto-generated method stub
230         return 0;
231     }
232
233     @Override
234     public int getResultSetHoldability() throws SQLException {
235         // TODO Auto-generated method stub
236         return 0;
237     }
238
239     @Override
240     public int getResultSetType() throws SQLException {
241         // TODO Auto-generated method stub
242         return 0;
243     }
244
245     @Override
246     public int getUpdateCount() throws SQLException {
247         // TODO Auto-generated method stub
248         return 0;
249     }
250
251     @Override
252     public SQLWarning getWarnings() throws SQLException {
253         // TODO Auto-generated method stub
254         return null;
255     }
256
257     @Override
258     public boolean isClosed() throws SQLException {
259         // TODO Auto-generated method stub
260         return false;
261     }
262
263     @Override
264     public boolean isPoolable() throws SQLException {
265         // TODO Auto-generated method stub
266         return false;
267     }
268
269     @Override
270     public void setCursorName(String name) throws SQLException {
271         // TODO Auto-generated method stub
272
273     }
274
275     @Override
276     public void setEscapeProcessing(boolean enable) throws SQLException {
277         // TODO Auto-generated method stub
278
279     }
280
281     @Override
282     public void setFetchDirection(int direction) throws SQLException {
283         // TODO Auto-generated method stub
284
285     }
286
287     @Override
288     public void setFetchSize(int rows) throws SQLException {
289         // TODO Auto-generated method stub
290
291     }
292
293     @Override
294     public void setMaxFieldSize(int max) throws SQLException {
295         // TODO Auto-generated method stub
296
297     }
298
299     @Override
300     public void setMaxRows(int max) throws SQLException {
301         // TODO Auto-generated method stub
302
303     }
304
305     @Override
306     public void setPoolable(boolean poolable) throws SQLException {
307         // TODO Auto-generated method stub
308
309     }
310
311     @Override
312     public void setQueryTimeout(int seconds) throws SQLException {
313         // TODO Auto-generated method stub
314
315     }
316
317     @Override
318     public void closeOnCompletion() throws SQLException {
319         // TODO Auto-generated method stub
320
321     }
322
323     @Override
324     public boolean isCloseOnCompletion() throws SQLException {
325         // TODO Auto-generated method stub
326         return false;
327     }
328
329
330 }