Search in sources :

Example 1 with MeaningfulPKTest1

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testToManyRelationshipWithMeaningfulPK1.

@Test
public void testToManyRelationshipWithMeaningfulPK1() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    // must be able to resolve to-many relationship
    ObjectContext context = runtime.newContext();
    List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
    assertEquals(1, objects.size());
    obj = objects.get(0);
    assertEquals(0, obj.getMeaningfulPKDepArray().size());
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 2 with MeaningfulPKTest1

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testChangeKey.

@Test
public void testChangeKey() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    obj.setPkAttribute(2000);
    context.commitChanges();
    // assert that object id got fixed
    ObjectId id = obj.getObjectId();
    assertEquals(2000, id.getIdSnapshot().get("PK_ATTRIBUTE"));
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 3 with MeaningfulPKTest1

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testInsertWithMeaningfulPK.

@Test
public void testInsertWithMeaningfulPK() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    ObjectId objId = new ObjectId("MeaningfulPKTest1", MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN, 1000);
    ObjectIdQuery q = new ObjectIdQuery(objId, true, ObjectIdQuery.CACHE_REFRESH);
    @SuppressWarnings("unchecked") List<DataRow> result = (List<DataRow>) context.performQuery(q);
    assertEquals(1, result.size());
    assertEquals(1000, result.get(0).get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectId(org.apache.cayenne.ObjectId) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 4 with MeaningfulPKTest1

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testGeneratedIntPK.

@Test
public void testGeneratedIntPK() {
    MeaningfulPKTest1 obj1 = context.newObject(MeaningfulPKTest1.class);
    obj1.setIntAttribute(10);
    MeaningfulPKTest1 obj2 = context.newObject(MeaningfulPKTest1.class);
    obj2.setIntAttribute(20);
    context.commitChanges();
    ObjectContext context = runtime.newContext();
    List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
    assertEquals(2, objects.size());
    assertNotEquals(0, obj1.getPkAttribute());
    assertNotEquals(0, obj2.getPkAttribute());
    assertNotEquals(obj1.getPkAttribute(), obj2.getPkAttribute());
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 5 with MeaningfulPKTest1

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testGeneratedKey.

@Test
public void testGeneratedKey() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    assertNotEquals(0, obj.getPkAttribute());
    assertSame(obj, Cayenne.objectForPK(context, MeaningfulPKTest1.class, obj.getPkAttribute()));
    int id = Cayenne.intPKForObject(obj);
    Map snapshot = context.getObjectStore().getDataRowCache().getCachedSnapshot(obj.getObjectId());
    assertNotNull(snapshot);
    assertTrue(snapshot.containsKey(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
    assertEquals(id, snapshot.get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MeaningfulPKTest1 (org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1)7 Test (org.junit.Test)7 ObjectContext (org.apache.cayenne.ObjectContext)3 ObjectId (org.apache.cayenne.ObjectId)2 List (java.util.List)1 Map (java.util.Map)1 DataRow (org.apache.cayenne.DataRow)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 MeaningfulPKDep (org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKDep)1