Search in sources :

Example 56 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ExpressionTest method testAppendAsEJBQL_PersistentParamater.

@Test
public void testAppendAsEJBQL_PersistentParamater() throws IOException {
    Artist a = new Artist();
    ObjectId aId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 1);
    a.setObjectId(aId);
    Expression e = ExpressionFactory.matchExp("artist", a);
    StringBuilder buffer = new StringBuilder();
    e.appendAsEJBQL(buffer, "x");
    String ejbql = buffer.toString();
    assertEquals("x.artist = 1", ejbql);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 57 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ASTListTest method testEquals.

@Test
public void testEquals() throws Exception {
    ObjectId objectId = new ObjectId("Artist", "ARTIST_ID", 1);
    Persistent artist = mock(Persistent.class);
    when(artist.getObjectId()).thenReturn(objectId);
    ASTList exp = new ASTList(Collections.singletonList(artist));
    List<Persistent> collection = new ArrayList<>();
    collection.add(artist);
    ASTList exp2 = new ASTList(collection);
    ASTList exp3 = new ASTList(Collections.emptyList());
    assertEquals(exp, exp2);
    assertNotEquals(exp, exp3);
}
Also used : ObjectId(org.apache.cayenne.ObjectId) ArrayList(java.util.ArrayList) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 58 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ASTListTest method testConstructorWithCollection.

@Test
public void testConstructorWithCollection() {
    ObjectId objectId = new ObjectId("Artist", "ARTIST_ID", 1);
    Persistent artist = mock(Persistent.class);
    when(artist.getObjectId()).thenReturn(objectId);
    ASTList exp = new ASTList(Collections.singletonList(artist));
    assertNotNull(exp.getOperand(0));
    List<Persistent> collection = new ArrayList<>();
    collection.add(artist);
    exp = new ASTList(collection);
    assertNotNull(exp.getOperand(0));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) ArrayList(java.util.ArrayList) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 59 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ObjectIdQueryTest method testMetadata.

@Test
public void testMetadata() {
    ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("abc", "a", 1), true, ObjectIdQuery.CACHE_REFRESH);
    assertTrue(q1.isFetchAllowed());
    assertTrue(q1.isFetchMandatory());
    QueryMetadata md1 = q1.getMetaData(null);
    assertTrue(md1.isFetchingDataRows());
    ObjectIdQuery q2 = new ObjectIdQuery(new ObjectId("abc", "a", 1), false, ObjectIdQuery.CACHE);
    assertTrue(q2.isFetchAllowed());
    assertFalse(q2.isFetchMandatory());
    QueryMetadata md2 = q2.getMetaData(null);
    assertFalse(md2.isFetchingDataRows());
    ObjectIdQuery q3 = new ObjectIdQuery(new ObjectId("abc", "a", 1), false, ObjectIdQuery.CACHE_NOREFRESH);
    assertFalse(q3.isFetchAllowed());
    assertFalse(q3.isFetchMandatory());
    QueryMetadata md3 = q3.getMetaData(null);
    assertFalse(md3.isFetchingDataRows());
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 60 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ObjectIdQueryTest method testSerializability.

@Test
public void testSerializability() throws Exception {
    ObjectId oid = new ObjectId("test", "a", "b");
    ObjectIdQuery query = new ObjectIdQuery(oid);
    Object o = Util.cloneViaSerialization(query);
    assertNotNull(o);
    assertTrue(o instanceof ObjectIdQuery);
    assertEquals(oid, ((ObjectIdQuery) o).getObjectId());
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Aggregations

ObjectId (org.apache.cayenne.ObjectId)156 Test (org.junit.Test)104 Persistent (org.apache.cayenne.Persistent)38 DataObject (org.apache.cayenne.DataObject)20 DataRow (org.apache.cayenne.DataRow)20 ObjectContext (org.apache.cayenne.ObjectContext)20 ObjEntity (org.apache.cayenne.map.ObjEntity)20 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)18 HashMap (java.util.HashMap)17 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)16 ArrayList (java.util.ArrayList)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)14 Artist (org.apache.cayenne.testdo.testmap.Artist)14 Map (java.util.Map)13 EntityResolver (org.apache.cayenne.map.EntityResolver)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ChangeMap (org.apache.cayenne.commitlog.model.ChangeMap)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)10 SelectQuery (org.apache.cayenne.query.SelectQuery)10 ObjectChange (org.apache.cayenne.commitlog.model.ObjectChange)9