コード例 #1
0
  @Override
  public void visit(AggregateFunction obj) {
    if (!obj.getParameters().isEmpty()) {
      visitNodes(obj.getParameters());
    }

    if (obj.getName().equals(AggregateFunction.COUNT)) {
      HashMap<String, String> options = new HashMap<String, String>();
      options.put(CountStarIterator.ALIAS, this.currentAlias);
      options.put(CountStarIterator.ENCODING, this.ef.getEncoding());
      IteratorSetting it =
          new IteratorSetting(this.iteratorPriority++, CountStarIterator.class, options);

      // expression expects a column
      Column c = new Column();
      c.setName(this.currentAlias);
      c.setDatatype(
          SystemMetadata.getInstance()
              .getSystemStore()
              .getDatatypes()
              .get("integer")); // $NON-NLS-1$
      c.setProperty(AccumuloMetadataProcessor.CF, this.currentAlias);

      this.scanIterators.add(it);
      this.onGoingExpression.push(c);
    } else if (obj.getName().equals(AggregateFunction.AVG)) {
    } else if (obj.getName().equals(AggregateFunction.SUM)) {
    } else if (obj.getName().equals(AggregateFunction.MIN)) {
    } else if (obj.getName().equals(AggregateFunction.MAX)) {
    } else {
    }
  }
コード例 #2
0
  /**
   * method to execute the supplied query
   *
   * @param query the query object.
   * @param maxBatchSize the max batch size.
   */
  @Override
  public void execute() throws TranslatorException {
    String ctxName = this.searchDetails.getContextName();
    String filter = this.searchDetails.getContextFilter();
    if (ctxName == null || filter == null || this.ctrls == null) {
      throw new TranslatorException(
          "Search context, filter, or controls were null. Cannot execute search."); //$NON-NLS-1$
    }

    ArrayList<Column> attributeList = searchDetails.getElementList();

    // determine if there is an array value to unwrap
    for (int i = 0; i < attributeList.size(); i++) {
      Column col = attributeList.get(i);
      if (Boolean.valueOf(col.getProperty(LDAPExecutionFactory.UNWRAP, false))) {
        if (unwrapPos > -1) {
          throw new TranslatorException(
              LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12014, col, attributeList.get(unwrapPos)));
        }
        unwrapPos = i;
      }
    }

    setRequestControls(null);
    // Execute the search.
    executeSearch();
  }
コード例 #3
0
 static List<String> getColumnNames(List<Column> columns) {
   ArrayList<String> names = new ArrayList<String>();
   for (Column c : columns) {
     names.add(c.getName());
   }
   return names;
 }
コード例 #4
0
  @Test
  public void testEnititySet() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf =
        new MetadataFactory(
            "vdb",
            1,
            "trippin",
            SystemMetadata.getInstance().getRuntimeTypeMap(),
            new Properties(),
            null);

    ArrayList<CsdlProperty> properties = new ArrayList<CsdlProperty>();
    properties.add(
        createProperty("name", EdmPrimitiveTypeKind.String).setMaxLength(25).setNullable(false));
    properties.add(createProperty("dob", EdmPrimitiveTypeKind.DateTimeOffset).setNullable(true));
    properties.add(createProperty("ssn", EdmPrimitiveTypeKind.Int64).setNullable(false));

    CsdlEntityType entityType = new CsdlEntityType();
    entityType.setName("Person");
    entityType.setProperties(properties);
    entityType.setKey(Arrays.asList(new CsdlPropertyRef().setName("ssn")));

    CsdlEntitySet es = createES("Persons", "namespace.Person");

    XMLMetadata metadata = buildXmlMetadata(es, entityType);

    processor.getMetadata(mf, metadata);

    assertNotNull(mf.getSchema().getTable("Persons"));

    Table person = mf.getSchema().getTable("Persons");
    assertEquals(3, person.getColumns().size());

    assertNotNull(person.getColumnByName("name"));
    assertNotNull(person.getColumnByName("dob"));
    assertNotNull(person.getColumnByName("ssn"));

    Column name = person.getColumnByName("name");
    Column dob = person.getColumnByName("dob");
    Column ssn = person.getColumnByName("ssn");

    assertEquals("string", name.getDatatype().getRuntimeTypeName());
    assertEquals("timestamp", dob.getDatatype().getRuntimeTypeName());
    assertEquals("long", ssn.getDatatype().getRuntimeTypeName());

    assertTrue(name.getNullType() == NullType.No_Nulls);
    assertTrue(dob.getNullType() == NullType.Nullable);
    assertTrue(ssn.getNullType() == NullType.No_Nulls);

    assertEquals(25, name.getLength());

    assertNotNull(person.getPrimaryKey());

    assertEquals(1, person.getPrimaryKey().getColumns().size());
    assertEquals("ssn", person.getPrimaryKey().getColumns().get(0).getName());

    assertTrue(person.getForeignKeys().isEmpty());
  }
コード例 #5
0
 private Column addColumn(String name, Class<?> type, Table table, MetadataFactory mf)
     throws Exception {
   if (type == null) {
     throw new Exception(Messages.gs(Messages.TEIID.TEIID31086, name, table.getFullName()));
   }
   Column column =
       mf.addColumn(
           name, DataTypeManagerService.getInstance(teiidVersion).getDataTypeName(type), table);
   column.setUpdatable(table.supportsUpdate());
   return column;
 }
