예제 #1
0
  /** Simply appends column name with optional table reference and alias. */
  protected void appendColumnName(StringBuilder query, DbEntityDescriptor ded, String column) {
    query.append(resolveTable(tableRef, ded)).append('.').append(column);

    if (templateData.getColumnAliasType() != null) { // create column aliases
      String tableName = ded.getTableName();
      query.append(AS);
      switch (templateData.getColumnAliasType()) {
        case TABLE_NAME:
          query
              .append(tableName)
              .append(templateData.getDbOomManager().getColumnAliasSeparator())
              .append(column);
          break;
        case TABLE_REFERENCE:
          templateData.registerColumnDataForTableRef(tableRef, tableName);
          query
              .append(tableRef)
              .append(templateData.getDbOomManager().getColumnAliasSeparator())
              .append(column);
          break;
        case COLUMN_CODE:
          String code = templateData.registerColumnDataForColumnCode(tableName, column);
          query.append(code);
          break;
      }
    }
  }
예제 #2
0
  @Override
  public void process(StringBuilder out) {
    if (isPreviousChunkOfType(CHUNK_TABLE)) {
      appendMissingSpace(out);
    }

    DbEntityDescriptor ded =
        tableRef != null ? lookupTableRef(tableRef) : lookupType(resolveClass(data));

    out.append(SET);

    DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
    String typeName = StringUtil.uncapitalize(ded.getEntityName());
    // String table = resolveTable(tableRef, ded);

    int size = 0;
    for (DbEntityColumnDescriptor dec : decList) {
      String property = dec.getPropertyName();
      Object value = BeanUtil.getDeclaredProperty(data, property);

      if (includeColumns == COLS_ONLY_EXISTING) {
        if (DbOomUtil.isEmptyColumnValue(dec, value)) {
          continue;
        }
      }

      if (size > 0) {
        out.append(',').append(' ');
      }

      size++;

      // do not add table reference in set
      // as only one table can be updated
      // also, Postgress database does not allow it (see #JODD-21)

      // out.append(table).append('.');

      out.append(dec.getColumnName()).append('=');

      String propertyName = typeName + '.' + property;
      defineParameter(out, propertyName, value, dec);
    }
    if (size > 0) {
      out.append(' ');
    }
  }
예제 #3
0
  /** Appends alias. */
  protected void appendAlias(StringBuilder query, DbEntityDescriptor ded, String column) {
    String tableName = ded.getTableName();

    ColumnAliasType columnAliasType = templateData.getColumnAliasType();
    String columnAliasSeparator = templateData.getDbOomManager().getColumnAliasSeparator();

    if (columnAliasType == null || columnAliasType == ColumnAliasType.TABLE_REFERENCE) {
      templateData.registerColumnDataForTableRef(tableRef, tableName);
      query.append(tableRef).append(columnAliasSeparator).append(column);
    } else if (columnAliasType == ColumnAliasType.COLUMN_CODE) {
      String code = templateData.registerColumnDataForColumnCode(tableName, column);
      query.append(code);
    } else if (columnAliasType == ColumnAliasType.TABLE_NAME) {
      query.append(tableName).append(columnAliasSeparator).append(column);
    }
  }
예제 #4
0
  @Override
  public void process(StringBuilder out) {
    // hints
    if (templateData.hasHints()) {
      templateData.registerHint(hint == null ? tableRef : hint);
    }

    // columns
    separateByCommaOrSpace(out);

    // special case, only column name, no table ref/name
    if (tableRef.length() == 0) {
      out.append(columnRef);
      return;
    }

    boolean useTableReference = true;
    DbEntityDescriptor ded = lookupTableRef(tableRef, false);
    if (ded == null) {
      useTableReference = false;
      ded = lookupName(tableRef);
    }

    if (columnRef == null) {
      DbEntityColumnDescriptor[] decList = ded.getColumnDescriptors();
      int count = 0;
      boolean withIds =
          (columnRefArr != null) && ArraysUtil.contains(columnRefArr, StringPool.PLUS);
      for (DbEntityColumnDescriptor dec : decList) {
        if ((includeColumns == COLS_ONLY_IDS) && (dec.isId() == false)) {
          continue;
        }
        if ((includeColumns == COLS_ALL_BUT_ID) && (dec.isId() == true)) {
          continue;
        }
        if ((includeColumns == COLS_NA_MULTI)
            && (!withIds || (dec.isId() == false))
            && (!ArraysUtil.contains(columnRefArr, dec.getPropertyName()))) {
          continue;
        }
        if (count > 0) {
          out.append(',').append(' ');
        }
        templateData.lastColumnDec = dec;

        if (useTableReference) {
          appendColumnName(out, ded, dec.getColumnName());
        } else {
          appendAlias(out, ded, dec.getColumnName());
        }
        count++;
      }
    } else {
      DbEntityColumnDescriptor dec = ded.findByPropertyName(columnRef);
      templateData.lastColumnDec = dec;
      String columnName = dec == null ? null : dec.getColumnName();
      // String columnName = ded.getColumnName(columnRef);
      if (columnName == null) {
        throw new DbSqlBuilderException("Invalid column reference: " + tableRef + '.' + columnRef);
      }
      if (useTableReference) {
        appendColumnName(out, ded, columnName);
      } else {
        appendAlias(out, ded, columnName);
      }
    }
  }