Search in sources :

Example 1 with EEOTMMapValue

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

the class TestReadEntityEntity1MMapMapping method setup.

@Override
public void setup() {
    mapping = (OneToManyMapping) getSession().getProject().getDescriptor(EntityEntity1MMapHolder.class).getMappingForAttributeName("entityToEntityMap");
    oldFetchJoinValue = mapping.getJoinFetch();
    mapping.setJoinFetch(fetchJoinRelationship);
    getSession().getProject().getDescriptor(EntityEntity1MMapHolder.class).reInitializeJoinedAttributes();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    EntityEntity1MMapHolder holder = new EntityEntity1MMapHolder();
    EEOTMMapValue value = new EEOTMMapValue();
    value.setId(1);
    value.getHolder().setValue(holder);
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    key.setData("data1");
    holder.addEntityToEntityMapItem(key, value);
    uow.registerObject(key);
    EEOTMMapValue value2 = new EEOTMMapValue();
    value2.setId(2);
    value2.getHolder().setValue(holder);
    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 : EntityEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntity1MMapHolder) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.EEOTMMapValue) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 2 with EEOTMMapValue

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

the class TestUpdateEntityEntity1MMapMapping method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    holders = getSession().readAllObjects(EntityEntity1MMapHolder.class, holderExp);
    EntityEntity1MMapHolder holder = (EntityEntity1MMapHolder) 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);
    EEOTMMapValue value = (EEOTMMapValue) 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(EEOTMMapValue.class);
        ExpressionBuilder values = new ExpressionBuilder();
        Expression criteria = values.get("id").equal(1);
        query.setSelectionCriteria(criteria);
        value = (EEOTMMapValue) getSession().executeQuery(query);
        if (value != null) {
            throw new TestErrorException("PrivateOwned DEOTMMapValue 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 : EntityEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntity1MMapHolder) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.EEOTMMapValue) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 3 with EEOTMMapValue

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

the class TestUpdateEntityEntity1MMapMapping method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holders = uow.readAllObjects(EntityEntity1MMapHolder.class, holderExp);
    changedHolder = (EntityEntity1MMapHolder) holders.get(0);
    EntityMapKey key = new EntityMapKey();
    key.setId(11);
    changedHolder.removeEntityToEntityMapItem(key);
    EEOTMMapValue mapValue = new EEOTMMapValue();
    mapValue.setId(3);
    mapValue = (EEOTMMapValue) uow.registerObject(mapValue);
    key = new EntityMapKey();
    key.setId(33);
    key = (EntityMapKey) uow.registerObject(key);
    mapValue.getHolder().setValue(changedHolder);
    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) EntityEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntity1MMapHolder) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.EEOTMMapValue) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 4 with EEOTMMapValue

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

the class TestReadEntityEntity1MMapMapping method verify.

@Override
public void verify() {
    if (holders == null || holders.size() != 1) {
        throw new TestErrorException("Incorrect number of MapHolders was read.");
    }
    EntityEntity1MMapHolder holder = (EntityEntity1MMapHolder) 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);
    EEOTMMapValue value = (EEOTMMapValue) 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 : EntityEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntity1MMapHolder) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.EEOTMMapValue) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Aggregations

EEOTMMapValue (org.eclipse.persistence.testing.models.collections.map.EEOTMMapValue)4 EntityEntity1MMapHolder (org.eclipse.persistence.testing.models.collections.map.EntityEntity1MMapHolder)4 EntityMapKey (org.eclipse.persistence.testing.models.collections.map.EntityMapKey)4 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)2 Expression (org.eclipse.persistence.expressions.Expression)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1