// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package cache.infinispan.jnosql;

import java.util.HashMap;
import java.util.Map;

import jakarta.nosql.Settings;
import jakarta.nosql.keyvalue.BucketManagerFactory;
import jakarta.nosql.keyvalue.KeyValueConfiguration;

import org.eclipse.jnosql.diana.infinispan.keyvalue.InfinispanKeyValueConfiguration;

public class TestFunctional {
    private static void test(Map<String,Integer> cache) {
        // basic put, get and remove
        cache.put("v", 123);
        System.out.println(cache.get("v"));
        cache.remove("v");
        System.out.println(cache.get("v"));
        cache.put("v", 123);
        System.out.println(cache.get("v"));
        // persistence
        Integer counter = cache.get("counter");
        if(counter == null) {
            counter = 0;
        }
        counter++;
        System.out.println(counter);
        cache.put("counter", counter);
        // list all not supported
        // listener not supported
    }
    public static void main(String[] args) throws Exception {
        KeyValueConfiguration cfg = new InfinispanKeyValueConfiguration();
        Map<String, Object> props = new HashMap<>();
        props.put("infinispan.host", "localhost"); // necessary to get remote cache instead of local cache
        BucketManagerFactory bmf = cfg.get(Settings.of(props));
        Map<String,Integer> cache = bmf.getMap("functional_cache", String.class, Integer.class);
        test(cache);
        bmf.close();
    }
}
