public void deleteMetaClass(MetaClass meta) { ClassInfo classInfo = map.remove(meta.getName()); metaClassMap.remove(meta.getName()); // update class info that referenced by deleted meta for (MetaRelationship outReference : classInfo.getToReference()) { ClassInfo i = map.get(outReference.getRefDataType()); if (i != null && !i.getFromReference().isEmpty()) { i.getFromReference().remove(outReference); } } // update ancestors' descendants List<String> ancestors = meta.getAncestors(); if (ancestors != null) { for (String ancestor : ancestors) { ClassInfo parentInfo = map.get(ancestor); if (parentInfo != null) { List<String> descendants = new ArrayList<String>(parentInfo.getDescendants()); descendants.remove(meta.getName()); parentInfo.setDescendants(descendants); } } } }
info = new ClassInfo(); info.setToReference(toReferences); map.put(m.getName(), info); } else { List<MetaRelationship> oldOuts = info.getToReference(); info.setToReference(toReferences); for (MetaRelationship mr : oldOuts) { if (i != null && !i.getFromReference().isEmpty()) { i.getFromReference().remove(mr); ClassInfo i = map.get(ancestor); if (i == null) { i = new ClassInfo(); map.put(ancestor, i); if (!i.getDescendants().contains(m.getName())) { List<String> old = i.getDescendants(); ArrayList<String> n = new ArrayList<String>(old.size() + 1); n.addAll(old); n.add(m.getName()); i.setDescendants(n); i = new ClassInfo(); map.put(refName, i); if (!i.getFromReference().contains(to)) { List<MetaRelationship> old = i.getFromReference(); List<MetaRelationship> n = new ArrayList<MetaRelationship>(old.size() + 1);
public List<MetaClass> getDescendants(MetaClass m) { ClassInfo info = map.get(m.getName()); if (info == null) { throw new MetaDataException(MetaErrCodeEnum.META_CLASS_NOT_FOUND_IN_GRAPH, "can not find metaclass in graph: " + m.getName()); } List<String> metas = info.getDescendants(); if (metas.isEmpty()) { return Collections.emptyList(); } List<MetaClass> result = new ArrayList<MetaClass>(metas.size()); for (String name : metas) { result.add(metaClassMap.get(name)); } return result; }
public List<MetaRelationship> getFromReference(MetaClass m) { ClassInfo info = map.get(m.getName()); if (info == null) { throw new MetaDataException(MetaErrCodeEnum.META_CLASS_NOT_FOUND_IN_GRAPH, "can not find metaclass in graph: " + m.getName()); } return info.getFromReference(); }
public List<MetaRelationship> getToReference(MetaClass m) { ClassInfo info = map.get(m.getName()); if (info == null) { throw new MetaDataException(MetaErrCodeEnum.META_CLASS_NOT_FOUND_IN_GRAPH, "can not find metaclass in graph: " + m.getName()); } return info.getToReference(); }