ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-1192: Apache Ignite Spring repository interface and implementation
Date Sat, 25 Mar 2017 00:02:01 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1192 b80b1a7b4 -> e6be4206c


IGNITE-1192: Apache Ignite Spring repository interface and implementation


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

Branch: refs/heads/ignite-1192
Commit: e6be4206cfb08bcbf197c6ba070031a02d2b73d9
Parents: b80b1a7
Author: Denis Magda <dmagda@gridgain.com>
Authored: Fri Mar 24 17:01:56 2017 -0700
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Fri Mar 24 17:01:56 2017 -0700

----------------------------------------------------------------------
 .../springdata/repository/IgniteRepository.java | 51 ++++++++++++++++
 .../support/SimpleIgniteRepository.java         | 64 ++++++++++++++++++++
 2 files changed, 115 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e6be4206/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/IgniteRepository.java
----------------------------------------------------------------------
diff --git a/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/IgniteRepository.java
b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/IgniteRepository.java
new file mode 100644
index 0000000..656f7d6
--- /dev/null
+++ b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/IgniteRepository.java
@@ -0,0 +1,51 @@
+/*
+ * 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.ignite.springdata.repository;
+
+import java.io.Serializable;
+import java.util.Map;
+import org.springframework.data.keyvalue.repository.KeyValueRepository;
+
+/**
+ * Apache Ignite repository that extends basic capabilities of {@link KeyValueRepository}.
+ */
+public interface IgniteRepository<T, ID extends Serializable> extends KeyValueRepository<T,
ID> {
+    /**
+     * Saves a given entity using provided key.
+     * </p>
+     * It's suggested to use this method instead of default {@link KeyValueRepository#save(Object)}
that generates
+     * IDs (keys) that are not unique cluster wide.
+     *
+     * @param key Entity's key.
+     * @param entity Entity to save.
+     * @param <S> Entity type.
+     * @return Saved entity.
+     */
+    <S extends T> S save(ID key, S entity);
+
+    /**
+     * Saves all given keys and entities combinations.
+     * </p>
+     * It's suggested to use this method instead of default {@link KeyValueRepository#save(Iterable)}
that generates
+     * IDs (keys) that are not unique cluster wide.
+     *
+     * @param entities Map of key-entities pairs to save.
+     * @param <S> type of entities.
+     * @return Saved entities.
+     */
+    <S extends T> Iterable<S> save(Map<ID, S> entities);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e6be4206/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/SimpleIgniteRepository.java
----------------------------------------------------------------------
diff --git a/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/SimpleIgniteRepository.java
b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/SimpleIgniteRepository.java
new file mode 100644
index 0000000..2f75652
--- /dev/null
+++ b/modules/spring-data/src/main/java/org/apache/ignite/springdata/repository/support/SimpleIgniteRepository.java
@@ -0,0 +1,64 @@
+/*
+ * 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.ignite.springdata.repository.support;
+
+import java.io.Serializable;
+import java.util.Map;
+import org.apache.ignite.springdata.repository.IgniteRepository;
+import org.springframework.data.keyvalue.core.KeyValueOperations;
+import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
+import org.springframework.data.repository.core.EntityInformation;
+import org.springframework.util.Assert;
+
+/**
+ * General Apache Ignite repository implementation.
+ */
+public class SimpleIgniteRepository<T, ID extends Serializable>
+    extends SimpleKeyValueRepository<T, ID> implements IgniteRepository<T, ID>
{
+    /** */
+    private final KeyValueOperations operations;
+
+    /**
+     * Creates a new {@link SimpleKeyValueRepository} for the given {@link EntityInformation}
and {@link
+     * KeyValueOperations}.
+     *
+     * @param metadata must not be {@literal null}.
+     * @param operations must not be {@literal null}.
+     */
+    public SimpleIgniteRepository(EntityInformation<T, ID> metadata, KeyValueOperations
operations) {
+        super(metadata, operations);
+
+        this.operations = operations;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <S extends T> S save(ID key, S entity) {
+        Assert.notNull(entity, "Entity must not be null!");
+
+        operations.update(key, entity);
+
+        return entity;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <S extends T> Iterable<S> save(Map<ID, S> entities)
{
+        for (ID key : entities.keySet())
+            operations.update(key, entities.get(key));
+
+        return entities.values();
+    }
+}


Mime
View raw message