Exemple #1
0
  public static void marshell(VDBMetaData vdb, OutputStream out)
      throws XMLStreamException, IOException {
    XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(out);

    writer.writeStartDocument();
    writer.writeStartElement(Element.VDB.getLocalName());
    writeAttribute(writer, Element.NAME.getLocalName(), vdb.getName());
    writeAttribute(writer, Element.VERSION.getLocalName(), String.valueOf(vdb.getVersion()));

    if (vdb.getDescription() != null) {
      writeElement(writer, Element.DESCRIPTION, vdb.getDescription());
    }
    writeProperties(writer, vdb.getProperties());

    for (VDBImport vdbImport : vdb.getVDBImports()) {
      writer.writeStartElement(Element.IMPORT_VDB.getLocalName());
      writeAttribute(writer, Element.NAME.getLocalName(), vdbImport.getName());
      writeAttribute(
          writer, Element.VERSION.getLocalName(), String.valueOf(vdbImport.getVersion()));
      writeAttribute(
          writer,
          Element.IMPORT_POLICIES.getLocalName(),
          String.valueOf(vdbImport.isImportDataPolicies()));
      writer.writeEndElement();
    }

    // models
    Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
    for (ModelMetaData model : models) {
      writeModel(writer, model);
    }

    // override translators
    for (Translator translator : vdb.getOverrideTranslators()) {
      writeTranslator(writer, translator);
    }

    // data-roles
    for (DataPolicy dp : vdb.getDataPolicies()) {
      writeDataPolicy(writer, dp);
    }

    // entry
    // designer only
    for (EntryMetaData em : vdb.getEntries()) {
      writer.writeStartElement(Element.ENTRY.getLocalName());
      writeAttribute(writer, Element.PATH.getLocalName(), em.getPath());
      if (em.getDescription() != null) {
        writeElement(writer, Element.DESCRIPTION, em.getDescription());
      }
      writeProperties(writer, em.getProperties());
      writer.writeEndElement();
    }

    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    out.close();
  }
Exemple #2
0
 /**
  * Create an unauthenticated session
  *
  * @param userName
  * @param app
  * @param vdb
  * @return
  */
 public static SessionMetadata createTemporarySession(
     String userName, String app, VDBMetaData vdb) {
   long creationTime = System.currentTimeMillis();
   SessionMetadata newSession = new SessionMetadata();
   newSession.setSessionToken(new SessionToken(userName));
   newSession.setSessionId(newSession.getSessionToken().getSessionID());
   newSession.setUserName(userName);
   newSession.setCreatedTime(creationTime);
   newSession.setApplicationName(app);
   newSession.setVDBName(vdb.getName());
   newSession.setVDBVersion(vdb.getVersion());
   newSession.setVdb(vdb);
   newSession.setEmbedded(true);
   return newSession;
 }