コード例 #6
0
 public boolean isPartOfPrimaryKey(Column column) {
   KeyRecord pk = ((Table) column.getParent()).getPrimaryKey();
   if (pk != null) {
     for (Column col : pk.getColumns()) {
       if (col.getName().equals(column.getName())) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #7
0
ファイル: IonicSQLVisitor.java プロジェクト: rareddy/ionic
  @Override
  public void visit(In obj) {
    visitNode(obj.getLeftExpression());
    Column c = (Column) this.onGoingExpression.pop();

    ArrayList<Object> values = new ArrayList<Object>();
    for (Expression expr : obj.getRightExpressions()) {
      visitNode(expr);
      values.add(this.onGoingExpression.pop().toString());
    }
    this.filterValues.put(c.getName(), values);
  }
コード例 #8
0
ファイル: IonicSQLVisitor.java プロジェクト: rareddy/ionic
 @Override
 public void visit(Comparison obj) {
   if (obj.getOperator() == Operator.EQ) {
     visitNode(obj.getLeftExpression());
     Column c = (Column) this.onGoingExpression.pop();
     visitNode(obj.getRightExpression());
     ArrayList<Object> values = new ArrayList<Object>();
     values.add(this.onGoingExpression.pop().toString());
     this.filterValues.put(c.getName(), values);
   } else {
     this.exceptions.add(new TranslatorException("Only Equality supported"));
   }
 }
コード例 #9
0
ファイル: DSLSearch.java プロジェクト: mathwaa/teiid
  @SuppressWarnings("rawtypes")
  public static List<Object> performSearch(
      Condition where, OrderBy orderby, String cacheName, InfinispanConnection conn)
      throws TranslatorException {

    QueryBuilder qb = getQueryBuilder(cacheName, conn);

    if (orderby != null) {
      List<SortSpecification> sss = orderby.getSortSpecifications();
      for (SortSpecification spec : sss) {
        Expression exp = spec.getExpression();
        Column mdIDElement = ((ColumnReference) exp).getMetadataObject();
        SortOrder so = SortOrder.ASC;
        if (spec.getOrdering().name().equalsIgnoreCase(SortOrder.DESC.name())) {
          so = SortOrder.DESC;
        }
        qb = qb.orderBy(mdIDElement.getSourceName(), so);
      }
    }

    FilterConditionContext fcc = buildQueryFromWhereClause(where, qb, null);

    List<Object> results = null;

    Query query = null;
    if (fcc != null) {
      query = fcc.toBuilder().build();
      results = query.list();

      if (results == null) {
        return Collections.emptyList();
      }

    } else if (orderby != null) {
      query = qb.build();
      results = query.list();
      if (results == null) {
        return Collections.emptyList();
      }

    } else {
      results = new ArrayList<Object>();
      RemoteCache<?, Object> c = (RemoteCache<?, Object>) conn.getCache();
      for (Object id : c.keySet()) {
        results.add(c.get(id));
      }
    }

    return results;
  }
コード例 #10
0
 private boolean keyMatches(List<String> names, KeyRecord record) {
   if (names.size() != record.getColumns().size()) {
     return false;
   }
   Set<String> keyNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
   for (Column c : record.getColumns()) {
     keyNames.add(c.getName());
   }
   for (int i = 0; i < names.size(); i++) {
     if (!keyNames.contains(names.get(i))) {
       return false;
     }
   }
   return true;
 }
コード例 #11
0
ファイル: TestCreateDrop.java プロジェクト: TSurendhar/teiid
 @Test
 public void testForeignTemp() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   create.setOn("source");
   Table t = new Table();
   t.setName("tempTable");
   t.setUUID("tid:0");
   Column c = new Column();
   c.setName("x");
   c.setUUID("tid:0");
   Datatype string = SystemMetadata.getInstance().getRuntimeTypeMap().get("string");
   c.setDatatype(string, true);
   t.addColumn(c);
   c = new Column();
   c.setName("y");
   c.setUUID("tid:0");
   Datatype decimal = SystemMetadata.getInstance().getRuntimeTypeMap().get("decimal");
   c.setDatatype(decimal, true);
   t.addColumn(c);
   t.setCardinality(10000);
   create.setTableMetadata(t);
   helpTest(
       "create foreign temporary table tempTable (x string, y decimal) options (cardinality 10000) on source",
       "CREATE FOREIGN TEMPORARY TABLE tempTable (\n	x string,\n	y bigdecimal\n) OPTIONS (CARDINALITY 10000) ON 'source'",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
コード例 #12
0
  private static HashMap<String, String> buildTableMetadata(
      String tableName, List<Column> columns, String encoding) {
    HashMap<String, String> options = new HashMap<String, String>();
    options.put(EvaluatorIterator.COLUMNS_COUNT, String.valueOf(columns.size()));
    options.put(EvaluatorIterator.TABLENAME, tableName);
    options.put(EvaluatorIterator.ENCODING, encoding);

    for (int i = 0; i < columns.size(); i++) {
      Column column = columns.get(i);
      options.put(EvaluatorIterator.createColumnName(EvaluatorIterator.NAME, i), column.getName());
      if (!SQLStringVisitor.getRecordName(column).equals(AccumuloMetadataProcessor.ROWID)) {
        options.put(
            EvaluatorIterator.createColumnName(EvaluatorIterator.CF, i),
            column.getProperty(AccumuloMetadataProcessor.CF, false));
        if (column.getProperty(AccumuloMetadataProcessor.CQ, false) != null) {
          options.put(
              EvaluatorIterator.createColumnName(EvaluatorIterator.CQ, i),
              column.getProperty(AccumuloMetadataProcessor.CQ, false));
        }
        if (column.getProperty(AccumuloMetadataProcessor.VALUE_IN, false) != null) {
          options.put(
              EvaluatorIterator.createColumnName(EvaluatorIterator.VALUE_IN, i),
              column.getProperty(AccumuloMetadataProcessor.VALUE_IN, false));
        }
      }
      options.put(
          EvaluatorIterator.createColumnName(EvaluatorIterator.DATA_TYPE, i),
          column.getDatatype().getJavaClassName());
    }
    return options;
  }
コード例 #13
0
  @Override
  public void visit(DerivedColumn obj) {
    this.currentAlias = buildAlias(obj.getAlias());
    visitNode(obj.getExpression());

    Column column = (Column) this.onGoingExpression.pop();

    String CF = column.getProperty(AccumuloMetadataProcessor.CF, false);
    String CQ = column.getProperty(AccumuloMetadataProcessor.CQ, false);
    if (CQ != null) {
      this.keybasedColumnMap.put(CF + "/" + CQ, column); // $NON-NLS-1$
    } else {
      this.keybasedColumnMap.put(CF, column);
    }

    // no expressions in select are allowed.
    this.selectColumns.add(column);
  }
コード例 #14
0
ファイル: DSLSearch.java プロジェクト: mathwaa/teiid
  @SuppressWarnings({"rawtypes", "unchecked"})
  public static FilterConditionContext visit(
      In obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); // $NON-NLS-1$

    Expression lhs = obj.getLeftExpression();

    List<Expression> rhsList = obj.getRightExpressions();

    List v = new ArrayList(rhsList.size());
    // = Arrays.asList(1
    boolean createdQuery = false;
    for (Expression expr : rhsList) {

      if (expr instanceof Literal) {
        Literal literal = (Literal) expr;

        Object value = escapeReservedChars(literal.getValue());
        v.add(value);
        createdQuery = true;
      } else {
        throw new TranslatorException(
            InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25052, new Object[] {expr, "IN"}));
      }
    }

    if (createdQuery) {
      Column col = ((ColumnReference) lhs).getMetadataObject();

      if (fcbc == null) {
        if (obj.isNegated()) {
          return queryBuilder.not().having(col.getSourceName()).in(v);
        }
        return queryBuilder.having(col.getSourceName()).in(v);
      }
      if (obj.isNegated()) {
        return fcbc.not().having(col.getSourceName()).in(v);
      }
      return fcbc.having(col.getSourceName()).in(v);
    }
    return null;
  }
コード例 #15
0
ファイル: TestDDLParser.java プロジェクト: vchintal/teiid
  @Test
  public void testAlterTableAddColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(ADD CARDINALITY 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD NULL_VALUE_COUNT 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD FOO 'BAR');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(12, table.getCardinality());
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertEquals("BAR", c.getProperty("FOO", false));
    assertEquals(12, c.getNullValues());
  }
コード例 #16
0
ファイル: TestDDLParser.java プロジェクト: vchintal/teiid
  @Test
  public void testAlterTableRemoveColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer OPTIONS (NULL_VALUE_COUNT 12, FOO 'BAR'), e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP NULL_VALUE_COUNT);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP FOO);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS( ADD x 'y');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertNull(c.getProperty("FOO", false));
    assertEquals(-1, c.getNullValues());
    assertEquals("y", c.getProperty("x", false));
  }
