Update the XSQL jdbc driver to support pentaho 24/11724/5
authorSharon Aicler <saichler@cisco.com>
Fri, 3 Oct 2014 15:36:10 +0000 (08:36 -0700)
committerSharon Aicler <saichler@cisco.com>
Wed, 8 Oct 2014 23:29:11 +0000 (16:29 -0700)
Change-Id: I72f54b36a87c84c9fa493a1d35300b241a53ec34
Signed-off-by: Sharon Aicler <saichler@cisco.com>
14 files changed:
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModificationTest.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java [moved from opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCDriver.java with 84% similarity]
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLAdapter.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLColumn.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCCommand.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCConnection.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCProxy.java [new file with mode: 0644]
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCResultSet.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCServer.java
opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCStatement.java
opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat [new file with mode: 0644]

index 03aaace0e354543f63d8e9f7ed5d74f998fc142c..f8116aa78d72f4b08597cee693d592ca8c32ed87 100644 (file)
@@ -35,8 +35,9 @@ public class MutableCompositeModificationTest extends AbstractModificationTest {
         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);
     }
 }
similarity index 84%
rename from opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCDriver.java
rename to opendaylight/md-sal/sal-dom-xsql/src/main/java/org/odl/xsql/JDBCDriver.java
index e4b4e249dfe01b14730e4d4c83210e6ddd3953b9..cc92b48a157abc00a9baf5c80b8b37aa034fcf30 100644 (file)
@@ -1,4 +1,4 @@
-package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
+package org.odl.xsql;
 
 import java.sql.Connection;
 import java.sql.Driver;
@@ -9,6 +9,8 @@ import java.sql.SQLFeatureNotSupportedException;
 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();
@@ -34,11 +36,12 @@ public class JDBCDriver implements Driver {
             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;
     }
 
@@ -55,7 +58,7 @@ public class JDBCDriver implements Driver {
     @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};
     }
 
index d1f11ba9a36e693e223930b2fb4269e03acf21da..beab6d2fb1a0014e3dece9b1c07f77aa611ee090 100644 (file)
@@ -63,6 +63,18 @@ public class XSQLAdapter extends Thread implements SchemaContextListener {
 
     }
 
+    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;
     }
@@ -164,6 +176,10 @@ public class XSQLAdapter extends Thread implements SchemaContextListener {
     }
 
     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));
@@ -282,6 +298,8 @@ public class XSQLAdapter extends Thread implements SchemaContextListener {
                 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);
index 1a31662020e8dc6856e9e68adee83e5a10ac6c71..7b51d03a97aaa6c9a9d1592eb5ba963ec63e6d8c 100644 (file)
@@ -1,5 +1,12 @@
 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;
@@ -17,18 +24,20 @@ import java.util.List;
 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();
@@ -47,9 +56,41 @@ public class XSQLBluePrint implements DatabaseMetaData {
     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);
         }
@@ -58,9 +99,9 @@ public class XSQLBluePrint implements DatabaseMetaData {
     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();
@@ -69,22 +110,12 @@ public class XSQLBluePrint implements DatabaseMetaData {
         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()]);
     }
 
@@ -106,26 +137,28 @@ public class XSQLBluePrint implements DatabaseMetaData {
         }
 
         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;
     }
@@ -133,7 +166,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
     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>();
@@ -171,10 +204,11 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     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);
     }
@@ -265,15 +299,15 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -304,15 +338,15 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -325,8 +359,8 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -344,7 +378,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @Override
     public String getDatabaseProductName() throws SQLException {
-        return "VNE Query Language";
+        return "OpenDayLight";
     }
 
     @Override
@@ -383,9 +417,8 @@ public class XSQLBluePrint implements DatabaseMetaData {
     }
 
     @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;
     }
@@ -398,15 +431,15 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -418,16 +451,15 @@ public class XSQLBluePrint implements DatabaseMetaData {
     }
 
     @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;
     }
@@ -572,22 +604,22 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -618,7 +650,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @Override
     public ResultSet getSchemas(String catalog, String schemaPattern)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -655,14 +687,14 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -675,14 +707,14 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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);
     }
 
@@ -706,7 +738,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -725,7 +757,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @Override
     public ResultSet getVersionColumns(String catalog, String schema,
-        String table) throws SQLException {
+            String table) throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -905,8 +937,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
     }
 
     @Override
-    public boolean supportsCatalogsInPrivilegeDefinitions()
-        throws SQLException {
+    public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
         // TODO Auto-generated method stub
         return false;
     }
