Search in sources :

Example 1 with TypedAssociation

use of org.eclipse.persistence.mappings.TypedAssociation in project eclipselink by eclipse-ee4j.

the class VariableOneToOneMapping2 method runTests.

public void runTests() {
    /**
     ***********************************************************************
     */
    mapping.addClassIndicator(Employee.class, null);
    if (mapping.getClassIndicatorAssociations().isEmpty()) {
        testFailures += "addClassIndicator = null did not add a null wrapper type indicator";
    } else {
        Enumeration e = mapping.getClassIndicatorAssociations().elements();
        while (e.hasMoreElements()) {
            TypedAssociation association = (TypedAssociation) e.nextElement();
            if (association.getKey() == Employee.class) {
                if (!(association.getValue() instanceof Helper)) {
                    testFailures += "addClassIndicator = null, type indicator does not = Helper class";
                }
            }
        }
    }
    /**
     ***********************************************************************
     */
    Vector vectorIn = new Vector();
    vectorIn.add(new Association(Actor.class, new String("ASHLEY JUDD")));
    vectorIn.add(new Association(Secretary.class, new String("DARTH VADER")));
    vectorIn.add(new Association(Broadcastor.class, new String("RED KELLY")));
    mapping.setClassIndicatorAssociations(vectorIn);
    Vector vectorOut = mapping.getClassIndicatorAssociations();
    if (vectorOut.size() != 3) {
        testFailures += "setClassIndicatorAssociations - the set failed";
    } else {
        int foundCount = 0;
        for (int i = 0; i < vectorOut.size(); i++) {
            Association ass = (Association) vectorOut.elementAt(i);
            if (ass.getKey() == Actor.class.getName() && ass.getValue().equals("ASHLEY JUDD")) {
                foundCount++;
            }
            if (ass.getKey() == Secretary.class.getName() && ass.getValue().equals("DARTH VADER")) {
                foundCount++;
            }
            if (ass.getKey() == Broadcastor.class.getName() && ass.getValue().equals("RED KELLY")) {
                foundCount++;
            }
        }
        if (foundCount != 3) {
            testFailures += "setClassIndicatorAssociations - association values not found";
        }
    }
    /**
     ***********************************************************************
     */
    Association assoc = new Association(new String("key"), new String("value"));
    Vector in = new Vector();
    in.add(assoc);
    mapping.setSourceToTargetQueryKeyFieldAssociations(in);
    Vector out = mapping.getSourceToTargetQueryKeyFieldAssociations();
    if (out.size() != 1) {
        testFailures += "setSourceToTargetQueryFieldAssociations - the set failed";
    } else {
        Association a = (Association) out.elementAt(0);
        if (!(a.getKey().equals("key") && a.getValue().equals("value"))) {
            testFailures += "setSourceToTargetQueryFieldAssociations - value in the set failed";
        }
    }
    /**
     ***********************************************************************
     */
    Vector foreignKeyNames = new Vector();
    foreignKeyNames.add("fkey1");
    foreignKeyNames.add("fkey2");
    foreignKeyNames.add("fkey3");
    mapping.setForeignKeyFieldNames(foreignKeyNames);
    Vector fieldNames = mapping.getForeignKeyFieldNames();
    if (!(mapping.getForeignKeyFieldNames().contains("fkey1"))) {
        testFailures += "addForeignQueryKeyName - fkey1";
    }
    if (!(mapping.getForeignKeyFieldNames().contains("fkey2"))) {
        testFailures += "addForeignQueryKeyName - fkey2";
    }
    if (!(mapping.getForeignKeyFieldNames().contains("fkey3"))) {
        testFailures += "addForeignQueryKeyName - fkey3";
    }
    /**
     ***********************************************************************
     */
    mapping.setTypeFieldName("doesNotExist");
    if (!mapping.getTypeFieldName().equals("doesNotExist")) {
        testFailures += "setTypeFieldName failed";
    }
    /**
     ***********************************************************************
     */
    // tests done through the wrapper
    /**
     ***********************************************************************
     */
    /**
     ***********************************************************************
     */
    VariableOneToOneMapping2 wrappedMapping = new VariableOneToOneMapping2();
    wrappedMapping.setTypeField(null);
    if (wrappedMapping.getTypeFieldName() != null) {
        testFailures += "setTypeField - set to null failed";
    }
    /**
     ***********************************************************************
     */
    wrappedMapping.addClassIndicator(Employee.class, null);
    if (wrappedMapping.getTypeForImplementor(Employee.class) != null) {
        testFailures += "getTypeForImplementor failed";
    }
    if (wrappedMapping.getImplementorForType(null, getSession()) != Employee.class) {
        testFailures += "getImplementorForType failed";
    }
}
Also used : Helper(org.eclipse.persistence.internal.helper.Helper) Enumeration(java.util.Enumeration) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) Association(org.eclipse.persistence.mappings.Association) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) Vector(java.util.Vector)

Example 2 with TypedAssociation

use of org.eclipse.persistence.mappings.TypedAssociation in project eclipselink by eclipse-ee4j.

the class InheritancePolicy method getClassIndicatorAssociations.

/**
 * INTERNAL:
 * Return the class indicator associations for XML.
 * List of class-name/value associations.
 */
public Vector<Association> getClassIndicatorAssociations() {
    Vector<Association> associations = new Vector<>(getClassNameIndicatorMapping().size() / 2);
    Iterator classesEnum = getClassNameIndicatorMapping().keySet().iterator();
    Iterator valuesEnum = getClassNameIndicatorMapping().values().iterator();
    while (classesEnum.hasNext()) {
        Object className = classesEnum.next();
        // If the project was built in runtime is a class, MW is a string.
        if (className instanceof Class) {
            className = ((Class<?>) className).getName();
        }
        Object value = valuesEnum.next();
        associations.addElement(new TypedAssociation(className, value));
    }
    return associations;
}
Also used : Association(org.eclipse.persistence.mappings.Association) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) Iterator(java.util.Iterator) Vector(java.util.Vector)

Aggregations

Vector (java.util.Vector)2 Association (org.eclipse.persistence.mappings.Association)2 TypedAssociation (org.eclipse.persistence.mappings.TypedAssociation)2 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 Helper (org.eclipse.persistence.internal.helper.Helper)1