コード例 #17
0
ファイル: DSLSearch.java プロジェクト: mathwaa/teiid
  @SuppressWarnings("rawtypes")
  public static FilterConditionContext visit(
      IsNull obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc) {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IsNull criteria."); // $NON-NLS-1$

    Expression exp = obj.getExpression();
    Column c = ((ColumnReference) exp).getMetadataObject();

    if (fcbc == null) {
      if (obj.isNegated()) {
        return queryBuilder.not().having(c.getSourceName()).isNull();
      }
      return queryBuilder.having(c.getSourceName()).isNull();
    }
    if (obj.isNegated()) {
      return fcbc.not().having(c.getSourceName()).isNull();
    }

    return fcbc.having(c.getSourceName()).isNull();
  }
コード例 #18
0
ファイル: DDLStringVisitor.java プロジェクト: teiid/teiid
 private void addColumns(List<Column> columns, boolean includeType) {
   append(LPAREN);
   boolean first = true;
   for (Column c : columns) {
     if (first) {
       first = false;
     } else {
       append(COMMA).append(SPACE);
     }
     if (includeType) {
       appendColumn(c, true, includeType);
       appendColumnOptions(c);
     } else if (c.getParent() instanceof KeyRecord) {
       // function based column
       append(c.getNameInSource());
     } else {
       append(SQLStringVisitor.escapeSinglePart(c.getName()));
     }
   }
   append(RPAREN);
 }
コード例 #19
0
  static boolean sameColumnSet(KeyRecord recordOne, KeyRecord recordTwo) {

    if (recordOne == null || recordTwo == null) {
      return false;
    }

    List<Column> setOne = recordOne.getColumns();
    List<Column> setTwo = recordTwo.getColumns();

    if (setOne.size() != setTwo.size()) {
      return false;
    }
    for (int i = 0; i < setOne.size(); i++) {
      Column one = setOne.get(i);
      Column two = setTwo.get(i);
      if (!one.getName().equals(two.getName())) {
        return false;
      }
    }
    return true;
  }