@@ -937,7 +968,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @Override
     public boolean supportsConvert(int fromType, int toType)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return false;
     }
@@ -956,21 +987,20 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -1133,14 +1163,14 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
@@ -1200,8 +1230,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
     }
 
     @Override
-    public boolean supportsStoredFunctionsUsingCallSyntax()
-        throws SQLException {
+    public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
         // TODO Auto-generated method stub
         return false;
     }
@@ -1244,7 +1273,7 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @Override
     public boolean supportsTransactionIsolationLevel(int level)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return false;
     }
@@ -1299,8 +1328,8 @@ public class XSQLBluePrint implements DatabaseMetaData {
 
     @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;
     }
index fbd818e63216c40e6c6cb3a053c214584a5bc248..8d905f208132aed258886a58b5c01ab56682e76c 100644 (file)
@@ -3,7 +3,9 @@ package org.opendaylight.controller.md.sal.dom.xsql;
 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 {
@@ -11,10 +13,8 @@ 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;
 
@@ -22,11 +22,20 @@ public class XSQLBluePrintNode implements Serializable {
     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;
@@ -35,16 +44,21 @@ public class XSQLBluePrintNode implements Serializable {
         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;
     }
 
@@ -82,10 +96,11 @@ public class XSQLBluePrintNode implements Serializable {
         }
         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;
             }
         }
@@ -109,8 +124,16 @@ public class XSQLBluePrintNode implements Serializable {
     }
 
     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) {
@@ -165,17 +188,16 @@ public class XSQLBluePrintNode implements Serializable {
         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();
@@ -187,8 +209,7 @@ public class XSQLBluePrintNode implements Serializable {
     }
 
     public Set<XSQLBluePrintRelation> getClonedParents() {
-        Set<XSQLBluePrintRelation> result =
-            new HashSet<XSQLBluePrintRelation>();
+        Set<XSQLBluePrintRelation> result = new HashSet<XSQLBluePrintRelation>();
         result.addAll(this.relations);
         return result;
     }
@@ -200,6 +221,9 @@ public class XSQLBluePrintNode implements Serializable {
         if (odlNode != null) {
             return getBluePrintNodeName();
         }
+        if (odlTableName != null) {
+            return odlTableName;
+        }
         return "Unknown";
     }
 
@@ -216,11 +240,12 @@ public class XSQLBluePrintNode implements Serializable {
         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
index 55ac600f4a3010ccd0b8e63e240fb00b23d31351..4c6cca7fa612d9d00be8bdb47f8f6dd52f339b94 100644 (file)
@@ -8,6 +8,8 @@ public class XSQLColumn implements Serializable, Comparable {
     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);
@@ -16,6 +18,13 @@ public class XSQLColumn implements Serializable, Comparable {
         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;
     }
index 85ce0e5392b7f249ebe0e095931309fce68ed63f..019711157cc30db5bb7a2e43a6d4f5b2725858f2 100644 (file)
@@ -3,6 +3,8 @@ package org.opendaylight.controller.md.sal.dom.xsql.jdbc;
 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;
@@ -10,11 +12,22 @@ public class JDBCCommand implements Serializable {
     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;
@@ -22,6 +35,11 @@ public class JDBCCommand implements Serializable {
         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;
@@ -59,4 +77,8 @@ public class JDBCCommand implements Serializable {
     public Exception getERROR() {
         return this.err;
     }
+
+    public XSQLBluePrint getBluePrint() {
+        return this.bluePrint;
+    }
 }
index 3e72dc95ee83a572d9b45f240afcf5b34468df0c..bf1244f2e3cd90787984105d5395cb7df3c9e853 100644 (file)
@@ -31,38 +31,59 @@ import java.util.Properties;
 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();
         }
@@ -73,12 +94,12 @@ public class JDBCConnection extends Thread implements Connection {
             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();
             }
@@ -87,7 +108,6 @@ public class JDBCConnection extends Thread implements Connection {
         }
     }
 
-
     private boolean isStopped() {
         if (adapter != null && adapter.stopped) {
             return true;
@@ -109,11 +129,21 @@ public class JDBCConnection extends Thread implements Connection {
 
             } 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;
             }
         }
     }
@@ -167,38 +197,46 @@ public class JDBCConnection extends Thread implements Connection {
 
     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();
+            }
         }
     }
 
@@ -221,6 +259,15 @@ public class JDBCConnection extends Thread implements Connection {
     }
 
     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);
