コード例 #1
0
  /**
   * INTERNAL: This methods clones all the fields and ensures that each collection refers to the
   * same clones.
   */
  @Override
  public Object clone() {
    VariableOneToOneMapping clone = (VariableOneToOneMapping) super.clone();
    Map setOfKeys = new HashMap(getSourceToTargetQueryKeyNames().size());
    Map sourceToTarget = new HashMap(getSourceToTargetQueryKeyNames().size());
    Vector foreignKeys =
        org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(
            getForeignKeyFields().size());

    if (getTypeField() != null) {
      clone.setTypeField((DatabaseField) this.getTypeField().clone());
    }

    for (Iterator enumtr = getSourceToTargetQueryKeyNames().keySet().iterator();
        enumtr.hasNext(); ) {
      // Clone the SourceKeyFields
      DatabaseField field = (DatabaseField) enumtr.next();
      DatabaseField clonedField = (DatabaseField) field.clone();
      setOfKeys.put(field, clonedField);
      // on the next line I'm cloning the query key names
      sourceToTarget.put(clonedField, getSourceToTargetQueryKeyNames().get(field));
    }

    for (Enumeration enumtr = getForeignKeyFields().elements(); enumtr.hasMoreElements(); ) {
      DatabaseField field = (DatabaseField) enumtr.nextElement();
      foreignKeys.addElement(setOfKeys.get(field));
    }
    clone.setSourceToTargetQueryKeyFields(sourceToTarget);
    clone.setForeignKeyFields(foreignKeys);
    clone.setTypeIndicatorTranslation(new HashMap(this.getTypeIndicatorTranslation()));
    return clone;
  }
  protected void setup() {

    descriptor = ((DatabaseSession) getSession()).getDescriptor(Actor.class);
    mapping = (VariableOneToOneMapping) descriptor.getMappingForAttributeName("program");

    sourceField = new DatabaseField("ACTOR.PROGRAM_ID");
    targetQueryKeyName = (String) mapping.getSourceToTargetQueryKeyNames().get(sourceField);
    mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", "name2");
    mapping.getForeignKeyFields().removeElement(sourceField);

    actor = Actor.example4();
    databaseRow = new DatabaseRecord();

    if (testMode == 0) {
      // nothing extra needed
    } else if (testMode == 1) {
      ObjectChangeSet changeSet =
          new ObjectChangeSet(new Vector(), descriptor, actor, new UnitOfWorkChangeSet(), true);
      changeRecord = new ObjectReferenceChangeRecord(changeSet);
      changeRecord.setNewValue(changeSet);
    } else if (testMode == 2) {
      deleteObjectQuery = new DeleteObjectQuery(actor);
      deleteObjectQuery.setSession((AbstractSession) getSession());
    }

    expectedException =
        DescriptorException.variableOneToOneMappingIsNotDefinedProperly(
            mapping, descriptor, targetQueryKeyName);
  }
 public void test() {
   try {
     if (testMode == 0) {
       mapping.writeFromObjectIntoRow(
           actor, databaseRow, (AbstractSession) getSession(), WriteType.UNDEFINED); // test one
     } else if (testMode == 1) {
       mapping.writeFromObjectIntoRowWithChangeRecord(
           (org.eclipse.persistence.internal.sessions.ChangeRecord) changeRecord,
           databaseRow,
           (AbstractSession) getSession(),
           WriteType.UNDEFINED); // test two
     } else if (testMode == 2) {
       mapping.writeFromObjectIntoRowForWhereClause(deleteObjectQuery, databaseRow); // test three
     } else {
       throw new org.eclipse.persistence.testing.framework.TestProblemException(
           "Invalid method test name for VariableOneToOneMappingIsNotDefinedProperlyTest");
     }
   } catch (EclipseLinkException exception) {
     caughtException = exception;
   }
 }
  protected void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    descriptorToModify = (ClassDescriptor) project.getDescriptors().get(Employee.class);
    VariableOneToOneMapping typeMapping = new VariableOneToOneMapping();
    typeMapping.setAttributeName("test");
    typeMapping.setReferenceClass(Employee.class);
    typeMapping.setForeignQueryKeyName("T_ID", "id");
    typeMapping.addTargetForeignQueryKeyName("testTargerFKQueryName", "testSourcePKFieldName");
    typeMapping.dontUseIndirection();
    typeMapping.privateOwnedRelationship();
    descriptorToModify.addMapping(typeMapping);
  }
 public void reset() {
   mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", targetQueryKeyName);
   mapping.getForeignKeyFields().removeElement(sourceField);
 }