コード例 #20
0
ファイル: DSLSearch.java プロジェクト: mathwaa/teiid
  @SuppressWarnings("rawtypes")
  public static FilterConditionContext visit(
      Like obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing LIKE criteria."); // $NON-NLS-1$

    Expression lhs = obj.getLeftExpression();
    Expression rhs = obj.getRightExpression();

    Column c = null;
    Expression literalExp = null;
    if (lhs instanceof ColumnReference) {
      c = ((ColumnReference) lhs).getMetadataObject();
      literalExp = rhs;
    } else {
      c = ((ColumnReference) rhs).getMetadataObject();
      literalExp = lhs;
    }

    String value = null;
    if (literalExp instanceof Literal) {

      value = (String) escapeReservedChars(((Literal) literalExp).getValue());

      if (fcbc == null) {
        if (obj.isNegated()) {
          return queryBuilder.not().having(c.getSourceName()).like(value);
        }
        return queryBuilder.having(c.getSourceName()).like(value);
      }
      if (obj.isNegated()) {
        return fcbc.not().having(c.getSourceName()).like(value);
      }

      return fcbc.having(c.getSourceName()).like(value);
    }
    throw new TranslatorException(
        InfinispanPlugin.Util.gs(
            InfinispanPlugin.Event.TEIID25052, new Object[] {literalExp.toString(), "LIKE"}));
  }
コード例 #21
0
ファイル: DDLStringVisitor.java プロジェクト: teiid/teiid
  private void visit(Table table, Column column) {
    append(NEWLINE).append(TAB);
    if (table.getTableType() == Table.Type.TemporaryTable
        && column.isAutoIncremented()
        && column.getNullType() == NullType.No_Nulls
        && column.getJavaType() == DataTypeManager.DefaultDataClasses.INTEGER) {
      append(SQLStringVisitor.escapeSinglePart(column.getName()));
      append(SPACE);
      append(SERIAL);
    } else {
      appendColumn(column, true, true);

      if (column.isAutoIncremented()) {
        append(SPACE).append(AUTO_INCREMENT);
      }
    }

    appendDefault(column);

    // options
    appendColumnOptions(column);
  }
コード例 #22
0
    @Override
    public void execute(
        VDBMetaData vdb,
        MetadataStore store,
        ValidatorReport report,
        MetadataValidator metadataValidator) {
      for (Schema schema : store.getSchemaList()) {
        if (vdb.getImportedModels().contains(schema.getName())) {
          continue;
        }
        ModelMetaData model = vdb.getModel(schema.getName());

        for (Table t : schema.getTables().values()) {
          if (t.isVirtual()) {
            if (t.isMaterialized() && t.getMaterializedTable() != null) {
              String matTableName = t.getMaterializedTable().getFullName();
              int index = matTableName.indexOf(Table.NAME_DELIM_CHAR);
              if (index == -1) {
                metadataValidator.log(
                    report,
                    model,
                    Messages.gs(Messages.TEIID.TEIID31088, matTableName, t.getFullName()));
              } else {
                String schemaName = matTableName.substring(0, index);
                Schema matSchema = store.getSchema(schemaName);
                if (matSchema == null) {
                  metadataValidator.log(
                      report,
                      model,
                      Messages.gs(
                          Messages.TEIID.TEIID31089, schemaName, matTableName, t.getFullName()));
                } else {
                  Table matTable = matSchema.getTable(matTableName.substring(index + 1));
                  if (matTable == null) {
                    metadataValidator.log(
                        report,
                        model,
                        Messages.gs(
                            Messages.TEIID.TEIID31090,
                            matTableName.substring(index + 1),
                            schemaName,
                            t.getFullName()));
                  } else {
                    t.setMaterializedTable(matTable);
                  }
                }
              }
            }
          }

          for (KeyRecord record : t.getAllKeys()) {
            if (record.getColumns() == null || record.getColumns().isEmpty()) {
              metadataValidator.log(
                  report,
                  model,
                  Messages.gs(Messages.TEIID.TEIID31149, t.getFullName(), record.getName()));
            }
          }

          List<ForeignKey> fks = t.getForeignKeys();
          if (fks == null || fks.isEmpty()) {
            continue;
          }

          for (ForeignKey fk : fks) {
            // Only applicable to older teiid releases than 8.9
            if (fk.getReferenceKey() != null
                && !metadataValidator.isTeiidOrGreater(Version.TEIID_8_9)) {
              // ensure derived fields are set
              fk.setReferenceKey(fk.getReferenceKey());
              continue;
            }

            String referenceTableName = fk.getReferenceTableName();
            Table referenceTable = null;
            if (fk.getReferenceKey() == null) {
              if (referenceTableName == null) {
                metadataValidator.log(
                    report, model, Messages.gs(Messages.TEIID.TEIID31091, t.getFullName()));
                continue;
              }

              // TODO there is an ambiguity here because we don't properly track the name parts
              // so we have to first check for a table name that may contain .
              referenceTable = schema.getTable(referenceTableName);
            } else {
              referenceTableName = fk.getReferenceKey().getParent().getFullName();
            }

            String referenceSchemaName = schema.getName();
            int index = referenceTableName.indexOf(Table.NAME_DELIM_CHAR);
            if (referenceTable == null) {
              if (index != -1) {
                referenceSchemaName = referenceTableName.substring(0, index);
                Schema referenceSchema = store.getSchema(referenceSchemaName);
                if (referenceSchema == null) {
                  metadataValidator.log(
                      report,
                      model,
                      Messages.gs(Messages.TEIID.TEIID31093, referenceSchemaName, t.getFullName()));
                  continue;
                }
                referenceTable = referenceSchema.getTable(referenceTableName.substring(index + 1));
              }
              if (referenceTable == null) {
                metadataValidator.log(
                    report,
                    model,
                    Messages.gs(
                        Messages.TEIID.TEIID31092,
                        t.getFullName(),
                        referenceTableName.substring(index + 1),
                        referenceSchemaName));
                continue;
              }
            }

            KeyRecord uniqueKey = null;
            List<String> referenceColumns = fk.getReferenceColumns();
            if (fk.getReferenceKey() != null) {
              // index metadata logic sets the key prior to having the column names
              List<Column> cols = fk.getReferenceKey().getColumns();
              referenceColumns = new ArrayList<String>();
              for (Column col : cols) {
                referenceColumns.add(col.getName());
              }
            }
            if (referenceColumns == null || referenceColumns.isEmpty()) {
              if (referenceTable.getPrimaryKey() == null) {
                metadataValidator.log(
                    report,
                    model,
                    Messages.gs(
                        Messages.TEIID.TEIID31094,
                        t.getFullName(),
                        referenceTableName.substring(index + 1),
                        referenceSchemaName));
              } else {
                uniqueKey = referenceTable.getPrimaryKey();
              }

            } else {
              for (KeyRecord record : referenceTable.getUniqueKeys()) {
                if (keyMatches(fk.getReferenceColumns(), record)) {
                  uniqueKey = record;
                  break;
                }
              }
              if (uniqueKey == null
                  && referenceTable.getPrimaryKey() != null
                  && keyMatches(fk.getReferenceColumns(), referenceTable.getPrimaryKey())) {
                uniqueKey = referenceTable.getPrimaryKey();
              }
            }
            if (uniqueKey == null) {
              metadataValidator.log(
                  report,
                  model,
                  Messages.gs(
                      Messages.TEIID.TEIID31095,
                      t.getFullName(),
                      referenceTableName.substring(index + 1),
                      referenceSchemaName,
                      fk.getReferenceColumns()));
            } else {
              fk.setReferenceKey(uniqueKey);
            }
          }
        }
      }
    }