@@ -256,6 +303,7 @@ public class JDBCConnection extends Thread implements Connection {
 
     @Override
     public void close() throws SQLException {
+        wasClosed = true;
         try {
             socket.close();
         } catch (Exception err) {
@@ -271,7 +319,7 @@ public class JDBCConnection extends Thread implements Connection {
 
     @Override
     public Array createArrayOf(String typeName, Object[] elements)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -302,28 +350,25 @@ public class JDBCConnection extends Thread implements Connection {
 
     @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;
     }
@@ -360,8 +405,19 @@ public class JDBCConnection extends Thread implements Connection {
 
     @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
@@ -384,7 +440,6 @@ public class JDBCConnection extends Thread implements Connection {
 
     @Override
     public boolean isClosed() throws SQLException {
-        // TODO Auto-generated method stub
         return false;
     }
 
@@ -408,15 +463,15 @@ public class JDBCConnection extends Thread implements Connection {
 
     @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;
     }
@@ -429,44 +484,44 @@ public class JDBCConnection extends Thread implements Connection {
 
     @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
@@ -501,14 +556,14 @@ public class JDBCConnection extends Thread implements Connection {
 
     @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
 
     }
@@ -569,7 +624,7 @@ public class JDBCConnection extends Thread implements Connection {
 
     @Override
     public void setNetworkTimeout(Executor executor, int milliseconds)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
 
     }
@@ -579,5 +634,5 @@ public class JDBCConnection extends Thread implements Connection {
         // TODO Auto-generated method stub
         return 0;
     }
-}
 
+}
diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCProxy.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/jdbc/JDBCProxy.java
new file mode 100644 (file)
index 0000000..7e29947
--- /dev/null
@@ -0,0 +1,24 @@
+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);
+    }
+
+}
index 7603a3e9ae34aac783b0f049e8e671d7bbd1a549..021f6ee19b7d0bfdb71cdfc8f954783191e99f4f 100644 (file)
@@ -4,6 +4,7 @@ import java.io.InputStream;
 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;
@@ -37,15 +38,13 @@ import org.opendaylight.controller.md.sal.dom.xsql.XSQLColumn;
 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;
@@ -53,10 +52,32 @@ public class JDBCResultSet
     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) {
@@ -88,12 +109,13 @@ public class JDBCResultSet
     }
 
     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);
@@ -106,16 +128,16 @@ public class JDBCResultSet
     }
 
     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;
                 }
@@ -185,16 +207,15 @@ public class JDBCResultSet
         }
     }
 
-
     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) {
@@ -276,18 +297,16 @@ public class JDBCResultSet
         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());
                         }
                     }
                 }
@@ -295,20 +314,27 @@ public class JDBCResultSet
                 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) {
@@ -346,7 +372,8 @@ public class JDBCResultSet
         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>();
@@ -354,28 +381,33 @@ public class JDBCResultSet
         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);
                     }
                 }
@@ -386,21 +418,26 @@ public class JDBCResultSet
         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);
@@ -411,9 +448,11 @@ public class JDBCResultSet
         }
 
         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();
@@ -421,18 +460,21 @@ public class JDBCResultSet
                     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;
                         }
@@ -440,7 +482,7 @@ public class JDBCResultSet
 
                     if (isObjectInCriteria) {
                         if (root) {
-                            if(!rec.data.isEmpty())
+                            if (!rec.data.isEmpty())
                                 addRecord(rec.data);
                         } else {
                             result.add(rec);
@@ -545,7 +587,7 @@ public class JDBCResultSet
 
     @Override
     public BigDecimal getBigDecimal(int columnIndex, int scale)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -558,7 +600,7 @@ public class JDBCResultSet
 
     @Override
     public BigDecimal getBigDecimal(String columnLabel, int scale)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -798,22 +840,20 @@ public class JDBCResultSet
 
     @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
@@ -883,14 +923,12 @@ public class JDBCResultSet
 
     @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
@@ -919,7 +957,7 @@ public class JDBCResultSet
 
     @Override
     public Timestamp getTimestamp(int columnIndex, Calendar cal)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -932,7 +970,7 @@ public class JDBCResultSet
 
     @Override
     public Timestamp getTimestamp(String columnLabel, Calendar cal)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -945,8 +983,7 @@ public class JDBCResultSet
 
     @Override
     public int getType() throws SQLException {
-        // TODO Auto-generated method stub
-        return 0;
+        return ResultSet.TYPE_FORWARD_ONLY;
     }
 
     @Override
@@ -968,8 +1005,7 @@ public class JDBCResultSet
     }
 
     @Override
-    public InputStream getUnicodeStream(String columnLabel)
-        throws SQLException {
+    public InputStream getUnicodeStream(String columnLabel) throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
@@ -1096,100 +1132,98 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1201,16 +1235,15 @@ public class JDBCResultSet
     }
 
     @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
 
     }
