Esempio 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();
    }
  }
Esempio n. 2
0
  public Object setPrimaryKeyValue(Object primaryKey, Object value)
      throws IllegalArgumentException {
    try {
      if (pkField != null) {
        // if we are trying to set a null value into a null pk, we are already done.
        if (value == null && primaryKey == null) {
          return null;
        }

        // if we don't have a pk object yet create one
        if (primaryKey == null) {
          primaryKey = pkClass.newInstance();
        }

        // Set this field's value into the primary key object.
        pkField.set(primaryKey, value);
        return primaryKey;
      } else {
        // This field is the primary key, so no extraction is necessary.
        return value;
      }
    } catch (Exception e) {
      // Non recoverable internal exception
      throw CmpMessages.MESSAGES.errorSettingInstanceField(fieldName, e);
    }
  }
  public void setInstanceValue(CmpEntityBeanContext ctx, Object value) {
    FieldState fieldState = getFieldState(ctx);
    // update current value
    if (cmpFieldIAmMappedTo != null && cmpFieldIAmMappedTo.isPrimaryKeyMember()) {
      // if this field shares the column with the primary key field and new value
      // changes the primary key then we are in an illegal state.
      if (value != null) {
        if (fieldState.isLoaded() && fieldState.isValueChanged(value)) {
          throw CmpMessages.MESSAGES.foreignKeyChangedPrimaryKey(
              value, getFieldName(), cmpFieldIAmMappedTo.getFieldName(), fieldState.value);

        } else {
          fieldState.setValue(value);
        }
      }
    } else {
      if (cmrChainLink != null
          && JDBCEntityBridge.isEjbCreateDone(ctx)
          && fieldState.isLoaded()
          && fieldState.isValueChanged(value)) {
        cmrChainLink.execute(ctx, fieldState, value);
      }

      fieldState.setValue(value);
    }

    // we are loading the field right now so it isLoaded
    fieldState.setLoaded();
  }
 private KeyGenerator initKeyGenerator(String keygenFactoryName) {
   try {
     KeyGeneratorFactory keygenFactory = new UUIDKeyGeneratorFactory();
     return keygenFactory.getKeyGenerator();
   } catch (Exception e) {
     throw CmpMessages.MESSAGES.failedToInitKeyGenerator(e);
   }
 }
Esempio n. 5
0
 public int setArgumentParameters(PreparedStatement ps, int parameterIndex, Object arg) {
   try {
     int[] jdbcTypes = jdbcType.getJDBCTypes();
     for (int i = 0; i < jdbcTypes.length; i++) {
       Object columnValue = jdbcType.getColumnValue(i, arg);
       jdbcType.getParameterSetter()[i].set(ps, parameterIndex++, jdbcTypes[i], columnValue, log);
       // JDBCUtil.setParameter(log, ps, parameterIndex++, jdbcTypes[i], columnValue);
     }
     return parameterIndex;
   } catch (SQLException e) {
     // Non recoverable internal exception
     throw CmpMessages.MESSAGES.errorSettingParameterForField(fieldName, e);
   }
 }
Esempio n. 6
0
  public Object getPrimaryKeyValue(Object primaryKey) throws IllegalArgumentException {
    try {
      if (pkField != null) {
        if (primaryKey == null) {
          return null;
        }

        return pkField.get(primaryKey);
      } else {
        return primaryKey;
      }
    } catch (Exception e) {
      throw CmpMessages.MESSAGES.errorGettingPk(fieldName, e);
    }
  }
Esempio n. 7
0
  public Object loadArgumentResults(ResultSet rs, int parameterIndex)
      throws IllegalArgumentException {
    try {
      // update the value from the result set
      Class[] javaTypes = jdbcType.getJavaTypes();
      if (javaTypes.length > 1) {
        throw CmpMessages.MESSAGES.complexTypesNotSupported();
      }

      JDBCResultSetReader[] rsReaders = jdbcType.getResultSetReaders();

      Object columnValue = null;
      for (int i = 0; i < javaTypes.length; i++) {
        columnValue = rsReaders[i].get(rs, parameterIndex++, javaTypes[i], log);
        columnValue = jdbcType.setColumnValue(i, null, columnValue);
      }

      // return the updated parameterIndex
      return columnValue;
    } catch (SQLException e) {
      // Non recoverable internal exception
      throw CmpMessages.MESSAGES.errorGettingResultsForField(fieldName, e);
    }
  }
Esempio n. 8
0
 public boolean isLoaded(CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 9
0
 public boolean isReadTimedOut(CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 10
0
 public boolean isReadOnly() {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 11
0
 public void setClean(CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 12
0
 public int loadArgumentResults(ResultSet rs, int parameterIndex, Object[] argumentRef) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 13
0
 public int loadInstanceResults(ResultSet rs, int parameterIndex, CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 14
0
 public void setInstanceValue(CmpEntityBeanContext ctx, Object value) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 15
0
 public int setInstanceParameters(
     PreparedStatement ps, int parameterIndex, CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }
Esempio n. 16
0
 public void resetPersistenceContext(CmpEntityBeanContext ctx) {
   throw CmpMessages.MESSAGES.methodNotSupported();
 }