Ejemplo n.º 1
0
  public void setValueInternal(CmpEntityBeanContext ctx, Object value, boolean makeDirty) {
    PersistentContext pctx = (PersistentContext) ctx.getPersistenceContext();

    // todo this is weird
    if (cmpFieldIAmMappedTo != null && cmpFieldIAmMappedTo.isPrimaryKeyMember) {
      Object curValue = pctx.getFieldValue(rowIndex);
      if (value != null && !value.equals(curValue)) {
        throw CmpMessages.MESSAGES.attemptToModifyPkThroughFk(
            entity.getEntityName(),
            cmpFieldIAmMappedTo.getFieldName(),
            entity.getQualifiedTableName(),
            cmpFieldIAmMappedTo.getColumnName(),
            curValue,
            value);
      }

      makeDirty = false;
    } else {
      pctx.setFieldValue(rowIndex, value);
    }

    if (makeDirty) {
      pctx.setDirty();
    }
  }
Ejemplo n.º 2
0
  private String buildSQL(JDBCDeclaredQueryMetaData metadata) {
    StringBuffer sql = new StringBuffer(300);

    sql.append(SQLUtil.SELECT);
    if (metadata.isSelectDistinct()) {
      sql.append(SQLUtil.DISTINCT);
    }

    String alias = metadata.getAlias();
    String from = metadata.getFrom();
    String table;
    String selectList;
    if (metadata.getFieldName() == null) {
      // we are selecting a full entity
      table = this.entity.getQualifiedTableName();

      // get a list of all fields to be loaded
      // put pk fields in front
      String tableAlias = getTableAlias(alias, from, this.entity.getTableName());
      selectList =
          SQLUtil.getColumnNamesClause(
                  this.entity.getPrimaryKeyFields(), tableAlias, new StringBuffer(35))
              .toString();
    } else {
      // we are just selecting one field
      JDBCStoreManager2 manager = (JDBCStoreManager2) selectedField.getManager();
      table = manager.getEntityBridge().getQualifiedTableName();
      selectList =
          SQLUtil.getColumnNamesClause(
                  selectedField,
                  getTableAlias(alias, from, manager.getEntityBridge().getTableName()),
                  new StringBuffer())
              .toString();
    }
    sql.append(selectList);
    String additionalColumns = metadata.getAdditionalColumns();
    if (additionalColumns != null) {
      sql.append(additionalColumns);
    }
    sql.append(SQLUtil.FROM).append(table);
    if (alias != null) {
      sql.append(' ').append(alias);
    }
    if (from != null) {
      sql.append(' ').append(from);
    }

    String where = metadata.getWhere();
    if (where != null && where.trim().length() > 0) {
      sql.append(SQLUtil.WHERE).append(where);
    }

    String order = metadata.getOrder();
    if (order != null && order.trim().length() > 0) {
      sql.append(SQLUtil.ORDERBY).append(order);
    }

    String other = metadata.getOther();
    if (other != null && other.trim().length() > 0) {
      sql.append(' ').append(other);
    }
    return sql.toString();
  }