Search in sources :

Example 1 with EntityMapPersist

use of com.tvd12.calabash.persist.EntityMapPersist in project calabash by youngmonkeys.

the class SimpleEntityMapPersistExecutor method persist.

@Override
public void persist(EntityMapSetting mapSetting, Object key, Object value) {
    EntityMapPersist mapPersist = getMapPersist(mapSetting);
    if (mapPersist != null) {
        PersistSaveOneAction action = new PersistSaveOneAction(key, value);
        addPersistActionToQueue(mapSetting, action);
    }
}
Also used : EntityMapPersist(com.tvd12.calabash.persist.EntityMapPersist)

Example 2 with EntityMapPersist

use of com.tvd12.calabash.persist.EntityMapPersist in project calabash by youngmonkeys.

the class SimpleEntityMapPersistExecutor method delete.

@Override
public void delete(EntityMapSetting mapSetting, Set keys) {
    EntityMapPersist mapPersist = getMapPersist(mapSetting);
    if (mapPersist != null) {
        PersistDeleteManyAction action = new PersistDeleteManyAction(keys);
        addPersistActionToQueue(mapSetting, action);
    }
}
Also used : EntityMapPersist(com.tvd12.calabash.persist.EntityMapPersist)

Example 3 with EntityMapPersist

use of com.tvd12.calabash.persist.EntityMapPersist in project calabash by youngmonkeys.

the class LocalMapAnimalPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() throws Exception {
    SimpleSettings settings = new SimpleSettings();
    SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
    mapPersistSetting.setWriteDelay(0);
    SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
    mapSetting.setMapName(CollectionNames.ANIMAL);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistences = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistences) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Animal animal = new Animal(2, "animal 2", "cat");
    EntityMap<Long, Animal> entityMap = calabash.getEntityMap(CollectionNames.ANIMAL);
    entityMap.put(animal.getId(), animal);
    AnimalByNickQuery query = new AnimalByNickQuery(animal.getNick());
    Animal animalByQuery = entityMap.getByQuery(1L, query);
    System.out.println("animal by query: " + animalByQuery);
    Map<String, Object> statistics = new HashMap<>();
    // noinspection InfiniteLoopStatement
    while (true) {
        // noinspection BusyWait
        Thread.sleep(1000);
        ((StatisticsAware) calabash).addStatistics(statistics);
        System.out.println("statistics: " + statistics);
    }
}
Also used : SimpleEntityMapSetting(com.tvd12.calabash.local.setting.SimpleEntityMapSetting) SimpleSettings(com.tvd12.calabash.local.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) HashMap(java.util.HashMap) SimpleEntityMapPersistSetting(com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting) CalabashBuilder(com.tvd12.calabash.local.CalabashBuilder) Animal(com.tvd12.calabash.local.test.mappersist.Animal) List(java.util.List) StatisticsAware(com.tvd12.calabash.core.statistic.StatisticsAware) Calabash(com.tvd12.calabash.Calabash) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)

Example 4 with EntityMapPersist

use of com.tvd12.calabash.persist.EntityMapPersist in project calabash by youngmonkeys.

the class LocalMapPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() throws Exception {
    SimpleSettings settings = new SimpleSettings();
    SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
    mapPersistSetting.setWriteDelay(0);
    SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
    mapSetting.setMapName(CollectionNames.PERSON);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistenceList) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Person person = new Person(11, "person 6", 18);
    EntityMap<Long, Person> entityMap = calabash.getEntityMap(CollectionNames.PERSON);
    entityMap.put(person.getId(), person);
    IAtomicLong atomicLong = calabash.getAtomicLong("hello");
    long newValue = atomicLong.addAndGet(100L);
    System.out.println("atomic long new value: " + newValue);
    Map<String, Object> statistics = new HashMap<>();
    // noinspection InfiniteLoopStatement
    while (true) {
        // noinspection BusyWait
        Thread.sleep(1000);
        ((StatisticsAware) calabash).addStatistics(statistics);
        System.out.println("statistics: " + statistics);
    }
}
Also used : SimpleEntityMapSetting(com.tvd12.calabash.local.setting.SimpleEntityMapSetting) SimpleSettings(com.tvd12.calabash.local.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) HashMap(java.util.HashMap) SimpleEntityMapPersistSetting(com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting) CalabashBuilder(com.tvd12.calabash.local.CalabashBuilder) IAtomicLong(com.tvd12.calabash.core.IAtomicLong) List(java.util.List) StatisticsAware(com.tvd12.calabash.core.statistic.StatisticsAware) Calabash(com.tvd12.calabash.Calabash) IAtomicLong(com.tvd12.calabash.core.IAtomicLong) Person(com.tvd12.calabash.local.test.mappersist.Person) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)

Example 5 with EntityMapPersist

use of com.tvd12.calabash.persist.EntityMapPersist in project calabash by youngmonkeys.

the class PersistSaveActionBulk method execute.

@Override
public void execute() {
    Map<Object, Object> keyValues = new HashMap<>();
    for (PersistAction action : actions) {
        if (action.getType() == PersistActionType.SAVE_ONE) {
            PersistSaveOneAction one = (PersistSaveOneAction) action;
            keyValues.put(one.getKey(), one.getValue());
        } else {
            PersistSaveManyAction many = (PersistSaveManyAction) action;
            keyValues.putAll(many.getKeyValues());
        }
    }
    ((EntityMapPersist) mapPersist).persist(keyValues);
}
Also used : PersistSaveManyAction(com.tvd12.calabash.persist.action.PersistSaveManyAction) HashMap(java.util.HashMap) PersistSaveOneAction(com.tvd12.calabash.persist.action.PersistSaveOneAction) EntityMapPersist(com.tvd12.calabash.persist.EntityMapPersist) PersistAction(com.tvd12.calabash.persist.action.PersistAction)

Aggregations

EntityMapPersist (com.tvd12.calabash.persist.EntityMapPersist)6 Calabash (com.tvd12.calabash.Calabash)3 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)3 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)3 HashMap (java.util.HashMap)3 List (java.util.List)3 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)2 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)2 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)2 SimpleEntityMapSetting (com.tvd12.calabash.local.setting.SimpleEntityMapSetting)2 SimpleSettings (com.tvd12.calabash.local.setting.SimpleSettings)2 PersistAction (com.tvd12.calabash.persist.action.PersistAction)2 BytesMap (com.tvd12.calabash.core.BytesMap)1 IAtomicLong (com.tvd12.calabash.core.IAtomicLong)1 ByteArray (com.tvd12.calabash.core.util.ByteArray)1 Animal (com.tvd12.calabash.local.test.mappersist.Animal)1 Person (com.tvd12.calabash.local.test.mappersist.Person)1 PersistSaveManyAction (com.tvd12.calabash.persist.action.PersistSaveManyAction)1 PersistSaveOneAction (com.tvd12.calabash.persist.action.PersistSaveOneAction)1 BytesMapPersistFactory (com.tvd12.calabash.persist.factory.BytesMapPersistFactory)1