gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [02/17] gora git commit: initial poc commit
Date Fri, 05 Aug 2016 10:41:25 GMT
initial poc commit


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/e28c661b
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/e28c661b
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/e28c661b

Branch: refs/heads/master
Commit: e28c661bccd40a0b03221ad6af08c2bcb3075149
Parents: 2b8b061
Author: Kevin Ratnasekera <djkevincr@yahoo.com>
Authored: Sun Jun 19 15:16:41 2016 +0530
Committer: Kevin Ratnasekera <djkevincr@yahoo.com>
Committed: Sun Jun 19 15:16:41 2016 +0530

----------------------------------------------------------------------
 .../org/apache/gora/store/DataStoreFactory.java | 39 ++++++++++
 .../jcache/store/JCacheCacheEntryListener.java  | 53 ++++++++++++++
 .../store/JCacheCacheEntryListenerFactory.java  | 55 ++++++++++++++
 .../jcache/store/JCacheCacheFactoryBuilder.java | 41 +++++++++++
 .../gora/jcache/store/JCacheCacheLoader.java    | 68 ++++++++++++++++++
 .../jcache/store/JCacheCacheLoaderFactory.java  | 63 ++++++++++++++++
 .../gora/jcache/store/JCacheCacheWriter.java    | 75 ++++++++++++++++++++
 .../jcache/store/JCacheCacheWriterFactory.java  | 62 ++++++++++++++++
 .../apache/gora/jcache/store/JCacheStore.java   | 42 +++++++++--
 gora-jcache/src/test/resources/gora.properties  |  3 +-
 gora-jcache/src/test/resources/hazelcast.xml    | 35 +++++++++
 11 files changed, 531 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java b/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java
