Ejemplo n.º 1
0
  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);
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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);
    }
  }