use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityIdCoderTest method testSingleLongPk.
@Test
public void testSingleLongPk() {
DbEntity dbEntity = new DbEntity("X");
DbAttribute pk = new DbAttribute("ID");
pk.setType(Types.BIGINT);
pk.setPrimaryKey(true);
dbEntity.addAttribute(pk);
ObjEntity entity = mock(ObjEntity.class);
when(entity.getName()).thenReturn("x");
when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
when(entity.getDbEntity()).thenReturn(dbEntity);
ObjectId id = new ObjectId("x", "ID", 3L);
EntityIdCoder coder = new EntityIdCoder(entity);
assertEquals("x:3", coder.toStringId(id));
ObjectId parsedId = coder.toObjectId("x:3");
assertEquals(id, parsedId);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityIdCoderTest method testSingleIntPk.
@Test
public void testSingleIntPk() {
DbEntity dbEntity = new DbEntity("X");
DbAttribute pk = new DbAttribute("ID");
pk.setType(Types.INTEGER);
pk.setPrimaryKey(true);
dbEntity.addAttribute(pk);
ObjEntity entity = mock(ObjEntity.class);
when(entity.getName()).thenReturn("x");
when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
when(entity.getDbEntity()).thenReturn(dbEntity);
ObjectId id = new ObjectId("x", "ID", 3);
EntityIdCoder coder = new EntityIdCoder(entity);
assertEquals("x:3", coder.toStringId(id));
ObjectId parsedId = coder.toObjectId("x:3");
assertEquals(id, parsedId);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityIdCoderTest method testSingleStringPk.
@Test
public void testSingleStringPk() {
DbEntity dbEntity = new DbEntity("X");
DbAttribute pk = new DbAttribute("ID");
pk.setType(Types.VARCHAR);
pk.setPrimaryKey(true);
dbEntity.addAttribute(pk);
ObjEntity entity = mock(ObjEntity.class);
when(entity.getName()).thenReturn("x");
when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
when(entity.getDbEntity()).thenReturn(dbEntity);
EntityIdCoder coder = new EntityIdCoder(entity);
ObjectId id = new ObjectId("x", "ID", "AbC");
assertEquals("x:AbC", coder.toStringId(id));
ObjectId parsedId = coder.toObjectId("x:AbC");
assertEquals(id, parsedId);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityIdCoderTest method testIdEncoding.
@Test
public void testIdEncoding() {
DbEntity dbEntity = new DbEntity("X");
DbAttribute pk = new DbAttribute("ID");
pk.setType(Types.VARCHAR);
pk.setPrimaryKey(true);
dbEntity.addAttribute(pk);
ObjEntity entity = mock(ObjEntity.class);
when(entity.getName()).thenReturn("x");
when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
when(entity.getDbEntity()).thenReturn(dbEntity);
EntityIdCoder coder = new EntityIdCoder(entity);
ObjectId id = new ObjectId("x", "ID", "Ab:C");
assertEquals("x:Ab%3AC", coder.toStringId(id));
ObjectId parsedId = coder.toObjectId("x:Ab%3AC");
assertEquals(id, parsedId);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DataDomainFlushAction method runQueries.
private void runQueries() {
DataDomainFlushObserver observer = new DataDomainFlushObserver(domain.getJdbcEventLogger());
try {
DataNode lastNode = null;
DbEntity lastEntity = null;
int rangeStart = 0;
int len = queries.size();
for (int i = 0; i < len; i++) {
BatchQuery query = (BatchQuery) queries.get(i);
if (query.getDbEntity() != lastEntity) {
lastEntity = query.getDbEntity();
DataNode node = domain.lookupDataNode(lastEntity.getDataMap());
if (node != lastNode) {
if (i - rangeStart > 0) {
lastNode.performQueries(queries.subList(rangeStart, i), observer);
}
rangeStart = i;
lastNode = node;
}
}
}
// process last segment of the query list...
lastNode.performQueries(queries.subList(rangeStart, len), observer);
} catch (Throwable th) {
BaseTransaction.getThreadTransaction().setRollbackOnly();
throw new CayenneRuntimeException("Transaction was rolledback.", th);
}
}
Aggregations