Java Code Examples for io.vlingo.symbio.store.MapQueryExpression#using()

The following examples show how to use io.vlingo.symbio.store.MapQueryExpression#using() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectEntity.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
private QueryExpression queryExpression() {
  if (queryExpression == null) {
    if (info.queryObjectExpression.isListQueryExpression()) {
      queryExpression =
              ListQueryExpression.using(
                      info.queryObjectExpression.type,
                      info.queryObjectExpression.query,
                      stateObject().queryList());
    } else if (info.queryObjectExpression.isMapQueryExpression()) {
      queryExpression =
              MapQueryExpression.using(
                      info.queryObjectExpression.type,
                      info.queryObjectExpression.query,
                      stateObject().queryMap());
    } else {
      throw new IllegalStateException("Unknown QueryExpression type: " + queryExpression);
    }
  }
  return queryExpression;
}
 
Example 2
Source File: EmployeeEntityTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setUp() {
  world = World.startWithDefaults("test-object-entity");
  objectStore = world.actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

  registry = new ObjectTypeRegistry(world);

  // NOTE: The InMemoryObjectStoreActor implementation currently
  // does not use PersistentObjectMapper, and thus the no-op decl.
  final Info<Employee> employeeInfo =
          new Info(
          objectStore,
          EmployeeState.class,
          "HR-Database",
          MapQueryExpression.using(Employee.class, "find", MapQueryExpression.map("number", "number")),
          StateObjectMapper.with(Employee.class, new Object(), new Object()));

  registry.register(employeeInfo);
}
 
Example 3
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap(final VlingoServer vlingoServer) {
    this.server = vlingoServer.getServer();
    this.world = vlingoServer.getVlingoScene().getWorld();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(StockEntity.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(StockEntity.class, new Object(), new Object());

    final Info<StockState> info =
            new Info(objectStore, StockState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    StockQueryProvider.using(world.stage(), objectStore);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        stopAndCleanup();
    }));
}
 
Example 4
Source File: StockTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    final World world = TestWorld.start("stock-test").world();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Stock.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(Stock.class, new Object(), new Object());

    final Info<StockState> info =
            new Info(objectStore, StockState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    StockQueryProvider.using(world.stage(), objectStore);
}
 
Example 5
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap(final VlingoServer vlingoServer) {
    this.server = vlingoServer.getServer();
    this.world = vlingoServer.getVlingoScene().getWorld();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Order.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(Order.class, new Object(), new Object());

    final Info<OrderState> info =
            new Info(objectStore, OrderState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    OrderQueryProvider.using(world.stage(), objectStore);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        stopAndCleanup();
    }));
}
 
Example 6
Source File: OrderTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    final World world = TestWorld.start("order-test").world();

    messagingClient = Mockito.mock(MessagingClient.class);
    applicationRegistry = Mockito.mock(ApplicationRegistry.class);
    Mockito.when(applicationRegistry.retrieveStage()).thenReturn(world.stage());
    Mockito.when(applicationRegistry.retrieveMessagingClient()).thenReturn(messagingClient);

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Order.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(Order.class, new Object(), new Object());

    final ObjectTypeRegistry.Info<OrderState> info =
            new ObjectTypeRegistry.Info(objectStore, OrderState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    OrderQueryProvider.using(world.stage(), objectStore);
}
 
Example 7
Source File: OrganizationEntityTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() throws Exception {
  grid = Grid.start("object-entity-test", Configuration.define(), ClusterProperties.oneNode(), "node1");
  grid.quorumAchieved();
  objectStore = grid.actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());
  registry = new ObjectTypeRegistry(grid.world());

  final Info<Organization> info =
          new Info(
          objectStore,
          io.vlingo.entity.object.State.class,
          "ObjectStore",
          MapQueryExpression.using(Organization.class, "find", MapQueryExpression.map("id", "id")),
          StateObjectMapper.with(Organization.class, new Object(), new Object()));

  registry.register(info);
}
 
Example 8
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap(final VlingoServer vlingoServer) {
    this.server = vlingoServer.getServer();
    this.world = vlingoServer.getVlingoScene().getWorld();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Calculation.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(Calculation.class, new Object(), new Object());

    final Info<CalculationState> info =
            new Info(objectStore, CalculationState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    CalculationQueryProvider.using(world.stage(), objectStore);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        stopAndCleanup();
    }));
}
 
