public static void copy(IMetaStore from, IMetaStore to, boolean overwrite) throws MetaStoreException { // get all of the namespace in the "from" metastore List<String> namespaces = from.getNamespaces(); for (String namespace : namespaces) { // create the sme namespace in the "to" metastore try { to.createNamespace(namespace); } catch (MetaStoreNamespaceExistsException e) { // already there } // get all of the element types defined in this namespace List<IMetaStoreElementType> elementTypes = from.getElementTypes(namespace); for (IMetaStoreElementType elementType : elementTypes) { // See if it's already there IMetaStoreElementType existingType = to.getElementTypeByName(namespace, elementType.getName()); if (existingType != null) { if (overwrite) { // we looked it up by name, but need to update it by id elementType.setId(existingType.getId()); to.updateElementType(namespace, elementType); } else { elementType = existingType; } } else { // create the elementType in the "to" metastore to.createElementType(namespace, elementType); } // get all of the elements defined for this type List<IMetaStoreElement> elements = from.getElements(namespace, elementType); for (IMetaStoreElement element : elements) { IMetaStoreElement existingElement = to.getElementByName(namespace, elementType, element.getName()); if (existingElement != null) { element.setId(existingElement.getId()); if (overwrite) { to.updateElement(namespace, elementType, existingElement.getId(), element); } } else { to.createElement(namespace, elementType, element); } } } } }
/** * Get a sorted list of element names for the specified element type in the given namespace. * * @param namespace * @param metaStore * @param elementType * @return * @throws MetaStoreException */ public String[] getElementNames( String namespace, IMetaStore metaStore, IMetaStoreElementType elementType) throws MetaStoreException { List<String> names = new ArrayList<String>(); List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType); for (IMetaStoreElement element : elements) { names.add(element.getName()); } // Alphabetical sort // Collections.sort(names); return names.toArray(new String[names.size()]); }