Search in sources :

Example 1 with EntityEntityU1MMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.

the class TestReadEntityEntityU1MMapMapping method setup.

@Override
public void setup() {
    mapping = (UnidirectionalOneToManyMapping) getSession().getProject().getDescriptor(EntityEntityU1MMapHolder.class).getMappingForAttributeName("entityToEntityMap");
    oldFetchJoinValue = mapping.getJoinFetch();
    mapping.setJoinFetch(fetchJoinRelationship);
    getSession().getProject().getDescriptor(EntityEntityU1MMapHolder.class).reInitializeJoinedAttributes();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    EntityEntityU1MMapHolder holder = new EntityEntityU1MMapHolder();
    EntityMapValue value = new EntityMapValue();
    value.setId(1);
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    key.setData("data1");
    holder.addEntityToEntityMapItem(key, value);
    uow.registerObject(key);
    EntityMapValue value2 = new EntityMapValue();
    value2.setId(2);
    key = new EntityMapKey();
    key.setId(22);
    holder.addEntityToEntityMapItem(key, value2);
    uow.registerObject(holder);
    uow.registerObject(key);
    uow.registerObject(value);
    uow.registerObject(value2);
    uow.commit();
    holderExp = (new ExpressionBuilder()).get("id").equal(holder.getId());
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 2 with EntityEntityU1MMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.

the class TestReadEntityEntityU1MMapMapping method verify.

@Override
public void verify() {
    if (holders == null || holders.size() != 1) {
        throw new TestErrorException("Incorrect number of MapHolders was read.");
    }
    EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) holders.get(0);
    if (!((IndirectMap) holder.getEntityToEntityMap()).getValueHolder().isInstantiated() && fetchJoinRelationship > 0) {
        throw new TestErrorException("Relationship was not properly joined.");
    }
    if (holder.getEntityToEntityMap().size() != 2) {
        throw new TestErrorException("Incorrect Number of MapEntityValues was read.");
    }
    EntityMapKey mapKey = new EntityMapKey();
    mapKey.setId(11);
    EntityMapValue value = (EntityMapValue) holder.getEntityToEntityMap().get(mapKey);
    if (value.getId() != 1) {
        throw new TestErrorException("Incorrect MapEntityValues was read.");
    }
    mapKey = (EntityMapKey) getSession().readObject(mapKey);
    if (!mapKey.getData().equals("data1")) {
        throw new TestErrorException("EntityMapKey had wrong data");
    }
}
Also used : EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 3 with EntityEntityU1MMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.

the class TestReadEntityEntityU1MMapMapping method reset.

@Override
public void reset() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Iterator i = holders.iterator();
    while (i.hasNext()) {
        EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) i.next();
        Iterator j = holder.getEntityToEntityMap().keySet().iterator();
        while (j.hasNext()) {
            Object key = j.next();
            uow.deleteObject(holder.getEntityToEntityMap().get(key));
            uow.deleteObject(key);
        }
    }
    uow.deleteAllObjects(holders);
    uow.commit();
    if (!verifyDelete(holders.get(0))) {
        throw new TestErrorException("Delete was unsuccessful.");
    }
    mapping.setJoinFetch(oldFetchJoinValue);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) Iterator(java.util.Iterator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 4 with EntityEntityU1MMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityEntityU1MMapMapping method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holders = uow.readAllObjects(EntityEntityU1MMapHolder.class, holderExp);
    changedHolder = (EntityEntityU1MMapHolder) holders.get(0);
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    changedHolder.removeEntityToEntityMapItem(key);
    EntityMapValue mapValue = new EntityMapValue();
    mapValue.setId(3);
    mapValue = (EntityMapValue) uow.registerObject(mapValue);
    key = new EntityMapKey();
    key.setId(33);
    key = (EntityMapKey) uow.registerObject(key);
    changedHolder.addEntityToEntityMapItem(key, mapValue);
    uow.commit();
    Object holderForComparison = uow.readObject(changedHolder);
    if (!compareObjects(changedHolder, holderForComparison)) {
        throw new TestErrorException("Objects do not match after write");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 5 with EntityEntityU1MMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityEntityU1MMapMapping method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    holders = getSession().readAllObjects(EntityEntityU1MMapHolder.class, holderExp);
    EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) holders.get(0);
    if (!compareObjects(holder, changedHolder)) {
        throw new TestErrorException("Objects do not match reinitialize");
    }
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    if (holder.getEntityToEntityMap().containsKey(key)) {
        throw new TestErrorException("Item that was removed is still present in map.");
    }
    key = new EntityMapKey();
    key.setId(33);
    EntityMapValue value = (EntityMapValue) holder.getEntityToEntityMap().get(key);
    if (value.getId() != 3) {
        throw new TestErrorException("Item was not correctly added to map");
    }
    if (mapping.isPrivateOwned()) {
        ReadObjectQuery query = new ReadObjectQuery(EntityMapValue.class);
        ExpressionBuilder values = new ExpressionBuilder();
        Expression criteria = values.get("id").equal(1);
        query.setSelectionCriteria(criteria);
        value = (EntityMapValue) getSession().executeQuery(query);
        if (value != null) {
            throw new TestErrorException("PrivateOwned EntityMapValue was not deleted.");
        }
        query = new ReadObjectQuery(EntityMapKey.class);
        ExpressionBuilder keys = new ExpressionBuilder();
        Expression keycriteria = keys.get("id").equal(11);
        query.setSelectionCriteria(keycriteria);
        key = (EntityMapKey) getSession().executeQuery(query);
        if (key != null) {
            throw new TestErrorException("PrivateOwned EntityMapKey was not deleted.");
        }
    }
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) Expression(org.eclipse.persistence.expressions.Expression) EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Aggregations

EntityEntityU1MMapHolder (org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder)5 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)4 EntityMapKey (org.eclipse.persistence.testing.models.collections.map.EntityMapKey)4 EntityMapValue (org.eclipse.persistence.testing.models.collections.map.EntityMapValue)4 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 Iterator (java.util.Iterator)1 Expression (org.eclipse.persistence.expressions.Expression)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1