Package org.teiid.query.metadata

Examples of org.teiid.query.metadata.TransformationMetadata


      assertEquals("Procedure 'y' is ambiguous, use the fully qualified name instead", e.getMessage()); //$NON-NLS-1$
    }
  }
 
  @Test public void testProcVisibility() throws Exception {
    TransformationMetadata tm = exampleTransformationMetadata();
    VDBMetaData vdb = tm.getVdbMetaData();
    vdb.getModel("x").setVisible(false);
    StoredProcedureInfo spi = tm.getStoredProcedureInfoForProcedure("y"); //$NON-NLS-1$
    assertEquals("x1.y", spi.getProcedureCallableName());
    spi = tm.getStoredProcedureInfoForProcedure("x.y"); //$NON-NLS-1$
    assertEquals("x.y", spi.getProcedureCallableName());
  }
View Full Code Here


   
    vdb.addModel(buildModel("x"));
    vdb.addModel(buildModel("x1"));
    vdb.addModel(buildModel("y"));
   
    return new TransformationMetadata(vdb, cms, resources, FakeMetadataFactory.SFM.getSystemFunctions(), null);
  }
View Full Code Here

    ModelMetaData model2 = new ModelMetaData();
    model2.setName("x");
    model2.setVisible(true);
    vdb.addModel(model2);   

    TransformationMetadata tm = new TransformationMetadata(vdb, cms, null, FakeMetadataFactory.SFM.getSystemFunctions(), null);
    Collection result = tm.getGroupsForPartialName("y"); //$NON-NLS-1$
    assertEquals(2, result.size());

    FakeMetadataFactory.buildWorkContext(tm, vdb);

    model.setVisible(false);

    tm = new TransformationMetadata(vdb, cms, null, FakeMetadataFactory.SFM.getSystemFunctions(), null);
    result = tm.getGroupsForPartialName("y"); //$NON-NLS-1$
    assertEquals(1, result.size());
  }
View Full Code Here

    result = tm.getGroupsForPartialName("y"); //$NON-NLS-1$
    assertEquals(1, result.size());
  }
 
  @Test public void testElementId() throws Exception {
    TransformationMetadata tm = exampleTransformationMetadata();
    tm.getElementID("x.FoO.coL");
  }
View Full Code Here

    TransformationMetadata tm = exampleTransformationMetadata();
    tm.getElementID("x.FoO.coL");
  }
 
  @Test public void testRelativeSchemas() throws Exception {
    TransformationMetadata tm = exampleTransformationMetadata();
    assertEquals(1, tm.getXMLSchemas(tm.getGroupID("x1.doc")).size());
  }
View Full Code Here

    }

  public static void alterView(VDBMetaData vdb, Table t, String sql) {
    t.setSelectTransformation(sql);
    t.setLastModified(System.currentTimeMillis());
    TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
    indexMetadata.addToMetadataCache(t, "transformation/"+SQLConstants.Reserved.SELECT, null); //$NON-NLS-1$
  }
View Full Code Here

  }

  public static void alterProcedureDefinition(VDBMetaData vdb, Procedure p, String sql) {
    p.setQueryPlan(sql);
    p.setLastModified(System.currentTimeMillis());
    TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
    indexMetadata.addToMetadataCache(p, "transformation/"+StoredProcedure.class.getSimpleName().toUpperCase(), null); //$NON-NLS-1$
  }
View Full Code Here

      } else {
        t.setUpdatePlanEnabled(enabled);
      }
      break;
    }
    TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
    indexMetadata.addToMetadataCache(t, "transformation/"+event, null); //$NON-NLS-1$
    t.setLastModified(System.currentTimeMillis());
  }