@@ -1223,14 +1256,14 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1243,7 +1276,7 @@ public class JDBCResultSet
 
     @Override
     public void updateBoolean(String columnLabel, boolean x)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
 
     }
@@ -1274,42 +1307,42 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1322,7 +1355,7 @@ public class JDBCResultSet
 
     @Override
     public void updateClob(int columnIndex, Reader reader, long length)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
 
     }
@@ -1341,14 +1374,14 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1415,28 +1448,28 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1449,49 +1482,48 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1510,7 +1542,7 @@ public class JDBCResultSet
 
     @Override
     public void updateObject(int columnIndex, Object x, int scaleOrLength)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
 
     }
@@ -1523,7 +1555,7 @@ public class JDBCResultSet
 
     @Override
     public void updateObject(String columnLabel, Object x, int scaleOrLength)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
 
     }
@@ -1566,14 +1598,14 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1616,14 +1648,14 @@ public class JDBCResultSet
 
     @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
 
     }
@@ -1670,8 +1702,7 @@ public class JDBCResultSet
 
     @Override
     public int getColumnType(int column) throws SQLException {
-        // TODO Auto-generated method stub
-        return 0;
+        return 12;
     }
 
     @Override
@@ -1766,15 +1797,11 @@ public class JDBCResultSet
 
     @Override
     public <T> T getObject(String columnLabel, Class<T> type)
-        throws SQLException {
+            throws SQLException {
         // TODO Auto-generated method stub
         return null;
     }
 
-
-
-    ////Metadata
-
-
+    // //Metadata
 
 }
index 26b8c70b8bd82afc1dc2d9c3f9ffa9f268b27fde..5be701f82e64497fea4ef863dfd7a147bd360499 100644 (file)
@@ -1,20 +1,22 @@
 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;
@@ -47,19 +49,179 @@ public class JDBCServer extends Thread {
     }
 
     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");
@@ -90,20 +252,19 @@ public class JDBCServer extends Thread {
             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);
@@ -115,7 +276,7 @@ public class JDBCServer extends Thread {
     }
 
     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.");
@@ -135,8 +296,8 @@ public class JDBCServer extends Thread {
                 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()) {
@@ -158,8 +319,8 @@ public class JDBCServer extends Thread {
                     }
                 }
                 if (col == null) {
-                    throw new SQLException(
-                        "Unknown field name '" + token + "'.");
+                    throw new SQLException("Unknown field name '" + token
+                            + "'.");
                 }
 
                 rs.getFields().add(col);
@@ -171,28 +332,21 @@ public class JDBCServer extends Thread {
         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()) {
index a9ce1dd9bfe171059414ec32e19d7f44c9b445e5..b71b0153512ba51051c513564fe3e7594ef7b903 100644 (file)
@@ -1,28 +1,63 @@
 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);
     }
@@ -36,8 +71,8 @@ public class JDBCStatement implements Statement {
         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) {
@@ -46,7 +81,7 @@ public class JDBCStatement implements Statement {
                 throw ((SQLException) rs.getError());
             }
         }
-        return rs;
+        return rs.getProxy();
     }
 
     @Override
@@ -118,21 +153,20 @@ public class JDBCStatement implements Statement {
 
     @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;
     }
@@ -145,21 +179,21 @@ public class JDBCStatement implements Statement {
 
     @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;
     }
@@ -202,8 +236,7 @@ public class JDBCStatement implements Statement {
 
     @Override
     public int getMaxRows() throws SQLException {
-        // TODO Auto-generated method stub
-        return 0;
+        return 200;
     }
 
     @Override
@@ -326,5 +359,358 @@ public class JDBCStatement implements Statement {
         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
+
+    }
 
 }
diff --git a/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java b/opendaylight/md-sal/sal-dom-xsql/src/test/java/org/opendaylight/xsql/test/XSQLTest.java
new file mode 100644 (file)
index 0000000..8a6b184
--- /dev/null
@@ -0,0 +1,170 @@
+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);
+    }
+}
diff --git a/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat b/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat
new file mode 100644 (file)
index 0000000..b6b34ac
Binary files /dev/null and b/opendaylight/md-sal/sal-dom-xsql/src/test/resources/BluePrintCache.dat differ