Exemple #3
0
  private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
    if (vdb.getVDBImports().isEmpty()) {
      this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
      return;
    }

    VDBMetaData newMergedVDB = this.vdb.clone();
    ConnectorManagerRepository mergedRepo = this.cmr;
    if (!this.cmr.isShared()) {
      mergedRepo = new ConnectorManagerRepository();
      mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
    }
    newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
    ClassLoader[] toSearch = new ClassLoader[vdb.getVDBImports().size() + 1];
    toSearch[0] = this.vdb.getAttachment(ClassLoader.class);
    this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
    newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
    int i = 1;
    for (VDBImport vdbImport : vdb.getVDBImports()) {
      CompositeVDB importedVDB =
          vdbRepository.getCompositeVDB(new VDBKey(vdbImport.getName(), vdbImport.getVersion()));
      if (importedVDB == null) {
        throw new VirtualDatabaseException(
            RuntimePlugin.Event.TEIID40083,
            RuntimePlugin.Util.gs(
                RuntimePlugin.Event.TEIID40083,
                vdb.getName(),
                vdb.getVersion(),
                vdbImport.getName(),
                vdbImport.getVersion()));
      }
      VDBMetaData childVDB = importedVDB.getVDB();
      newMergedVDB.getVisibilityOverrides().putAll(childVDB.getVisibilityOverrides());
      toSearch[i++] = childVDB.getAttachment(ClassLoader.class);
      this.children.put(new VDBKey(childVDB.getName(), childVDB.getVersion()), importedVDB);

      if (vdbImport.isImportDataPolicies()) {
        for (DataPolicy dp : importedVDB.getVDB().getDataPolicies()) {
          DataPolicyMetadata role = (DataPolicyMetadata) dp;
          if (newMergedVDB.addDataPolicy(role) != null) {
            throw new VirtualDatabaseException(
                RuntimePlugin.Event.TEIID40084,
                RuntimePlugin.Util.gs(
                    RuntimePlugin.Event.TEIID40084,
                    vdb.getName(),
                    vdb.getVersion(),
                    vdbImport.getName(),
                    vdbImport.getVersion(),
                    role.getName()));
          }
          if (role.isGrantAll()) {
            role.setSchemas(childVDB.getModelMetaDatas().keySet());
          }
        }
      }

      // add models
      for (ModelMetaData m : childVDB.getModelMetaDatas().values()) {
        if (newMergedVDB.addModel(m) != null) {
          throw new VirtualDatabaseException(
              RuntimePlugin.Event.TEIID40085,
              RuntimePlugin.Util.gs(
                  RuntimePlugin.Event.TEIID40085,
                  vdb.getName(),
                  vdb.getVersion(),
                  vdbImport.getName(),
                  vdbImport.getVersion(),
                  m.getName()));
        }
        newMergedVDB.getImportedModels().add(m.getName());
        String visibilityOverride =
            newMergedVDB.getPropertyValue(m.getName() + ".visible"); // $NON-NLS-1$
        if (visibilityOverride != null) {
          boolean visible = Boolean.valueOf(visibilityOverride);
          newMergedVDB.setVisibilityOverride(m.getName(), visible);
        }
      }
      ConnectorManagerRepository childCmr =
          childVDB.getAttachment(ConnectorManagerRepository.class);
      if (childCmr == null) {
        throw new AssertionError("childVdb had not connector manager repository"); // $NON-NLS-1$
      }
      if (!this.cmr.isShared()) {
        for (Map.Entry<String, ConnectorManager> entry :
            childCmr.getConnectorManagers().entrySet()) {
          if (mergedRepo.getConnectorManagers().put(entry.getKey(), entry.getValue()) != null) {
            throw new VirtualDatabaseException(
                RuntimePlugin.Event.TEIID40086,
                RuntimePlugin.Util.gs(
                    RuntimePlugin.Event.TEIID40086,
                    vdb.getName(),
                    vdb.getVersion(),
                    vdbImport.getName(),
                    vdbImport.getVersion(),
                    entry.getKey()));
          }
        }
      }
    }
    if (toSearch[0] != null) {
      CombinedClassLoader ccl = new CombinedClassLoader(toSearch[0].getParent(), toSearch);
      this.mergedVDB.addAttchment(ClassLoader.class, ccl);
    }
    this.mergedVDB = newMergedVDB;
  }
    @Override
    public void execute(
        VDBMetaData vdb,
        MetadataStore store,
        ValidatorReport report,
        MetadataValidator metadataValidator) {
      IQueryMetadataInterface metadata = vdb.getAttachment(IQueryMetadataInterface.class);
      metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
      for (Schema schema : store.getSchemaList()) {
        if (vdb.getImportedModels().contains(schema.getName())) {
          continue;
        }
        ModelMetaData model = vdb.getModel(schema.getName());
        MetadataFactory mf =
            new MetadataFactory(
                teiidVersion, vdb.getName(), vdb.getVersion(), metadataValidator.typeMap, model) {
              @Override
              protected void setUUID(AbstractMetadataRecord record) {
                if (count >= 0) {
                  count = Integer.MIN_VALUE;
                }
                super.setUUID(record);
              }
            };
        mf.setBuiltinDataTypes(store.getDatatypes());
        for (AbstractMetadataRecord record : schema.getResolvingOrder()) {
          if (record instanceof Table) {
            Table t = (Table) record;
            // no need to verify the transformation of the xml mapping document,
            // as this is very specific and designer already validates it.
            if (t.getTableType() == Table.Type.Document
                || t.getTableType() == Table.Type.XmlMappingClass
                || t.getTableType() == Table.Type.XmlStagingTable) {
              continue;
            }
            if (t.isVirtual() && t.getTableType() != Table.Type.TemporaryTable) {
              if (t.getSelectTransformation() == null) {
                metadataValidator.log(
                    report,
                    model,
                    Messages.gs(Messages.TEIID.TEIID31079, t.getFullName(), model.getName()));
              } else {
                metadataValidator.validate(vdb, model, t, report, metadata, mf);
              }
            }
          } else if (record instanceof Procedure) {
            Procedure p = (Procedure) record;

            boolean test = p.isVirtual();
            if (teiidVersion.isLessThan(Version.TEIID_8_11)) test = test && !p.isFunction();

            if (test) {
              if (p.getQueryPlan() == null) {
                metadataValidator.log(
                    report,
                    model,
                    Messages.gs(Messages.TEIID.TEIID31081, p.getFullName(), model.getName()));
              } else {
                metadataValidator.validate(vdb, model, p, report, metadata, mf);
              }
            }
          }
        }
      }
    }