MutableCompositeModification compositeModification = new MutableCompositeModification();
compositeModification.addModification(new WriteModification(TestModel.TEST_PATH,
ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext()));
-
- assertNotEquals(compositeModification.toSerializable(), compositeModification.toSerializable());
-
+ Object one = compositeModification.toSerializable();
+ try{Thread.sleep(10);}catch(Exception err){}
+ Object two = compositeModification.toSerializable();
+ assertNotEquals(one,two);
}
}
-package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
+package org.odl.xsql;
import java.sql.Connection;
import java.sql.Driver;
import java.util.Properties;
import java.util.logging.Logger;
+import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCConnection;
+
public class JDBCDriver implements Driver {
public static JDBCDriver drv = new JDBCDriver();
if (url.equals("svr")) {
return new JDBCConnection(true);
} else {
- return new JDBCConnection(url);
+ return new JDBCConnection(url).getProxy();
}
} catch (Exception err) {
err.printStackTrace();
}
+ System.err.println("Error JDBC Connection");
return null;
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
throws SQLException {
- DriverPropertyInfo i = new DriverPropertyInfo("NQL", "NQL");
+ DriverPropertyInfo i = new DriverPropertyInfo("OpenDayLight", "OpenDayLight");
return new DriverPropertyInfo[] {i};
}
}
+ public void loadBluePrint(){
+ try{
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream("BluePrintCache.dat");
+ if(in!=null){
+ this.bluePrint = XSQLBluePrint.load(in);
+ }
+ in.close();
+ }catch(Exception err){
+ err.printStackTrace();
+ }
+ }
+
public static XSQLAdapter getInstance() {
return a;
}
}
public void execute(JDBCResultSet rs) {
+ if(this.domDataBroker==null){
+ rs.setFinished(true);
+ return;
+ }
List<XSQLBluePrintNode> tables = rs.getTables();
List<Object> roots = collectModuleRoots(tables.get(0),LogicalDatastoreType.OPERATIONAL);
roots.addAll(collectModuleRoots(tables.get(0),LogicalDatastoreType.CONFIGURATION));
sout.close();
} catch (Exception err) {
}
+ } else if (input.equals("save")) {
+ XSQLBluePrint.save(this.bluePrint);
} else if (input.equals("tocsv")) {
toCsv = !toCsv;
sout.println("to csv file is " + toCsv);
package org.opendaylight.controller.md.sal.dom.xsql;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.Map;
import java.util.Set;
-public class XSQLBluePrint implements DatabaseMetaData {
+public class XSQLBluePrint implements DatabaseMetaData, Serializable {
- public static final String CACHE_FILE_NAME = "BluePrintCache.dat";
+ private static final long serialVersionUID = 1L;
+
+ public static final String CACHE_FILE_NAME = "./BluePrintCache.dat";
private Map<String, XSQLBluePrintNode> tableNameToBluePrint = new HashMap<String, XSQLBluePrintNode>();
- private Map<String, Map<String,XSQLBluePrintNode>> odlNameToBluePrint = new HashMap<String, Map<String,XSQLBluePrintNode>>();
+ private Map<String, Map<String, XSQLBluePrintNode>> odlNameToBluePrint = new HashMap<String, Map<String, XSQLBluePrintNode>>();
private boolean cacheLoadedSuccessfuly = false;
private DatabaseMetaData myProxy = null;
public static final String replaceAll(String source, String toReplace,
- String withThis) {
+ String withThis) {
int index = source.indexOf(toReplace);
int index2 = 0;
StringBuffer result = new StringBuffer();
public XSQLBluePrint() {
}
+ public static void save(XSQLBluePrint bp) {
+ ObjectOutputStream out = null;
+ try {
+ out = new ObjectOutputStream(new DataOutputStream(
+ new FileOutputStream(CACHE_FILE_NAME)));
+ out.writeObject(bp);
+ } catch (Exception err) {
+ err.printStackTrace();
+ } finally {
+ try {
+ out.close();
+ } catch (Exception err) {
+ }
+ }
+ }
+
+ public static XSQLBluePrint load(InputStream ins) {
+ ObjectInputStream in = null;
+ try {
+ in = new ObjectInputStream(new DataInputStream(ins));
+ return (XSQLBluePrint) in.readObject();
+ } catch (Exception err) {
+ err.printStackTrace();
+ } finally {
+ try {
+ in.close();
+ } catch (Exception err) {
+ }
+ }
+ return null;
+ }
+
private class NQLBluePrintProxy implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ throws Throwable {
System.out.println("Method " + method);
return method.invoke(XSQLBluePrint.this, args);
}
public DatabaseMetaData getProxy() {
if (myProxy == null) {
try {
- myProxy = (DatabaseMetaData) Proxy
- .newProxyInstance(getClass().getClassLoader(),
- new Class[] {DatabaseMetaData.class},
+ myProxy = (DatabaseMetaData) Proxy.newProxyInstance(getClass()
+ .getClassLoader(),
+ new Class[] { DatabaseMetaData.class },
new NQLBluePrintProxy());
} catch (Exception err) {
err.printStackTrace();
return myProxy;
}
- /*
- public void loadBluePrintCache(String hostName) {
- try {
- ObjectInputStream in = new ObjectInputStream(
- new FileInputStream(hostName + "-" + CACHE_FILE_NAME));
- cache = (Map) in.readObject();
- in.close();
- cacheLoadedSuccessfuly = true;
- } catch (Exception err) {
- //err.printStackTrace();
- }
- }*/
-
- public XSQLBluePrintNode[] getBluePrintNodeByODLTableName(String odlTableName) {
- Map<String,XSQLBluePrintNode> map = this.odlNameToBluePrint.get(odlTableName);
- if(map==null) return null;
+ public XSQLBluePrintNode[] getBluePrintNodeByODLTableName(
+ String odlTableName) {
+ Map<String, XSQLBluePrintNode> map = this.odlNameToBluePrint
+ .get(odlTableName);
+ if (map == null)
+ return null;
return map.values().toArray(new XSQLBluePrintNode[map.size()]);
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().endsWith(tableName.toLowerCase())) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .endsWith(tableName.toLowerCase())) {
return n;
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().equals(tableName.toLowerCase())) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .equals(tableName.toLowerCase())) {
return n;
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().indexOf(tableName.toLowerCase())!= -1) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .indexOf(tableName.toLowerCase()) != -1) {
return n;
}
}
return null;
}
-
public boolean isCacheLoaded() {
return cacheLoadedSuccessfuly;
}
private static Map<Class, Set<Class>> superClassMap = new HashMap<Class, Set<Class>>();
public static Set<Class> getInheritance(Class myObjectClass,
- Class returnType) {
+ Class returnType) {
if (returnType != null && myObjectClass.equals(returnType)) {
return new HashSet<Class>();
public void addToBluePrintCache(XSQLBluePrintNode blNode) {
this.tableNameToBluePrint.put(blNode.getBluePrintNodeName(), blNode);
- Map<String,XSQLBluePrintNode> map = this.odlNameToBluePrint.get(blNode.getODLTableName());
- if(map==null){
- map = new HashMap<String,XSQLBluePrintNode>();
- this.odlNameToBluePrint.put(blNode.getODLTableName(),map);
+ Map<String, XSQLBluePrintNode> map = this.odlNameToBluePrint.get(blNode
+ .getODLTableName());
+ if (map == null) {
+ map = new HashMap<String, XSQLBluePrintNode>();
+ this.odlNameToBluePrint.put(blNode.getODLTableName(), map);
}
map.put(blNode.getBluePrintNodeName(), blNode);
}
@Override
public ResultSet getAttributes(String catalog, String schemaPattern,
- String typeNamePattern, String attributeNamePattern)
- throws SQLException {
+ String typeNamePattern, String attributeNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getBestRowIdentifier(String catalog, String schema,
- String table, int scope, boolean nullable) throws SQLException {
+ String table, int scope, boolean nullable) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getColumnPrivileges(String catalog, String schema,
- String table, String columnNamePattern) throws SQLException {
+ String table, String columnNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getColumns(String catalog, String schemaPattern,
- String tableNamePattern, String columnNamePattern)
- throws SQLException {
+ String tableNamePattern, String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getCrossReference(String parentCatalog,
- String parentSchema, String parentTable, String foreignCatalog,
- String foreignSchema, String foreignTable) throws SQLException {
+ String parentSchema, String parentTable, String foreignCatalog,
+ String foreignSchema, String foreignTable) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getDatabaseProductName() throws SQLException {
- return "VNE Query Language";
+ return "OpenDayLight";
}
@Override
}
@Override
- public ResultSet getExportedKeys(String catalog, String schema,
- String table)
- throws SQLException {
+ public ResultSet getExportedKeys(String catalog, String schema, String table)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getFunctionColumns(String catalog, String schemaPattern,
- String functionNamePattern, String columnNamePattern)
- throws SQLException {
+ String functionNamePattern, String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getFunctions(String catalog, String schemaPattern,
- String functionNamePattern) throws SQLException {
+ String functionNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public ResultSet getImportedKeys(String catalog, String schema,
- String table)
- throws SQLException {
+ public ResultSet getImportedKeys(String catalog, String schema, String table)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getIndexInfo(String catalog, String schema, String table,
- boolean unique, boolean approximate) throws SQLException {
+ boolean unique, boolean approximate) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String table)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getProcedureColumns(String catalog, String schemaPattern,
- String procedureNamePattern, String columnNamePattern)
- throws SQLException {
+ String procedureNamePattern, String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getProcedures(String catalog, String schemaPattern,
- String procedureNamePattern) throws SQLException {
+ String procedureNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getSchemas(String catalog, String schemaPattern)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getSuperTables(String catalog, String schemaPattern,
- String tableNamePattern) throws SQLException {
+ String tableNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getSuperTypes(String catalog, String schemaPattern,
- String typeNamePattern) throws SQLException {
+ String typeNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getTablePrivileges(String catalog, String schemaPattern,
- String tableNamePattern) throws SQLException {
+ String tableNamePattern) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getTables(String catalog, String schemaPattern,
- String tableNamePattern, String[] types) throws SQLException {
+ String tableNamePattern, String[] types) throws SQLException {
return new TablesResultSet(this);
}
@Override
public ResultSet getUDTs(String catalog, String schemaPattern,
- String typeNamePattern, int[] types) throws SQLException {
+ String typeNamePattern, int[] types) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultSet getVersionColumns(String catalog, String schema,
- String table) throws SQLException {
+ String table) throws SQLException {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public boolean supportsCatalogsInPrivilegeDefinitions()
- throws SQLException {
+ public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsConvert(int fromType, int toType)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions()
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsDataManipulationTransactionsOnly()
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
- public boolean supportsDifferentTableCorrelationNames()
- throws SQLException {
+ public boolean supportsDifferentTableCorrelationNames() throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsResultSetConcurrency(int type, int concurrency)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsResultSetHoldability(int holdability)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public boolean supportsStoredFunctionsUsingCallSyntax()
- throws SQLException {
+ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsTransactionIsolationLevel(int level)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public ResultSet getPseudoColumns(String catalog, String schemaPattern,
- String tableNamePattern, String columnNamePattern)
- throws SQLException {
+ String tableNamePattern, String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
public class XSQLBluePrintNode implements Serializable {
private static final long serialVersionUID = 1L;
private Class<?> myInterface = null;
private String myInterfaceString = null;
- private Set<XSQLBluePrintRelation> relations =
- new HashSet<XSQLBluePrintRelation>();
- private Set<XSQLBluePrintNode> inheritingNodes =
- new HashSet<XSQLBluePrintNode>();
+ private Set<XSQLBluePrintRelation> relations = new HashSet<XSQLBluePrintRelation>();
+ private Set<XSQLBluePrintNode> inheritingNodes = new HashSet<XSQLBluePrintNode>();
private Set<XSQLBluePrintNode> children = new HashSet<XSQLBluePrintNode>();
private XSQLBluePrintNode parent = null;
private transient Set<String> parentHierarchySet = null;
private String myInterfaceName = null;
private Set<XSQLColumn> columns = new HashSet<XSQLColumn>();
+ private Map<String, XSQLColumn> origNameToColumn = new HashMap<String, XSQLColumn>();
private transient Object odlNode = null;
private boolean module = false;
private String bluePrintTableName = null;
private String odlTableName = null;
+ private String origName = null;
+
+ public XSQLBluePrintNode(String name, String _origName, int _level) {
+ this.level = _level;
+ this.odlTableName = name;
+ this.bluePrintTableName = name;
+ this.origName = _origName;
+ }
public XSQLBluePrintNode(Class<?> _myInterface, int _level) {
this.myInterface = _myInterface;
this.level = _level;
}
- public XSQLBluePrintNode(Object _odlNode, int _level,XSQLBluePrintNode _parent) {
+ public XSQLBluePrintNode(Object _odlNode, int _level,
+ XSQLBluePrintNode _parent) {
this.odlNode = _odlNode;
this.level = _level;
this.module = XSQLODLUtils.isModule(_odlNode);
this.parent = _parent;
this.bluePrintTableName = XSQLODLUtils.getBluePrintName(_odlNode);
+ this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode);
+ }
+ public String getOrigName() {
+ return this.origName;
}
- public String getBluePrintNodeName(){
+ public String getBluePrintNodeName() {
return this.bluePrintTableName;
}
}
for (XSQLBluePrintRelation dtr : this.relations) {
XSQLBluePrintNode parent = dtr.getParent();
- if (!parent.getInterface().equals(this.getInterface()) && !parent
- .getInterface().isAssignableFrom(this.getInterface()) &&
- this.getInterface().isAssignableFrom(parent.getInterface())
- && parent.isModelChild(p)) {
+ if (!parent.getInterface().equals(this.getInterface())
+ && !parent.getInterface().isAssignableFrom(
+ this.getInterface())
+ && this.getInterface().isAssignableFrom(
+ parent.getInterface()) && parent.isModelChild(p)) {
return true;
}
}
}
public void addColumn(Object node, String tableName) {
- XSQLColumn c = new XSQLColumn(node,getBluePrintNodeName(), this);
+ XSQLColumn c = new XSQLColumn(node, getBluePrintNodeName(), this);
+ this.columns.add(c);
+ }
+
+ public XSQLColumn addColumn(String name, String tableName, String origName,
+ String origTableName) {
+ XSQLColumn c = new XSQLColumn(name, tableName, origName, origTableName);
this.columns.add(c);
+ this.origNameToColumn.put(origName, c);
+ return c;
}
public void addColumn(String methodName) {
throw new SQLException("Unknown field name '" + name + "'");
}
-
public void addParent(XSQLBluePrintNode parent, String property) {
try {
if (property.equals("ContainingTPs")) {
return;
}
- //Method m = parent.getInterface().getMethod("get"+property, null);
- //if(!m.getDeclaringClass().equals(parent.getInterface()))
- //return;
- XSQLBluePrintRelation rel =
- new XSQLBluePrintRelation(parent, property, myInterface);
+ // Method m = parent.getInterface().getMethod("get"+property, null);
+ // if(!m.getDeclaringClass().equals(parent.getInterface()))
+ // return;
+ XSQLBluePrintRelation rel = new XSQLBluePrintRelation(parent,
+ property, myInterface);
relations.add(rel);
} catch (Exception err) {
err.printStackTrace();
}
public Set<XSQLBluePrintRelation> getClonedParents() {
- Set<XSQLBluePrintRelation> result =
- new HashSet<XSQLBluePrintRelation>();
+ Set<XSQLBluePrintRelation> result = new HashSet<XSQLBluePrintRelation>();
result.addAll(this.relations);
return result;
}
if (odlNode != null) {
return getBluePrintNodeName();
}
+ if (odlTableName != null) {
+ return odlTableName;
+ }
return "Unknown";
}
XSQLBluePrintNode other = (XSQLBluePrintNode) obj;
if (odlNode != null) {
return getBluePrintNodeName().equals(other.getBluePrintNodeName());
- } else if (this.odlTableName != null) {
+ } else if (this.odlTableName == null && other.odlTableName != null)
+ return false;
+ if (this.odlTableName != null && other.odlTableName == null)
+ return false;
+ else
return this.odlTableName.equals(other.odlTableName);
- } else {
- return other.myInterface.equals(myInterface);
- }
}
@Override
private int charWidth = -1;
private Class type = null;
private transient Object bluePrintNode = null;
+ private String origName = null;
+ private String origTableName = null;
public XSQLColumn(Object odlNode, String _tableName, Object _bluePrintNode) {
this.name = XSQLODLUtils.getNodeNameFromDSN(odlNode);
this.type = XSQLODLUtils.getTypeForODLColumn(odlNode);
}
+ public XSQLColumn(String _name, String _tableName,String _origName, String _origTableName){
+ this.name = _name;
+ this.tableName = _tableName;
+ this.origName = _origName;
+ this.origTableName = _origTableName;
+ }
+
public String getName() {
return name;
}
import java.io.Serializable;
import java.util.Map;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
+
public class JDBCCommand implements Serializable {
public int type = 0;
public static final int TYPE_EXECUTE_QUERY = 1;
public static final int TYPE_QUERY_RECORD = 3;
public static final int TYPE_QUERY_FINISH = 4;
public static final int TYPE_QUERY_ERROR = 5;
+ public static final int TYPE_METADATA = 6;
+ public static final int TYPE_METADATA_REPLY = 7;
private JDBCResultSet rs = null;
private Map record = null;
private int rsID = -1;
private Exception err = null;
+ private XSQLBluePrint bluePrint = null;
+
+ public JDBCCommand() {
+
+ }
+
+ public void setType(int t) {
+ this.type = t;
+ }
public JDBCCommand(Exception _err, int _RSID) {
this.type = TYPE_QUERY_ERROR;
this.rsID = _RSID;
}
+ public JDBCCommand(XSQLBluePrint bl) {
+ this.type = TYPE_METADATA_REPLY;
+ this.bluePrint = bl;
+ }
+
public JDBCCommand(JDBCResultSet _rs, int _type) {
this.type = TYPE_EXECUTE_QUERY;
this.rs = _rs;
public Exception getERROR() {
return this.err;
}
+
+ public XSQLBluePrint getBluePrint() {
+ return this.bluePrint;
+ }
}
import java.util.concurrent.Executor;
import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
-public class JDBCConnection extends Thread implements Connection {
+public class JDBCConnection implements Connection, Runnable {
private Socket socket = null;
private DataInputStream in = null;
private DataOutputStream out = null;
private LinkedList<byte[]> queue = new LinkedList<byte[]>();
private XSQLAdapter adapter = null;
+ private XSQLBluePrint metaData = null;
+ private String addr = null;
+ private boolean wasClosed = false;
public JDBCConnection(Socket s, XSQLAdapter _a) {
this.socket = s;
this.adapter = _a;
try {
in = new DataInputStream(
- new BufferedInputStream(s.getInputStream()));
- out = new DataOutputStream(
- new BufferedOutputStream(s.getOutputStream()));
+ new BufferedInputStream(s.getInputStream()));
+ out = new DataOutputStream(new BufferedOutputStream(
+ s.getOutputStream()));
new JDBCObjectReader();
- this.start();
+ new Thread(this).start();
} catch (Exception err) {
err.printStackTrace();
}
}
- public JDBCConnection(String addr) throws Exception {
+ public Connection getProxy() {
+ return this;
+ /*
+ return (Connection) Proxy.newProxyInstance(this.getClass()
+ .getClassLoader(), new Class[] { Connection.class },
+ new JDBCProxy(this));
+ */
+ }
+
+ public JDBCConnection(String _addr) throws Exception {
+ this.addr = _addr;
+ init();
+ }
+
+ private void init() throws Exception {
+ if (addr.startsWith("http://"))
+ addr = addr.substring(7);
+ System.err.print("Address is:" + addr);
socket = new Socket(addr, 40004);
try {
- in = new DataInputStream(
- new BufferedInputStream(socket.getInputStream()));
- out = new DataOutputStream(
- new BufferedOutputStream(socket.getOutputStream()));
+ in = new DataInputStream(new BufferedInputStream(
+ socket.getInputStream()));
+ out = new DataOutputStream(new BufferedOutputStream(
+ socket.getOutputStream()));
new JDBCObjectReader();
- this.start();
+ new Thread(this).start();
} catch (Exception err) {
err.printStackTrace();
}
ServerSocket s = new ServerSocket(50003);
socket = s.accept();
try {
- in = new DataInputStream(
- new BufferedInputStream(socket.getInputStream()));
- out = new DataOutputStream(
- new BufferedOutputStream(socket.getOutputStream()));
+ in = new DataInputStream(new BufferedInputStream(
+ socket.getInputStream()));
+ out = new DataOutputStream(new BufferedOutputStream(
+ socket.getOutputStream()));
new JDBCObjectReader();
- this.start();
+ new Thread(this).start();
} catch (Exception err) {
err.printStackTrace();
}
}
}
-
private boolean isStopped() {
if (adapter != null && adapter.stopped) {
return true;
} catch (Exception err) {
System.out.println("Connection Lost or Closed.");
+ try {
+ out.close();
+ } catch (Exception er) {
+ }
+ out = null;
+ try {
+ in.close();
+ } catch (Exception er) {
+ }
+ in = null;
try {
socket.close();
} catch (Exception err2) {
}
- //err.printStackTrace();
+ socket = null;
}
}
}
public void processCommand(JDBCCommand cmd) {
switch (cmd.getType()) {
- case JDBCCommand.TYPE_EXECUTE_QUERY:
- try {
- JDBCServer.execute(cmd.getRS(), adapter);
- send(new JDBCCommand(cmd.getRS(),
- JDBCCommand.TYPE_QUERY_REPLY));
- QueryUpdater u = new QueryUpdater(cmd.getRS());
- new Thread(u).start();
- } catch (Exception err) {
- send(new JDBCCommand(err, cmd.getRSID()));
- }
- break;
- case JDBCCommand.TYPE_QUERY_REPLY:
- JDBCResultSet rs1 = JDBCStatement.getQuery(cmd.getRS().getID());
- rs1.updateData(cmd.getRS());
- break;
- case JDBCCommand.TYPE_QUERY_RECORD:
- JDBCResultSet rs2 = JDBCStatement.getQuery(cmd.getRSID());
- rs2.addRecord(cmd.getRecord());
- break;
- case JDBCCommand.TYPE_QUERY_FINISH:
- JDBCResultSet rs3 = JDBCStatement.removeQuery(cmd.getRSID());
- rs3.setFinished(true);
- break;
- case JDBCCommand.TYPE_QUERY_ERROR:
- System.err.println("ERROR Executing Query\n");
- cmd.getERROR().printStackTrace();
- JDBCResultSet rs4 = JDBCStatement.removeQuery(cmd.getRSID());
- rs4.setError(cmd.getERROR());
- rs4.setFinished(true);
- synchronized (rs4) {
- rs4.notifyAll();
- }
+ case JDBCCommand.TYPE_METADATA_REPLY:
+ this.metaData = cmd.getBluePrint();
+ synchronized (this) {
+ this.notifyAll();
+ }
+ break;
+ case JDBCCommand.TYPE_METADATA:
+ send(new JDBCCommand(this.adapter.getBluePrint()));
+ break;
+ case JDBCCommand.TYPE_EXECUTE_QUERY:
+ try {
+ JDBCServer.execute(cmd.getRS(), adapter);
+ send(new JDBCCommand(cmd.getRS(), JDBCCommand.TYPE_QUERY_REPLY));
+ QueryUpdater u = new QueryUpdater(cmd.getRS());
+ new Thread(u).start();
+ } catch (Exception err) {
+ send(new JDBCCommand(err, cmd.getRSID()));
+ }
+ break;
+ case JDBCCommand.TYPE_QUERY_REPLY:
+ JDBCResultSet rs1 = JDBCStatement.getQuery(cmd.getRS().getID());
+ rs1.updateData(cmd.getRS());
+ break;
+ case JDBCCommand.TYPE_QUERY_RECORD:
+ JDBCResultSet rs2 = JDBCStatement.getQuery(cmd.getRSID());
+ rs2.addRecord(cmd.getRecord());
+ break;
+ case JDBCCommand.TYPE_QUERY_FINISH:
+ JDBCResultSet rs3 = JDBCStatement.removeQuery(cmd.getRSID());
+ rs3.setFinished(true);
+ break;
+ case JDBCCommand.TYPE_QUERY_ERROR:
+ System.err.println("ERROR Executing Query\n");
+ cmd.getERROR().printStackTrace();
+ JDBCResultSet rs4 = JDBCStatement.removeQuery(cmd.getRSID());
+ rs4.setError(cmd.getERROR());
+ rs4.setFinished(true);
+ synchronized (rs4) {
+ rs4.notifyAll();
+ }
}
}
}
public void send(Object o) {
+
+ if (this.socket == null) {
+ try {
+ init();
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
@Override
public void close() throws SQLException {
+ wasClosed = true;
try {
socket.close();
} catch (Exception err) {
@Override
public Array createArrayOf(String typeName, Object[] elements)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public Statement createStatement() throws SQLException {
- return new JDBCStatement(this);
+ return new JDBCStatement(this).getProxy();
}
@Override
public Statement createStatement(int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return new JDBCStatement(this).getProxy();
}
@Override
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ public Statement createStatement(int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return new JDBCStatement(this).getProxy();
}
@Override
public Struct createStruct(String typeName, Object[] attributes)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ if (this.metaData == null) {
+ JDBCCommand cmd = new JDBCCommand();
+ cmd.setType(JDBCCommand.TYPE_METADATA);
+ synchronized (this) {
+ send(cmd);
+ try {
+ this.wait();
+ } catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+ }
+ return metaData;
}
@Override
@Override
public boolean isClosed() throws SQLException {
- // TODO Auto-generated method stub
return false;
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
+ int resultSetConcurrency) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ System.err.println("SQL 1=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ int resultSetConcurrency) throws SQLException {
+ System.err.println("SQL 2=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ throws SQLException {
+ System.err.println("SQL 3=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ throws SQLException {
+ System.err.println("SQL 4=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ throws SQLException {
+ System.err.println("SQL 5=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ System.err.println("SQL 6=" + sql);
+ return new JDBCStatement(this, sql).getProxy();
}
@Override
@Override
public void setClientInfo(Properties properties)
- throws SQLClientInfoException {
+ throws SQLClientInfoException {
// TODO Auto-generated method stub
}
@Override
public void setClientInfo(String name, String value)
- throws SQLClientInfoException {
+ throws SQLClientInfoException {
// TODO Auto-generated method stub
}
@Override
public void setNetworkTimeout(Executor executor, int milliseconds)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
// TODO Auto-generated method stub
return 0;
}
-}
+}
--- /dev/null
+package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class JDBCProxy implements InvocationHandler {
+
+ private Object myObject = null;
+ private Class<?> myObjectClass = null;
+
+ public JDBCProxy(Object obj) {
+ this.myObject = obj;
+ this.myObjectClass = this.myObject.getClass();
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ System.err.println("Class " + this.myObjectClass.getSimpleName()
+ + " Method " + method.getName());
+ return method.invoke(this.myObject, args);
+ }
+
+}
import java.io.Reader;
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import org.opendaylight.controller.md.sal.dom.xsql.XSQLCriteria;
import org.opendaylight.controller.md.sal.dom.xsql.XSQLODLUtils;
-public class JDBCResultSet
- implements Serializable, ResultSet, ResultSetMetaData {
+public class JDBCResultSet implements Serializable, ResultSet,
+ ResultSetMetaData {
private static final long serialVersionUID = -7450200738431047057L;
private String sql = null;
- private List<XSQLBluePrintNode> tablesInQuery =
- new ArrayList<XSQLBluePrintNode>();
- private Map<String, XSQLBluePrintNode> tablesInQueryMap =
- new ConcurrentHashMap<String, XSQLBluePrintNode>();
+ private List<XSQLBluePrintNode> tablesInQuery = new ArrayList<XSQLBluePrintNode>();
+ private Map<String, XSQLBluePrintNode> tablesInQueryMap = new ConcurrentHashMap<String, XSQLBluePrintNode>();
private List<XSQLColumn> fieldsInQuery = new ArrayList<XSQLColumn>();
private transient LinkedList<Map> records = new LinkedList<Map>();
private transient Map currentRecord = null;
private int id = 0;
private static Integer nextID = new Integer(0);
public int numberOfTasks = 0;
- private Map<String, Map<XSQLColumn, List<XSQLCriteria>>> criteria =
- new ConcurrentHashMap<String, Map<XSQLColumn, List<XSQLCriteria>>>();
+ private Map<String, Map<XSQLColumn, List<XSQLCriteria>>> criteria = new ConcurrentHashMap<String, Map<XSQLColumn, List<XSQLCriteria>>>();
private Exception err = null;
private List<Record> EMPTY_RESULT = new LinkedList<Record>();
+ private transient Map<String,JDBCResultSet> subQueries = new HashMap<String,JDBCResultSet>();
+
+ public ResultSet getProxy() {
+ return (ResultSet) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {ResultSet.class }, new JDBCProxy(this));
+ }
+
+ public void setSQL(String _sql) {
+ this.sql = _sql;
+ }
+
+ public JDBCResultSet addSubQuery(String _sql,String logicalName) {
+ if(subQueries == null)
+ subQueries = new HashMap<String,JDBCResultSet>();
+ JDBCResultSet rs = new JDBCResultSet(_sql);
+ this.subQueries.put(logicalName,rs);
+ return rs;
+ }
+
+ public Map<String,JDBCResultSet> getSubQueries() {
+ if(this.subQueries==null)
+ this.subQueries = new HashMap<>();
+ return this.subQueries;
+ }
public JDBCResultSet(String _sql) {
synchronized (JDBCResultSet.class) {
}
public int isObjectFitCriteria(Map objValues, String tableName) {
- Map<XSQLColumn, List<XSQLCriteria>> tblCriteria = criteria.get(tableName);
+ Map<XSQLColumn, List<XSQLCriteria>> tblCriteria = criteria
+ .get(tableName);
if (tblCriteria == null) {
return 1;
}
for (Map.Entry<XSQLColumn, List<XSQLCriteria>> cc : tblCriteria
- .entrySet()) {
+ .entrySet()) {
for (XSQLCriteria c : cc.getValue()) {
Object value = objValues.get(cc.getKey().toString());
int result = c.checkValue(value);
}
public int isObjectFitCriteria(Object element, Class cls) {
- Map<XSQLColumn, List<XSQLCriteria>> tblCriteria =
- criteria.get(cls.getName());
+ Map<XSQLColumn, List<XSQLCriteria>> tblCriteria = criteria.get(cls
+ .getName());
if (tblCriteria == null) {
return 1;
}
for (Map.Entry<XSQLColumn, List<XSQLCriteria>> cc : tblCriteria
- .entrySet()) {
+ .entrySet()) {
for (XSQLCriteria c : cc.getValue()) {
- int result =
- c.isObjectFitCriteria(element, cc.getKey().getName());
+ int result = c.isObjectFitCriteria(element, cc.getKey()
+ .getName());
if (result == 0) {
return 0;
}
}
}
-
public void addRecord(ArrayList hierarchy) {
Map rec = new HashMap();
for (int i = hierarchy.size() - 1; i >= 0; i--) {
Object element = hierarchy.get(i);
for (XSQLColumn c : fieldsInQuery) {
- if (c.getTableName()
- .equals(element.getClass().getSimpleName())) {
+ if (c.getTableName().equals(element.getClass().getSimpleName())) {
try {
- Method m = element.getClass().getMethod(c.getName(), null);
+ Method m = element.getClass().getMethod(c.getName(),
+ null);
Object value = m.invoke(element, null);
rec.put(c.getName(), value);
} catch (Exception err) {
Map subChildren = XSQLODLUtils.getChildren(node);
Map result = new HashMap();
for (Object stc : subChildren.values()) {
- if (stc.getClass().getName()
- .endsWith("ImmutableAugmentationNode")) {
+ if (stc.getClass().getName().endsWith("ImmutableAugmentationNode")) {
Map values = XSQLODLUtils.getChildren(stc);
for (Object key : values.keySet()) {
Object val = values.get(key);
- if (val.getClass().getName()
- .endsWith("ImmutableLeafNode")) {
+ if (val.getClass().getName().endsWith("ImmutableLeafNode")) {
Object value = XSQLODLUtils.getValue(val);
String k = XSQLODLUtils.getNodeName(val);
if (value != null) {
result.put(bpn.getBluePrintNodeName() + "." + k,
- value.toString());
+ value.toString());
}
}
}
String k = XSQLODLUtils.getNodeName(stc);
Object value = XSQLODLUtils.getValue(stc);
if (value != null) {
- result.put(bpn.getBluePrintNodeName() + "." + k, value.toString());
+ result.put(bpn.getBluePrintNodeName() + "." + k,
+ value.toString());
}
}
}
return result;
}
- private void addToData(Record rec, XSQLBluePrintNode bpn, XSQLBluePrint bluePrint, Map fullRecord) {
- XSQLBluePrintNode eNodes[] = bluePrint.getBluePrintNodeByODLTableName(XSQLODLUtils.getNodeIdentiofier(rec.element));
+ private void addToData(Record rec, XSQLBluePrintNode bpn,
+ XSQLBluePrint bluePrint, Map fullRecord) {
+ XSQLBluePrintNode eNodes[] = bluePrint
+ .getBluePrintNodeByODLTableName(XSQLODLUtils
+ .getNodeIdentiofier(rec.element));
if (bpn != null) {
for (XSQLColumn c : fieldsInQuery) {
- for(XSQLBluePrintNode eNode:eNodes){
- if (((XSQLBluePrintNode) c.getBluePrintNode()).getBluePrintNodeName().equals(eNode.getBluePrintNodeName())) {
- //Object value = Criteria.getValue(rec.element, c.getName());
+ for (XSQLBluePrintNode eNode : eNodes) {
+ if (((XSQLBluePrintNode) c.getBluePrintNode())
+ .getBluePrintNodeName().equals(
+ eNode.getBluePrintNodeName())) {
+ // Object value = Criteria.getValue(rec.element,
+ // c.getName());
String columnName = c.toString();
Object value = fullRecord.get(columnName);
if (value != null) {
return false;
}
- public List<Object> getChildren(Object node, String tableName,XSQLBluePrint bluePrint) {
+ public List<Object> getChildren(Object node, String tableName,
+ XSQLBluePrint bluePrint) {
List<Object> children = XSQLODLUtils.getMChildren(node);
List<Object> result = new LinkedList<Object>();
for (Object child : children) {
String odlNodeName = XSQLODLUtils.getNodeIdentiofier(child);
- if(odlNodeName==null) continue;
+ if (odlNodeName == null)
+ continue;
- XSQLBluePrintNode eNodes[] = bluePrint.getBluePrintNodeByODLTableName(odlNodeName);
- if(eNodes==null) continue;
+ XSQLBluePrintNode eNodes[] = bluePrint
+ .getBluePrintNodeByODLTableName(odlNodeName);
+ if (eNodes == null)
+ continue;
boolean match = false;
- for(XSQLBluePrintNode enode:eNodes){
- if(tableName.startsWith(enode.toString())){
+ for (XSQLBluePrintNode enode : eNodes) {
+ if (tableName.startsWith(enode.toString())) {
match = true;
break;
}
}
- if(!match) continue;
+ if (!match)
+ continue;
if (child.getClass().getName().endsWith("ImmutableContainerNode")) {
result.add(child);
- }else
- if (child.getClass().getName().endsWith("ImmutableAugmentationNode")) {
+ } else if (child.getClass().getName()
+ .endsWith("ImmutableAugmentationNode")) {
List<Object> _children = XSQLODLUtils.getMChildren(child);
for (Object c : _children) {
- if (c.getClass().getName().endsWith("ImmutableContainerNode")) {
+ if (c.getClass().getName()
+ .endsWith("ImmutableContainerNode")) {
result.add(c);
}
}
return result;
}
- public List<Record> addRecords(Object element, XSQLBluePrintNode node,boolean root, String tableName,XSQLBluePrint bluePrint) {
+ public List<Record> addRecords(Object element, XSQLBluePrintNode node,
+ boolean root, String tableName, XSQLBluePrint bluePrint) {
List<Record> result = new LinkedList<Record>();
String nodeID = XSQLODLUtils.getNodeIdentiofier(element);
if (node.getODLTableName().equals(nodeID)) {
- XSQLBluePrintNode bluePrintNode = bluePrint.getBluePrintNodeByODLTableName(nodeID)[0];
+ XSQLBluePrintNode bluePrintNode = bluePrint
+ .getBluePrintNodeByODLTableName(nodeID)[0];
Record rec = new Record();
rec.element = element;
- XSQLBluePrintNode bpn = this.tablesInQueryMap.get(bluePrintNode.getBluePrintNodeName());
- if (this.criteria.containsKey(bluePrintNode.getBluePrintNodeName()) || bpn != null) {
+ XSQLBluePrintNode bpn = this.tablesInQueryMap.get(bluePrintNode
+ .getBluePrintNodeName());
+ if (this.criteria.containsKey(bluePrintNode.getBluePrintNodeName())
+ || bpn != null) {
Map<?, ?> allKeyValues = collectColumnValues(element, bpn);
- if (!(isObjectFitCriteria(allKeyValues, bpn.getBluePrintNodeName()) == 1)) {
+ if (!(isObjectFitCriteria(allKeyValues,
+ bpn.getBluePrintNodeName()) == 1)) {
return EMPTY_RESULT;
}
- addToData(rec, bpn, bluePrint,allKeyValues);
+ addToData(rec, bpn, bluePrint, allKeyValues);
}
if (root) {
addRecord(rec.data);
}
XSQLBluePrintNode parent = node.getParent();
- List<Record> subRecords = addRecords(element, parent, false, tableName,bluePrint);
+ List<Record> subRecords = addRecords(element, parent, false, tableName,
+ bluePrint);
for (Record subRec : subRecords) {
- List<Object> subO = getChildren(subRec.element, tableName,bluePrint);
+ List<Object> subO = getChildren(subRec.element, tableName,
+ bluePrint);
if (subO != null) {
for (Object subData : subO) {
Record rec = new Record();
rec.data.putAll(subRec.data);
String recID = XSQLODLUtils.getNodeIdentiofier(rec.element);
- XSQLBluePrintNode eNodes[] = bluePrint.getBluePrintNodeByODLTableName(recID);
+ XSQLBluePrintNode eNodes[] = bluePrint
+ .getBluePrintNodeByODLTableName(recID);
XSQLBluePrintNode bpn = null;
- for(XSQLBluePrintNode eNode:eNodes){
- bpn = this.tablesInQueryMap.get(eNode.getBluePrintNodeName());
- if(bpn!=null)
+ for (XSQLBluePrintNode eNode : eNodes) {
+ bpn = this.tablesInQueryMap.get(eNode
+ .getBluePrintNodeName());
+ if (bpn != null)
break;
}
boolean isObjectInCriteria = true;
if (bpn != null) {
Map allKeyValues = collectColumnValues(rec.element, bpn);
- if ((isObjectFitCriteria(allKeyValues, bpn.getBluePrintNodeName()) == 1)) {
- addToData(rec, bpn,bluePrint,allKeyValues);
+ if ((isObjectFitCriteria(allKeyValues,
+ bpn.getBluePrintNodeName()) == 1)) {
+ addToData(rec, bpn, bluePrint, allKeyValues);
} else {
isObjectInCriteria = false;
}
if (isObjectInCriteria) {
if (root) {
- if(!rec.data.isEmpty())
+ if (!rec.data.isEmpty())
addRecord(rec.data);
} else {
result.add(rec);
@Override
public BigDecimal getBigDecimal(int columnIndex, int scale)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public BigDecimal getBigDecimal(String columnLabel, int scale)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getObject(int columnIndex, Map<String, Class<?>> map)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ throws SQLException {
+ return getObject(columnIndex);
}
@Override
public Object getObject(int columnIndex) throws SQLException {
- return currentRecord
- .get(this.fieldsInQuery.get(columnIndex - 1).toString());
+ return currentRecord.get(this.fieldsInQuery.get(columnIndex - 1)
+ .toString());
}
@Override
public Object getObject(String columnLabel, Map<String, Class<?>> map)
- throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ throws SQLException {
+ return getObject(columnLabel);
}
@Override
@Override
public String getString(int columnIndex) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return "Kuku";
}
@Override
public String getString(String columnLabel) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return "Kuku";
}
@Override
@Override
public Timestamp getTimestamp(int columnIndex, Calendar cal)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public Timestamp getTimestamp(String columnLabel, Calendar cal)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public int getType() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return ResultSet.TYPE_FORWARD_ONLY;
}
@Override
}
@Override
- public InputStream getUnicodeStream(String columnLabel)
- throws SQLException {
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x, int length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x, int length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
- public void updateAsciiStream(String columnLabel, InputStream x,
- long length)
- throws SQLException {
+ public void updateAsciiStream(String columnLabel, InputStream x, long length)
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBigDecimal(int columnIndex, BigDecimal x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBigDecimal(String columnLabel, BigDecimal x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x, int length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
- public void updateBinaryStream(String columnLabel, InputStream x,
- int length)
- throws SQLException {
+ public void updateBinaryStream(String columnLabel, InputStream x, int length)
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x,
- long length) throws SQLException {
+ long length) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
}
@Override
- public void updateBlob(int columnIndex, InputStream inputStream,
- long length)
- throws SQLException {
+ public void updateBlob(int columnIndex, InputStream inputStream, long length)
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBlob(int columnIndex, InputStream inputStream)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBlob(String columnLabel, InputStream inputStream,
- long length) throws SQLException {
+ long length) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBlob(String columnLabel, InputStream inputStream)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateBoolean(String columnLabel, boolean x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(int columnIndex, Reader x, int length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(int columnIndex, Reader x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader,
- int length) throws SQLException {
+ int length) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
+ long length) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateClob(int columnIndex, Reader reader, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateClob(String columnLabel, Reader reader, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateClob(String columnLabel, Reader reader)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNCharacterStream(int columnIndex, Reader x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
+ long length) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNClob(int columnIndex, Reader reader, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
- public void updateNClob(int columnIndex, Reader reader)
- throws SQLException {
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNClob(String columnLabel, NClob nClob)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNClob(String columnLabel, Reader reader, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNClob(String columnLabel, Reader reader)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNString(int columnIndex, String nString)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateNString(String columnLabel, String nString)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateObject(int columnIndex, Object x, int scaleOrLength)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateObject(String columnLabel, Object x, int scaleOrLength)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateSQLXML(int columnIndex, SQLXML xmlObject)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateSQLXML(String columnLabel, SQLXML xmlObject)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateTimestamp(int columnIndex, Timestamp x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public void updateTimestamp(String columnLabel, Timestamp x)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
}
@Override
public int getColumnType(int column) throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return 12;
}
@Override
@Override
public <T> T getObject(String columnLabel, Class<T> type)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
-
-
- ////Metadata
-
-
+ // //Metadata
}
package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
-import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter;
-import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
-import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrintNode;
-import org.opendaylight.controller.md.sal.dom.xsql.XSQLColumn;
-import org.opendaylight.controller.md.sal.dom.xsql.XSQLCriteria;
-
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrintNode;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLColumn;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLCriteria;
+
public class JDBCServer extends Thread {
private ServerSocket socket = null;
private XSQLAdapter adapter = null;
}
public static void execute(JDBCResultSet rs, XSQLAdapter adapter)
- throws SQLException {
- parseTables(rs, adapter.getBluePrint());
- parseFields(rs, adapter.getBluePrint());
- parseCriteria(rs, adapter.getBluePrint());
+ throws SQLException {
+ if(rs.getSQL().toLowerCase().trim().equals("select 1")){
+ rs.setFinished(true);
+ return;
+ }
+ checkAndBreakSubQueries(rs, adapter);
+ if (rs.getSubQueries().size() == 0) {
+ parseTables(rs, adapter.getBluePrint());
+ parseFields(rs, adapter.getBluePrint());
+ parseCriteria(rs, adapter.getBluePrint());
+ try {
+ adapter.execute(rs);
+ } catch (Exception err) {
+ throw new SQLException("Error", err);
+ }
+ } else {
+ parseExternalQuery(rs);
+ }
+ }
+
+ public static void parseExternalQuery(JDBCResultSet rs) throws SQLException {
+ String sql = rs.getSQL();
+ for (Map.Entry<String, JDBCResultSet> entry : rs.getSubQueries()
+ .entrySet()) {
+ int index = sql.toLowerCase().indexOf(entry.getValue().getSQL());
+ String extSql = sql.substring(0, index);
+ index = extSql.lastIndexOf("(");
+ extSql = extSql.substring(0, index);
+ System.out.println("External SQL=" + extSql);
+ parseLogicalFields(extSql, rs);
+ }
+ }
+
+ public static void parseLogicalFields(String sql, JDBCResultSet rs)
+ throws SQLException {
+ if(sql.trim().toLowerCase().equals("select * from")){
+ for (Map.Entry<String, JDBCResultSet> entry : rs.getSubQueries().entrySet()) {
+ for(XSQLBluePrintNode node:entry.getValue().getTables()){
+ rs.addTableToQuery(node);
+ }
+ rs.getFields().addAll(entry.getValue().getFields());
+ while (entry.getValue().next()) {
+ Map rec = entry.getValue().getCurrent();
+ Map newRec = new HashMap();
+ newRec.putAll(rec);
+ rs.addRecord(newRec);
+ }
+ }
+ rs.setFinished(true);
+ return;
+ }
+
+ Map<String, XSQLBluePrintNode> logicalNameToNode = new HashMap<String, XSQLBluePrintNode>();
+ Map<String, String> origNameToName = new HashMap<String, String>();
+ List<XSQLColumn> columnOrder = new ArrayList<>();
+ int nextLogField = addNextLogicalField(sql, 0,
+ logicalNameToNode, origNameToName,columnOrder);
+ int next = sql.toLowerCase().indexOf(" as ", nextLogField);
+ while (next != -1) {
+ nextLogField = addNextLogicalField(sql, nextLogField + 1,
+ logicalNameToNode, origNameToName,columnOrder);
+ next = sql.toLowerCase().indexOf(" as ", nextLogField + 1);
+ }
+
+ for (XSQLBluePrintNode node : logicalNameToNode.values()) {
+ rs.addTableToQuery(node);
+ }
+ rs.getFields().addAll(columnOrder);
+ for (Map.Entry<String, JDBCResultSet> entry : rs.getSubQueries().entrySet()) {
+ while (entry.getValue().next()) {
+ Map rec = entry.getValue().getCurrent();
+ Map newRec = new HashMap();
+ for (Iterator iter = rec.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry e = (Map.Entry) iter.next();
+ String key = (String) e.getKey();
+ Object value = e.getValue();
+ String logicalKey = origNameToName.get(key);
+ if (value != null && logicalKey != null) {
+ newRec.put(logicalKey, value);
+ }
+ }
+ rs.addRecord(newRec);
+ }
+ }
+ rs.setFinished(true);
+ }
+
+ public static void main(String args[]) {
+ String sql = "SELECT DISTINCT"
+ + "\"LOGICAL_TABLE_1\".\"nodes/node.id\" AS \"COL0\"\n"
+ + ",\"LOGICAL_TABLE_1\".\"nodes/node.id\" AS \"COL1\"\n"
+ + ",\"LOGICAL_TABLE_1\".\"nodes/node.id\" AS \"COL2\"\n"
+ + "FROM\n"
+ + "(select * from nodes/node;) \"LOGICAL_TABLE_1\"\n";
+ JDBCResultSet rs = new JDBCResultSet(sql);
try {
- adapter.execute(rs);
+ parseLogicalFields(sql, rs);
} catch (Exception err) {
- throw new SQLException("Error", err);
+ err.printStackTrace();
+ }
+ }
+
+ public static int addNextLogicalField(String sql, int startIndex,
+ Map<String, XSQLBluePrintNode> logicalNameToNode,
+ Map<String, String> origNameToName, List<XSQLColumn> columnOrder) {
+ int index1 = sql.indexOf("\"", startIndex);
+ int index2 = sql.indexOf("\".\"", index1);
+ int index3 = sql.indexOf("\"", index2 + 3);
+ int index4 = sql.toLowerCase().indexOf(" as ", startIndex);
+ int index5 = sql.indexOf("\"", index4);
+ int index6 = sql.indexOf("\"", index5 + 1);
+
+ String tblName = sql.substring(index1 + 1, index2);
+ String origFieldNameFull = sql.substring(index2 + 3, index3);
+ String origTableName = "";
+ String origFieldName = "";
+ if (origFieldNameFull.indexOf(".") != -1) {
+ origTableName = origFieldNameFull.substring(0,origFieldNameFull.indexOf("."));
+ origFieldName = origFieldNameFull.substring(origFieldNameFull.indexOf(".") + 1);
+ }
+ String logicalFieldName = sql.substring(index5 + 1, index6);
+ XSQLBluePrintNode node = logicalNameToNode.get(tblName);
+ if (node == null) {
+ node = new XSQLBluePrintNode(tblName, origTableName, 0);
+ logicalNameToNode.put(tblName, node);
+ }
+ columnOrder.add(node.addColumn(logicalFieldName, tblName, origFieldName, origTableName));
+ origNameToName.put(origFieldNameFull, tblName + "." + logicalFieldName);
+ return index6;
+ }
+
+ public static void checkAndBreakSubQueries(JDBCResultSet rs,XSQLAdapter adapter) throws SQLException {
+ String sql = rs.getSQL().toLowerCase();
+ int index = sql.indexOf("select");
+ if (index == -1)
+ throw new SQLException("Select statement is missing...");
+ int index2 = sql.indexOf("select", index + 6);
+ if (index2 != -1) {
+ int startSubQuery = index2;
+ for (int i = startSubQuery; i >= 0; i--) {
+ if (sql.charAt(i) == '(') {
+ startSubQuery = i;
+ break;
+ }
+ }
+ int braketCount = 0;
+ int endSubQuery = startSubQuery;
+ do {
+ if (sql.charAt(endSubQuery) == '(')
+ braketCount++;
+ else if (sql.charAt(endSubQuery) == ')')
+ braketCount--;
+ endSubQuery++;
+ } while (braketCount > 0 || endSubQuery == sql.length());
+ String subQuerySQL = sql.substring(startSubQuery + 1,endSubQuery - 1);
+ if(rs.getSQL().toLowerCase().substring(0,startSubQuery).trim().equals("select * from")){
+ rs.setSQL(subQuerySQL);
+ return;
+ }
+ index = sql.indexOf("\"", endSubQuery);
+ index2 = sql.indexOf("\"", index + 1);
+ if(index==-1){
+ index = endSubQuery;
+ index2 = sql.length();
+ }
+ String logicalName = rs.getSQL().substring(index + 1, index2).trim();
+ JDBCResultSet subRS = rs.addSubQuery(subQuerySQL, logicalName);
+ JDBCServer.execute(subRS, adapter);
}
}
public static void parseTables(JDBCResultSet rs, XSQLBluePrint bp)
- throws SQLException {
+ throws SQLException {
String lowSQL = rs.getSQL().toLowerCase();
int from = lowSQL.indexOf("from");
int where = lowSQL.indexOf("where");
String tableName = tokens.nextToken().trim();
XSQLBluePrintNode table = bp.getBluePrintNodeByTableName(tableName);
if (table == null) {
- throw new SQLException(
- "Unknown table name \"" + tableName + "\"");
+ throw new SQLException("Unknown table name \"" + tableName
+ + "\"");
}
rs.addTableToQuery(table);
}
}
public static void addCriteria(XSQLColumn col, XSQLCriteria c,
- JDBCResultSet rs) {
- Map<XSQLColumn, List<XSQLCriteria>> tblCriteria =
- rs.getCriteria().get(col.getTableName());
+ JDBCResultSet rs) {
+ Map<XSQLColumn, List<XSQLCriteria>> tblCriteria = rs.getCriteria().get(
+ col.getTableName());
if (tblCriteria == null) {
- tblCriteria =
- new ConcurrentHashMap<XSQLColumn, List<XSQLCriteria>>();
+ tblCriteria = new ConcurrentHashMap<XSQLColumn, List<XSQLCriteria>>();
rs.getCriteria().put(col.getTableName(), tblCriteria);
}
List<XSQLCriteria> lstCriteria = tblCriteria.get(col);
}
public static void parseFields(JDBCResultSet rs, XSQLBluePrint bp)
- throws SQLException {
+ throws SQLException {
String lowSQL = rs.getSQL().toLowerCase();
if (!lowSQL.startsWith("select")) {
throw new SQLException("Missing 'select' statement.");
return;
}
if (token.indexOf(".") != -1) {
- XSQLBluePrintNode tbl = bp.getBluePrintNodeByTableName(
- token.substring(0, token.indexOf(".")).trim());
+ XSQLBluePrintNode tbl = bp.getBluePrintNodeByTableName(token
+ .substring(0, token.indexOf(".")).trim());
String p = token.substring(token.indexOf(".") + 1);
if (p.equals("*")) {
for (XSQLColumn c : tbl.getColumns()) {
}
}
if (col == null) {
- throw new SQLException(
- "Unknown field name '" + token + "'.");
+ throw new SQLException("Unknown field name '" + token
+ + "'.");
}
rs.getFields().add(col);
String lowSQL = rs.getSQL().toLowerCase();
int where = lowSQL.indexOf("where");
int order = lowSQL.indexOf("order");
- int subQuery = lowSQL.indexOf("select", 2);
int whereTo = lowSQL.indexOf(";");
if (where == -1) {
return;
}
- if (where != -1 && subQuery != -1 && subQuery < where) {
- return;
- }
-
- if (order != -1 && subQuery != -1 && order < subQuery) {
- whereTo = order;
- } else if (order != -1 && subQuery != -1 && order > subQuery) {
- whereTo = subQuery;
- } else if (order != -1) {
+ if (order != -1) {
whereTo = order;
- } else if (subQuery != -1) {
- whereTo = subQuery;
}
- String whereStatement =
- rs.getSQL().substring(where + 5, whereTo).trim();
+
+ if(whereTo==-1)
+ whereTo=lowSQL.length();
+
+ String whereStatement = rs.getSQL().substring(where + 5, whereTo)
+ .trim();
XSQLCriteria cr = new XSQLCriteria(whereStatement, -1);
for (XSQLBluePrintNode tbl : rs.getTables()) {
for (XSQLColumn col : tbl.getColumns()) {
package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
-import java.sql.Statement;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-public class JDBCStatement implements Statement {
+public class JDBCStatement implements PreparedStatement {
private JDBCResultSet rs = null;
private transient JDBCConnection connection = null;
- private static Map<Integer, JDBCResultSet> queries =
- new ConcurrentHashMap<Integer, JDBCResultSet>();
+ private static Map<Integer, JDBCResultSet> queries = new ConcurrentHashMap<Integer, JDBCResultSet>();
+ private String sql = null;
+
+ public JDBCStatement(JDBCConnection con,String _sql) {
+ this.connection = con;
+ this.sql = _sql;
+ }
public JDBCStatement(JDBCConnection con) {
this.connection = con;
}
+ public void setSQL(String _sql){
+ this.sql = _sql;
+ }
+
public JDBCStatement() {
}
+ public PreparedStatement getProxy() {
+ return this;
+ /*
+ return (PreparedStatement) Proxy.newProxyInstance(this.getClass()
+ .getClassLoader(), new Class[] { PreparedStatement.class },
+ new JDBCProxy(this));
+ */
+ }
+
public static JDBCResultSet getQuery(int id) {
return queries.get(id);
}
rs = new JDBCResultSet(_sql);
queries.put(rs.getID(), rs);
synchronized (rs) {
- this.connection
- .send(new JDBCCommand(rs, JDBCCommand.TYPE_EXECUTE_QUERY));
+ this.connection.send(new JDBCCommand(rs,
+ JDBCCommand.TYPE_EXECUTE_QUERY));
try {
rs.wait();
} catch (Exception err) {
throw ((SQLException) rs.getError());
}
}
- return rs;
+ return rs.getProxy();
}
@Override
@Override
public boolean execute(String sql, int autoGeneratedKeys)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
- public boolean execute(String sql, int[] columnIndexes)
- throws SQLException {
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean execute(String sql, String[] columnNames)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int executeUpdate(String sql, int[] columnIndexes)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int executeUpdate(String sql, String[] columnNames)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getMaxRows() throws SQLException {
- // TODO Auto-generated method stub
- return 0;
+ return 200;
}
@Override
return false;
}
+ @Override
+ public ResultSet executeQuery() throws SQLException {
+ return this.executeQuery(this.sql);
+ }
+
+ @Override
+ public int executeUpdate() throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setNull(int parameterIndex, int sqlType) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setByte(int parameterIndex, byte x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setShort(int parameterIndex, short x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setInt(int parameterIndex, int x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLong(int parameterIndex, long x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setFloat(int parameterIndex, float x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setDouble(int parameterIndex, double x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBigDecimal(int parameterIndex, BigDecimal x)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setString(int parameterIndex, String x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setDate(int parameterIndex, Date x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTime(int parameterIndex, Time x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTimestamp(int parameterIndex, Timestamp x)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x, int length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x, int length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void clearParameters() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x, int targetSqlType)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x) throws SQLException {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public boolean execute() throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void addBatch() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader, int length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setRef(int parameterIndex, Ref x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, Blob x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Clob x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setArray(int parameterIndex, Array x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public ResultSetMetaData getMetaData() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDate(int parameterIndex, Date x, Calendar cal)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTime(int parameterIndex, Time x, Calendar cal)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNull(int parameterIndex, int sqlType, String typeName)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setURL(int parameterIndex, URL x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public ParameterMetaData getParameterMetaData() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setRowId(int parameterIndex, RowId x) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNString(int parameterIndex, String value)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNCharacterStream(int parameterIndex, Reader value,
+ long length) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, NClob value) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, InputStream inputStream, long length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setSQLXML(int parameterIndex, SQLXML xmlObject)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x, int targetSqlType,
+ int scaleOrLength) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x, long length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x, long length)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader,
+ long length) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNCharacterStream(int parameterIndex, Reader value)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Reader reader) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, InputStream inputStream)
+ throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
}
--- /dev/null
+package org.opendaylight.xsql.test;
+
+import java.io.InputStream;
+import java.sql.SQLException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter;
+import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
+import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCResultSet;
+import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCServer;
+
+public class XSQLTest {
+
+ XSQLBluePrint bluePrint = null;
+
+ @Before
+ public void before() {
+ try{
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream("BluePrintCache.dat");
+ if(in!=null){
+ bluePrint = XSQLBluePrint.load(in);
+ log("Loaded Blue Print!");
+ }else{
+ log("Can't find Blue Print!");
+ }
+ in.close();
+ }catch(Exception err){
+ err.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testQueryParsingSimpleNoCriteria() {
+ String sql = "select * from nodes/node;";
+ JDBCResultSet rs = new JDBCResultSet(sql);
+ parseTables(sql,bluePrint, rs);
+ parseFields(sql, bluePrint, rs);
+ JDBCServer.parseCriteria(rs, bluePrint);
+ if(rs.getCriteria().isEmpty()){
+ log("Test Criteria parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true, true);
+ }else{
+ log("Test Criteria parsing of \""+sql+"\" Failed!");
+ Assert.assertEquals(false, true);
+ }
+ }
+
+ @Test
+ public void testQueryParsingComplexNoCriteria() {
+ String sql = "select nodes/node.id,nodes/node/node-connector.id,nodes/node/node-connector.hardware-address from nodes/node,nodes/node/node-connector;";
+ JDBCResultSet rs = new JDBCResultSet(sql);
+ parseTables(sql,bluePrint, rs);
+ parseFields(sql, bluePrint, rs);
+ JDBCServer.parseCriteria(rs, bluePrint);
+ if(rs.getCriteria().isEmpty()){
+ log("Test Criteria parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true, true);
+ }else{
+ log("Test Criteria parsing of \""+sql+"\" Failed!");
+ Assert.assertEquals(false, true);
+ }
+ }
+
+ @Test
+ public void testQueryParsingComplexWithCriteria() {
+ String sql = "select nodes/node.id,nodes/node/node-connector.id,nodes/node/node-connector.hardware-address from nodes/node,nodes/node/node-connector where hardware-address like 'AB';";
+ JDBCResultSet rs = new JDBCResultSet(sql);
+ parseTables(sql,bluePrint, rs);
+ parseFields(sql, bluePrint, rs);
+ JDBCServer.parseCriteria(rs, bluePrint);
+ if(!rs.getCriteria().isEmpty()){
+ log("Test Criteria parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true, true);
+ }else{
+ log("Test Criteria parsing of \""+sql+"\" Failed!");
+ Assert.assertEquals(false, true);
+ }
+ }
+
+ @Test
+ public void testQueryParsingSimpleWithCriteria() {
+ String sql = "select * from nodes/node where nodes/node.id like 'something...';";
+ JDBCResultSet rs = new JDBCResultSet(sql);
+ parseTables(sql,bluePrint, rs);
+ parseFields(sql, bluePrint, rs);
+ JDBCServer.parseCriteria(rs, bluePrint);
+ if(!rs.getCriteria().isEmpty()){
+ log("Test Criteria parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true, true);
+ }else{
+ log("Test Criteria parsing of \""+sql+"\" Failed!");
+ Assert.assertEquals(false, true);
+ }
+ }
+
+ private static void parseTables(String sql,XSQLBluePrint bp,JDBCResultSet rs){
+ try{
+ JDBCServer.parseTables(rs, bp);
+ log("Test Table parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true,true);
+ }catch(SQLException err){
+ log("Test Table parsing of \""+sql+"\" Failed!");
+ err.printStackTrace();
+ Assert.assertEquals(false,true);
+ }
+ }
+
+ @Test
+ public void testQueryParsingComplexWithCriteriaAndGrouping() {
+
+ String sub_sql = "select nodes/node.id,nodes/node/node-connector.id,nodes/node/node-connector.hardware-address from nodes/node,nodes/node/node-connector where hardware-address like 'AB';";
+
+ String sql = "SELECT DISTINCT"
+ + "\"LOGICAL_TABLE_1\".\"nodes/node.id\" AS \"COL0\"\n"
+ + ",\"LOGICAL_TABLE_1\".\"nodes/node.address\" AS \"COL1\"\n"
+ + ",\"LOGICAL_TABLE_1\".\"nodes/node/node-connector.hardware-address\" AS \"COL2\"\n"
+ + "FROM\n"
+ + "("+sub_sql+") \"LOGICAL_TABLE_1\"\n";
+
+
+
+ JDBCResultSet rs = new JDBCResultSet(sql);
+ XSQLAdapter.getInstance().loadBluePrint();
+ try{
+ JDBCServer.checkAndBreakSubQueries(rs, XSQLAdapter.getInstance());
+ if(rs.getSubQueries().isEmpty()){
+ log("Logical table parsing for "+sql+" Failed!");
+ }else{
+ JDBCServer.parseExternalQuery(rs);
+ log("Fields="+rs.getFields().size());
+ Assert.assertEquals(rs.getFields().size(), 3);
+ Assert.assertEquals(rs.getTables().size(), 1);
+ Assert.assertEquals(rs.getTables().get(0).getODLTableName(), "LOGICAL_TABLE_1");
+
+ JDBCResultSet subRS = rs.getSubQueries().values().iterator().next();
+ parseTables(sql,bluePrint, subRS);
+ parseFields(sql, bluePrint, subRS);
+ JDBCServer.parseCriteria(subRS, bluePrint);
+ if(!subRS.getCriteria().isEmpty()){
+ log("Test Criteria parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true, true);
+ }else{
+ log("Test Criteria parsing of \""+sql+"\" Failed!");
+ Assert.assertEquals(false, true);
+ }
+ }
+ }catch(SQLException err){
+ err.printStackTrace();
+ }
+ }
+
+ private static void parseFields(String sql,XSQLBluePrint bp,JDBCResultSet rs){
+ try{
+ JDBCServer.parseFields(rs, bp);
+ log("Test Fields parsing of \""+sql+"\" Passed!");
+ Assert.assertEquals(true,true);
+ }catch(SQLException err){
+ log("Test Fields parsing of \""+sql+"\" Failed!");
+ err.printStackTrace();
+ Assert.assertEquals(false,true);
+ }
+ }
+
+ private static void log(String str) {
+ System.out.print("*** XSQL Tests -");
+ System.out.println(str);
+ }
+}