Example 9
Source File: CalculationTests.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    final World world = TestWorld.start("calculation-test").world();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Calculation.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(CalculationState.class, new Object(), new Object());

    final ObjectTypeRegistry.Info<CalculationState> info =
            new ObjectTypeRegistry.Info(objectStore, CalculationState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    CalculationQueryProvider.using(world.stage(), objectStore);
}
 
Example 10
Source File: InMemoryObjectStoreActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatObjectPersistsQueries() {
  dispatcher.afterCompleting(1);
  final AccessSafely persistAccess = persistInterest.afterCompleting(1);
  final Person person = new Person("Tom Jones", 85);
  final Test1Source source = new Test1Source();
  objectStore.persist(StateSources.of(person, source), persistInterest);
  final int persistSize = persistAccess.readFrom("size");
  assertEquals(1, persistSize);
  assertEquals(person, persistAccess.readFrom("object", 0));

  final QueryExpression query = MapQueryExpression
          .using(Person.class, "find", MapQueryExpression.map("id", "" + person.persistenceId()));

  final AccessSafely queryAccess = queryResultInterest.afterCompleting(1);
  objectStore.queryObject(query, queryResultInterest, null);
  final int querySize = queryAccess.readFrom("size");
  assertEquals(1, querySize);
  assertEquals(person, queryAccess.readFrom("object", 0));

  assertEquals(1, dispatcher.dispatchedCount());
  final Dispatchable<Entry<?>, State<?>> dispatched = dispatcher.getDispatched().get(0);
  validateDispatchedState(person, dispatched);

  final List<Entry<?>> dispatchedEntries = dispatched.entries();
  Assert.assertEquals(1, dispatchedEntries.size());
  final Entry<?> entry = dispatchedEntries.get(0);
  Assert.assertNotNull(entry.id());
  Assert.assertEquals(source.getClass().getName(), entry.typeName());
  Assert.assertEquals(Metadata.nullMetadata(), entry.metadata());
}
 
Example 11
Source File: ObjectProcessTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
  world = World.startWithDefaults("five-step-process-test");

  final MessageQueue queue = new AsyncMessageQueue(null);
  exchange = new LocalExchange(queue);
  final ProcessMessageTextAdapter adapter = new ProcessMessageTextAdapter();
  EntryAdapterProvider.instance(world).registerAdapter(ProcessMessage.class, adapter);

  dispatcher = new MockTextDispatcher();
  objectStore = world.actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, dispatcher);

  objectTypeRegistry = new ObjectTypeRegistry(world);

  final Info<StepCountObjectState> stepCountStateInfo =
          new ObjectTypeRegistry.Info(
          objectStore,
          StepCountObjectState.class,
          StepCountObjectState.class.getSimpleName(),
          MapQueryExpression.using(StepCountObjectState.class, "find", MapQueryExpression.map("id", "id")),
          StateObjectMapper.with(StepCountObjectState.class, new Object(), new Object()));

  objectTypeRegistry.register(stepCountStateInfo);

  exchangeReceivers = new ExchangeReceivers();
  exchangeSender = new LocalExchangeSender(queue);

  registerExchangeCoveys();

  processTypeRegistry = new ProcessTypeRegistry(world);
  processTypeRegistry.register(new ObjectProcessInfo(FiveStepEmittingObjectProcess.class, FiveStepEmittingObjectProcess.class.getSimpleName(), exchange, objectTypeRegistry));
}
 
Example 12
Source File: StockQueriesActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<StockState> queryByLocation(final Location location) {
    final QueryExpression queryExpression =
            MapQueryExpression.using(StockState.class, "findAll");

    final Function<Set<StockState>, StockState> filter = states ->
            states.stream().filter(state -> state.locatedIn(location)).findFirst().get();

    return this.queryAll(Set.class, queryExpression, filter);
}
 
Example 13
Source File: OrderQueriesActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Set<OrderState>> allOrders() {
    final QueryExpression queryExpression =
            MapQueryExpression.using(OrderState.class, "findAll");

    return this.queryAll(Set.class, queryExpression, states -> (Set) states);
}
 
Example 14
Source File: CalculationQueriesActor.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Set<CalculationState>> allCalculations() {
    final QueryExpression queryExpression =
            MapQueryExpression.using(CalculationState.class, "findAll");

    return this.queryAll(Set.class, queryExpression, states -> (Set) states);
}