Пример #1
0
  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);
          }
        }
      }
    }
  }