public static EdmDataServices buildMetadata(MetadataStore metadataStore) {
   try {
     List<EdmSchema.Builder> edmSchemas = new ArrayList<EdmSchema.Builder>();
     buildEntityTypes(metadataStore, edmSchemas);
     buildFunctionImports(metadataStore, edmSchemas);
     buildAssosiationSets(metadataStore, edmSchemas);
     return EdmDataServices.newBuilder().addSchemas(edmSchemas).build();
   } catch (Exception e) {
     throw new TeiidRuntimeException(e);
   }
 }
  public static EdmDataServices buildMetadata(VDBMetaData vdb, MetadataStore metadataStore) {
    try {
      List<EdmSchema.Builder> edmSchemas = new ArrayList<EdmSchema.Builder>();
      for (Schema schema : metadataStore.getSchemaList()) {
        if (isVisible(vdb, schema)) {
          ODataEntitySchemaBuilder.buildEntityTypes(schema, edmSchemas, false);
        }
      }
      for (Schema schema : metadataStore.getSchemaList()) {
        if (isVisible(vdb, schema)) {
          ODataEntitySchemaBuilder.buildFunctionImports(schema, edmSchemas, false);
        }
      }
      for (Schema schema : metadataStore.getSchemaList()) {
        if (isVisible(vdb, schema)) {
          ODataEntitySchemaBuilder.buildAssosiationSets(schema, edmSchemas, false);
        }
      }
      final EdmDataServices edmDataServices =
          EdmDataServices.newBuilder().addSchemas(edmSchemas).build();

      EdmDataServicesDecorator decorator =
          new EdmDataServicesDecorator() {

            @Override
            protected EdmDataServices getDelegate() {
              return edmDataServices;
            }

            public EdmEntitySet findEdmEntitySet(String entitySetName) {
              int idx = entitySetName.indexOf('.');
              if (idx != -1) {
                EdmEntitySet ees = super.findEdmEntitySet(entitySetName);
                if (ees != null) {
                  return ees;
                }
              }
              EdmEntitySet result = null;
              for (EdmSchema schema : this.getSchemas()) {
                for (EdmEntityContainer eec : schema.getEntityContainers()) {
                  for (EdmEntitySet ees : eec.getEntitySets()) {
                    if (ees.getName().equals(entitySetName)) {
                      if (result != null) {
                        throw new NotFoundException(
                            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16017, entitySetName));
                      }
                      result = ees;
                    }
                  }
                }
              }
              return result;
            }

            public EdmFunctionImport findEdmFunctionImport(String functionImportName) {
              int idx = functionImportName.indexOf('.');
              if (idx != -1) {
                EdmFunctionImport efi = super.findEdmFunctionImport(functionImportName);
                if (efi != null) {
                  return efi;
                }
              }
              EdmFunctionImport result = null;
              for (EdmSchema schema : this.getSchemas()) {
                for (EdmEntityContainer eec : schema.getEntityContainers()) {
                  for (EdmFunctionImport efi : eec.getFunctionImports()) {
                    if (efi.getName().equals(functionImportName)) {
                      if (result != null) {
                        throw new NotFoundException(
                            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16017, functionImportName));
                      }
                      result = efi;
                    }
                  }
                }
              }
              return result;
            }
          };

      return decorator;
    } catch (Exception e) {
      throw new TeiidRuntimeException(e);
    }
  }