コード例 #23
0
  public void handleInsertSequences(Insert insert) throws TranslatorException {
    /*
     * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence
     * then pull the Sequence name out of the name in source of the column.
     */
    if (!(insert.getValueSource() instanceof ExpressionValueSource)) {
      return;
    }
    ExpressionValueSource values = (ExpressionValueSource) insert.getValueSource();
    if (insert.getTable().getMetadataObject() == null) {
      return;
    }
    List<Column> allElements = insert.getTable().getMetadataObject().getColumns();
    if (allElements.size() == values.getValues().size()) {
      return;
    }

    int index = 0;
    List<ColumnReference> elements = insert.getColumns();

    for (Column element : allElements) {
      if (!element.isAutoIncremented()) {
        continue;
      }
      String name = element.getNameInSource();
      int seqIndex = name.indexOf(SEQUENCE);
      if (seqIndex == -1) {
        continue;
      }
      boolean found = false;
      while (index < elements.size()) {
        if (element.equals(elements.get(index).getMetadataObject())) {
          found = true;
          break;
        }
        index++;
      }
      if (found) {
        continue;
      }

      String sequence = name.substring(seqIndex + SEQUENCE.length());

      int delimiterIndex = sequence.indexOf(Tokens.DOT);
      if (delimiterIndex == -1) {
        throw new TranslatorException(
            JDBCPlugin.Event.TEIID11017,
            JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11017, SEQUENCE, name));
      }
      String sequenceGroupName = sequence.substring(0, delimiterIndex);
      String sequenceElementName = sequence.substring(delimiterIndex + 1);

      NamedTable sequenceGroup =
          this.getLanguageFactory().createNamedTable(sequenceGroupName, null, null);
      ColumnReference sequenceElement =
          this.getLanguageFactory()
              .createColumnReference(
                  sequenceElementName, sequenceGroup, null, element.getJavaType());
      insert
          .getColumns()
          .add(
              index,
              this.getLanguageFactory()
                  .createColumnReference(
                      element.getName(), insert.getTable(), element, element.getJavaType()));
      values.getValues().add(index, sequenceElement);
    }
  }
コード例 #24
0
ファイル: DDLStringVisitor.java プロジェクト: teiid/teiid
  private void buildColumnOptions(BaseColumn baseColumn, StringBuilder options) {
    if (baseColumn instanceof Column) {
      Column column = (Column) baseColumn;
      if (!column.isSelectable()) {
        addOption(options, SELECTABLE, column.isSelectable());
      }

      // if table is already updatable, then columns are implicitly updatable.
      if (!column.isUpdatable()
          && column.getParent() instanceof Table
          && ((Table) column.getParent()).supportsUpdate()) {
        addOption(options, UPDATABLE, column.isUpdatable());
      }

      if (column.isCurrency()) {
        addOption(options, CURRENCY, column.isCurrency());
      }

      // only record if not default
      if (!column.isCaseSensitive() && column.getDatatype().isCaseSensitive()) {
        addOption(options, CASE_SENSITIVE, column.isCaseSensitive());
      }

      if (!column.isSigned() && column.getDatatype().isSigned()) {
        addOption(options, SIGNED, column.isSigned());
      }
      if (column.isFixedLength()) {
        addOption(options, FIXED_LENGTH, column.isFixedLength());
      }
      // length and octet length should be same. so this should be never be true.
      // TODO - this is not quite valid since we are dealing with length representing chars in
      // UTF-16, then there should be twice the bytes
      if (column.getCharOctetLength() != 0 && column.getLength() != column.getCharOctetLength()) {
        addOption(options, CHAR_OCTET_LENGTH, column.getCharOctetLength());
      }

      // by default the search type is default data type search, so avoid it.
      if (column.getSearchType() != null
          && (!column.getSearchType().equals(column.getDatatype().getSearchType())
              || column.isSearchTypeSet())) {
        addOption(options, SEARCHABLE, column.getSearchType().name());
      }

      if (column.getMinimumValue() != null) {
        addOption(options, MIN_VALUE, column.getMinimumValue());
      }

      if (column.getMaximumValue() != null) {
        addOption(options, MAX_VALUE, column.getMaximumValue());
      }

      if (column.getNullValues() != -1) {
        addOption(options, NULL_VALUE_COUNT, column.getNullValues());
      }

      if (column.getDistinctValues() != -1) {
        addOption(options, DISTINCT_VALUES, column.getDistinctValues());
      }
    }

    if (baseColumn.getNativeType() != null) {
      addOption(options, NATIVE_TYPE, baseColumn.getNativeType());
    }

    buildOptions(baseColumn, options);
  }
