use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateNotEqualID.
@Test
public void testProcessTemplateNotEqualID() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE " + "COLUMN1 #bindNotEqual($helper.cayenneExp($a, 'db:ID_COLUMN1')) " + "AND COLUMN2 #bindNotEqual($helper.cayenneExp($a, 'db:ID_COLUMN2'))";
Map<String, Object> idMap = new HashMap<>();
idMap.put("ID_COLUMN1", 3);
idMap.put("ID_COLUMN2", "aaa");
ObjectId id = new ObjectId("T", idMap);
DataObject dataObject = new CayenneDataObject();
dataObject.setObjectId(id);
Map<String, Object> map = Collections.singletonMap("a", dataObject);
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN1 <> ? AND COLUMN2 <> ?", compiled.getSql());
assertEquals(2, compiled.getBindings().length);
assertBindingValue(3, compiled.getBindings()[0]);
assertBindingValue("aaa", compiled.getBindings()[1]);
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class QualifierTranslatorIT method testExtras.
@Test
public void testExtras() throws Exception {
ObjectId oid1 = new ObjectId("Gallery", "GALLERY_ID", 1);
ObjectId oid2 = new ObjectId("Gallery", "GALLERY_ID", 2);
Gallery g1 = new Gallery();
Gallery g2 = new Gallery();
g1.setObjectId(oid1);
g2.setObjectId(oid2);
Expression e1 = ExpressionFactory.matchExp("toGallery", g1);
Expression e2 = e1.orExp(ExpressionFactory.matchExp("toGallery", g2));
doExpressionTest(Exhibit.class, e2, "(ta.GALLERY_ID = ?) OR (ta.GALLERY_ID = ?)");
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class FlattenedArcKeyIT method testHashCode.
@Test
public void testHashCode() {
ObjectId src = new ObjectId("X");
ObjectId target = new ObjectId("Y");
ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(FlattenedTest1.FT3OVER_COMPLEX.getName());
FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
int h = update.hashCode();
int h1 = update1.hashCode();
int h2 = update2.hashCode();
assertTrue(h == h1);
assertTrue(h == update.hashCode());
assertFalse(h == h2);
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class IdentityColumnsIT method testCompoundPKWithGeneratedColumn.
@Test
public void testCompoundPKWithGeneratedColumn() throws Exception {
if (adapter.supportsGeneratedKeys()) {
// only works for generated keys, as the entity tested has one
// Cayenne
// auto-pk and one generated key
String masterName = "m_" + System.currentTimeMillis();
String depName1 = "dep1_" + System.currentTimeMillis();
String depName2 = "dep2_" + System.currentTimeMillis();
GeneratedColumnCompMaster master = context.newObject(GeneratedColumnCompMaster.class);
master.setName(masterName);
GeneratedColumnCompKey dep1 = context.newObject(GeneratedColumnCompKey.class);
dep1.setName(depName1);
dep1.setToMaster(master);
GeneratedColumnCompKey dep2 = context.newObject(GeneratedColumnCompKey.class);
dep2.setName(depName2);
dep2.setToMaster(master);
context.commitChanges();
int masterId = Cayenne.intPKForObject(master);
ObjectId id2 = dep2.getObjectId();
// check propagated id
Number propagatedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.PROPAGATED_PK_PK_COLUMN);
assertNotNull(propagatedID2);
assertEquals(masterId, propagatedID2.intValue());
// check Cayenne-generated ID
Number cayenneGeneratedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.AUTO_PK_PK_COLUMN);
assertNotNull(cayenneGeneratedID2);
// check DB-generated ID
Number dbGeneratedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.GENERATED_COLUMN_PK_COLUMN);
assertNotNull(dbGeneratedID2);
context.invalidateObjects(master, dep1, dep2);
Object fetchedDep2 = Cayenne.objectForPK(context, id2);
assertNotNull(fetchedDep2);
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetchMultiStep.
@Test
public void testJointPrefetchMultiStep() throws Exception {
createJointPrefetchDataSet();
// query with to-many joint prefetches
SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
q.addPrefetch(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).joint());
final DataContext context = this.context;
// make sure phantomly prefetched objects are not deallocated
context.getObjectStore().objectMap = new HashMap<>();
// sanity check...
DataObject g1 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
assertNull(g1);
final List<Artist> objects = q.select(context);
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(3, objects.size());
for (Artist a : objects) {
ValueHolder list = (ValueHolder) a.getPaintingArray();
assertNotNull(list);
// intermediate relationship is not fetched...
assertTrue(list.isFault());
}
// however both galleries must be in memory...
DataObject g11 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
assertNotNull(g11);
assertEquals(PersistenceState.COMMITTED, g11.getPersistenceState());
DataObject g2 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33002));
assertNotNull(g2);
assertEquals(PersistenceState.COMMITTED, g2.getPersistenceState());
});
}
Aggregations