+/*
+ * 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.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<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 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 {
}
}
- 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));
}
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);
}
public XSQLBluePrintNode[] getBluePrintNodeByODLTableName(
- String odlTableName) {
+ final String odlTableName) {
Map<String, XSQLBluePrintNode> map = this.odlNameToBluePrint
.get(odlTableName);
- if (map == null)
+ if (map == null) {
return null;
+ }
return map.values().toArray(new XSQLBluePrintNode[map.size()]);
}
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<>();
return result;
}
- public static Set<Class<?>> collectInterfaces(Class<?> cls) {
+ public static Set<Class<?>> collectInterfaces(final Class<?> cls) {
Set<Class<?>> result = new HashSet<>();
Class<?> myInterfaces[] = cls.getInterfaces();
if (myInterfaces != null) {
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) {
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)
+ 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)
+ 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 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;
}
@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;
}
}
@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;
}
}
@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;
}
}
@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;
}
@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 supportsConvert(int fromType, int toType)
+ public boolean supportsConvert(final int fromType, final int toType)
throws SQLException {
// TODO Auto-generated method stub
return false;
}
@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;
}
}
@Override
- public boolean supportsTransactionIsolationLevel(int level)
+ 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)
+ 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;
}
-
}