You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/01/15 15:43:01 UTC
[4/5] incubator-ignite git commit: # ignite-42
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
new file mode 100644
index 0000000..8c13db9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcBlobStore.java
@@ -0,0 +1,573 @@
+/*
+ * 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.cache.store.jdbc;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.store.*;
+import org.apache.ignite.marshaller.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.transactions.*;
+import org.gridgain.grid.*;
+import org.gridgain.grid.util.tostring.*;
+import org.gridgain.grid.util.typedef.*;
+import org.gridgain.grid.util.typedef.internal.*;
+import org.jdk8.backport.*;
+import org.jetbrains.annotations.*;
+
+import javax.cache.integration.*;
+import javax.sql.*;
+import java.sql.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * {@link org.apache.ignite.cache.store.CacheStore} implementation backed by JDBC. This implementation
+ * stores objects in underlying database in {@code BLOB} format.
+ * <p>
+ * Store will create table {@code ENTRIES} in the database to store data.
+ * Table will have {@code key} and {@code val} fields.
+ * <p>
+ * If custom DDL and DML statements are provided, table and field names have
+ * to be consistent for all statements and sequence of parameters have to be
+ * preserved.
+ * <h2 class="header">Configuration</h2>
+ * Sections below describe mandatory and optional configuration settings as well
+ * as providing example using Java and Spring XML.
+ * <h3>Mandatory</h3>
+ * There are no mandatory configuration parameters.
+ * <h3>Optional</h3>
+ * <ul>
+ * <li>Data source (see {@link #setDataSource(DataSource)}</li>
+ * <li>Connection URL (see {@link #setConnectionUrl(String)})</li>
+ * <li>User name (see {@link #setUser(String)})</li>
+ * <li>Password (see {@link #setPassword(String)})</li>
+ * <li>Create table query (see {@link #setConnectionUrl(String)})</li>
+ * <li>Load entry query (see {@link #setLoadQuery(String)})</li>
+ * <li>Update entry query (see {@link #setUpdateQuery(String)})</li>
+ * <li>Insert entry query (see {@link #setInsertQuery(String)})</li>
+ * <li>Delete entry query (see {@link #setDeleteQuery(String)})</li>
+ * </ul>
+ * <h2 class="header">Java Example</h2>
+ * <pre name="code" class="java">
+ * ...
+ * GridCacheJdbcBlobStore<String, String> store = new GridCacheJdbcBlobStore<String, String>();
+ * ...
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * <pre name="code" class="xml">
+ * ...
+ * <bean id="cache.jdbc.store"
+ * class="org.gridgain.grid.cache.store.jdbc.GridCacheJdbcBlobStore">
+ * <property name="connectionUrl" value="jdbc:h2:mem:"/>
+ * <property name="createTableQuery"
+ * value="create table if not exists ENTRIES (key other, val other)"/>
+ * </bean>
+ * ...
+ * </pre>
+ * <p>
+ * <img src="http://www.gridgain.com/images/spring-small.png">
+ * <br>
+ * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
+ */
+public class CacheJdbcBlobStore<K, V> extends CacheStoreAdapter<K, V> {
+ /** Default connection URL (value is <tt>jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1</tt>). */
+ public static final String DFLT_CONN_URL = "jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1";
+
+ /**
+ * Default create table query
+ * (value is <tt>create table if not exists ENTRIES (key other primary key, val other)</tt>).
+ */
+ public static final String DFLT_CREATE_TBL_QRY = "create table if not exists ENTRIES " +
+ "(key binary primary key, val binary)";
+
+ /** Default load entry query (value is <tt>select * from ENTRIES where key=?</tt>). */
+ public static final String DFLT_LOAD_QRY = "select * from ENTRIES where key=?";
+
+ /** Default update entry query (value is <tt>select * from ENTRIES where key=?</tt>). */
+ public static final String DFLT_UPDATE_QRY = "update ENTRIES set val=? where key=?";
+
+ /** Default insert entry query (value is <tt>insert into ENTRIES (key, val) values (?, ?)</tt>). */
+ public static final String DFLT_INSERT_QRY = "insert into ENTRIES (key, val) values (?, ?)";
+
+ /** Default delete entry query (value is <tt>delete from ENTRIES where key=?</tt>). */
+ public static final String DFLT_DEL_QRY = "delete from ENTRIES where key=?";
+
+ /** Connection attribute name. */
+ private static final String ATTR_CONN = "JDBC_STORE_CONNECTION";
+
+ /** Connection URL. */
+ private String connUrl = DFLT_CONN_URL;
+
+ /** Query to create table. */
+ private String createTblQry = DFLT_CREATE_TBL_QRY;
+
+ /** Query to load entry. */
+ private String loadQry = DFLT_LOAD_QRY;
+
+ /** Query to update entry. */
+ private String updateQry = DFLT_UPDATE_QRY;
+
+ /** Query to insert entries. */
+ private String insertQry = DFLT_INSERT_QRY;
+
+ /** Query to delete entries. */
+ private String delQry = DFLT_DEL_QRY;
+
+ /** User name for database access. */
+ private String user;
+
+ /** Password for database access. */
+ @GridToStringExclude
+ private String passwd;
+
+ /** Data source. */
+ private DataSource dataSrc;
+
+ /** Flag for schema initialization. */
+ private boolean initSchema = true;
+
+ /** Log. */
+ @IgniteLoggerResource
+ private IgniteLogger log;
+
+ /** Marshaller. */
+ @IgniteMarshallerResource
+ private IgniteMarshaller marsh;
+
+ /** Init guard. */
+ @GridToStringExclude
+ private final AtomicBoolean initGuard = new AtomicBoolean();
+
+ /** Init latch. */
+ @GridToStringExclude
+ private final CountDownLatch initLatch = new CountDownLatch(1);
+
+ /** Opened connections. */
+ @GridToStringExclude
+ private final LongAdder opened = new LongAdder();
+
+ /** Closed connections. */
+ @GridToStringExclude
+ private final LongAdder closed = new LongAdder();
+
+ /** Test mode flag. */
+ @GridToStringExclude
+ private boolean testMode;
+
+ /** Successful initialization flag. */
+ private boolean initOk;
+
+ /** {@inheritDoc} */
+ @Override public void txEnd(boolean commit) {
+ init();
+
+ IgniteTx tx = transaction();
+
+ Map<Object, Object> props = session().properties();
+
+ Connection conn = (Connection)props.remove(ATTR_CONN);
+
+ if (conn != null) {
+ try {
+ if (commit)
+ conn.commit();
+ else
+ conn.rollback();
+ }
+ catch (SQLException e) {
+ throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e);
+ }
+ finally {
+ closeConnection(conn);
+ }
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"RedundantTypeArguments"})
+ @Override public V load(K key) {
+ init();
+
+ IgniteTx tx = transaction();
+
+ if (log.isDebugEnabled())
+ log.debug("Store load [key=" + key + ", tx=" + tx + ']');
+
+ Connection conn = null;
+
+ PreparedStatement stmt = null;
+
+ try {
+ conn = connection(tx);
+
+ stmt = conn.prepareStatement(loadQry);
+
+ stmt.setObject(1, toBytes(key));
+
+ ResultSet rs = stmt.executeQuery();
+
+ if (rs.next())
+ return fromBytes(rs.getBytes(2));
+ }
+ catch (IgniteCheckedException | SQLException e) {
+ throw new CacheLoaderException("Failed to load object: " + key, e);
+ }
+ finally {
+ end(tx, conn, stmt);
+ }
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(K key, V val) {
+ init();
+
+ IgniteTx tx = transaction();
+
+ if (log.isDebugEnabled())
+ log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
+
+ Connection conn = null;
+
+ PreparedStatement stmt = null;
+
+ try {
+ conn = connection(tx);
+
+ stmt = conn.prepareStatement(updateQry);
+
+ stmt.setObject(1, toBytes(val));
+ stmt.setObject(2, toBytes(key));
+
+ if (stmt.executeUpdate() == 0) {
+ stmt.close();
+
+ stmt = conn.prepareStatement(insertQry);
+
+ stmt.setObject(1, toBytes(key));
+ stmt.setObject(2, toBytes(val));
+
+ stmt.executeUpdate();
+ }
+ }
+ catch (IgniteCheckedException | SQLException e) {
+ throw new CacheWriterException("Failed to put object [key=" + key + ", val=" + val + ']', e);
+ }
+ finally {
+ end(tx, conn, stmt);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void remove(K key) {
+ init();
+
+ IgniteTx tx = transaction();
+
+ if (log.isDebugEnabled())
+ log.debug("Store remove [key=" + key + ", tx=" + tx + ']');
+
+ Connection conn = null;
+
+ PreparedStatement stmt = null;
+
+ try {
+ conn = connection(tx);
+
+ stmt = conn.prepareStatement(delQry);
+
+ stmt.setObject(1, toBytes(key));
+
+ stmt.executeUpdate();
+ }
+ catch (IgniteCheckedException | SQLException e) {
+ throw new CacheWriterException("Failed to remove object: " + key, e);
+ }
+ finally {
+ end(tx, conn, stmt);
+ }
+ }
+
+ /**
+ * @param tx Cache transaction.
+ * @return Connection.
+ * @throws SQLException In case of error.
+ */
+ private Connection connection(@Nullable IgniteTx tx) throws SQLException {
+ if (tx != null) {
+ Map<Object, Object> props = session().properties();
+
+ Connection conn = (Connection)props.get(ATTR_CONN);
+
+ if (conn == null) {
+ conn = openConnection(false);
+
+ // Store connection in session properties, so it can be accessed
+ // for other operations on the same transaction.
+ props.put(ATTR_CONN, conn);
+ }
+
+ return conn;
+ }
+ // Transaction can be null in case of simple load operation.
+ else
+ return openConnection(true);
+ }
+
+ /**
+ * Closes allocated resources depending on transaction status.
+ *
+ * @param tx Active transaction, if any.
+ * @param conn Allocated connection.
+ * @param st Created statement,
+ */
+ private void end(@Nullable IgniteTx tx, Connection conn, Statement st) {
+ U.closeQuiet(st);
+
+ if (tx == null)
+ // Close connection right away if there is no transaction.
+ closeConnection(conn);
+ }
+
+ /**
+ * Gets connection from a pool.
+ *
+ * @param autocommit {@code true} If connection should use autocommit mode.
+ * @return Pooled connection.
+ * @throws SQLException In case of error.
+ */
+ private Connection openConnection(boolean autocommit) throws SQLException {
+ Connection conn = dataSrc != null ? dataSrc.getConnection() :
+ DriverManager.getConnection(connUrl, user, passwd);
+
+ if (testMode)
+ opened.increment();
+
+ conn.setAutoCommit(autocommit);
+
+ return conn;
+ }
+
+ /**
+ * Closes connection.
+ *
+ * @param conn Connection to close.
+ */
+ private void closeConnection(Connection conn) {
+ U.closeQuiet(conn);
+
+ if (testMode)
+ closed.increment();
+ }
+
+ /**
+ * Initializes store.
+ *
+ * @throws IgniteException If failed to initialize.
+ */
+ private void init() {
+ if (initLatch.getCount() > 0) {
+ if (initGuard.compareAndSet(false, true)) {
+ if (log.isDebugEnabled())
+ log.debug("Initializing cache store.");
+
+ if (F.isEmpty(connUrl))
+ throw new IgniteException("Failed to initialize cache store (connection URL is not provided).");
+
+ if (!initSchema) {
+ initLatch.countDown();
+
+ return;
+ }
+
+ if (F.isEmpty(createTblQry))
+ throw new IgniteException("Failed to initialize cache store (create table query is not provided).");
+
+ Connection conn = null;
+
+ Statement stmt = null;
+
+ try {
+ conn = openConnection(false);
+
+ stmt = conn.createStatement();
+
+ stmt.execute(createTblQry);
+
+ conn.commit();
+
+ initOk = true;
+ }
+ catch (SQLException e) {
+ throw new IgniteException("Failed to create database table.", e);
+ }
+ finally {
+ U.closeQuiet(stmt);
+
+ closeConnection(conn);
+
+ initLatch.countDown();
+ }
+ }
+ else {
+ try {
+ U.await(initLatch);
+ }
+ catch (GridInterruptedException e) {
+ throw new IgniteException(e);
+ }
+ }
+ }
+
+ if (!initOk)
+ throw new IgniteException("Cache store was not properly initialized.");
+ }
+
+ /**
+ * Flag indicating whether DB schema should be initialized by GridGain (default behaviour) or
+ * was explicitly created by user.
+ *
+ * @param initSchema {@code True} if DB schema should be initialized by GridGain (default behaviour),
+ * {code @false} if schema was explicitly created by user.
+ */
+ public void setInitSchema(boolean initSchema) {
+ this.initSchema = initSchema;
+ }
+
+ /**
+ * Sets connection URL.
+ *
+ * @param connUrl Connection URL.
+ */
+ public void setConnectionUrl(String connUrl) {
+ this.connUrl = connUrl;
+ }
+
+ /**
+ * Sets create table query.
+ *
+ * @param createTblQry Create table query.
+ */
+ public void setCreateTableQuery(String createTblQry) {
+ this.createTblQry = createTblQry;
+ }
+
+ /**
+ * Sets load query.
+ *
+ * @param loadQry Load query
+ */
+ public void setLoadQuery(String loadQry) {
+ this.loadQry = loadQry;
+ }
+
+ /**
+ * Sets update entry query.
+ *
+ * @param updateQry Update entry query.
+ */
+ public void setUpdateQuery(String updateQry) {
+ this.updateQry = updateQry;
+ }
+
+ /**
+ * Sets insert entry query.
+ *
+ * @param insertQry Insert entry query.
+ */
+ public void setInsertQuery(String insertQry) {
+ this.insertQry = insertQry;
+ }
+
+ /**
+ * Sets delete entry query.
+ *
+ * @param delQry Delete entry query.
+ */
+ public void setDeleteQuery(String delQry) {
+ this.delQry = delQry;
+ }
+
+ /**
+ * Sets user name for database access.
+ *
+ * @param user User name.
+ */
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ /**
+ * Sets password for database access.
+ *
+ * @param passwd Password.
+ */
+ public void setPassword(String passwd) {
+ this.passwd = passwd;
+ }
+
+ /**
+ * Sets data source. Data source should be fully configured and ready-to-use.
+ * <p>
+ * Note that if data source is provided, all connections will be
+ * acquired via this data source. If data source is not provided, a new connection
+ * will be created for each store call ({@code connectionUrl},
+ * {@code user} and {@code password} parameters will be used).
+ *
+ * @param dataSrc Data source.
+ */
+ public void setDataSource(DataSource dataSrc) {
+ this.dataSrc = dataSrc;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(CacheJdbcBlobStore.class, this, "passwd", passwd != null ? "*" : null);
+ }
+
+ /**
+ * Serialize object to byte array using marshaller.
+ *
+ * @param obj Object to convert to byte array.
+ * @return Byte array.
+ * @throws IgniteCheckedException If failed to convert.
+ */
+ protected byte[] toBytes(Object obj) throws IgniteCheckedException {
+ return marsh.marshal(obj);
+ }
+
+ /**
+ * Deserialize object from byte array using marshaller.
+ *
+ * @param bytes Bytes to deserialize.
+ * @param <X> Result object type.
+ * @return Deserialized object.
+ * @throws IgniteCheckedException If failed.
+ */
+ protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {
+ if (bytes == null || bytes.length == 0)
+ return null;
+
+ return marsh.unmarshal(bytes, getClass().getClassLoader());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/package.html
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/package.html b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/package.html
new file mode 100644
index 0000000..50755cd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/package.html
@@ -0,0 +1,24 @@
+<!--
+ 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.
+ -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<body>
+ <!-- Package description. -->
+ Contains reference JDBC-based cache store implementation.
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/apache/ignite/cache/store/package.html
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/package.html b/modules/core/src/main/java/org/apache/ignite/cache/store/package.html
new file mode 100644
index 0000000..8f597d7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/package.html
@@ -0,0 +1,23 @@
+<!--
+ 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.
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<body>
+ <!-- Package description. -->
+ Contains cache store interfaces.
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/GridCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/GridCache.java b/modules/core/src/main/java/org/gridgain/grid/cache/GridCache.java
index bc46201..95a002b 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/GridCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/GridCache.java
@@ -23,7 +23,6 @@ import org.apache.ignite.transactions.*;
import org.gridgain.grid.cache.affinity.*;
import org.gridgain.grid.cache.affinity.consistenthash.*;
import org.gridgain.grid.cache.datastructures.*;
-import org.gridgain.grid.cache.store.*;
import org.jetbrains.annotations.*;
import java.util.*;
@@ -187,14 +186,14 @@ public interface GridCache<K, V> extends GridCacheProjection<K, V> {
public Iterator<Map.Entry<K, V>> offHeapIterator() throws IgniteCheckedException;
/**
- * Delegates to {@link GridCacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)} method
+ * Delegates to {@link org.apache.ignite.cache.store.CacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)} method
* to load state from the underlying persistent storage. The loaded values
* will then be given to the optionally passed in predicate, and, if the predicate returns
* {@code true}, will be stored in cache. If predicate is {@code null}, then
* all loaded values will be stored in cache.
* <p>
* Note that this method does not receive keys as a parameter, so it is up to
- * {@link GridCacheStore} implementation to provide all the data to be loaded.
+ * {@link org.apache.ignite.cache.store.CacheStore} implementation to provide all the data to be loaded.
* <p>
* This method is not transactional and may end up loading a stale value into
* cache if another thread has updated the value immediately after it has been
@@ -205,20 +204,20 @@ public interface GridCache<K, V> extends GridCacheProjection<K, V> {
* filter values to be put into cache.
* @param ttl Time to live for loaded entries ({@code 0} for infinity).
* @param args Optional user arguments to be passed into
- * {@link GridCacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)} method.
+ * {@link org.apache.ignite.cache.store.CacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)} method.
* @throws IgniteCheckedException If loading failed.
*/
public void loadCache(@Nullable IgniteBiPredicate<K, V> p, long ttl, @Nullable Object... args) throws IgniteCheckedException;
/**
- * Asynchronously delegates to {@link GridCacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)} method
+ * Asynchronously delegates to {@link org.apache.ignite.cache.store.CacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)} method
* to reload state from the underlying persistent storage. The reloaded values
* will then be given to the optionally passed in predicate, and if the predicate returns
* {@code true}, will be stored in cache. If predicate is {@code null}, then
* all reloaded values will be stored in cache.
* <p>
* Note that this method does not receive keys as a parameter, so it is up to
- * {@link GridCacheStore} implementation to provide all the data to be loaded.
+ * {@link org.apache.ignite.cache.store.CacheStore} implementation to provide all the data to be loaded.
* <p>
* This method is not transactional and may end up loading a stale value into
* cache if another thread has updated the value immediately after it has been
@@ -229,7 +228,7 @@ public interface GridCache<K, V> extends GridCacheProjection<K, V> {
* filter values to be put into cache.
* @param ttl Time to live for loaded entries ({@code 0} for infinity).
* @param args Optional user arguments to be passed into
- * {@link GridCacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)} method.
+ * {@link org.apache.ignite.cache.store.CacheStore#loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)} method.
* @return Future to be completed whenever loading completes.
*/
public IgniteFuture<?> loadCacheAsync(@Nullable IgniteBiPredicate<K, V> p, long ttl, @Nullable Object... args);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
index fe0deea..95e3523 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
@@ -18,6 +18,7 @@
package org.gridgain.grid.cache;
import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.store.*;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.portables.PortableObject;
import org.apache.ignite.spi.indexing.*;
@@ -28,7 +29,6 @@ import org.gridgain.grid.cache.cloner.*;
import org.gridgain.grid.cache.datastructures.*;
import org.gridgain.grid.cache.eviction.*;
import org.gridgain.grid.cache.query.*;
-import org.gridgain.grid.cache.store.*;
import org.gridgain.grid.util.typedef.internal.*;
import org.jetbrains.annotations.*;
@@ -236,7 +236,7 @@ public class GridCacheConfiguration extends MutableConfiguration {
private GridCacheWriteSynchronizationMode writeSync;
/** */
- private GridCacheStore<?, ?> store;
+ private CacheStore<?, ?> store;
/** Node group resolver. */
private GridCacheAffinityFunction aff;
@@ -794,8 +794,8 @@ public class GridCacheConfiguration extends MutableConfiguration {
* @return Underlying persistent storage for read-through and write-through operations.
*/
@SuppressWarnings({"unchecked"})
- public <K, V> GridCacheStore<K, V> getStore() {
- return (GridCacheStore<K, V>)store;
+ public <K, V> CacheStore<K, V> getStore() {
+ return (CacheStore<K, V>)store;
}
/**
@@ -803,7 +803,7 @@ public class GridCacheConfiguration extends MutableConfiguration {
*
* @param store Persistent cache store.
*/
- public <K, V> void setStore(GridCacheStore<K, V> store) {
+ public <K, V> void setStore(CacheStore<K, V> store) {
this.store = store;
}
@@ -1241,8 +1241,8 @@ public class GridCacheConfiguration extends MutableConfiguration {
/**
* Maximum batch size for write-behind cache store operations. Store operations (get or remove)
* are combined in a batch of this size to be passed to
- * {@link GridCacheStore#putAll(IgniteTx, Map)} or
- * {@link GridCacheStore#removeAll(IgniteTx, Collection)} methods.
+ * {@link org.apache.ignite.cache.store.CacheStore#putAll(IgniteTx, Map)} or
+ * {@link org.apache.ignite.cache.store.CacheStore#removeAll(IgniteTx, Collection)} methods.
* <p/>
* If not provided, default value is {@link #DFLT_WRITE_BEHIND_BATCH_SIZE}.
*
@@ -1659,7 +1659,7 @@ public class GridCacheConfiguration extends MutableConfiguration {
}
/**
- * Flag indicating that {@link GridCacheStore} implementation
+ * Flag indicating that {@link org.apache.ignite.cache.store.CacheStore} implementation
* is working with portable objects instead of Java objects
* if portable mode for this cache is enabled ({@link #isPortableEnabled()}
* flag is {@code true}). Default value of this flag is {@code true},
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheProjection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheProjection.java b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheProjection.java
index 6dbb607..5a4fb32 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheProjection.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheProjection.java
@@ -23,7 +23,6 @@ import org.apache.ignite.lang.*;
import org.apache.ignite.transactions.*;
import org.gridgain.grid.cache.affinity.*;
import org.gridgain.grid.cache.query.*;
-import org.gridgain.grid.cache.store.*;
import org.jetbrains.annotations.*;
import java.sql.*;
@@ -378,7 +377,7 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
/**
* Reloads a single key from persistent storage. This method
- * delegates to {@link GridCacheStore#load(IgniteTx, Object)}
+ * delegates to {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)}
* method.
* <h2 class="header">Transactions</h2>
* This method does not participate in transactions, however it does not violate
@@ -392,7 +391,7 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
/**
* Asynchronously reloads a single key from persistent storage. This method
- * delegates to {@link GridCacheStore#load(IgniteTx, Object)}
+ * delegates to {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)}
* method.
* <h2 class="header">Transactions</h2>
* This method does not participate in transactions, however it does not violate
@@ -492,8 +491,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* If the value is not present in cache, then it will be looked up from swap storage. If
* it's not present in swap, or if swap is disable, and if read-through is allowed, value
- * will be loaded from {@link GridCacheStore} persistent storage via
- * {@link GridCacheStore#load(IgniteTx, Object)} method.
+ * will be loaded from {@link org.apache.ignite.cache.store.CacheStore} persistent storage via
+ * {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -517,8 +516,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* If the value is not present in cache, then it will be looked up from swap storage. If
* it's not present in swap, or if swap is disabled, and if read-through is allowed, value
- * will be loaded from {@link GridCacheStore} persistent storage via
- * {@link GridCacheStore#load(IgniteTx, Object)} method.
+ * will be loaded from {@link org.apache.ignite.cache.store.CacheStore} persistent storage via
+ * {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -541,8 +540,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* If some value is not present in cache, then it will be looked up from swap storage. If
* it's not present in swap, or if swap is disabled, and if read-through is allowed, value
- * will be loaded from {@link GridCacheStore} persistent storage via
- * {@link GridCacheStore#loadAll(IgniteTx, Collection, org.apache.ignite.lang.IgniteBiInClosure)} method.
+ * will be loaded from {@link org.apache.ignite.cache.store.CacheStore} persistent storage via
+ * {@link org.apache.ignite.cache.store.CacheStore#loadAll(IgniteTx, Collection, org.apache.ignite.lang.IgniteBiInClosure)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -565,8 +564,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* If some value is not present in cache, then it will be looked up from swap storage. If
* it's not present in swap, or if swap is disabled, and if read-through is allowed, value
- * will be loaded from {@link GridCacheStore} persistent storage via
- * {@link GridCacheStore#loadAll(IgniteTx, Collection, org.apache.ignite.lang.IgniteBiInClosure)} method.
+ * will be loaded from {@link org.apache.ignite.cache.store.CacheStore} persistent storage via
+ * {@link org.apache.ignite.cache.store.CacheStore#loadAll(IgniteTx, Collection, org.apache.ignite.lang.IgniteBiInClosure)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -588,13 +587,13 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #putx(Object, Object, org.apache.ignite.lang.IgnitePredicate[])} should
* always be used instead of this one to avoid the overhead associated with returning of the previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -623,17 +622,17 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* previously contained value for the given key, then this value is returned. Otherwise,
* in case of {@link GridCacheMode#REPLICATED} caches, the value will be loaded from swap
* and, if it's not there, and read-through is allowed, from the underlying
- * {@link GridCacheStore} storage. In case of {@link GridCacheMode#PARTITIONED} caches,
+ * {@link org.apache.ignite.cache.store.CacheStore} storage. In case of {@link GridCacheMode#PARTITIONED} caches,
* the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap and read-through is allowed,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #putx(Object, Object, org.apache.ignite.lang.IgnitePredicate[])} should
* always be used instead of this one to avoid the overhead associated with returning of the previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -661,8 +660,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning a value. It
* should be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -694,8 +693,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning of a value. It
* should always be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -722,14 +721,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #putxIfAbsent(Object, Object)} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -753,14 +752,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #putxIfAbsentAsync(Object, Object)} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -785,8 +784,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning of a value. It
* should always be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -811,8 +810,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning of a value. It
* should always be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -834,14 +833,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #replacex(Object, Object)} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -864,14 +863,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* {@link GridCacheMode#PARTITIONED} caches, the value will be loaded from the primary node,
* which in its turn may load the value from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #replacex(Object, Object)} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -895,8 +894,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning of a value. It
* should always be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -921,8 +920,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* value and, therefore, does not have any overhead associated with returning of a value. It
* should always be used whenever return value is not required.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -944,8 +943,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* This method will return {@code true} if value is stored in cache and {@code false} otherwise.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -969,8 +968,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <p>
* This method will return {@code true} if value is stored in cache and {@code false} otherwise.
* <p>
- * If write-through is enabled, the stored value will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#put(IgniteTx, Object, Object)} method.
+ * If write-through is enabled, the stored value will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#put(IgniteTx, Object, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -992,8 +991,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* be stored in cache only if they pass the filter. Note that filter check is atomic,
* so value stored in cache is guaranteed to be consistent with the filters.
* <p>
- * If write-through is enabled, the stored values will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#putAll(IgniteTx, Map)} method.
+ * If write-through is enabled, the stored values will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#putAll(IgniteTx, Map)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1015,8 +1014,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* be stored in cache only if they pass the filter. Note that filter check is atomic,
* so value stored in cache is guaranteed to be consistent with the filters.
* <p>
- * If write-through is enabled, the stored values will be persisted to {@link GridCacheStore}
- * via {@link GridCacheStore#putAll(IgniteTx, Map)} method.
+ * If write-through is enabled, the stored values will be persisted to {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#putAll(IgniteTx, Map)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1404,14 +1403,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* caches, the value will be loaded from the primary node, which in its turn may load the value
* from the disk-based swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #removex(Object, org.apache.ignite.lang.IgnitePredicate[])} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1437,14 +1436,14 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* caches, the value will be loaded from the primary node, which in its turn may load the value
* from the swap storage, and consecutively, if it's not in swap,
* from the underlying persistent storage. If value has to be loaded from persistent
- * storage, {@link GridCacheStore#load(IgniteTx, Object)} method will be used.
+ * storage, {@link org.apache.ignite.cache.store.CacheStore#load(IgniteTx, Object)} method will be used.
* <p>
* If the returned value is not needed, method {@link #removex(Object, org.apache.ignite.lang.IgnitePredicate[])} should
* always be used instead of this one to avoid the overhead associated with returning of the
* previous value.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1467,8 +1466,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* This method will return {@code true} if remove did occur, which means that all optionally
* provided filters have passed and there was something to remove, {@code false} otherwise.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1494,8 +1493,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* This method will return {@code true} if remove did occur, which means that all optionally
* provided filters have passed and there was something to remove, {@code false} otherwise.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1518,8 +1517,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
/**
* Removes given key mapping from cache if one exists and value is equal to the passed in value.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1543,8 +1542,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* This method will return {@code true} if remove did occur, which means that all optionally
* provided filters have passed and there was something to remove, {@code false} otherwise.
* <p>
- * If write-through is enabled, the value will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#remove(IgniteTx, Object)} method.
+ * If write-through is enabled, the value will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#remove(IgniteTx, Object)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1565,8 +1564,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* Removes given key mappings from cache for entries for which the optionally passed in filters do
* pass.
* <p>
- * If write-through is enabled, the values will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#removeAll(IgniteTx, Collection)} method.
+ * If write-through is enabled, the values will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#removeAll(IgniteTx, Collection)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1587,8 +1586,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* Asynchronously removes given key mappings from cache for entries for which the optionally
* passed in filters do pass.
* <p>
- * If write-through is enabled, the values will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#removeAll(IgniteTx, Collection)} method.
+ * If write-through is enabled, the values will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#removeAll(IgniteTx, Collection)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1616,8 +1615,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* are acquired in undefined order, so it may cause a deadlock when used with
* other concurrent transactional updates.
* <p>
- * If write-through is enabled, the values will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#removeAll(IgniteTx, Collection)} method.
+ * If write-through is enabled, the values will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#removeAll(IgniteTx, Collection)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
@@ -1641,8 +1640,8 @@ public interface GridCacheProjection<K, V> extends Iterable<GridCacheEntry<K, V>
* <b>USE WITH CARE</b> - if your cache has many entries that pass through the filter or if filter
* is empty, then transaction will quickly become very heavy and slow.
* <p>
- * If write-through is enabled, the values will be removed from {@link GridCacheStore}
- * via {@link GridCacheStore#removeAll(IgniteTx, Collection)} method.
+ * If write-through is enabled, the values will be removed from {@link org.apache.ignite.cache.store.CacheStore}
+ * via {@link org.apache.ignite.cache.store.CacheStore#removeAll(IgniteTx, Collection)} method.
* <h2 class="header">Transactions</h2>
* This method is transactional and will enlist the entry into ongoing transaction
* if there is one.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLoadOnlyStoreAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLoadOnlyStoreAdapter.java b/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLoadOnlyStoreAdapter.java
deleted file mode 100644
index dcd7508..0000000
--- a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLoadOnlyStoreAdapter.java
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * 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.gridgain.grid.cache.store;
-
-import org.apache.ignite.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.resources.*;
-import org.apache.ignite.transactions.*;
-import org.gridgain.grid.cache.*;
-import org.gridgain.grid.util.typedef.internal.*;
-import org.jetbrains.annotations.*;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-import static java.util.concurrent.TimeUnit.*;
-
-/**
- * This adepter designed to support stores with bulk loading from stream-like source.
- * <p>
- * This class processes input data in the following way:
- * <ul>
- * <li>
- * Iterator of input record obtained from user-defined {@link #inputIterator(Object...)}.
- * </li>
- * <li>
- * Iterator continuously queried for input records and they are grouped into batches of {@link #batchSize}.
- * </li>
- * <li>
- * Batch is placed into processing queue and puled by one of {@link #threadsCnt} working threads.
- * </li>
- * <li>
- * Each record in batch is passed to user-defined {@link #parse(Object, Object...)} method
- * and result is stored into cache.
- * </li>
- * </ul>
- * <p>
- * Two methods should be implemented by inheritants:
- * <ul>
- * <li>
- * {@link #inputIterator(Object...)}. It should open underlying data source
- * and iterate all record available in it. Individual records could be in very raw form,
- * like text lines for CSV files.
- * </li>
- * <li>
- * {@link #parse(Object, Object...)}. This method should process input records
- * and transform them into key-value pairs for cache.
- * </li>
- * </ul>
- * <p>
- *
- * @param <K> Key type.
- * @param <V> Value type.
- * @param <I> Input type.
- */
-public abstract class GridCacheLoadOnlyStoreAdapter<K, V, I> implements GridCacheStore<K, V> {
- /**
- * Default batch size (number of records read with {@link #inputIterator(Object...)}
- * and then submitted to internal pool at a time).
- */
- public static final int DFLT_BATCH_SIZE = 100;
-
- /** Default batch queue size (max batches count to limit memory usage). */
- public static final int DFLT_BATCH_QUEUE_SIZE = 100;
-
- /** Default number of working threads (equal to the number of available processors). */
- public static final int DFLT_THREADS_COUNT = Runtime.getRuntime().availableProcessors();
-
- /** Auto-injected logger. */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** Batch size. */
- private int batchSize = DFLT_BATCH_SIZE;
-
- /** Size of queue of batches to process. */
- private int batchQueueSize = DFLT_BATCH_QUEUE_SIZE;
-
- /** Number fo working threads. */
- private int threadsCnt = DFLT_THREADS_COUNT;
-
- /**
- * Returns iterator of input records.
- * <p>
- * Note that returned iterator doesn't have to be thread-safe. Thus it could
- * operate on raw streams, DB connections, etc. without additional synchronization.
- *
- * @param args Arguments passes into {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)} method.
- * @return Iterator over input records.
- * @throws IgniteCheckedException If iterator can't be created with the given arguments.
- */
- protected abstract Iterator<I> inputIterator(@Nullable Object... args) throws IgniteCheckedException;
-
- /**
- * This method should transform raw data records into valid key-value pairs
- * to be stored into cache.
- * <p>
- * If {@code null} is returned then this record will be just skipped.
- *
- * @param rec A raw data record.
- * @param args Arguments passed into {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)} method.
- * @return Cache entry to be saved in cache or {@code null} if no entry could be produced from this record.
- */
- @Nullable protected abstract IgniteBiTuple<K, V> parse(I rec, @Nullable Object... args);
-
- /** {@inheritDoc} */
- @Override public void loadCache(IgniteBiInClosure<K, V> c, @Nullable Object... args)
- throws IgniteCheckedException {
- ExecutorService exec = new ThreadPoolExecutor(
- threadsCnt,
- threadsCnt,
- 0L,
- MILLISECONDS,
- new ArrayBlockingQueue<Runnable>(batchQueueSize),
- new BlockingRejectedExecutionHandler());
-
- Iterator<I> iter = inputIterator(args);
-
- Collection<I> buf = new ArrayList<>(batchSize);
-
- try {
- while (iter.hasNext()) {
- if (Thread.currentThread().isInterrupted()) {
- U.warn(log, "Working thread was interrupted while loading data.");
-
- break;
- }
-
- buf.add(iter.next());
-
- if (buf.size() == batchSize) {
- exec.submit(new Worker(c, buf, args));
-
- buf = new ArrayList<>(batchSize);
- }
- }
-
- if (!buf.isEmpty())
- exec.submit(new Worker(c, buf, args));
- }
- catch (RejectedExecutionException ignored) {
- // Because of custom RejectedExecutionHandler.
- assert false : "RejectedExecutionException was thrown while it shouldn't.";
- }
- finally {
- exec.shutdown();
-
- try {
- exec.awaitTermination(Long.MAX_VALUE, MILLISECONDS);
- }
- catch (InterruptedException ignored) {
- U.warn(log, "Working thread was interrupted while waiting for put operations to complete.");
-
- Thread.currentThread().interrupt();
- }
- }
- }
-
- /**
- * Returns batch size.
- *
- * @return Batch size.
- */
- public int getBatchSize() {
- return batchSize;
- }
-
- /**
- * Sets batch size.
- *
- * @param batchSize Batch size.
- */
- public void setBatchSize(int batchSize) {
- this.batchSize = batchSize;
- }
-
- /**
- * Returns batch queue size.
- *
- * @return Batch queue size.
- */
- public int getBatchQueueSize() {
- return batchQueueSize;
- }
-
- /**
- * Sets batch queue size.
- *
- * @param batchQueueSize Batch queue size.
- */
- public void setBatchQueueSize(int batchQueueSize) {
- this.batchQueueSize = batchQueueSize;
- }
-
- /**
- * Returns number of worker threads.
- *
- * @return Number of worker threads.
- */
- public int getThreadsCount() {
- return threadsCnt;
- }
-
- /**
- * Sets number of worker threads.
- *
- * @param threadsCnt Number of worker threads.
- */
- public void setThreadsCount(int threadsCnt) {
- this.threadsCnt = threadsCnt;
- }
-
- /** {@inheritDoc} */
- @Override public V load(@Nullable IgniteTx tx, K key)
- throws IgniteCheckedException {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void loadAll(@Nullable IgniteTx tx,
- @Nullable Collection<? extends K> keys, IgniteBiInClosure<K, V> c) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void put(@Nullable IgniteTx tx, K key, @Nullable V val) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void putAll(@Nullable IgniteTx tx, @Nullable Map<? extends K, ? extends V> map)
- throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void remove(@Nullable IgniteTx tx, K key) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void removeAll(@Nullable IgniteTx tx, @Nullable Collection<? extends K> keys)
- throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void txEnd(IgniteTx tx, boolean commit) throws IgniteCheckedException {
- // No-op.
- }
-
- /**
- * Worker.
- */
- private class Worker implements Runnable {
- /** */
- private final IgniteBiInClosure<K, V> c;
-
- /** */
- private final Collection<I> buf;
-
- /** */
- private final Object[] args;
-
- /**
- * @param c Closure for loaded entries.
- * @param buf Set of input records to process.
- * @param args Arguments passed into {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)} method.
- */
- Worker(IgniteBiInClosure<K, V> c, Collection<I> buf, Object[] args) {
- this.c = c;
- this.buf = buf;
- this.args = args;
- }
-
- /** {@inheritDoc} */
- @Override public void run() {
- for (I rec : buf) {
- IgniteBiTuple<K, V> entry = parse(rec, args);
-
- if (entry != null)
- c.apply(entry.getKey(), entry.getValue());
- }
- }
- }
-
- /**
- * This handler blocks the caller thread until free space will be available in tasks queue.
- * If the executor is shut down than it throws {@link RejectedExecutionException}.
- * <p>
- * It is save to apply this policy when:
- * <ol>
- * <li>{@code shutdownNow} is not used on the pool.</li>
- * <li>{@code shutdown} is called from the thread where all submissions where performed.</li>
- * </ol>
- */
- private class BlockingRejectedExecutionHandler implements RejectedExecutionHandler {
- /** {@inheritDoc} */
- @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
- try {
- if (executor.isShutdown())
- throw new RejectedExecutionException();
- else
- executor.getQueue().put(r);
- }
- catch (InterruptedException ignored) {
- U.warn(log, "Working thread was interrupted while loading data.");
-
- Thread.currentThread().interrupt();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLocalStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLocalStore.java b/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLocalStore.java
deleted file mode 100644
index 31f3672..0000000
--- a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheLocalStore.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.gridgain.grid.cache.store;
-
-import java.lang.annotation.*;
-
-/**
- * Annotation for local {@link GridCacheStore} implementation. "Local" here means that there is no global
- * database behind the grid but each node has an independent one.
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE})
-public @interface GridCacheLocalStore {
- // No-op.
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4b8ec5f2/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheStore.java b/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheStore.java
deleted file mode 100644
index e2f4cc6..0000000
--- a/modules/core/src/main/java/org/gridgain/grid/cache/store/GridCacheStore.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * 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.gridgain.grid.cache.store;
-
-import org.apache.ignite.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.portables.*;
-import org.apache.ignite.transactions.*;
-import org.gridgain.grid.*;
-import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.store.jdbc.*;
-import org.jetbrains.annotations.*;
-
-import java.sql.*;
-import java.util.*;
-import java.util.Date;
-
-/**
- * API for cache persistent storage for read-through and write-through behavior.
- * Persistent store is configured via {@link GridCacheConfiguration#getStore()}
- * configuration property. If not provided, values will be only kept in cache memory
- * or swap storage without ever being persisted to a persistent storage.
- * <p>
- * {@link GridCacheStoreAdapter} provides default implementation for bulk operations,
- * such as {@link #loadAll(IgniteTx, Collection, org.apache.ignite.lang.IgniteBiInClosure)},
- * {@link #putAll(IgniteTx, Map)}, and {@link #removeAll(IgniteTx, Collection)}
- * by sequentially calling corresponding {@link #load(IgniteTx, Object)},
- * {@link #put(IgniteTx, Object, Object)}, and {@link #remove(IgniteTx, Object)}
- * operations. Use this adapter whenever such behaviour is acceptable. However
- * in many cases it maybe more preferable to take advantage of database batch update
- * functionality, and therefore default adapter implementation may not be the best option.
- * <p>
- * Provided implementations may be used for test purposes:
- * <ul>
- * <li>{@gglink org.gridgain.grid.cache.store.hibernate.GridCacheHibernateBlobStore}</li>
- * <li>{@link GridCacheJdbcBlobStore}</li>
- * </ul>
- * <p>
- * All transactional operations of this API are provided with ongoing {@link IgniteTx},
- * if any. As transaction is {@link GridMetadataAware}, you can attach any metadata to
- * it, e.g. to recognize if several operations belong to the same transaction or not.
- * Here is an example of how attach a JDBC connection as transaction metadata:
- * <pre name="code" class="java">
- * Connection conn = tx.meta("some.name");
- *
- * if (conn == null) {
- * conn = ...; // Get JDBC connection.
- *
- * // Store connection in transaction metadata, so it can be accessed
- * // for other operations on the same transaction.
- * tx.addMeta("some.name", conn);
- * }
- * </pre>
- * <h1 class="header">Working With Portable Objects</h1>
- * When portables are enabled for cache by setting {@link GridCacheConfiguration#isPortableEnabled()} to
- * {@code true}), all portable keys and values are converted to instances of {@link PortableObject}.
- * Therefore, all cache store methods will take parameters in portable format. To avoid class
- * cast exceptions, store must have signature compatible with portables. E.g., if you use {@link Integer}
- * as a key and {@code Value} class as a value (which will be converted to portable format), cache store
- * signature should be the following:
- * <pre name="code" class="java">
- * public class PortableCacheStore implements GridCacheStore<Integer, GridPortableObject> {
- * public void put(@Nullable GridCacheTx tx, Integer key, GridPortableObject val) throws IgniteCheckedException {
- * ...
- * }
- *
- * ...
- * }
- * </pre>
- * This behavior can be overridden by setting {@link GridCacheConfiguration#setKeepPortableInStore(boolean)}
- * flag value to {@code false}. In this case, GridGain will deserialize keys and values stored in portable
- * format before they are passed to cache store, so that you can use the following cache store signature instead:
- * <pre name="code" class="java">
- * public class ObjectsCacheStore implements GridCacheStore<Integer, Person> {
- * public void put(@Nullable GridCacheTx tx, Integer key, Person val) throws GridException {
- * ...
- * }
- *
- * ...
- * }
- * </pre>
- * Note that while this can simplify store implementation in some cases, it will cause performance degradation
- * due to additional serializations and deserializations of portable objects. You will also need to have key
- * and value classes on all nodes since portables will be deserialized when store is invoked.
- * <p>
- * Note that only portable classes are converted to {@link PortableObject} format. Following
- * types are stored in cache without changes and therefore should not affect cache store signature:
- * <ul>
- * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
- * <li>Arrays of primitives (byte[], int[], ...)</li>
- * <li>{@link String} and array of {@link String}s</li>
- * <li>{@link UUID} and array of {@link UUID}s</li>
- * <li>{@link Date} and array of {@link Date}s</li>
- * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
- * <li>Enums and array of enums</li>
- * <li>
- * Maps, collections and array of objects (but objects inside
- * them will still be converted if they are portable)
- * </li>
- * </ul>
- *
- * @see org.apache.ignite.IgnitePortables
- */
-public interface GridCacheStore<K, V> {
- /**
- * Loads value for the key from underlying persistent storage.
- *
- * @param tx Cache transaction.
- * @param key Key to load.
- * @return Loaded value or {@code null} if value was not found.
- * @throws IgniteCheckedException If load failed.
- */
- @Nullable public V load(@Nullable IgniteTx tx, K key) throws IgniteCheckedException;
-
- /**
- * Loads all values from underlying persistent storage. Note that keys are not
- * passed, so it is up to implementation to figure out what to load. This method
- * is called whenever {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)}
- * method is invoked which is usually to preload the cache from persistent storage.
- * <p>
- * This method is optional, and cache implementation does not depend on this
- * method to do anything. Default implementation of this method in
- * {@link GridCacheStoreAdapter} does nothing.
- * <p>
- * For every loaded value method {@link org.apache.ignite.lang.IgniteBiInClosure#apply(Object, Object)}
- * should be called on the passed in closure. The closure will then make sure
- * that the loaded value is stored in cache.
- *
- * @param clo Closure for loaded values.
- * @param args Arguments passes into
- * {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)} method.
- * @throws IgniteCheckedException If loading failed.
- */
- public void loadCache(IgniteBiInClosure<K, V> clo, @Nullable Object... args) throws IgniteCheckedException;
-
- /**
- * Loads all values for given keys and passes every value to the provided closure.
- * <p>
- * For every loaded value method {@link org.apache.ignite.lang.IgniteInClosure#apply(Object)} should be called on
- * the passed in closure. The closure will then make sure that the loaded value is stored
- * in cache.
- *
- * @param tx Cache transaction.
- * @param keys Collection of keys to load.
- * @param c Closure to call for every loaded element.
- * @throws IgniteCheckedException If load failed.
- */
- public void loadAll(@Nullable IgniteTx tx, Collection<? extends K> keys, IgniteBiInClosure<K, V> c)
- throws IgniteCheckedException;
-
- /**
- * Stores a given value in persistent storage. Note that if write-behind is configured for a
- * particular cache, transaction object passed in the cache store will be always {@code null}.
- *
- * @param tx Cache transaction, if write-behind is not enabled, {@code null} otherwise.
- * @param key Key to put.
- * @param val Value to put.
- * @throws IgniteCheckedException If put failed.
- */
- public void put(@Nullable IgniteTx tx, K key, V val) throws IgniteCheckedException;
-
- /**
- * Stores given key value pairs in persistent storage. Note that if write-behind is configured
- * for a particular cache, transaction object passed in the cache store will be always {@code null}.
- *
- * @param tx Cache transaction, if write-behind is not enabled, {@code null} otherwise.
- * @param map Values to store.
- * @throws IgniteCheckedException If store failed.
- */
- public void putAll(@Nullable IgniteTx tx, Map<? extends K, ? extends V> map) throws IgniteCheckedException;
-
- /**
- * Removes the value identified by given key from persistent storage. Note that if write-behind is
- * configured for a particular cache, transaction object passed in the cache store will be always
- * {@code null}.
- *
- * @param tx Cache transaction, if write-behind is not enabled, {@code null} otherwise.
- * @param key Key to remove.
- * @throws IgniteCheckedException If remove failed.
- */
- public void remove(@Nullable IgniteTx tx, K key) throws IgniteCheckedException;
-
- /**
- * Removes all vales identified by given keys from persistent storage. Note that if write-behind
- * is configured for a particular cache, transaction object passed in the cache store will be
- * always {@code null}.
- *
- * @param tx Cache transaction, if write-behind is not enabled, {@code null} otherwise.
- * @param keys Keys to remove.
- * @throws IgniteCheckedException If remove failed.
- */
- public void removeAll(@Nullable IgniteTx tx, Collection<? extends K> keys) throws IgniteCheckedException;
-
- /**
- * Tells store to commit or rollback a transaction depending on the value of the {@code 'commit'}
- * parameter.
- *
- * @param tx Cache transaction being ended.
- * @param commit {@code True} if transaction should commit, {@code false} for rollback.
- * @throws IgniteCheckedException If commit or rollback failed. Note that commit failure in some cases
- * may bring cache transaction into {@link IgniteTxState#UNKNOWN} which will
- * consequently cause all transacted entries to be invalidated.
- */
- public void txEnd(IgniteTx tx, boolean commit) throws IgniteCheckedException;
-}