Search in sources :

Example 91 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ContainsAllTest method performContainsAllStringValueTest.

private ExampleEntity performContainsAllStringValueTest(Set<String> entityStrings, Set<String> queryableStrings) throws Exception {
    UnitOfWork creatingUOW = this.module.newUnitOfWork();
    String[] entityStringsArray = new String[entityStrings.size()];
    createEntityWithComplexValues(creatingUOW, this.module, entityStrings.toArray(entityStringsArray));
    creatingUOW.complete();
    UnitOfWork queryingUOW = this.module.newUnitOfWork();
    try {
        String[] queryableStringsArray = new String[queryableStrings.size()];
        ExampleEntity entity = this.findEntityBasedOnValueStrings(queryableStrings.toArray(queryableStringsArray));
        return entity;
    } finally {
        queryingUOW.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork)

Example 92 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ContainsTest method performContainsStringValueTest.

private ExampleEntity performContainsStringValueTest(Set<String> entityStrings, String queryableString) throws Exception {
    UnitOfWork creatingUOW = this.module.newUnitOfWork();
    String[] entityStringsArray = new String[entityStrings.size()];
    ContainsAllTest.createEntityWithComplexValues(creatingUOW, this.module, entityStrings.toArray(entityStringsArray));
    creatingUOW.complete();
    UnitOfWork queryingUOW = this.module.newUnitOfWork();
    try {
        ExampleEntity entity = this.findEntityBasedOnValueString(queryableString);
        return entity;
    } finally {
        queryingUOW.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ExampleEntity(org.qi4j.index.rdf.ContainsAllTest.ExampleEntity)

Example 93 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ContainsTest method performContainsStringTest.

private ExampleEntity performContainsStringTest(Set<String> entityStrings, String queryableString) throws Exception {
    UnitOfWork creatingUOW = this.module.newUnitOfWork();
    String[] entityStringsArray = new String[entityStrings.size()];
    ContainsAllTest.createEntityWithStrings(creatingUOW, this.module, entityStrings.toArray(entityStringsArray));
    creatingUOW.complete();
    UnitOfWork queryingUOW = this.module.newUnitOfWork();
    try {
        ExampleEntity entity = this.findEntity(queryableString);
        return entity;
    } finally {
        queryingUOW.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ExampleEntity(org.qi4j.index.rdf.ContainsAllTest.ExampleEntity)

Example 94 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class RDFPerformanceTest method doList.

private List<ExampleEntity> doList(int howMany) {
    List<ExampleEntity> list = new ArrayList<ExampleEntity>();
    UnitOfWork uow = this.module.newUnitOfWork();
    Iterator<ExampleEntity> iter = uow.newQuery(this.module.newQueryBuilder(ExampleEntity.class)).iterator();
    int found = 0;
    while (iter.hasNext()) {
        found++;
        ExampleEntity exampleEntity = iter.next();
        if (exampleEntity != null)
            list.add(exampleEntity);
    }
    uow.discard();
    if (found != howMany) {
        LOG.warn("Found " + found + " entities instead of " + howMany + ".");
    }
    return list;
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ArrayList(java.util.ArrayList)

Example 95 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class DomainEventSourceResourceSample method generateTestData.

private static void generateTestData(UnitOfWorkFactory unitOfWorkFactory) throws UnitOfWorkCompletionException {
    // Set principal for the UoW
    Principal administratorPrincipal = new Principal() {

        public String getName() {
            return "administrator";
        }
    };
    // Perform UoW with usecase defined
    for (int i = 0; i < 43; i++) {
        UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(UsecaseBuilder.newUsecase("Change description " + (i + 1)));
        uow.setMetaInfo(administratorPrincipal);
        TestEntity entity = uow.newEntity(TestEntity.class);
        entity.changedDescription("New description");
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Principal(java.security.Principal) CurrentUserUoWPrincipal(org.qi4j.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal)

Aggregations

UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)332 Test (org.junit.Test)232 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)108 Before (org.junit.Before)21 AssemblyException (org.qi4j.bootstrap.AssemblyException)21 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)18 Delivery (org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery)17 HandlingEventsEntity (org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity)15 PersonEntity (org.qi4j.library.conversion.values.TestModel.PersonEntity)13 CargoAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot)13 IOException (java.io.IOException)12 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)12 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 Cargos (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos)12 HandlingEvent (org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent)12 Location (org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location)11 HandlingEventAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot)11 Date (java.util.Date)10 BalanceData (org.qi4j.dci.moneytransfer.domain.data.BalanceData)10 File (java.io.File)8