コード例 #25
0
ファイル: TestDDLParser.java プロジェクト: vchintal/teiid
  @Test
  public void testForeignTable() throws Exception {

    String ddl =
        "CREATE FOREIGN TABLE G1(\n"
            + "e1 integer primary key,\n"
            + "e2 varchar(10) unique,\n"
            + "e3 date not null unique,\n"
            + "e4 decimal(12,3) default 12.2 options (searchable 'unsearchable'),\n"
            + "e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE 'NO'),\n"
            + "e6 varchar index default 'hello')\n"
            + "OPTIONS (CARDINALITY 12, UUID 'uuid2',  UPDATABLE 'true', FOO 'BAR', ANNOTATION 'Test Table')";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertTrue(table.isPhysical());
    assertFalse(table.isVirtual());
    assertFalse(table.isSystem());
    assertFalse(table.isMaterialized());
    assertFalse(table.isDeletePlanEnabled());
    assertEquals("uuid2", table.getUUID());
    assertEquals(12, table.getCardinality());
    assertTrue(table.supportsUpdate());
    assertEquals("BAR", table.getProperties().get("FOO"));
    assertEquals("Test Table", table.getAnnotation());

    assertEquals(6, table.getColumns().size());

    List<Column> columns = table.getColumns();
    Column e1 = columns.get(0);
    Column e2 = columns.get(1);
    Column e3 = columns.get(2);
    Column e4 = columns.get(3);
    Column e5 = columns.get(4);
    Column e6 = columns.get(5);

    assertEquals("e1", e1.getName());
    assertEquals("int", e1.getDatatype().getName());
    assertEquals("primary key not same", e1, table.getPrimaryKey().getColumns().get(0));

    assertEquals("e2", e2.getName());
    assertEquals("string", e2.getDatatype().getName());
    assertEquals("unique", e2, table.getUniqueKeys().get(0).getColumns().get(0));
    assertEquals(NullType.Nullable, e2.getNullType());
    assertEquals(10, e2.getLength());
    assertEquals(0, e2.getPrecision());

    assertEquals("e3", e3.getName());
    assertEquals("date", e3.getDatatype().getName());
    assertEquals("unique", e3, table.getUniqueKeys().get(1).getColumns().get(0));
    assertEquals(NullType.No_Nulls, e3.getNullType());

    assertEquals("e4", e4.getName());
    assertEquals("bigdecimal", e4.getDatatype().getName());
    assertEquals(false, e4.isAutoIncremented());
    assertEquals(12, e4.getPrecision());
    assertEquals(3, e4.getScale());
    assertEquals(SearchType.Unsearchable, e4.getSearchType());
    assertEquals("12.2", e4.getDefaultValue());

    assertEquals("e5", e5.getName());
    assertEquals("int", e5.getDatatype().getName());
    assertEquals(true, e5.isAutoIncremented());
    assertEquals("uuid", e5.getUUID());
    assertEquals("nis", e5.getNameInSource());
    assertEquals(false, e5.isSelectable());
    assertEquals("index", e5, table.getIndexes().get(0).getColumns().get(0));

    assertEquals("e6", e6.getName());
    assertEquals("string", e6.getDatatype().getName());
    assertEquals("index", e6, table.getIndexes().get(1).getColumns().get(0));
    assertEquals("hello", e6.getDefaultValue());
  }
コード例 #26
0
  private static void buildEntityTypes(
      MetadataStore metadataStore, List<EdmSchema.Builder> edmSchemas) {
    for (Schema schema : metadataStore.getSchemaList()) {

      List<EdmEntitySet.Builder> entitySets = new ArrayList<EdmEntitySet.Builder>();
      List<EdmEntityType.Builder> entityTypes = new ArrayList<EdmEntityType.Builder>();

      for (Table table : schema.getTables().values()) {

        KeyRecord primaryKey = table.getPrimaryKey();
        List<KeyRecord> uniques = table.getUniqueKeys();
        if (primaryKey == null && uniques.isEmpty()) {
          LogManager.logDetail(
              LogConstants.CTX_ODATA,
              ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16002, table.getFullName()));
          continue;
        }

        EdmEntityType.Builder entityType =
            EdmEntityType.newBuilder().setName(table.getName()).setNamespace(schema.getName());

        // adding key
        if (primaryKey != null) {
          for (Column c : primaryKey.getColumns()) {
            entityType.addKeys(c.getName());
          }
        } else {
          for (Column c : uniques.get(0).getColumns()) {
            entityType.addKeys(c.getName());
          }
        }

        // adding properties
        for (Column c : table.getColumns()) {
          EdmProperty.Builder property =
              EdmProperty.newBuilder(c.getName())
                  .setType(ODataTypeManager.odataType(c.getDatatype().getRuntimeTypeName()))
                  .setNullable(c.getNullType() == NullType.Nullable);
          if (c.getDatatype()
              .getRuntimeTypeName()
              .equals(DataTypeManager.DefaultDataTypes.STRING)) {
            property.setFixedLength(c.isFixedLength()).setMaxLength(c.getLength()).setUnicode(true);
          }
          entityType.addProperties(property);
        }

        // entity set one for one entity type
        EdmEntitySet.Builder entitySet =
            EdmEntitySet.newBuilder().setName(table.getName()).setEntityType(entityType);

        entityType.setNamespace(schema.getName());
        entitySets.add(entitySet);

        // add enitity types for entity schema
        entityTypes.add(entityType);
      }

      // entity container is holder entity sets, association sets, function imports
      EdmEntityContainer.Builder entityContainer =
          EdmEntityContainer.newBuilder()
              .setName(schema.getName())
              .setIsDefault(false)
              .addEntitySets(entitySets);

      // build entity schema
      EdmSchema.Builder modelSchema =
          EdmSchema.newBuilder()
              .setNamespace(schema.getName())
              .addEntityTypes(entityTypes)
              .addEntityContainers(entityContainer);

      edmSchemas.add(modelSchema);
    }
  }
