use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class PostgreSQLDBIntegrityTest method createAndRemoveEntityAndVerifyNoExtraDataLeftInDB.
@Test
public void createAndRemoveEntityAndVerifyNoExtraDataLeftInDB() throws Exception {
UnitOfWork uow = this.module.newUnitOfWork();
TestEntity entity = uow.newEntity(TestEntity.class);
uow.complete();
uow = this.module.newUnitOfWork();
entity = uow.get(entity);
SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY);
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = PostgreSQLAppStartup.DEFAULT_SCHEMA_NAME;
}
uow.remove(entity);
uow.complete();
Connection connection = this.module.findService(DataSource.class).get().getConnection();
try {
GenericDatabaseExplorer.visitDatabaseTables(connection, null, schemaName, null, new DatabaseProcessorAdapter() {
@Override
public void beginProcessRowInfo(String schemaNamee, String tableName, Object[] rowContents) {
if ((tableName.startsWith(DBNames.QNAME_TABLE_NAME_PREFIX) && (tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 0) || tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 1))) || tableName.equals(DBNames.ALL_QNAMES_TABLE_NAME) || tableName.equals(DBNames.ENTITY_TABLE_NAME)) {
throw new RuntimeException("Table: " + schemaNamee + "." + tableName);
}
}
}, SQLVendorProvider.createVendor(PostgreSQLVendor.class));
} finally {
SQLUtil.closeQuietly(connection);
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class SolrQueryServiceTest method index.
@Before
public void index() throws UnitOfWorkCompletionException, InterruptedException {
// Create and index an entity
UnitOfWork uow = module.newUnitOfWork();
TestEntity test = uow.newEntity(TestEntity.class);
test.name().set("Hello World");
uow.complete();
Thread.sleep(40);
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class NoMetricsInstalledTest method createEntity.
private void createEntity(int id) throws UnitOfWorkCompletionException {
UnitOfWork uow = module.newUnitOfWork();
try {
uow.newEntity(Person.class, "" + id);
uow.complete();
} finally {
if (uow.isOpen())
uow.discard();
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class YammerTest method createEntity.
private void createEntity(int id) throws UnitOfWorkCompletionException {
UnitOfWork uow = module.newUnitOfWork();
try {
uow.newEntity(Person.class, "" + id);
uow.complete();
} finally {
if (uow.isOpen())
uow.discard();
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class Qi173IssueTest method testPersistence.
@Test
public void testPersistence() {
UnitOfWork uow = module.newUnitOfWork();
try {
createCar("Volvo", "S80", 2007);
createCar("Volvo", "C70", 2006);
createCar("Ford", "Transit", 2007);
createCar("Ford", "Mustang", 2007);
createCar("Ford", "Mustang", 2006);
createCar("Ford", "Mustang", 2005);
uow.complete();
} catch (ConcurrentEntityModificationException e) {
// Can not happen.
e.printStackTrace();
} catch (UnitOfWorkCompletionException e) {
e.printStackTrace();
}
uow = module.newUnitOfWork();
QueryBuilder<Car> qb = module.newQueryBuilder(Car.class);
Car template = QueryExpressions.templateFor(Car.class);
qb = qb.where(QueryExpressions.eq(template.year(), 2007));
Query<Car> query = uow.newQuery(qb);
query.orderBy(orderBy(template.manufacturer()), orderBy(template.model()));
Iterator<Car> cars = query.iterator();
Assert.assertTrue(cars.hasNext());
Car car1 = cars.next();
Assert.assertEquals(car1.manufacturer().get(), "Ford");
Assert.assertEquals(car1.model().get(), "Mustang");
Assert.assertEquals((int) car1.year().get(), 2007);
Car car2 = cars.next();
Assert.assertEquals(car2.manufacturer().get(), "Ford");
Assert.assertEquals(car2.model().get(), "Transit");
Assert.assertEquals((int) car2.year().get(), 2007);
Car car3 = cars.next();
Assert.assertEquals(car3.manufacturer().get(), "Volvo");
Assert.assertEquals(car3.model().get(), "S80");
Assert.assertEquals((int) car3.year().get(), 2007);
for (Car car : query) {
System.out.println(car.manufacturer().get() + " " + car.model().get() + ", " + car.year().get());
}
uow.discard();
}
Aggregations