X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-xsql%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fxsql%2FXSQLBluePrint.java;h=d6aaa270b5941567352134dd01af5849dbf8b025;hp=7b51d03a97aaa6c9a9d1592eb5ba963ec63e6d8c;hb=d0dc66335889ecec5dbc962a8604c3df96eca758;hpb=531621aac4cff9d39cbd8668a53bdeba8a0e6d81 diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java index 7b51d03a97..d6aaa270b5 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrint.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.io.DataInputStream; @@ -23,21 +30,29 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ +/** + * To be removed in Nitrogen + */ +@Deprecated public class XSQLBluePrint implements DatabaseMetaData, Serializable { private static final long serialVersionUID = 1L; public static final String CACHE_FILE_NAME = "./BluePrintCache.dat"; - private Map tableNameToBluePrint = new HashMap(); - private Map> odlNameToBluePrint = new HashMap>(); + private final Map tableNameToBluePrint = new HashMap<>(); + private final Map> odlNameToBluePrint = new HashMap<>(); - private boolean cacheLoadedSuccessfuly = false; + private final boolean cacheLoadedSuccessfuly = false; private DatabaseMetaData myProxy = null; - public static final String replaceAll(String source, String toReplace, - String withThis) { + public static final String replaceAll(final String source, final String toReplace, + final String withThis) { int index = source.indexOf(toReplace); int index2 = 0; StringBuffer result = new StringBuffer(); @@ -53,15 +68,16 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { return result.toString(); } - public XSQLBluePrint() { + XSQLBluePrint() { + } - public static void save(XSQLBluePrint bp) { + public void save() { ObjectOutputStream out = null; try { out = new ObjectOutputStream(new DataOutputStream( new FileOutputStream(CACHE_FILE_NAME))); - out.writeObject(bp); + out.writeObject(this); } catch (Exception err) { err.printStackTrace(); } finally { @@ -72,7 +88,16 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } } - public static XSQLBluePrint load(InputStream ins) { + static XSQLBluePrint create(final SchemaContext context) { + final XSQLBluePrint ret = new XSQLBluePrint(); + for (Module m : context.getModules()) { + XSQLODLUtils.createOpenDaylightCache(ret, m); + } + + return ret; + } + + public static XSQLBluePrint load(final InputStream ins) { ObjectInputStream in = null; try { in = new ObjectInputStream(new DataInputStream(ins)); @@ -89,7 +114,8 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } private class NQLBluePrintProxy implements InvocationHandler { - public Object invoke(Object proxy, Method method, Object[] args) + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { System.out.println("Method " + method); return method.invoke(XSQLBluePrint.this, args); @@ -111,11 +137,12 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } public XSQLBluePrintNode[] getBluePrintNodeByODLTableName( - String odlTableName) { + final String odlTableName) { Map map = this.odlNameToBluePrint .get(odlTableName); - if (map == null) + if (map == null) { return null; + } return map.values().toArray(new XSQLBluePrintNode[map.size()]); } @@ -163,23 +190,23 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { return cacheLoadedSuccessfuly; } - private static Map> superClassMap = new HashMap>(); + private static Map, Set>> superClassMap = new HashMap<>(); - public static Set getInheritance(Class myObjectClass, - Class returnType) { + public static Set> getInheritance(final Class myObjectClass, + final Class returnType) { if (returnType != null && myObjectClass.equals(returnType)) { - return new HashSet(); + return new HashSet<>(); } - Set result = superClassMap.get(myObjectClass); + Set> result = superClassMap.get(myObjectClass); if (result != null) { return result; } - result = new HashSet(); + result = new HashSet<>(); superClassMap.put(myObjectClass, result); if (returnType != null) { if (!returnType.equals(myObjectClass)) { - Class mySuperClass = myObjectClass.getSuperclass(); + Class mySuperClass = myObjectClass.getSuperclass(); while (mySuperClass != null) { result.add(mySuperClass); mySuperClass = mySuperClass.getSuperclass(); @@ -190,11 +217,11 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { return result; } - public static Set collectInterfaces(Class cls) { - Set result = new HashSet(); - Class myInterfaces[] = cls.getInterfaces(); + public static Set> collectInterfaces(final Class cls) { + Set> result = new HashSet<>(); + Class myInterfaces[] = cls.getInterfaces(); if (myInterfaces != null) { - for (Class in : myInterfaces) { + for (Class in : myInterfaces) { result.add(in); result.addAll(collectInterfaces(in)); } @@ -202,31 +229,40 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { return result; } - public void addToBluePrintCache(XSQLBluePrintNode blNode) { - this.tableNameToBluePrint.put(blNode.getBluePrintNodeName(), blNode); - Map map = this.odlNameToBluePrint.get(blNode - .getODLTableName()); - if (map == null) { - map = new HashMap(); - this.odlNameToBluePrint.put(blNode.getODLTableName(), map); + public XSQLBluePrintNode addToBluePrintCache(final XSQLBluePrintNode blNode,final XSQLBluePrintNode parent) { + XSQLBluePrintNode existingNode = this.tableNameToBluePrint.get(blNode.getBluePrintNodeName()); + if(existingNode!=null){ + existingNode.mergeAugmentation(blNode); + return existingNode; + }else{ + this.tableNameToBluePrint.put(blNode.getBluePrintNodeName(), blNode); + Map map = this.odlNameToBluePrint.get(blNode.getODLTableName()); + if (map == null) { + map = new HashMap<>(); + this.odlNameToBluePrint.put(blNode.getODLTableName(), map); + } + map.put(blNode.getBluePrintNodeName(), blNode); + if(parent!=null) { + parent.addChild(blNode); + } + return blNode; } - map.put(blNode.getBluePrintNodeName(), blNode); } - public Class getGenericType(ParameterizedType type) { + public Class getGenericType(final ParameterizedType type) { Type[] typeArguments = type.getActualTypeArguments(); for (Type typeArgument : typeArguments) { if (typeArgument instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) typeArgument; - return (Class) pType.getRawType(); + return (Class) pType.getRawType(); } else if (typeArgument instanceof Class) { - return (Class) typeArgument; + return (Class) typeArgument; } } return null; } - public Class getMethodReturnTypeFromGeneric(Method m) { + public Class getMethodReturnTypeFromGeneric(final Method m) { Type rType = m.getGenericReturnType(); if (rType instanceof ParameterizedType) { return getGenericType((ParameterizedType) rType); @@ -235,7 +271,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } public List getAllTableNames() { - List names = new ArrayList(); + List names = new ArrayList<>(); for (XSQLBluePrintNode n : this.tableNameToBluePrint.values()) { if (!n.isModule() && !n.getColumns().isEmpty()) { names.add(n.getBluePrintNodeName()); @@ -245,9 +281,9 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } - public List getInterfaceNames(XSQLBluePrintNode node) { + public List getInterfaceNames(final XSQLBluePrintNode node) { Set children = node.getChildren(); - List names = new ArrayList(); + List names = new ArrayList<>(); for (XSQLBluePrintNode n : children) { if (!n.isModule() && !n.getColumns().isEmpty()) { names.add(n.toString()); @@ -286,7 +322,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean deletesAreDetected(int type) throws SQLException { + public boolean deletesAreDetected(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @@ -298,16 +334,16 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getAttributes(String catalog, String schemaPattern, - String typeNamePattern, String attributeNamePattern) + public ResultSet getAttributes(final String catalog, final String schemaPattern, + final String typeNamePattern, final 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 { + public ResultSet getBestRowIdentifier(final String catalog, final String schema, + final String table, final int scope, final boolean nullable) throws SQLException { // TODO Auto-generated method stub return null; } @@ -337,15 +373,15 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getColumnPrivileges(String catalog, String schema, - String table, String columnNamePattern) throws SQLException { + public ResultSet getColumnPrivileges(final String catalog, final String schema, + final String table, final String columnNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getColumns(String catalog, String schemaPattern, - String tableNamePattern, String columnNamePattern) + public ResultSet getColumns(final String catalog, final String schemaPattern, + final String tableNamePattern, final String columnNamePattern) throws SQLException { // TODO Auto-generated method stub return null; @@ -358,9 +394,9 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getCrossReference(String parentCatalog, - String parentSchema, String parentTable, String foreignCatalog, - String foreignSchema, String foreignTable) throws SQLException { + public ResultSet getCrossReference(final String parentCatalog, + final String parentSchema, final String parentTable, final String foreignCatalog, + final String foreignSchema, final String foreignTable) throws SQLException { // TODO Auto-generated method stub return null; } @@ -417,7 +453,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getExportedKeys(String catalog, String schema, String table) + public ResultSet getExportedKeys(final String catalog, final String schema, final String table) throws SQLException { // TODO Auto-generated method stub return null; @@ -430,16 +466,16 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getFunctionColumns(String catalog, String schemaPattern, - String functionNamePattern, String columnNamePattern) + public ResultSet getFunctionColumns(final String catalog, final String schemaPattern, + final String functionNamePattern, final String columnNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getFunctions(String catalog, String schemaPattern, - String functionNamePattern) throws SQLException { + public ResultSet getFunctions(final String catalog, final String schemaPattern, + final String functionNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @@ -451,15 +487,15 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getImportedKeys(String catalog, String schema, String table) + public ResultSet getImportedKeys(final String catalog, final String schema, final 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 { + public ResultSet getIndexInfo(final String catalog, final String schema, final String table, + final boolean unique, final boolean approximate) throws SQLException { // TODO Auto-generated method stub return null; } @@ -603,23 +639,23 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getPrimaryKeys(String catalog, String schema, String table) + public ResultSet getPrimaryKeys(final String catalog, final String schema, final String table) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getProcedureColumns(String catalog, String schemaPattern, - String procedureNamePattern, String columnNamePattern) + public ResultSet getProcedureColumns(final String catalog, final String schemaPattern, + final String procedureNamePattern, final String columnNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getProcedures(String catalog, String schemaPattern, - String procedureNamePattern) throws SQLException { + public ResultSet getProcedures(final String catalog, final String schemaPattern, + final String procedureNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @@ -649,7 +685,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getSchemas(String catalog, String schemaPattern) + public ResultSet getSchemas(final String catalog, final String schemaPattern) throws SQLException { // TODO Auto-generated method stub return null; @@ -686,15 +722,15 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getSuperTables(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { + public ResultSet getSuperTables(final String catalog, final String schemaPattern, + final String tableNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getSuperTypes(String catalog, String schemaPattern, - String typeNamePattern) throws SQLException { + public ResultSet getSuperTypes(final String catalog, final String schemaPattern, + final String typeNamePattern) throws SQLException { // TODO Auto-generated method stub return null; } @@ -706,15 +742,15 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getTablePrivileges(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { + public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, + final 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 { + public ResultSet getTables(final String catalog, final String schemaPattern, + final String tableNamePattern, final String[] types) throws SQLException { return new TablesResultSet(this); } @@ -737,8 +773,8 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getUDTs(String catalog, String schemaPattern, - String typeNamePattern, int[] types) throws SQLException { + public ResultSet getUDTs(final String catalog, final String schemaPattern, + final String typeNamePattern, final int[] types) throws SQLException { // TODO Auto-generated method stub return null; } @@ -756,14 +792,14 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public ResultSet getVersionColumns(String catalog, String schema, - String table) throws SQLException { + public ResultSet getVersionColumns(final String catalog, final String schema, + final String table) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public boolean insertsAreDetected(int type) throws SQLException { + public boolean insertsAreDetected(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @@ -817,37 +853,37 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean othersDeletesAreVisible(int type) throws SQLException { + public boolean othersDeletesAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean othersInsertsAreVisible(int type) throws SQLException { + public boolean othersInsertsAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean othersUpdatesAreVisible(int type) throws SQLException { + public boolean othersUpdatesAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean ownDeletesAreVisible(int type) throws SQLException { + public boolean ownDeletesAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean ownInsertsAreVisible(int type) throws SQLException { + public boolean ownInsertsAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean ownUpdatesAreVisible(int type) throws SQLException { + public boolean ownUpdatesAreVisible(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @@ -967,7 +1003,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean supportsConvert(int fromType, int toType) + public boolean supportsConvert(final int fromType, final int toType) throws SQLException { // TODO Auto-generated method stub return false; @@ -1162,21 +1198,21 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean supportsResultSetConcurrency(int type, int concurrency) + public boolean supportsResultSetConcurrency(final int type, final int concurrency) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean supportsResultSetHoldability(int holdability) + public boolean supportsResultSetHoldability(final int holdability) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public boolean supportsResultSetType(int type) throws SQLException { + public boolean supportsResultSetType(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @@ -1272,7 +1308,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean supportsTransactionIsolationLevel(int level) + public boolean supportsTransactionIsolationLevel(final int level) throws SQLException { // TODO Auto-generated method stub return false; @@ -1297,7 +1333,7 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean updatesAreDetected(int type) throws SQLException { + public boolean updatesAreDetected(final int type) throws SQLException { // TODO Auto-generated method stub return false; } @@ -1315,20 +1351,20 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { } @Override - public boolean isWrapperFor(Class iface) throws SQLException { + public boolean isWrapperFor(final Class iface) throws SQLException { // TODO Auto-generated method stub return false; } @Override - public T unwrap(Class iface) throws SQLException { + public T unwrap(final Class iface) throws SQLException { // TODO Auto-generated method stub return null; } @Override - public ResultSet getPseudoColumns(String catalog, String schemaPattern, - String tableNamePattern, String columnNamePattern) + public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, + final String tableNamePattern, final String columnNamePattern) throws SQLException { // TODO Auto-generated method stub return null; @@ -1339,5 +1375,4 @@ public class XSQLBluePrint implements DatabaseMetaData, Serializable { // TODO Auto-generated method stub return false; } - }