コード例 #27
0
ファイル: DSLSearch.java プロジェクト: mathwaa/teiid
  @SuppressWarnings("rawtypes")
  public static FilterConditionContext visit(
      Comparison obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {

    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison criteria."); // $NON-NLS-1$
    Comparison.Operator op = obj.getOperator();

    Expression lhs = obj.getLeftExpression();
    Expression rhs = obj.getRightExpression();

    // joins between the objects in the same cache is not usable
    if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference)
        || (lhs instanceof Literal && rhs instanceof Literal)) {
      return null;
    }

    Object value = null;
    Column mdIDElement = null;
    Literal literal = null;
    if (lhs instanceof ColumnReference) {

      mdIDElement = ((ColumnReference) lhs).getMetadataObject();
      literal = (Literal) rhs;
      value = literal.getValue();

    } else if (rhs instanceof ColumnReference) {
      mdIDElement = ((ColumnReference) rhs).getMetadataObject();
      literal = (Literal) lhs;
      value = literal.getValue();
    }

    if (value == null) {
      throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25051));
    }

    value = escapeReservedChars(value);
    switch (op) {
      case NE:
        if (fcbc == null) {
          return queryBuilder.not().having(mdIDElement.getSourceName()).eq(value);
        }
        return fcbc.not().having(mdIDElement.getSourceName()).eq(value);

      case EQ:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).eq(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).eq(value);

      case GT:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).gt(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).gt(value);

      case GE:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).gte(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).gte(value);

      case LT:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).lt(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).lt(value);

      case LE:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).lte(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).lte(value);

      default:
        throw new TranslatorException(
            InfinispanPlugin.Util.gs(
                InfinispanPlugin.Event.TEIID25050, new Object[] {op, "NE, EQ, GT, GE, LT, LE"}));
    }
  }
コード例 #28
0
  private Object convertSingleValue(
      Column modelElement, String modelAttrName, Class<?> modelAttrClass, Object objResult)
      throws TranslatorException, InvalidNameException {
    if (objResult == null) {
      return null;
    }
    // GHH 20080326 - if attribute is not a string or empty, just
    // return null.
    if (!(objResult instanceof String)) {
      return objResult;
    }

    String strResult = (String) objResult;
    // MPW - 3.9.07 - Also return NULL when attribute is unset or empty string.
    // There is no way to differentiate between being unset and being the empty string.
    if (strResult.equals("")) { // $NON-NLS-1$
      return null;
    }

    // MPW: 3-11-07: Added support for java.lang.Integer conversion.
    if (TypeFacility.RUNTIME_TYPES.TIMESTAMP.equals(modelAttrClass)) {
      String timestampFormat = modelElement.getFormat();
      if (timestampFormat == null) {
        timestampFormat = LDAPConnectorConstants.ldapTimestampFormat;
      }
      SimpleDateFormat dateFormat = new SimpleDateFormat(timestampFormat);
      try {
        Date dateResult = dateFormat.parse(strResult);
        Timestamp tsResult = new Timestamp(dateResult.getTime());
        return tsResult;
      } catch (ParseException pe) {
        throw new TranslatorException(
            pe,
            LDAPPlugin.Util.getString(
                "LDAPSyncQueryExecution.timestampParseFailed", modelAttrName)); // $NON-NLS-1$
      }

      //	TODO: Extend support for more types in the future.
      // Specifically, add support for byte arrays, since that's actually supported
      // in the underlying data source.
    }

    // extract rdn
    String type = modelElement.getProperty(LDAPExecutionFactory.RDN_TYPE, false);
    if (type != null) {
      String prefix = modelElement.getProperty(LDAPExecutionFactory.DN_PREFIX, false);
      LdapName name = new LdapName(strResult);
      if (prefix != null) {
        if (!name.getPrefix(name.size() - 1).toString().equals(prefix)) {
          throw new InvalidNameException();
        }
      } else if (name.size() > 1) {
        throw new InvalidNameException();
      }
      Rdn rdn = name.getRdn(name.size() - 1);
      if (!rdn.getType().equals(type)) {
        throw new InvalidNameException();
      }
      return rdn.getValue();
    }

    return strResult; // the Teiid type conversion logic will handle refine from here if necessary
  }
