public School findSchoolByName(String schoolName) {
   QueryBuilder<School> builder = qbf.newQueryBuilder(School.class);
   SchoolEntity.SchoolState template = templateFor(SchoolEntity.SchoolState.class);
   builder.where(eq(template.name(), schoolName));
   Query<School> query = builder.newQuery(uowf.currentUnitOfWork());
   return query.find();
 }
Beispiel #2
0
 @Test
 public void whenTraceOnMixinImplExpectTwoEntryInEntityStore() throws Exception {
   SomeService sc =
       moduleInstance.serviceFinder().<SomeService>findService(SomeService.class).get();
   assertEquals(123, sc.doSomethingImportant());
   assertEquals(789, sc.doSomethingModeratelyImportant());
   UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
   try {
     QueryBuilder<TraceRecord> builder = queryBuilderFactory.newQueryBuilder(TraceRecord.class);
     Query<TraceRecord> query = builder.newQuery(uow);
     // IS sorting needed??
     TraceRecord template = templateFor(TraceRecord.class);
     query.orderBy(orderBy(template.methodName()));
     Iterator<TraceRecord> result = query.iterator();
     assertTrue(result.hasNext());
     TraceRecord rec1 = result.next();
     assertEquals("doSomethingImportant", rec1.methodName().get());
     assertTrue(result.hasNext());
     TraceRecord rec2 = result.next();
     assertEquals("doSomethingModeratelyImportant", rec2.methodName().get());
     assertFalse(result.hasNext());
     uow.complete();
   } catch (Exception e) {
     uow.discard();
     throw e;
   } catch (Error e) {
     uow.discard();
     throw e;
   }
 }
  @Test
  public void testOperators()
      throws UnitOfWorkCompletionException, ActivationException, AssemblyException {
    SingletonAssembler assembler =
        new SingletonAssembler() {
          @Override
          public void assemble(ModuleAssembly module) throws AssemblyException {
            new EntityTestAssembler().assemble(module);

            module.entities(TestEntity.class);
            module.values(TestValue.class);
            module.forMixin(TestEntity.class).declareDefaults().foo().set("Bar");
            module.forMixin(TestValue.class).declareDefaults().bar().set("Xyz");
          }
        };

    UnitOfWork uow = assembler.module().newUnitOfWork();

    try {
      EntityBuilder<TestEntity> entityBuilder = uow.newEntityBuilder(TestEntity.class, "123");
      entityBuilder.instance().value().set(assembler.module().newValue(TestValue.class));
      TestEntity testEntity = entityBuilder.newInstance();

      uow.complete();
      uow = assembler.module().newUnitOfWork();

      Iterable<TestEntity> entities = Iterables.iterable(testEntity = uow.get(testEntity));

      QueryBuilder<TestEntity> builder = assembler.module().newQueryBuilder(TestEntity.class);

      {
        Specification<Composite> where =
            QueryExpressions.eq(QueryExpressions.templateFor(TestEntity.class).foo(), "Bar");
        Assert.assertTrue(where.satisfiedBy(testEntity));
        System.out.println(where);
      }
      {
        Specification<Composite> where =
            QueryExpressions.eq(
                QueryExpressions.templateFor(TestEntity.class).value().get().bar(), "Xyz");
        Assert.assertTrue(where.satisfiedBy(testEntity));
        System.out.println(where);

        Assert.assertTrue(builder.where(where).newQuery(entities).find().equals(testEntity));
      }
    } finally {
      uow.discard();
    }
  }
Beispiel #4
0
 @Test
 public void whenTraceOnMixinTypeMethodExpectOneEntryInEntityStore() throws Exception {
   SomeService sc =
       moduleInstance.serviceFinder().<SomeService>findService(SomeService.class).get();
   assertEquals(123, sc.doSomethingImportant());
   assertEquals(456, sc.doSomethingLessImportant());
   UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
   QueryBuilder<TraceRecord> builder = queryBuilderFactory.newQueryBuilder(TraceRecord.class);
   Query<TraceRecord> query = builder.newQuery(uow);
   // IS sorting needed??
   //        TraceRecord template = templateFor( TraceRecord.class );
   //        query.orderBy( orderBy( template.methodName() ) );
   Iterator<TraceRecord> result = query.iterator();
   assertTrue(result.hasNext());
   TraceRecord rec1 = result.next();
   assertEquals("doSomethingImportant", rec1.methodName().get());
   assertFalse(result.hasNext());
   uow.complete();
 }
Beispiel #5
0
  @Test
  public void whenTraceOnConcernExpectOneEntryInEntityStore() throws Exception {
    // It is not possible to put Annotation on Concern Methods, so it should only record one.

    SomeService sc =
        moduleInstance.serviceFinder().<SomeService>findService(SomeService.class).get();
    assertEquals(123, sc.doSomethingImportant());
    assertEquals(753, sc.doSomethingInsanelyImportant());
    UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
    QueryBuilder<TraceRecord> builder = queryBuilderFactory.newQueryBuilder(TraceRecord.class);
    Query<TraceRecord> query = builder.newQuery(uow);
    // IS sorting needed??
    //        TraceRecord template = templateFor( TraceRecord.class );
    //        query.orderBy( orderBy( template.methodName() ) );
    Iterator<TraceRecord> result = query.iterator();
    assertTrue(result.hasNext());
    TraceRecord rec1 = result.next();
    assertEquals("doSomethingImportant", rec1.methodName().get());
    assertFalse(result.hasNext());
    uow.complete();
  }