+/*
+ * 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;
+import java.io.DataOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.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 {
-public class XSQLBluePrint implements DatabaseMetaData {
+ private static final long serialVersionUID = 1L;
- public static final String CACHE_FILE_NAME = "BluePrintCache.dat";
+ 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 final Map<String, XSQLBluePrintNode> tableNameToBluePrint = new HashMap<>();
+ private final Map<String, Map<String, XSQLBluePrintNode>> 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();
return result.toString();
}
- public XSQLBluePrint() {
+ XSQLBluePrint() {
+
+ }
+
+ public void save() {
+ ObjectOutputStream out = null;
+ try {
+ out = new ObjectOutputStream(new DataOutputStream(
+ new FileOutputStream(CACHE_FILE_NAME)));
+ out.writeObject(this);
+ } catch (Exception err) {
+ err.printStackTrace();
+ } finally {
+ try {
+ out.close();
+ } catch (Exception err) {
+ }
+ }
+ }
+
+ 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));
+ 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 {
+ @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);
}
public DatabaseMetaData getProxy() {
if (myProxy == null) {
try {
- myProxy = (DatabaseMetaData) Proxy
- .newProxyInstance(getClass().getClassLoader(),
- new Class[] {DatabaseMetaData.class},
+ myProxy = (DatabaseMetaData) Proxy.newProxyInstance(getClass()
+ .getClassLoader(),
+ new Class[] { DatabaseMetaData.class },
new NQLBluePrintProxy());
} catch (Exception err) {
err.printStackTrace();
return myProxy;
}
- /*
- public void loadBluePrintCache(String hostName) {
- try {
- ObjectInputStream in = new ObjectInputStream(
- new FileInputStream(hostName + "-" + CACHE_FILE_NAME));
- cache = (Map) in.readObject();
- in.close();
- cacheLoadedSuccessfuly = true;
- } catch (Exception err) {
- //err.printStackTrace();
+ public XSQLBluePrintNode[] getBluePrintNodeByODLTableName(
+ final String odlTableName) {
+ Map<String, XSQLBluePrintNode> map = this.odlNameToBluePrint
+ .get(odlTableName);
+ if (map == null) {
+ return null;
}
- }*/
-
- public XSQLBluePrintNode[] getBluePrintNodeByODLTableName(String odlTableName) {
- Map<String,XSQLBluePrintNode> map = this.odlNameToBluePrint.get(odlTableName);
- if(map==null) return null;
return map.values().toArray(new XSQLBluePrintNode[map.size()]);
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().endsWith(tableName.toLowerCase())) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .endsWith(tableName.toLowerCase())) {
return n;
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().equals(tableName.toLowerCase())) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .equals(tableName.toLowerCase())) {
return n;
}
}
for (XSQLBluePrintNode n : tableNameToBluePrint.values()) {
- if (n.getBluePrintNodeName().toLowerCase().indexOf(tableName.toLowerCase())!= -1) {
+ if (n.getBluePrintNodeName().toLowerCase()
+ .indexOf(tableName.toLowerCase()) != -1) {
return n;
}
}
return null;
}
-
public boolean isCacheLoaded() {
return cacheLoadedSuccessfuly;
}
- private static Map<Class, Set<Class>> superClassMap = new HashMap<Class, Set<Class>>();
+ private static Map<Class<?>, Set<Class<?>>> superClassMap = new HashMap<>();
- public static Set<Class> getInheritance(Class myObjectClass,
- Class returnType) {
+ public static Set<Class<?>> getInheritance(final Class<?> myObjectClass,
+ final Class<?> returnType) {
if (returnType != null && myObjectClass.equals(returnType)) {
- return new HashSet<Class>();
+ return new HashSet<>();
}
- Set<Class> result = superClassMap.get(myObjectClass);
+ Set<Class<?>> result = superClassMap.get(myObjectClass);
if (result != null) {
return result;
}
- result = new HashSet<Class>();
+ 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();
return result;
}
- public static Set<Class> collectInterfaces(Class cls) {
- Set<Class> result = new HashSet();
- Class myInterfaces[] = cls.getInterfaces();
+ public static Set<Class<?>> collectInterfaces(final Class<?> cls) {
+ Set<Class<?>> 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));
}
return result;
}
- 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);
+ 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<String, XSQLBluePrintNode> 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);
}
public List<String> getAllTableNames() {
- List<String> names = new ArrayList<String>();
+ List<String> names = new ArrayList<>();
for (XSQLBluePrintNode n : this.tableNameToBluePrint.values()) {
if (!n.isModule() && !n.getColumns().isEmpty()) {
names.add(n.getBluePrintNodeName());
}
- public List<String> getInterfaceNames(XSQLBluePrintNode node) {
+ public List<String> getInterfaceNames(final XSQLBluePrintNode node) {
Set<XSQLBluePrintNode> children = node.getChildren();
- List<String> names = new ArrayList<String>();
+ List<String> names = new ArrayList<>();
for (XSQLBluePrintNode n : children) {
if (!n.isModule() && !n.getColumns().isEmpty()) {
names.add(n.toString());
}
@Override
- public boolean deletesAreDetected(int type) throws SQLException {
+ public boolean deletesAreDetected(final int type) throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public ResultSet getAttributes(String catalog, String schemaPattern,
- String typeNamePattern, String attributeNamePattern)
- throws SQLException {
+ 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;
}
}
@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)
- throws SQLException {
+ public ResultSet getColumns(final String catalog, final String schemaPattern,
+ final String tableNamePattern, final String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public ResultSet getCrossReference(String parentCatalog,
- String parentSchema, String parentTable, String foreignCatalog,
- String foreignSchema, String foreignTable) throws SQLException {
+ 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;
}
@Override
public String getDatabaseProductName() throws SQLException {
- return "VNE Query Language";
+ return "OpenDayLight";
}
@Override
}
@Override
- public ResultSet getExportedKeys(String catalog, String schema,
- String table)
- throws SQLException {
+ public ResultSet getExportedKeys(final String catalog, final String schema, final String table)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
}
@Override
- public ResultSet getFunctionColumns(String catalog, String schemaPattern,
- String functionNamePattern, String columnNamePattern)
- throws SQLException {
+ 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;
}
}
@Override
- public ResultSet getImportedKeys(String catalog, String schema,
- String table)
- throws SQLException {
+ 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;
}
}
@Override
- public ResultSet getPrimaryKeys(String catalog, String schema, String table)
- throws SQLException {
+ 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)
- throws SQLException {
+ 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;
}
}
@Override
- public ResultSet getSchemas(String catalog, String schemaPattern)
- throws SQLException {
+ public ResultSet getSchemas(final String catalog, final String schemaPattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
}
@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;
}
}
@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);
}
}
@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;
}
}
@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;
}
}
@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;
}
}
@Override
- public boolean supportsCatalogsInPrivilegeDefinitions()
- throws SQLException {
+ public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public boolean supportsConvert(int fromType, int toType)
- throws SQLException {
+ public boolean supportsConvert(final int fromType, final int toType)
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions()
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supportsDataManipulationTransactionsOnly()
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
- public boolean supportsDifferentTableCorrelationNames()
- throws SQLException {
+ public boolean supportsDifferentTableCorrelationNames() throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public boolean supportsResultSetConcurrency(int type, int concurrency)
- throws SQLException {
+ public boolean supportsResultSetConcurrency(final int type, final int concurrency)
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
@Override
- public boolean supportsResultSetHoldability(int holdability)
- throws SQLException {
+ 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;
}
}
@Override
- public boolean supportsStoredFunctionsUsingCallSyntax()
- throws SQLException {
+ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public boolean supportsTransactionIsolationLevel(int level)
- throws SQLException {
+ public boolean supportsTransactionIsolationLevel(final int level)
+ throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@Override
- public boolean updatesAreDetected(int type) throws SQLException {
+ public boolean updatesAreDetected(final int type) throws SQLException {
// TODO Auto-generated method stub
return false;
}
}
@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> T unwrap(Class<T> iface) throws SQLException {
+ public <T> T unwrap(final Class<T> iface) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
- public ResultSet getPseudoColumns(String catalog, String schemaPattern,
- String tableNamePattern, String columnNamePattern)
- throws SQLException {
+ public ResultSet getPseudoColumns(final String catalog, final String schemaPattern,
+ final String tableNamePattern, final String columnNamePattern)
+ throws SQLException {
// TODO Auto-generated method stub
return null;
}
// TODO Auto-generated method stub
return false;
}
-
}