View Full Code Here

      DQPWorkContext workContext) throws TeiidComponentException, TeiidProcessingException {
    String vdbName = workContext.getVdbName();
    int vdbVersion = workContext.getVdbVersion();
    VDBMetaData vdb = workContext.getVDB();
    CompositeMetadataStore metadata = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
    TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
    Collection rows = new ArrayList();
    int oid = 1;
    if (command instanceof Query) {
      Query query = (Query)command;
      UnaryFromClause ufc = (UnaryFromClause)query.getFrom().getClauses().get(0);
      GroupSymbol group = ufc.getGroup();
      if (StringUtil.startsWithIgnoreCase(group.getNonCorrelationName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
        final SystemAdminTables sysTable = SystemAdminTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
        switch (sysTable) {
        case MATVIEWS:
          for (Schema schema : getVisibleSchemas(vdb, metadata)) {
            for (Table table : schema.getTables().values()) {
              if (!table.isMaterialized()) {
                continue;
              }
              String targetSchema = null;
              String matTableName = null;
              String state = null;
              Timestamp updated = null;
              Integer cardinaltity = null;
              Boolean valid = null;
              if (table.getMaterializedTable() == null) {
                TempTableStore globalStore = context.getGlobalTableStore();
                matTableName = RelationalPlanner.MAT_PREFIX+table.getFullName().toUpperCase();
                MatTableInfo info = globalStore.getMatTableInfo(matTableName);
                valid = info.isValid();
                state = info.getState().name();
                updated = info.getUpdateTime()==-1?null:new Timestamp(info.getUpdateTime());
                TempMetadataID id = globalStore.getMetadataStore().getTempGroupID(matTableName);
                if (id != null) {
                  cardinaltity = id.getCardinality();
                }
                //ttl, pref_mem - not part of proper metadata
              } else {
                Table t = table.getMaterializedTable();
                matTableName = t.getName();
                targetSchema = t.getParent().getName();
              }
              rows.add(Arrays.asList(vdbName, schema.getName(), table.getName(), targetSchema, matTableName, valid, state, updated, cardinaltity));
            }
          }
          break;
        case VDBRESOURCES:
          String[] filePaths = indexMetadata.getVDBResourcePaths();
              for (String filePath : filePaths) {
                rows.add(Arrays.asList(filePath, new BlobType(indexMetadata.getVDBResourceAsBlob(filePath))));
              }
          break;
        }
        return new CollectionTupleSource(rows.iterator());
      }
      final SystemTables sysTable = SystemTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
      switch (sysTable) {
      case DATATYPES:
        for (Datatype datatype : metadata.getDatatypes()) {
          rows.add(Arrays.asList(datatype.getName(), datatype.isBuiltin(), datatype.isBuiltin(), datatype.getName(), datatype.getJavaClassName(), datatype.getScale(),
              datatype.getLength(), datatype.getNullType().toString(), datatype.isSigned(), datatype.isAutoIncrement(), datatype.isCaseSensitive(), datatype.getPrecisionLength(),
              datatype.getRadix(), datatype.getSearchType().toString(), datatype.getUUID(), datatype.getRuntimeTypeName(), datatype.getBasetypeName(), datatype.getAnnotation(), oid++));
        }
        break;
      case VIRTUALDATABASES:
        rows.add(Arrays.asList(vdbName, vdbVersion));
        break;
      case SCHEMAS:
        for (Schema model : getVisibleSchemas(vdb, metadata)) {
          rows.add(Arrays.asList(vdbName, model.getName(), model.isPhysical(), model.getUUID(), model.getAnnotation(), model.getPrimaryMetamodelUri(), oid++));
        }
        break;
      case PROCEDURES:
        for (Schema schema : getVisibleSchemas(vdb, metadata)) {
          for (Procedure proc : schema.getProcedures().values()) {
            rows.add(Arrays.asList(vdbName, proc.getParent().getName(), proc.getName(), proc.getNameInSource(), proc.getResultSet() != null, proc.getUUID(), proc.getAnnotation(), oid++));
          }
        }
        break;
      case PROCEDUREPARAMS:
        for (Schema schema : getVisibleSchemas(vdb, metadata)) {
          for (Procedure proc : schema.getProcedures().values()) {
            for (ProcedureParameter param : proc.getParameters()) {
              Datatype dt = param.getDatatype();
              rows.add(Arrays.asList(vdbName, proc.getParent().getName(), proc.getName(), param.getName(), dt!=null?dt.getRuntimeTypeName():null, param.getPosition(), param.getType().toString(), param.isOptional(),
                  param.getPrecision(), param.getLength(), param.getScale(), param.getRadix(), param.getNullType().toString(), param.getUUID(), param.getAnnotation(), oid++));
            }
            if (proc.getResultSet() != null) {
              for (Column param : proc.getResultSet().getColumns()) {
                Datatype dt = param.getDatatype();
                rows.add(Arrays.asList(vdbName, proc.getParent().getName(), proc.getName(), param.getName(), dt!=null?dt.getRuntimeTypeName():null, param.getPosition(), "ResultSet", false, //$NON-NLS-1$
                    param.getPrecision(), param.getLength(), param.getScale(), param.getRadix(), param.getNullType().toString(), param.getUUID(), param.getAnnotation(), oid++));
              }
            }
          }
        }
        break;
      case PROPERTIES: //TODO: consider storing separately in the metadatastore
        Collection<AbstractMetadataRecord> records = getAllPropertiedObjects(metadata, getVisibleSchemas(vdb, metadata));
        for (AbstractMetadataRecord record : records) {
          for (Map.Entry<String, String> entry : record.getProperties().entrySet()) {
            String value = entry.getValue();
            Clob clobValue = null;
            if (value != null) {
              try {
                clobValue = new ClobType(new SerialClob(value.toCharArray()));
              } catch (SQLException e) {
                throw new TeiidProcessingException(e);
              }
            }
            rows.add(Arrays.asList(entry.getKey(), entry.getValue(), record.getUUID(), oid++, clobValue));
          }
        }
        break;
      default:
        for (Schema schema : getVisibleSchemas(vdb, metadata)) {
          for (Table table : schema.getTables().values()) {
            switch (sysTable) {
            case TABLES:
              rows.add(Arrays.asList(vdbName, schema.getName(), table.getName(), table.getTableType().toString(), table.getNameInSource(),
                  table.isPhysical(), table.supportsUpdate(), table.getUUID(), table.getCardinality(), table.getAnnotation(), table.isSystem(), table.isMaterialized(), oid++));
              break;
            case COLUMNS:
              for (Column column : table.getColumns()) {
                Datatype dt = column.getDatatype();
                rows.add(Arrays.asList(vdbName, schema.getName(), table.getName(), column.getName(), column.getPosition(), column.getNameInSource(),
                    dt!=null?dt.getRuntimeTypeName():null, column.getScale(), column.getLength(), column.isFixedLength(), column.isSelectable(), column.isUpdatable(),
                    column.isCaseSensitive(), column.isSigned(), column.isCurrency(), column.isAutoIncremented(), column.getNullType().toString(), column.getMinimumValue(),
                    column.getMaximumValue(), column.getDistinctValues(), column.getNullValues(), column.getSearchType().toString(), column.getFormat(),
                    column.getDefaultValue(), dt!=null?dt.getJavaClassName():null, column.getPrecision(),
                    column.getCharOctetLength(), column.getRadix(), column.getUUID(), column.getAnnotation(), oid++));
              }
              break;
            case KEYS:
              for (KeyRecord key : table.getAllKeys()) {
                rows.add(Arrays.asList(vdbName, table.getParent().getName(), table.getName(), key.getName(), key.getAnnotation(), key.getNameInSource(), key.getType().toString(),
                    false, (key instanceof ForeignKey)?((ForeignKey)key).getUniqueKeyID():null, key.getUUID(), oid++));
              }
              break;
            case KEYCOLUMNS:
              for (KeyRecord key : table.getAllKeys()) {
                int postition = 1;
                for (Column column : key.getColumns()) {
                  rows.add(Arrays.asList(vdbName, schema.getName(), table.getName(), column.getName(), key.getName(), key.getType().toString(),
                      (key instanceof ForeignKey)?((ForeignKey)key).getUniqueKeyID():null, key.getUUID(), postition++, oid++));
                }
              }
              break;
            case REFERENCEKEYCOLUMNS:
              for (ForeignKey key : table.getForeignKeys()) {
                short postition = 0;
                for (Column column : key.getColumns()) {
                  Table pkTable = key.getPrimaryKey().getParent();
                  rows.add(Arrays.asList(vdbName, pkTable.getParent().getName(), pkTable.getName(), key.getPrimaryKey().getColumns().get(postition).getName(), vdbName, schema.getName(), table.getName(), column.getName(),
                      ++postition, DatabaseMetaData.importedKeyNoAction, DatabaseMetaData.importedKeyNoAction, key.getName(), key.getPrimaryKey().getName(), DatabaseMetaData.importedKeyInitiallyDeferred));
                }
              }
              break;
            }
          }
        }
        break;
      }
    } else {         
      StoredProcedure proc = (StoredProcedure)command;   
      if (StringUtil.startsWithIgnoreCase(proc.getProcedureCallableName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
        final SystemAdminProcs sysProc = SystemAdminProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
        switch (sysProc) {
        case SETPROPERTY:
          try {
            String uuid = (String)((Constant)proc.getParameter(2).getExpression()).getValue();
            String key = (String)((Constant)proc.getParameter(3).getExpression()).getValue();
            Clob value = (Clob)((Constant)proc.getParameter(4).getExpression()).getValue();
            String strVal = null;
            String result = null;
            if (value != null) {
              if (value.length() > MAX_VALUE_LENGTH) {
                throw new TeiidProcessingException(QueryPlugin.Util.getString("DataTierManagerImpl.max_value_length", MAX_VALUE_LENGTH)); //$NON-NLS-1$
              }
              strVal = ObjectConverterUtil.convertToString(value.getCharacterStream());
            }
            AbstractMetadataRecord target = getByUuid(metadata, uuid);
            if (target == null) {
              throw new TeiidProcessingException(QueryPlugin.Util.getString("DataTierManagerImpl.unknown_uuid", uuid)); //$NON-NLS-1$
            }
            if (this.metadataRepository != null) {
              this.metadataRepository.setProperty(vdbName, vdbVersion, target, key, strVal);
            }
            result = target.setProperty(key, strVal);
            if (eventDistributor != null) {
              eventDistributor.setProperty(vdbName, vdbVersion, uuid, key, strVal);
            }
            if (result == null) {
              rows.add(Arrays.asList((Clob)null));
            } else {
              rows.add(Arrays.asList(new ClobType(new SerialClob(result.toCharArray()))));
            }
            return new CollectionTupleSource(rows.iterator());
          } catch (SQLException e) {
            throw new TeiidProcessingException(e);
          } catch (IOException e) {
            throw new TeiidProcessingException(e);
          }
        }
        Table table = indexMetadata.getGroupID((String)((Constant)proc.getParameter(1).getExpression()).getValue());
        switch (sysProc) {
        case SETCOLUMNSTATS:
          String columnName = (String)((Constant)proc.getParameter(2).getExpression()).getValue();
          Column c = null;
          for (Column col : table.getColumns()) {
            if (col.getName().equalsIgnoreCase(columnName)) {
              c = col;
              break;
            }
          }
          if (c == null) {
            throw new TeiidProcessingException(columnName + TransformationMetadata.NOT_EXISTS_MESSAGE);
          }
          Integer distinctVals = (Integer)((Constant)proc.getParameter(3).getExpression()).getValue();
          Integer nullVals = (Integer)((Constant)proc.getParameter(4).getExpression()).getValue();
          String max = (String) ((Constant)proc.getParameter(5).getExpression()).getValue();
          String min = (String) ((Constant)proc.getParameter(6).getExpression()).getValue();
          ColumnStats columnStats = new ColumnStats();
          columnStats.setDistinctValues(distinctVals);
          columnStats.setNullValues(nullVals);
          columnStats.setMaximumValue(max);
          columnStats.setMinimumValue(min);
          if (this.metadataRepository != null) {
            this.metadataRepository.setColumnStats(vdbName, vdbVersion, c, columnStats);
          }
          c.setColumnStats(columnStats);
          if (eventDistributor != null) {
            eventDistributor.setColumnStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), columnName, columnStats);
          }
          break;
        case SETTABLESTATS:
          Constant val = (Constant)proc.getParameter(2).getExpression();
          int cardinality = (Integer)val.getValue();
          TableStats tableStats = new TableStats();
          tableStats.setCardinality(cardinality);
          if (this.metadataRepository != null) {
            this.metadataRepository.setTableStats(vdbName, vdbVersion, table, tableStats);
          }
          table.setCardinality(cardinality);
          if (eventDistributor != null) {
            eventDistributor.setTableStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), tableStats);
          }
          break;
        }
        table.setLastModified(System.currentTimeMillis());
        return new CollectionTupleSource(rows.iterator());
      }
      final SystemProcs sysTable = SystemProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
      switch (sysTable) {
      case GETXMLSCHEMAS:
        try {
          Object groupID = indexMetadata.getGroupID((String)((Constant)proc.getParameter(1).getExpression()).getValue());
          List<SQLXMLImpl> schemas = indexMetadata.getXMLSchemas(groupID);
          for (SQLXMLImpl schema : schemas) {
            rows.add(Arrays.asList(new XMLType(schema)));
          }
        } catch (QueryMetadataException e) {
          throw new TeiidProcessingException(e);
View Full Code Here

      vdbMetaData.addModel(FakeMetadataFactory.createModel(schema.getName(), schema.isPhysical()));
      if (!schema.getFunctions().isEmpty()) {
        udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true));
      }
    }
      return new TransformationMetadata(vdbMetaData, store, null, FakeMetadataFactory.SFM.getSystemFunctions(), udfs);
  }
View Full Code Here

TOP

Related Classes of org.teiid.query.metadata.TransformationMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.