コード例 #29
0
  // GHH 20080326 - added resultDistinguishedName to method signature.  If
  // there is an element in the model named "DN" and there is no attribute
  // with this name in the search result, we return this new parameter
  // value for that column in the result
  // GHH 20080326 - added handling of ClassCastException when non-string
  // attribute is returned
  private Object getValue(
      Column modelElement, SearchResult result, Attributes attrs, boolean unwrap)
      throws TranslatorException, InvalidNameException {

    String modelAttrName = modelElement.getSourceName();
    Class<?> modelAttrClass = modelElement.getJavaType();

    String multivalAttr = modelElement.getDefaultValue();

    if (modelAttrName == null) {
      final String msg =
          LDAPPlugin.Util.getString("LDAPSyncQueryExecution.nullAttrError"); // $NON-NLS-1$
      throw new TranslatorException(msg);
    }

    Attribute resultAttr = attrs.get(modelAttrName);

    // If the attribute is not present, we return NULL.
    if (resultAttr == null) {
      // GHH 20080326 - return DN from input parameter
      // if DN attribute is not present in search result
      if (modelAttrName.equalsIgnoreCase("DN")) { // $NON-NLS-1$
        return result.getNameInNamespace();
      }
      return null;
    }
    Object objResult = null;
    try {
      if (TypeFacility.RUNTIME_TYPES.STRING.equals(modelAttrClass)
          && MULTIVALUED_CONCAT.equalsIgnoreCase(multivalAttr)) {
        // mpw 5/09
        // Order the multi-valued attrs alphabetically before creating a single string,
        // using the delimiter to separate each token
        ArrayList<String> multivalList = new ArrayList<String>();
        NamingEnumeration<?> attrNE = resultAttr.getAll();
        int length = 0;
        while (attrNE.hasMore()) {
          String val = (String) attrNE.next();
          multivalList.add(val);
          length += ((val == null ? 0 : val.length()) + 1);
        }
        Collections.sort(multivalList);

        StringBuilder multivalSB = new StringBuilder(length);
        Iterator<String> itr = multivalList.iterator();
        while (itr.hasNext()) {
          multivalSB.append(itr.next());
          if (itr.hasNext()) {
            multivalSB.append(delimiter);
          }
        }
        return multivalSB.toString();
      }
      if (modelAttrClass.isArray()) {
        return getArray(modelAttrClass.getComponentType(), resultAttr, modelElement, modelAttrName);
      }
      if (unwrap && resultAttr.size() > 1) {
        return getArray(modelAttrClass, resultAttr, modelElement, modelAttrName);
      }

      // just a single value
      objResult = resultAttr.get();
    } catch (NamingException ne) {
      final String msg =
          LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12004, modelAttrName)
              + " : "
              + ne.getExplanation(); // $NON-NLS-1$m
      LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg);
      throw new TranslatorException(ne, msg);
    }

    return convertSingleValue(modelElement, modelAttrName, modelAttrClass, objResult);
  }
コード例 #30
0
  private static void buildFunctionImports(MetadataStore metadataStore, List<Builder> edmSchemas) {
    for (Schema schema : metadataStore.getSchemaList()) {

      EdmSchema.Builder odataSchema = findSchema(edmSchemas, schema.getName());
      EdmEntityContainer.Builder entityContainer =
          findEntityContainer(edmSchemas, schema.getName());

      // procedures
      for (Procedure proc : schema.getProcedures().values()) {
        EdmFunctionImport.Builder edmProcedure = EdmFunctionImport.newBuilder();
        edmProcedure.setName(proc.getName());
        String httpMethod = "POST";

        for (ProcedureParameter pp : proc.getParameters()) {
          if (pp.getName().equals("return")) {
            httpMethod = "GET";
            edmProcedure.setReturnType(
                ODataTypeManager.odataType(pp.getDatatype().getRuntimeTypeName()));
            continue;
          }

          EdmFunctionParameter.Builder param = EdmFunctionParameter.newBuilder();
          param.setName(pp.getName());
          param.setType(ODataTypeManager.odataType(pp.getDatatype().getRuntimeTypeName()));

          if (pp.getType() == ProcedureParameter.Type.In) {
            param.setMode(Mode.In);
          } else if (pp.getType() == ProcedureParameter.Type.InOut) {
            param.setMode(Mode.InOut);
          } else if (pp.getType() == ProcedureParameter.Type.Out) {
            param.setMode(Mode.Out);
          }

          param.setNullable(pp.getNullType() == NullType.Nullable);
          edmProcedure.addParameters(param);
        }

        // add a complex type for return resultset.
        ColumnSet<Procedure> returnColumns = proc.getResultSet();
        if (returnColumns != null) {
          httpMethod = "GET";
          EdmComplexType.Builder complexType = EdmComplexType.newBuilder();
          complexType.setName(proc.getName() + "_" + returnColumns.getName());
          complexType.setNamespace(schema.getName());
          for (Column c : returnColumns.getColumns()) {
            EdmProperty.Builder property =
                EdmProperty.newBuilder(c.getName())
                    .setType(ODataTypeManager.odataType(c.getDatatype().getRuntimeTypeName()))
                    .setNullable(c.getNullType() == NullType.Nullable);
            if (c.getDatatype()
                .getRuntimeTypeName()
                .equals(DataTypeManager.DefaultDataTypes.STRING)) {
              property
                  .setFixedLength(c.isFixedLength())
                  .setMaxLength(c.getLength())
                  .setUnicode(true);
            }
            complexType.addProperties(property);
          }
          odataSchema.addComplexTypes(complexType);
          edmProcedure.setIsCollection(true);
          edmProcedure.setReturnType(
              EdmCollectionType.newBuilder()
                  .setCollectionType(complexType)
                  .setKind(CollectionKind.Collection));
        }
        edmProcedure.setHttpMethod(httpMethod);
        entityContainer.addFunctionImports(edmProcedure);
      }
    }
  }