use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.
the class LocalMapPersistExample method test.
@SuppressWarnings("rawtypes")
public void test() {
EzyEntityCodec entityCodec = newEntityCodec();
SimpleSettings settings = new SimpleSettings();
SimpleMapPersistSetting mapPersistSetting = new SimpleMapPersistSetting();
SimpleMapSetting mapSetting = new SimpleMapSetting();
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);
}
BytesMapPersistFactory bytesMapPersistFactory = EntityBytesMapPersistFactory.builder().entityCodec(entityCodec).entityMapPersistFactory(mapPersistFactoryBuilder.build()).build();
Calabash calabash = CalabashServerContext.builder().settings(settings).bytesMapPersistFactory(bytesMapPersistFactory).build();
ByteArray keyBytes = new ByteArray(entityCodec.serialize(1L));
byte[] values = entityCodec.serialize(new Person(9L, "bar", 29));
BytesMap bytesMap = calabash.getBytesMap(CollectionNames.PERSON);
bytesMap.put(keyBytes, values);
}
use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.
the class MapRequestController method mapGetMany.
@Rpc(Commands.MAP_GET_MANY)
public List<byte[]> mapGetMany(MapGetManyRequest request) {
BytesMap map = getBytesMap(request.getMapId());
List<ByteArray> keys = ByteArray.wrap(request.getKeys());
Map<ByteArray, byte[]> m = map.get(keys);
List<byte[]> answer = new ArrayList<>(keys.size());
for (ByteArray key : keys) {
answer.add(m.get(key));
}
return answer;
}
use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.
the class LocalExample method main.
public static void main(String[] args) {
Settings settings = new SimpleSettings();
MapPersistManager mapPersistManager = new SimpleMapPersistManager();
BytesMapBackupExecutor backupExecutor = new SimpleBytesMapBackupExecutor();
BytesMapPersistExecutor persistExecutor = SimpleBytesMapPersistExecutor.builder().mapPersistManager(mapPersistManager).build();
BytesMap bytesMap = BytesMapImpl.builder().mapSetting(settings.getMapSetting("test")).mapBackupExecutor(backupExecutor).mapPersistExecutor(persistExecutor).build();
bytesMap.loadAll();
bytesMap.put(new ByteArray(new byte[] { 1, 2, 3 }), new byte[] { 1, 2, 3 });
System.out.println(Arrays.toString(bytesMap.get(new ByteArray(new byte[] { 1, 2, 3 }))));
}
use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.
the class SimpleBytesMapPersistExecutor method persist.
@Override
public void persist(MapSetting mapSetting, Map<ByteArray, byte[]> m) {
BytesMapPersist mapPersist = getMapPersist(mapSetting);
if (mapPersist != null) {
PersistSaveManyAction action = new PersistSaveManyAction(m);
addPersistActionToQueue(mapSetting, action);
}
}
use of com.tvd12.calabash.core.util.ByteArray in project calabash by youngmonkeys.
the class SimpleBytesMapPersistExecutor method delete.
@Override
public void delete(MapSetting mapSetting, Set<ByteArray> keys) {
BytesMapPersist mapPersist = getMapPersist(mapSetting);
if (mapPersist != null) {
PersistDeleteManyAction action = new PersistDeleteManyAction(keys);
addPersistActionToQueue(mapSetting, action);
}
}
Aggregations