index e892012..eca57bf 100644
--- a/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java
+++ b/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java
@@ -42,6 +42,8 @@ public class DataStoreFactory{
 
   public static final String GORA_DEFAULT_DATASTORE_KEY = "gora.datastore.default";
 
+  public static final String GORA_DEFAULT_CACHE_DATASTORE_KEY = "gora.cache.datastore.default";
+
   public static final String GORA = "gora";
 
   public static final String DATASTORE = "datastore";
@@ -274,6 +276,39 @@ public class DataStoreFactory{
     return createDataStore(c, keyClass, persistent, conf, createProps, null);
   }
 
+
+  /**
+   * Instantiate <i>the default</i> {@link DataStore} wrapped over JCache datastore
which provides caching
+   * abstraction over any GORA persistence dataStore.
+   * Uses default properties. Uses 'null' schema.
+   *
+   * Note:
+   *    consider that default dataStore is always visible
+   *
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @param isCacheEnabled caching enable
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  @SuppressWarnings("unchecked")
+  public static <K, T extends Persistent> DataStore<K, T> getDataStore(
+          Class<K> keyClass, Class<T> persistent, Configuration conf, boolean
isCacheEnabled) throws GoraException {
+    Properties createProps = createProps();
+    Class<? extends DataStore<K, T>> c;
+    try {
+      if (isCacheEnabled) {
+        c = (Class<? extends DataStore<K, T>>) Class.forName(getDefaultCacheDataStore(createProps));
+      } else {
+        c = (Class<? extends DataStore<K, T>>) Class.forName(getDefaultDataStore(createProps));
+      }
+    } catch (Exception ex) {
+      throw new GoraException(ex);
+    }
+    return createDataStore(c, keyClass, persistent, conf, createProps, null);
+  }
+
   /**
    * Tries to find a property with the given baseKey. First the property
    * key constructed as "gora.&lt;classname&gt;.&lt;baseKey&gt;" is searched.
@@ -381,6 +416,10 @@ public class DataStoreFactory{
     return getProperty(properties, GORA_DEFAULT_DATASTORE_KEY);
   }
 
+  private static String getDefaultCacheDataStore(Properties properties) {
+    return getProperty(properties, GORA_DEFAULT_CACHE_DATASTORE_KEY);
+  }
+
   private static String getProperty(Properties properties, String key) {
     return getProperty(properties, key, null);
   }

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
new file mode 100644
index 0000000..9284463
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListener.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+
+import javax.cache.event.CacheEntryCreatedListener;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryRemovedListener;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+public class JCacheCacheEntryListener<K, T extends PersistentBase>
+        implements CacheEntryCreatedListener<K, T>,
+        CacheEntryRemovedListener<K, T> {
+
+  private ConcurrentSkipListSet<K> cacheEntryList;
+
+  public JCacheCacheEntryListener(ConcurrentSkipListSet cacheEntryList) {
+    this.cacheEntryList = cacheEntryList;
+  }
+
+  @Override
+  public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends T>> cacheEntryEvents)
+          throws CacheEntryListenerException {
+    for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
+      cacheEntryList.add(event.getKey());
+    }
+  }
+
+  @Override
+  public void onRemoved(Iterable<CacheEntryEvent<? extends K, ? extends T>> cacheEntryEvents)
+          throws CacheEntryListenerException {
+    for (CacheEntryEvent<? extends K, ? extends T> event : cacheEntryEvents) {
+      cacheEntryList.remove(event.getKey());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
new file mode 100644
index 0000000..d1bfc1b
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheEntryListenerFactory.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.cache.configuration.Factory;
+
+public class JCacheCacheEntryListenerFactory <K,T extends PersistentBase>
+        implements Factory<JCacheCacheEntryListener<K, T>> {
+
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheEntryListenerFactory.class);
+  public static final long serialVersionUID = 201305101634L;
+  private JCacheCacheEntryListener<K, T> instance;
+
+  public JCacheCacheEntryListenerFactory(JCacheCacheEntryListener<K, T> instance) {
+    this.instance = instance;
+  }
+
+  public JCacheCacheEntryListener<K, T> create() {
+    return this.instance;
+  }
+
+  public boolean equals(Object other) {
+    if(this == other) {
+      return true;
+    } else if(other != null && this.getClass() == other.getClass()) {
+      JCacheCacheEntryListenerFactory that = (JCacheCacheEntryListenerFactory)other;
+      return this.instance.equals(that.instance);
+    } else {
+      return false;
+    }
+  }
+
+  public int hashCode() {
+    return this.instance.hashCode();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheFactoryBuilder.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheFactoryBuilder.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheFactoryBuilder.java
new file mode 100644
index 0000000..cfc8c77
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheFactoryBuilder.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+
+import javax.cache.configuration.Factory;
+
+public class JCacheCacheFactoryBuilder {
+
+  public static <K, T extends PersistentBase> Factory<JCacheCacheLoader<K,T>>
+  factoryOfCacheLoader(Class<K> keyClass, Class<T> persistentClass) {
+    return new JCacheCacheLoaderFactory<>(keyClass, persistentClass);
+  }
+
+  public static <K, T extends PersistentBase> Factory<JCacheCacheWriter<K,T>>
+  factoryOfCacheWriter(Class<K> keyClass, Class<T> persistentClass) {
+    return new JCacheCacheWriterFactory<>(keyClass, persistentClass);
+  }
+
+  public static <K,T extends PersistentBase> Factory<JCacheCacheEntryListener<K,
T>>
+  factoryOfEntryListener(JCacheCacheEntryListener<K, T> instance) {
+    return new JCacheCacheEntryListenerFactory<>(instance);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
new file mode 100644
index 0000000..f9b540b
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoader.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.util.GoraException;
+import org.apache.hadoop.conf.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.cache.integration.CacheLoader;
+import javax.cache.integration.CacheLoaderException;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class JCacheCacheLoader<K, T extends PersistentBase> implements CacheLoader<K,
T> {
+
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheLoader.class);
+  private DataStore<K, T> dataStore;
+
+  public JCacheCacheLoader(Class<K> keyClass,
+                           Class<T> persistent) throws GoraException {
+    dataStore = DataStoreFactory.getDataStore(keyClass, persistent,
+            new Configuration());
+  }
+
+  @Override
+  public T load(K key) throws CacheLoaderException {
+    T persistent = null;
+    try {
+      persistent = dataStore.get(key);
+    } catch (CacheLoaderException ex) {
+      throw ex;
+    }
+    return persistent;
+  }
+
+  @Override
+  public Map<K, T> loadAll(Iterable<? extends K> keys) throws CacheLoaderException
{
+    Map<K, T> loaded = new HashMap<K, T>();
+    for (K key : keys) {
+      T persistent = dataStore.get(key);
+      if (persistent != null) {
+        loaded.put(key, persistent);
+      }
+    }
+    return loaded;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
new file mode 100644
index 0000000..e710515
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheLoaderFactory.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.cache.configuration.Factory;
+import java.lang.reflect.Constructor;
+
+public class JCacheCacheLoaderFactory<K, T extends PersistentBase>
+        implements Factory<JCacheCacheLoader<K,T>> {
+
+  public static final long serialVersionUID = 201305101626L;
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheLoaderFactory.class);
+  private Class<K> keyClass;
+  private Class<T> persistentClass;
+
+  public JCacheCacheLoaderFactory(Class<K> keyClass,
+                                      Class<T> persistentClass) {
+    this.keyClass = keyClass;
+    this.persistentClass = persistentClass;
+  }
+
+  public JCacheCacheLoader<K,T> create() {
+    try {
+      return (JCacheCacheLoader<K,T>) new JCacheCacheLoader(keyClass, persistentClass);
+    } catch (Exception ex) {
+      throw new RuntimeException("Failed to create an instance of " + JCacheCacheLoader.class,
ex);
+    }
+  }
+
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    } else if (other != null && this.getClass() == other.getClass()) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  public int hashCode() {
+    return this.hashCode();
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
new file mode 100644
index 0000000..2e7fd00
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriter.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.util.GoraException;
+import org.apache.hadoop.conf.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.cache.Cache;
+import javax.cache.integration.CacheWriter;
+import javax.cache.integration.CacheWriterException;
+import java.util.Collection;
+import java.util.Iterator;
+
+public class JCacheCacheWriter<K, T extends PersistentBase> implements CacheWriter<K,
T> {
+
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheWriter.class);
+  private DataStore<K, T> dataStore;
+
+  public JCacheCacheWriter(Class<K> keyClass,
+                           Class<T> persistent) throws GoraException {
+    dataStore = DataStoreFactory.getDataStore(keyClass, persistent,
+            new Configuration());
+  }
+
+  @Override
+  public void write(Cache.Entry<? extends K,
+          ? extends T> entry) throws CacheWriterException {
+    dataStore.put(entry.getKey(), entry.getValue());
+  }
+
+  @Override
+  public void writeAll(Collection<Cache.Entry<? extends K,
+          ? extends T>> entries) throws CacheWriterException {
+    Iterator<Cache.Entry<? extends K, ? extends T>> iterator = entries.iterator();
+    while (iterator.hasNext()) {
+      write(iterator.next());
+      iterator.remove();
+    }
+  }
+
+  @Override
+  public void delete(Object key) throws CacheWriterException {
+    dataStore.delete((K) key);
+  }
+
+  @Override
+  public void deleteAll(Collection<?> keys) throws CacheWriterException {
+    Iterator<?> iterator = keys.iterator();
+    while (iterator.hasNext()) {
+      delete(iterator.next());
+      iterator.remove();
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
new file mode 100644
index 0000000..f50330b
--- /dev/null
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheCacheWriterFactory.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.jcache.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.cache.configuration.Factory;
+import java.lang.reflect.Constructor;
+
+public class JCacheCacheWriterFactory<K, T extends PersistentBase> implements Factory<JCacheCacheWriter<K,T>>
{
+
+  public static final long serialVersionUID = 201205101621L;
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheCacheWriterFactory.class);
+  private Class<K> keyClass;
+  private Class<T> persistentClass;
+
+  public JCacheCacheWriterFactory(Class<K> keyClass,
+                                  Class<T> persistentClass) {
+    this.keyClass = keyClass;
+    this.persistentClass = persistentClass;
+  }
+
+  public JCacheCacheWriter<K,T> create() {
+    try {
+      return (JCacheCacheWriter<K,T>) new JCacheCacheWriter(keyClass, persistentClass);
+    } catch (Exception ex) {
+      throw new RuntimeException("Failed to create an instance of " + JCacheCacheWriter.class,
ex);
+    }
+  }
+
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    } else if (other != null && this.getClass() == other.getClass()) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  public int hashCode() {
+    return this.hashCode();
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
----------------------------------------------------------------------
diff --git a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
index 1c52fdd..ab193f6 100644
--- a/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
+++ b/gora-jcache/src/main/java/org/apache/gora/jcache/store/JCacheStore.java
@@ -20,6 +20,7 @@ package org.apache.gora.jcache.store;
 import java.io.IOException;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentSkipListSet;
 
 import org.apache.gora.jcache.query.JCacheQuery;
 import org.apache.gora.persistency.impl.PersistentBase;
@@ -30,15 +31,42 @@ import org.apache.gora.store.impl.DataStoreBase;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
{
-
+import javax.cache.Cache;
+import javax.cache.CacheManager;
+import javax.cache.Caching;
+import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
+import javax.cache.configuration.MutableConfiguration;
+import javax.cache.spi.CachingProvider;
 
-  public static final Logger LOG = LoggerFactory.getLogger(JCacheStore.class);
+public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
{
 
+  private Cache<K, T> cache;
+  private CacheManager manager;
+  private ConcurrentSkipListSet<K> cacheEntryList;
+  private static final String GORA_DEFAULT_JCACHE_PROVIDER_KEY = "gora.datastore.jcache.provider";
+  private static final Logger LOG = LoggerFactory.getLogger(JCacheStore.class);
 
   @Override
   public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties
properties) {
     super.initialize(keyClass, persistentClass, properties);
+    CachingProvider cachingProvider = Caching.getCachingProvider(
+           properties.getProperty(GORA_DEFAULT_JCACHE_PROVIDER_KEY)
+    );
+    manager = cachingProvider.getCacheManager();
+    cacheEntryList = new ConcurrentSkipListSet<>();
+    MutableConfiguration<K, T> config = new MutableConfiguration<K, T>();
+    config.setTypes(keyClass, persistentClass);
+    config.setReadThrough(true);
+    config.setWriteThrough(true);
+    config.setCacheLoaderFactory(JCacheCacheFactoryBuilder.factoryOfCacheLoader(keyClass,persistentClass));
+    config.setCacheWriterFactory(JCacheCacheFactoryBuilder.factoryOfCacheWriter(keyClass,persistentClass));
+    config.addCacheEntryListenerConfiguration(
+            new MutableCacheEntryListenerConfiguration<>(
+                    JCacheCacheFactoryBuilder.factoryOfEntryListener(new JCacheCacheEntryListener<K,T>(cacheEntryList)),
+                    null, true, true
+            )
+    );
+    cache = manager.createCache(persistentClass.getSimpleName(),config);
   }
 
   @Override
@@ -66,12 +94,18 @@ public class JCacheStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
   }
 
   @Override
+  public T get(K key){
+    return cache.get(key);
+  }
+
+  @Override
   public void put(K key, T val) {
+    cache.put(key,val);
   }
 
   @Override
   public boolean delete(K key) {
-    return false;
+    return cache.remove(key);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/test/resources/gora.properties
----------------------------------------------------------------------
diff --git a/gora-jcache/src/test/resources/gora.properties b/gora-jcache/src/test/resources/gora.properties
index 83f920a..ccbd282 100644
--- a/gora-jcache/src/test/resources/gora.properties
+++ b/gora-jcache/src/test/resources/gora.properties
@@ -13,4 +13,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-gora.datastore.default=org.apache.gora.jcache.store.JCacheStore
+gora.cache.datastore.default=org.apache.gora.jcache.store.JCacheStore
+gora.datastore.jcache.provider=com.hazelcast.cache.HazelcastCachingProvider

http://git-wip-us.apache.org/repos/asf/gora/blob/e28c661b/gora-jcache/src/test/resources/hazelcast.xml
----------------------------------------------------------------------
diff --git a/gora-jcache/src/test/resources/hazelcast.xml b/gora-jcache/src/test/resources/hazelcast.xml
new file mode 100755
index 0000000..5f24979
--- /dev/null
+++ b/gora-jcache/src/test/resources/hazelcast.xml
@@ -0,0 +1,35 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<!--
+  Hazelcast instance configuration hazelcast.xml.
+-->
+
+<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.hazelcast.com/schema/config
+                               http://www.hazelcast.com/schema/config/hazelcast-config-3.6.xsd"
+           xmlns="http://www.hazelcast.com/schema/config">
+
+    <network>
+        <join>
+            <multicast enabled="false"/>
+            <tcp-ip enabled="true">
+                <member>127.0.0.1</member>
+            </tcp-ip>
+        </join>
+    </network>
+</hazelcast>


Mime
View raw message