use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class BatchActionGeneratedIT method testHasGeneratedKeys2.
@Test
public void testHasGeneratedKeys2() throws Exception {
EntityResolver resolver = runtime.getChannel().getEntityResolver();
// test with adapter that does not support keys...
JdbcAdapter adapter = buildAdapter(false);
InsertBatchQuery batch1 = new InsertBatchQuery(resolver.getObjEntity(GeneratedColumnTestEntity.class).getDbEntity(), 5);
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
assertFalse(new BatchAction(batch1, node, false).hasGeneratedKeys());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class BatchActionLockingIT method testRunAsIndividualQueriesOptimisticLockingFailure.
@Test
public void testRunAsIndividualQueriesOptimisticLockingFailure() throws Exception {
EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
// test with adapter that supports keys...
JdbcAdapter adapter = buildAdapter(true);
DbEntity dbEntity = resolver.getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
List<DbAttribute> qualifierAttributes = Arrays.asList(dbEntity.getAttribute("LOCKING_TEST_ID"), dbEntity.getAttribute("NAME"));
Collection<String> nullAttributeNames = Collections.singleton("NAME");
Map<String, Object> qualifierSnapshot = new HashMap<>();
qualifierSnapshot.put("LOCKING_TEST_ID", 1);
DeleteBatchQuery batchQuery = new DeleteBatchQuery(dbEntity, qualifierAttributes, nullAttributeNames, 5);
batchQuery.setUsingOptimisticLocking(true);
batchQuery.add(qualifierSnapshot);
DeleteBatchTranslator batchQueryBuilder = new DeleteBatchTranslator(batchQuery, adapter, null);
MockConnection mockConnection = new MockConnection();
PreparedStatementResultSetHandler preparedStatementResultSetHandler = mockConnection.getPreparedStatementResultSetHandler();
preparedStatementResultSetHandler.setExactMatch(false);
preparedStatementResultSetHandler.setCaseSensitive(false);
preparedStatementResultSetHandler.prepareUpdateCount("DELETE", 0);
boolean generatesKeys = false;
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
BatchAction action = new BatchAction(batchQuery, node, false);
try {
action.runAsIndividualQueries(mockConnection, batchQueryBuilder, new MockOperationObserver(), generatesKeys);
fail("No OptimisticLockingFailureException thrown.");
} catch (OptimisticLockException e) {
}
assertEquals(0, mockConnection.getNumberCommits());
assertEquals(0, mockConnection.getNumberRollbacks());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class BatchActionLockingIT method testRunAsIndividualQueriesSuccess.
@Test
public void testRunAsIndividualQueriesSuccess() throws Exception {
EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
// test with adapter that supports keys...
JdbcAdapter adapter = buildAdapter(true);
DbEntity dbEntity = resolver.getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
List<DbAttribute> qualifierAttributes = Arrays.asList(dbEntity.getAttribute("LOCKING_TEST_ID"), dbEntity.getAttribute("NAME"));
Collection<String> nullAttributeNames = Collections.singleton("NAME");
Map<String, Object> qualifierSnapshot = new HashMap<>();
qualifierSnapshot.put("LOCKING_TEST_ID", new Integer(1));
DeleteBatchQuery batchQuery = new DeleteBatchQuery(dbEntity, qualifierAttributes, nullAttributeNames, 5);
batchQuery.setUsingOptimisticLocking(true);
batchQuery.add(qualifierSnapshot);
DeleteBatchTranslator batchQueryBuilder = new DeleteBatchTranslator(batchQuery, adapter, null);
MockConnection mockConnection = new MockConnection();
PreparedStatementResultSetHandler preparedStatementResultSetHandler = mockConnection.getPreparedStatementResultSetHandler();
preparedStatementResultSetHandler.setExactMatch(false);
preparedStatementResultSetHandler.setCaseSensitive(false);
preparedStatementResultSetHandler.prepareUpdateCount("DELETE", 1);
boolean generatesKeys = false;
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
BatchAction action = new BatchAction(batchQuery, node, false);
action.runAsIndividualQueries(mockConnection, batchQueryBuilder, new MockOperationObserver(), generatesKeys);
assertEquals(0, mockConnection.getNumberCommits());
assertEquals(0, mockConnection.getNumberRollbacks());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ProcedureQueryCacheKeyIT method testSharedCache.
@Test
public void testSharedCache() {
EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
QueryMetadata md1 = query.getMetaData(resolver);
assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
assertNotNull(md1.getCacheKey());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class SelectQueryIT method testRouteQueryWithPrefetchesNoReverse.
/**
* Tests that all queries specified in prefetch are executed in a more
* complex prefetch scenario with no reverse obj relationships.
*/
@Test
public void testRouteQueryWithPrefetchesNoReverse() {
EntityResolver resolver = context.getEntityResolver();
ObjEntity paintingEntity = resolver.getObjEntity(Painting.class);
ObjEntity galleryEntity = resolver.getObjEntity(Gallery.class);
ObjEntity artistExhibitEntity = resolver.getObjEntity(ArtistExhibit.class);
ObjEntity exhibitEntity = resolver.getObjEntity(Exhibit.class);
ObjRelationship paintingToArtistRel = paintingEntity.getRelationship("toArtist");
paintingEntity.removeRelationship("toArtist");
ObjRelationship galleryToPaintingRel = galleryEntity.getRelationship("paintingArray");
galleryEntity.removeRelationship("paintingArray");
ObjRelationship artistExhibitToArtistRel = artistExhibitEntity.getRelationship("toArtist");
artistExhibitEntity.removeRelationship("toArtist");
ObjRelationship exhibitToArtistExhibitRel = exhibitEntity.getRelationship("artistExhibitArray");
exhibitEntity.removeRelationship("artistExhibitArray");
Expression e = ExpressionFactory.matchExp("artistName", "artist1");
SelectQuery<Artist> q = new SelectQuery<>(Artist.class, e);
q.addPrefetch("paintingArray");
q.addPrefetch("paintingArray.toGallery");
q.addPrefetch("artistExhibitArray.toExhibit");
try {
MockQueryRouter router = new MockQueryRouter();
q.route(router, resolver, null);
assertEquals(4, router.getQueryCount());
} finally {
paintingEntity.addRelationship(paintingToArtistRel);
galleryEntity.addRelationship(galleryToPaintingRel);
artistExhibitEntity.addRelationship(artistExhibitToArtistRel);
exhibitEntity.addRelationship(exhibitToArtistExhibitRel);
}
}
Aggregations