>
+* Ask a specific question using
+https://stackoverflow.com/questions/tagged/spring-data-aerospike[Spring Data Aerospike tag on StackOverflow]
-== Contributing to Spring Data
+== Contributing to Spring Data Aerospike
Here are some ways you can get involved:
-* Get involved with the Spring community on Stackoverflow and help out
-on the
-https://stackoverflow.com/questions/tagged/spring-data-aerospike[spring-data-aerospike]
-tag by responding to questions and joining the debate.
-* Create
+* Help out on the StackOverflow https://stackoverflow.com/questions/tagged/spring-data-aerospike[spring-data-aerospike]
+tag by responding to questions and joining the debate
+* Create a
https://github.com/aerospike/spring-data-aerospike/issues[GitHub
-issue] for bugs and new features and comment and vote on the ones that
-you are interested in.
-* GitHub is for social coding: if you want to write code, we encourage
-contributions through pull requests from
-https://help.github.com/forking/[forks of this repository]. If you want
-to contribute code this way, please reference a GitHub ticket as well
-covering the specific issue you are addressing.
+issue] for a feature request or bug fixing, comment and vote on the ones that
+you are interested in
+* GitHub is for social coding: we encourage contributions through pull requests from
+https://help.github.com/forking/[forks of this repository]. When contributing code, please reference a specific
+GitHub issue you are addressing
* Watch for upcoming articles by
https://www.aerospike.com/forms/subscribe-the-aerospike-standup/[subscribing]
-to Aerospike Stand-Up.
\ No newline at end of file
+to Aerospike Stand-Up
\ No newline at end of file
diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeInternalOperations.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeInternalOperations.java
deleted file mode 100644
index c4f0f41ff..000000000
--- a/src/main/java/org/springframework/data/aerospike/core/AerospikeInternalOperations.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.springframework.data.aerospike.core;
-
-import com.aerospike.client.AerospikeException;
-import org.springframework.data.aerospike.query.Qualifier;
-
-import java.util.Collection;
-import java.util.List;
-
-public interface AerospikeInternalOperations {
-
- /**
- * Find document by providing id, set name will be determined by the given entityClass.
- *
- * Documents will be mapped to the given targetClass.
- *
- * @param id The id of the document to find. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @param targetClass The class to map the document to.
- * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
- * @return The document from Aerospike, returned document will be mapped to targetClass's type.
- */
- Object findByIdInternal(Object id, Class entityClass, Class targetClass, Qualifier... qualifiers);
-
- /**
- * Find document by providing id with a given set name.
- *
- * Documents will be mapped to the given targetClass.
- *
- * @param id The id of the document to find. Must not be {@literal null}.
- * @param entityClass The class to get the entity properties from (such as expiration). Must not be
- * {@literal null}.
- * @param targetClass The class to map the document to.
- * @param setName Set name to find the document from.
- * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
- * @return The document from Aerospike, returned document will be mapped to targetClass's type.
- */
- Object findByIdInternal(Object id, Class entityClass, Class targetClass, String setName,
- Qualifier... qualifiers);
-
- /**
- * Find documents by providing multiple ids, set name will be determined by the given entityClass.
- *
- * Documents will be mapped to the given targetClass.
- *
- * @param ids The ids of the documents to find. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @param targetClass The class to map the document to.
- * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
- * @return The documents from Aerospike, returned documents will be mapped to targetClass's type, if no document
- * exists, an empty list is returned.
- */
- List> findByIdsInternal(Collection> ids, Class entityClass, Class targetClass,
- Qualifier... qualifiers);
-
- /**
- * Find documents by providing multiple ids with a given set name.
- *
- * Documents will be mapped to the given targetClass.
- *
- * @param ids The ids of the documents to find. Must not be {@literal null}.
- * @param entityClass The class to get the entity properties from (such as expiration). Must not be
- * {@literal null}.
- * @param targetClass The class to map the document to.
- * @param setName Set name to find the document from.
- * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
- * @return The documents from Aerospike, returned documents will be mapped to targetClass's type, if no document
- * exists, an empty list is returned.
- */
- List> findByIdsInternal(Collection> ids, Class entityClass, Class targetClass,
- String setName, Qualifier... qualifiers);
-
- /**
- * Batch delete documents by providing their ids. Set name will be determined by the given entityClass.
- *
- * This operation requires Server version 6.0+.
- *
- * @param ids The ids of the documents to delete. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
- */
- void deleteByIdsInternal(Collection> ids, Class entityClass);
-
- /**
- * Batch delete documents by providing their ids with a given set name.
- *
- * This operation requires Server version 6.0+.
- *
- * @param ids The ids of the documents to delete. Must not be {@literal null}.
- * @param setName Set name to delete the documents from.
- * @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
- */
- void deleteByIdsInternal(Collection> ids, String setName);
-}
diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java
index 694fa2fd6..4ec19c688 100644
--- a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java
+++ b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java
@@ -75,58 +75,6 @@ public interface AerospikeOperations {
*/
IAerospikeClient getAerospikeClient();
- /**
- * Insert a document using {@link com.aerospike.client.policy.RecordExistsAction#CREATE_ONLY} policy.
- *
- * If document has version property it will be updated with the server's version after successful operation.
- *
- * @param document The document to insert. Must not be {@literal null}.
- */
- void insert(T document);
-
- /**
- * Insert a document with a given set name (overrides the set associated with the document) using
- * {@link com.aerospike.client.policy.RecordExistsAction#CREATE_ONLY} policy.
- *
- * If document has version property it will be updated with the server's version after successful operation.
- *
- * @param document The document to insert. Must not be {@literal null}.
- * @param setName Set name to override the set associated with the document.
- */
- void insert(T document, String setName);
-
- /**
- * Insert multiple documents in one batch request. The policies are analogous to {@link #insert(Object)}.
- *
- * The order of returned results is preserved. The execution order is NOT preserved.
- *
- * This operation requires Server version 6.0+.
- *
- * @param documents Documents to insert. Must not be {@literal null}.
- * @throws AerospikeException.BatchRecordArray if batch insert succeeds, but results contain errors or null
- * records
- * @throws org.springframework.dao.DataAccessException if batch operation failed (see
- * {@link DefaultAerospikeExceptionTranslator} for details)
- */
- void insertAll(Iterable extends T> documents);
-
- /**
- * Insert multiple documents with a given set name (overrides the set associated with the document) in one batch
- * request. The policies are analogous to {@link #insert(Object)}.
- *
- * The order of returned results is preserved. The execution order is NOT preserved.
- *
- * This operation requires Server version 6.0+.
- *
- * @param documents Documents to insert. Must not be {@literal null}.
- * @param setName Set name to override the set associated with the document.
- * @throws AerospikeException.BatchRecordArray if batch insert succeeds, but results contain errors or null
- * records
- * @throws org.springframework.dao.DataAccessException if batch operation failed (see
- * {@link DefaultAerospikeExceptionTranslator} for details)
- */
- void insertAll(Iterable extends T> documents, String setName);
-
/**
* Save a document.
*
@@ -200,6 +148,58 @@ public interface AerospikeOperations {
*/
void saveAll(Iterable documents, String setName);
+ /**
+ * Insert a document using {@link com.aerospike.client.policy.RecordExistsAction#CREATE_ONLY} policy.
+ *
+ * If document has version property it will be updated with the server's version after successful operation.
+ *
+ * @param document The document to insert. Must not be {@literal null}.
+ */
+ void insert(T document);
+
+ /**
+ * Insert a document with a given set name (overrides the set associated with the document) using
+ * {@link com.aerospike.client.policy.RecordExistsAction#CREATE_ONLY} policy.
+ *
+ * If document has version property it will be updated with the server's version after successful operation.
+ *
+ * @param document The document to insert. Must not be {@literal null}.
+ * @param setName Set name to override the set associated with the document.
+ */
+ void insert(T document, String setName);
+
+ /**
+ * Insert multiple documents in one batch request. The policies are analogous to {@link #insert(Object)}.
+ *
+ * The order of returned results is preserved. The execution order is NOT preserved.
+ *
+ * This operation requires Server version 6.0+.
+ *
+ * @param documents Documents to insert. Must not be {@literal null}.
+ * @throws AerospikeException.BatchRecordArray if batch insert succeeds, but results contain errors or null
+ * records
+ * @throws org.springframework.dao.DataAccessException if batch operation failed (see
+ * {@link DefaultAerospikeExceptionTranslator} for details)
+ */
+ void insertAll(Iterable extends T> documents);
+
+ /**
+ * Insert multiple documents with a given set name (overrides the set associated with the document) in one batch
+ * request. The policies are analogous to {@link #insert(Object)}.
+ *
+ * The order of returned results is preserved. The execution order is NOT preserved.
+ *
+ * This operation requires Server version 6.0+.
+ *
+ * @param documents Documents to insert. Must not be {@literal null}.
+ * @param setName Set name to override the set associated with the document.
+ * @throws AerospikeException.BatchRecordArray if batch insert succeeds, but results contain errors or null
+ * records
+ * @throws org.springframework.dao.DataAccessException if batch operation failed (see
+ * {@link DefaultAerospikeExceptionTranslator} for details)
+ */
+ void insertAll(Iterable extends T> documents, String setName);
+
/**
* Persist a document using specified WritePolicy.
*
@@ -321,18 +321,21 @@ public interface AerospikeOperations {
boolean delete(Object id, Class entityClass);
/**
- * Truncate/Delete all the documents in the given entity's set.
+ * Delete a document.
*
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @param document The document to delete. Must not be {@literal null}.
+ * @return whether the document existed on server before deletion.
*/
- void deleteAll(Class entityClass);
+ boolean delete(T document);
/**
- * Truncate/Delete all the documents in the given set.
+ * Delete a document with a given set name.
*
- * @param setName Set name to truncate/delete all the documents in.
+ * @param document The document to delete. Must not be {@literal null}.
+ * @param setName Set name to delete the document from.
+ * @return whether the document existed on server before deletion.
*/
- void deleteAll(String setName);
+ boolean delete(T document, String setName);
/**
* Delete a document by id, set name will be determined by the given entityClass.
@@ -352,23 +355,6 @@ public interface AerospikeOperations {
*/
boolean deleteById(Object id, String setName);
- /**
- * Delete a document.
- *
- * @param document The document to delete. Must not be {@literal null}.
- * @return whether the document existed on server before deletion.
- */
- boolean delete(T document);
-
- /**
- * Delete a document with a given set name.
- *
- * @param document The document to delete. Must not be {@literal null}.
- * @param setName Set name to delete the document from.
- * @return whether the document existed on server before deletion.
- */
- boolean delete(T document, String setName);
-
/**
* Delete documents by providing multiple ids using a single batch delete operation, set name will be determined by
* the given entityClass.
@@ -397,6 +383,28 @@ public interface AerospikeOperations {
*/
void deleteByIds(Iterable> ids, String setName);
+ /**
+ * Batch delete documents by providing their ids. Set name will be determined by the given entityClass.
+ *
+ * This operation requires Server version 6.0+.
+ *
+ * @param ids The ids of the documents to delete. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
+ */
+ void deleteByIds(Collection> ids, Class entityClass);
+
+ /**
+ * Batch delete documents by providing their ids with a given set name.
+ *
+ * This operation requires Server version 6.0+.
+ *
+ * @param ids The ids of the documents to delete. Must not be {@literal null}.
+ * @param setName Set name to delete the documents from.
+ * @throws AerospikeException.BatchRecordArray if batch delete results contain errors or null records
+ */
+ void deleteByIds(Collection> ids, String setName);
+
/**
* Executes a single batch delete for several entities.
*
@@ -414,94 +422,180 @@ public interface AerospikeOperations {
void deleteByIds(GroupedKeys groupedKeys);
/**
- * Check if a document exists by providing document id and entityClass (set name will be determined by the given
- * entityClass).
+ * Truncate/Delete all the documents in the given entity's set.
*
- * @param id The id to check if exists. Must not be {@literal null}.
* @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @return whether the document exists.
*/
- boolean exists(Object id, Class entityClass);
+ void deleteAll(Class entityClass);
/**
- * Check if a document exists by providing document id and a set name.
+ * Truncate/Delete all the documents in the given set.
*
- * @param id The id to check if exists. Must not be {@literal null}.
- * @param setName Set name to check if document exists.
- * @return whether the document exists.
+ * @param setName Set name to truncate/delete all the documents in.
*/
- boolean exists(Object id, String setName);
+ void deleteAll(String setName);
/**
- * Find documents in the given entityClass's set using a query and map them to the given class type.
+ * Add integer/double bin values to existing document bin values, read the new modified document and map it back the
+ * given document class type.
*
- * @param query The query to filter results. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param values a Map of bin names and values to add. Must not be {@literal null}.
+ * @return Modified document after add operations.
*/
- Stream find(Query query, Class entityClass);
+ T add(T document, Map values);
/**
- * Find documents in the given entityClass's set using a query and map them to the given target class type.
+ * Add integer/double bin values to existing document bin values with a given set name, read the new modified
+ * document and map it back to the given document class type.
*
- * @param query The query to filter results. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @param targetClass The class to map the document to. Must not be {@literal null}.
- * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param setName Set name for the operation.
+ * @param values a Map of bin names and values to add. Must not be {@literal null}.
+ * @return Modified document after add operations.
*/
- Stream find(Query query, Class entityClass, Class targetClass);
+ T add(T document, String setName, Map values);
/**
- * Find documents in the given set using a query and map them to the given target class type.
+ * Add integer/double bin value to existing document bin value, read the new modified document and map it back the
+ * given document class type.
*
- * @param query The query to filter results. Must not be {@literal null}.
- * @param setName Set name to find the documents in.
- * @param targetClass The class to map the document to. Must not be {@literal null}.
- * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param binName Bin name to use add operation on. Must not be {@literal null}.
+ * @param value The value to add.
+ * @return Modified document after add operation.
*/
- Stream find(Query query, Class targetClass, String setName);
+ T add(T document, String binName, long value);
/**
- * Find all documents in the given entityClass's set and map them to the given class type.
+ * Add integer/double bin value to existing document bin value with a given set name, read the new modified document
+ * and map it back to the given document class type.
*
- * @param entityClass The class to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param setName Set name for the operation.
+ * @param binName Bin name to use add operation on. Must not be {@literal null}.
+ * @param value The value to add.
+ * @return Modified document after add operation.
*/
- Stream findAll(Class entityClass);
+ T add(T document, String setName, String binName, long value);
/**
- * Find all documents in the given entityClass's set and map them to the given target class type.
+ * Append bin string values to existing document bin values, read the new modified document and map it back the
+ * given document class type.
*
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @param targetClass The class to map the document to. Must not be {@literal null}.
- * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param values a Map of bin names and values to append. Must not be {@literal null}.
+ * @return Modified document after append operations.
*/
- Stream findAll(Class entityClass, Class targetClass);
+ T append(T document, Map values);
/**
- * Find all documents in the given set and map them to the given class type.
+ * Append bin string values to existing document bin values with a given set name, read the new modified document
+ * and map it back to the given document class type.
*
- * @param targetClass The class to map the documents to. Must not be {@literal null}.
- * @param setName Set name to find all documents.
- * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
+ * @param document The document to map the document to. Must not be {@literal null}.
+ * @param setName Set name for the operation.
+ * @param values a Map of bin names and values to append. Must not be {@literal null}.
+ * @return Modified document after append operations.
*/
- Stream findAll(Class targetClass, String setName);
+ T append(T document, String setName, Map values);
/**
- * Find a document by id, set name will be determined by the given entityClass.
- *
- * Document will be mapped to the given entityClass.
+ * Append bin string value to existing document bin value, read the new modified document and map it back the given
+ * document class type.
*
- * @param id The id of the document to find. Must not be {@literal null}.
- * @param entityClass The class to extract the Aerospike set from and to map the document to. Must not be
- * {@literal null}.
- * @return The document from Aerospike, returned document will be mapped to entityClass's type, if document doesn't
- * exist return null.
- */
- T findById(Object id, Class entityClass);
-
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param binName Bin name to use append operation on.
+ * @param value The value to append.
+ * @return Modified document after append operation.
+ */
+ T append(T document, String binName, String value);
+
+ /**
+ * Append bin string value to existing document bin value with a given set name, read the new modified document and
+ * map it back to the given document class type.
+ *
+ * @param document The document to map the document to. Must not be {@literal null}.
+ * @param setName Set name for the operation.
+ * @param binName Bin name to use append operation on.
+ * @param value The value to append.
+ * @return Modified document after append operation.
+ */
+ T append(T document, String setName, String binName, String value);
+
+ /**
+ * Prepend bin string values to existing document bin values, read the new modified document and map it back the
+ * given document class type.
+ *
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param values a Map of bin names and values to prepend. Must not be {@literal null}.
+ * @return Modified document after prepend operations.
+ */
+ T prepend(T document, Map values);
+
+ /**
+ * Prepend bin string values to existing document bin values with a given set name, read the new modified document
+ * and map it back to the given document class type.
+ *
+ * @param document The document to map the document to. Must not be {@literal null}.
+ * @param setName Set name for the operation.
+ * @param values a Map of bin names and values to prepend. Must not be {@literal null}.
+ * @return Modified document after prepend operations.
+ */
+ T prepend(T document, String setName, Map values);
+
+ /**
+ * Prepend bin string value to existing document bin value, read the new modified document and map it back the given
+ * document class type.
+ *
+ * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @param binName Bin name to use prepend operation on.
+ * @param value The value to prepend.
+ * @return Modified document after prepend operation.
+ */
+ T prepend(T document, String binName, String value);
+
+ /**
+ * Prepend bin string value to existing document bin value with a given set name, read the new modified document and
+ * map it back to the given document class type.
+ *
+ * @param document The document to map the document to. Must not be {@literal null}.
+ * @param setName Set name for the operation.
+ * @param binName Bin name to use prepend operation on.
+ * @param value The value to prepend.
+ * @return Modified document after prepend operation.
+ */
+ T prepend(T document, String setName, String binName, String value);
+
+ /**
+ * Execute operation against underlying store.
+ *
+ * @param supplier must not be {@literal null}.
+ * @return Execution result.
+ */
+ T execute(Supplier supplier);
+
+ /**
+ * Find a document by id, set name will be determined by the given entityClass.
+ *
+ * Document will be mapped to the given entityClass.
+ *
+ * @param id The id of the document to find. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from and to map the document to. Must not be
+ * {@literal null}.
+ * @return The document from Aerospike, returned document will be mapped to entityClass's type, if document doesn't
+ * exist return null.
+ */
+ T findById(Object id, Class entityClass);
+
/**
* Find a document by id with a given set name.
*
@@ -611,176 +705,168 @@ public interface AerospikeOperations {
GroupedEntities findByIds(GroupedKeys groupedKeys);
/**
- * Add integer/double bin values to existing document bin values, read the new modified document and map it back the
- * given document class type.
- *
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param values a Map of bin names and values to add. Must not be {@literal null}.
- * @return Modified document after add operations.
- */
- T add(T document, Map values);
-
- /**
- * Add integer/double bin values to existing document bin values with a given set name, read the new modified
- * document and map it back the given document class type.
+ * Find document by providing id, set name will be determined by the given entityClass.
+ *
+ * Documents will be mapped to the given targetClass.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param setName Set name for the operation.
- * @param values a Map of bin names and values to add. Must not be {@literal null}.
- * @return Modified document after add operations.
+ * @param id The id of the document to find. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @param targetClass The class to map the document to.
+ * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
+ * @return The document from Aerospike, returned document will be mapped to targetClass's type.
*/
- T add(T document, String setName, Map values);
+ Object findByIdUsingQualifiers(Object id, Class entityClass, Class targetClass,
+ Qualifier... qualifiers);
/**
- * Add integer/double bin value to existing document bin value, read the new modified document and map it back the
- * given document class type.
+ * Find document by providing id with a given set name.
+ *
+ * Documents will be mapped to the given targetClass.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param binName Bin name to use add operation on. Must not be {@literal null}.
- * @param value The value to add.
- * @return Modified document after add operation.
+ * @param id The id of the document to find. Must not be {@literal null}.
+ * @param entityClass The class to get the entity properties from (such as expiration). Must not be
+ * {@literal null}.
+ * @param targetClass The class to map the document to.
+ * @param setName Set name to find the document from.
+ * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
+ * @return The document from Aerospike, returned document will be mapped to targetClass's type.
*/
- T add(T document, String binName, long value);
+ Object findByIdUsingQualifiers(Object id, Class entityClass, Class targetClass, String setName,
+ Qualifier... qualifiers);
/**
- * Add integer/double bin value to existing document bin value with a given set name, read the new modified document
- * and map it back the given document class type.
+ * Find documents by providing multiple ids, set name will be determined by the given entityClass.
+ *
+ * Documents will be mapped to the given targetClass.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param setName Set name for the operation.
- * @param binName Bin name to use add operation on. Must not be {@literal null}.
- * @param value The value to add.
- * @return Modified document after add operation.
+ * @param ids The ids of the documents to find. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @param targetClass The class to map the document to.
+ * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
+ * @return The documents from Aerospike, returned documents will be mapped to targetClass's type, if no document
+ * exists, an empty list is returned.
*/
- T add(T document, String setName, String binName, long value);
+ List> findByIdsUsingQualifiers(Collection> ids, Class entityClass, Class targetClass,
+ Qualifier... qualifiers);
/**
- * Append bin string values to existing document bin values, read the new modified document and map it back the
- * given document class type.
+ * Find documents by providing multiple ids with a given set name.
+ *
+ * Documents will be mapped to the given targetClass.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param values a Map of bin names and values to append. Must not be {@literal null}.
- * @return Modified document after append operations.
+ * @param ids The ids of the documents to find. Must not be {@literal null}.
+ * @param entityClass The class to get the entity properties from (such as expiration). Must not be
+ * {@literal null}.
+ * @param targetClass The class to map the document to.
+ * @param setName Set name to find the document from.
+ * @param qualifiers {@link Qualifier}s provided to build a filter Expression for the query. Optional argument.
+ * @return The documents from Aerospike, returned documents will be mapped to targetClass's type, if no document
+ * exists, an empty list is returned.
*/
- T append(T document, Map values);
+ List> findByIdsUsingQualifiers(Collection> ids, Class entityClass, Class targetClass,
+ String setName, Qualifier... qualifiers);
/**
- * Append bin string values to existing document bin values with a given set name, read the new modified document
- * and map it back the given document class type.
+ * Find documents in the given entityClass's set using a query and map them to the given class type.
*
- * @param document The document to map the document to. Must not be {@literal null}.
- * @param setName Set name for the operation.
- * @param values a Map of bin names and values to append. Must not be {@literal null}.
- * @return Modified document after append operations.
+ * @param query The query to filter results. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
*/
- T append(T document, String setName, Map values);
+ Stream find(Query query, Class entityClass);
/**
- * Append bin string value to existing document bin value, read the new modified document and map it back the given
- * document class type.
+ * Find documents in the given entityClass's set using a query and map them to the given target class type.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param binName Bin name to use append operation on.
- * @param value The value to append.
- * @return Modified document after append operation.
+ * @param query The query to filter results. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @param targetClass The class to map the document to. Must not be {@literal null}.
+ * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
*/
- T append(T document, String binName, String value);
+ Stream find(Query query, Class entityClass, Class targetClass);
/**
- * Append bin string value to existing document bin value with a given set name, read the new modified document and
- * map it back the given document class type.
+ * Find documents in the given set using a query and map them to the given target class type.
*
- * @param document The document to map the document to. Must not be {@literal null}.
- * @param setName Set name for the operation.
- * @param binName Bin name to use append operation on.
- * @param value The value to append.
- * @return Modified document after append operation.
+ * @param query The query to filter results. Must not be {@literal null}.
+ * @param setName Set name to find the documents in.
+ * @param targetClass The class to map the document to. Must not be {@literal null}.
+ * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
*/
- T append(T document, String setName, String binName, String value);
+ Stream find(Query query, Class targetClass, String setName);
/**
- * Prepend bin string values to existing document bin values, read the new modified document and map it back the
- * given document class type.
+ * Find all documents in the given entityClass's set using provided {@link Qualifier}.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param values a Map of bin names and values to prepend. Must not be {@literal null}.
- * @return Modified document after prepend operations.
+ * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be
+ * {@literal null}.
+ * @param filter Secondary index filter.
+ * @param qualifier Qualifier to build filter expressions from. Can contain other qualifiers. Must not be
+ * {@literal null}. If filter param is null and qualifier has
+ * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the
+ * first processed qualifier.
+ * @return Stream of entities.
*/
- T prepend(T document, Map values);
+ Stream findUsingQualifier(Class entityClass, @Nullable Filter filter, Qualifier qualifier);
/**
- * Prepend bin string values to existing document bin values with a given set name, read the new modified document
- * and map it back the given document class type.
+ * Find all documents in the given entityClass's set using provided {@link Qualifier}.
*
- * @param document The document to map the document to. Must not be {@literal null}.
- * @param setName Set name for the operation.
- * @param values a Map of bin names and values to prepend. Must not be {@literal null}.
- * @return Modified document after prepend operations.
+ * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be
+ * {@literal null}.
+ * @param targetClass The class to map the entity to. Must not be {@literal null}.
+ * @param filter Secondary index filter.
+ * @param qualifier Qualifier to build filter expressions from. Can contain other qualifiers. Must not be
+ * {@literal null}. If filter param is null and qualifier has
+ * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the
+ * first processed qualifier.
+ * @return Stream of entities.
*/
- T prepend(T document, String setName, Map values);
+ Stream> findUsingQualifier(Class entityClass, Class targetClass, @Nullable Filter filter,
+ Qualifier qualifier);
/**
- * Prepend bin string value to existing document bin value, read the new modified document and map it back the given
- * document class type.
+ * Find all documents in the given set using provided {@link Qualifier}.
*
- * @param document The document to extract the Aerospike set from and to map the documents to. Must not be
- * {@literal null}.
- * @param binName Bin name to use prepend operation on.
- * @param value The value to prepend.
- * @return Modified document after prepend operation.
+ * @param targetClass The class to map the entity to. Must not be {@literal null}.
+ * @param setName Set name to find the documents in.
+ * @param filter Secondary index filter.
+ * @param qualifier Qualifier to build filter expressions from. Can contain other qualifiers. Must not be
+ * {@literal null}. If filter param is null and qualifier has
+ * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the
+ * first processed qualifier.
+ * @return Stream of entities.
*/
- T prepend(T document, String binName, String value);
+ Stream findUsingQualifier(Class targetClass, String setName, @Nullable Filter filter,
+ Qualifier qualifier);
/**
- * Prepend bin string value to existing document bin value with a given set name, read the new modified document and
- * map it back the given document class type.
+ * Find all documents in the given entityClass's set and map them to the given class type.
*
- * @param document The document to map the document to. Must not be {@literal null}.
- * @param setName Set name for the operation.
- * @param binName Bin name to use prepend operation on.
- * @param value The value to prepend.
- * @return Modified document after prepend operation.
+ * @param entityClass The class to extract the Aerospike set from and to map the documents to. Must not be
+ * {@literal null}.
+ * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
*/
- T prepend(T document, String setName, String binName, String value);
+ Stream findAll(Class entityClass);
/**
- * Execute query, apply statement's aggregation function, and return result iterator.
+ * Find all documents in the given entityClass's set and map them to the given target class type.
*
- * @param filter The filter to pass to the query.
* @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @param module server package where user defined function resides.
- * @param function aggregation function name.
- * @param arguments arguments to pass to function name, if any.
- * @return Result iterator.
- */
- ResultSet aggregate(Filter filter, Class entityClass, String module, String function, List arguments);
-
- /**
- * Execute query with a given set name, apply statement's aggregation function, and return result iterator.
- *
- * @param filter The filter to pass to the query.
- * @param setName Set name to aggregate the documents from.
- * @param module server package where user defined function resides.
- * @param function aggregation function name.
- * @param arguments arguments to pass to function name, if any.
- * @return Result iterator.
+ * @param targetClass The class to map the document to. Must not be {@literal null}.
+ * @return A Stream of matching documents, returned documents will be mapped to targetClass's type.
*/
- ResultSet aggregate(Filter filter, String setName, String module, String function, List arguments);
+ Stream findAll(Class entityClass, Class targetClass);
/**
- * Execute operation against underlying store.
+ * Find all documents in the given set and map them to the given class type.
*
- * @param supplier must not be {@literal null}.
- * @return Execution result.
+ * @param targetClass The class to map the documents to. Must not be {@literal null}.
+ * @param setName Set name to find all documents.
+ * @return A Stream of matching documents, returned documents will be mapped to entityClass's type.
*/
- T execute(Supplier supplier);
+ Stream findAll(Class targetClass, String setName);
/**
* Find all documents in the given entityClass's set using a provided sort and map them to the given class type.
@@ -857,6 +943,61 @@ public interface AerospikeOperations {
*/
Stream findInRange(long offset, long limit, Sort sort, Class targetClass, String setName);
+ /**
+ * Check if a document exists by providing document id and entityClass (set name will be determined by the given
+ * entityClass).
+ *
+ * @param id The id to check if exists. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @return whether the document exists.
+ */
+ boolean exists(Object id, Class entityClass);
+
+ /**
+ * Check if a document exists by providing document id and a set name.
+ *
+ * @param id The id to check if exists. Must not be {@literal null}.
+ * @param setName Set name to check if document exists.
+ * @return whether the document exists.
+ */
+ boolean exists(Object id, String setName);
+
+ /**
+ * Check if any document exists by defining a query and entityClass (set name will be determined by the given
+ * entityClass).
+ *
+ * @param query The query to check if any returned document exists. Must not be {@literal null}.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @return whether any document exists.
+ */
+ boolean existsByQuery(Query query, Class entityClass);
+
+ /**
+ * Check if any document exists by defining a query, entityClass and a given set name.
+ *
+ * @param query The query to check if any returned document exists. Must not be {@literal null}.
+ * @param entityClass The class to translate to returned results into. Must not be {@literal null}.
+ * @param setName The set name to check if documents exists in. Must not be {@literal null}.
+ * @return whether any document exists.
+ */
+ boolean existsByQuery(Query query, Class entityClass, String setName);
+
+ /**
+ * Return the amount of documents in the given entityClass's Aerospike set.
+ *
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @return amount of documents in the set (of the given entityClass).
+ */
+ long count(Class entityClass);
+
+ /**
+ * Return the amount of documents in the given Aerospike set.
+ *
+ * @param setName The name of the set to count. Must not be {@literal null}.
+ * @return amount of documents in the given set.
+ */
+ long count(String setName);
+
/**
* Return the amount of documents in query results. Set name will be determined by the given entityClass.
*
@@ -876,20 +1017,28 @@ public interface AerospikeOperations {
long count(Query query, String setName);
/**
- * Return the amount of documents in the given Aerospike set.
+ * Execute query, apply statement's aggregation function, and return result iterator.
*
- * @param setName The name of the set to count. Must not be {@literal null}.
- * @return amount of documents in the given set.
+ * @param filter The filter to pass to the query.
+ * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
+ * @param module server package where user defined function resides.
+ * @param function aggregation function name.
+ * @param arguments arguments to pass to function name, if any.
+ * @return Result iterator.
*/
- long count(String setName);
+ ResultSet aggregate(Filter filter, Class entityClass, String module, String function, List arguments);
/**
- * Return the amount of documents in the given entityClass's Aerospike set.
+ * Execute query with a given set name, apply statement's aggregation function, and return result iterator.
*
- * @param entityClass The class to extract the Aerospike set from. Must not be {@literal null}.
- * @return amount of documents in the set (of the given entityClass).
+ * @param filter The filter to pass to the query.
+ * @param setName Set name to aggregate the documents from.
+ * @param module server package where user defined function resides.
+ * @param function aggregation function name.
+ * @param arguments arguments to pass to function name, if any.
+ * @return Result iterator.
*/
- long count(Class entityClass);
+ ResultSet aggregate(Filter filter, String setName, String module, String function, List arguments);
/**
* Create an index with the specified name in Aerospike.
@@ -986,33 +1135,4 @@ void createIndex(String setName, String indexName, String binName,
* @return true if exists
*/
boolean indexExists(String indexName);
-
- /**
- * Find all documents in the given entityClass's set using provided {@link Qualifier}.
- *
- * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be
- * {@literal null}.
- * @param filter Secondary index filter.
- * @param qualifier Qualifier to build filter expressions from. Can contain other qualifiers. Must not be
- * {@literal null}. If filter param is null and qualifier has
- * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the
- * first processed qualifier.
- * @return Stream of entities.
- */
- Stream findAllUsingQuery(Class entityClass, @Nullable Filter filter, Qualifier qualifier);
-
- /**
- * Find all documents in the given set using provided {@link Qualifier}.
- *
- * @param targetClass The class to map the entity to. Must not be {@literal null}.
- * @param setName Set name to find the documents in.
- * @param filter Secondary index filter.
- * @param qualifier Qualifier to build filter expressions from. Can contain other qualifiers. Must not be
- * {@literal null}. If filter param is null and qualifier has
- * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the
- * first processed qualifier.
- * @return Stream of entities.
- */
- Stream findAllUsingQuery(Class targetClass, String setName, @Nullable Filter filter,
- Qualifier qualifier);
}
diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java
index d192bb674..eb110fbe5 100644
--- a/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java
+++ b/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java
@@ -86,7 +86,7 @@
*/
@Slf4j
public class AerospikeTemplate extends BaseAerospikeTemplate implements AerospikeOperations,
- AerospikeInternalOperations, IndexesCacheRefresher {
+ IndexesCacheRefresher {
private static final Pattern INDEX_EXISTS_REGEX_PATTERN = Pattern.compile("^FAIL:(-?\\d+).*$");
private final IAerospikeClient client;
@@ -111,130 +111,11 @@ public IAerospikeClient getAerospikeClient() {
return client;
}
- @Override
- public void createIndex(Class entityClass, String indexName,
- String binName, IndexType indexType) {
- Assert.notNull(entityClass, "Class must not be null!");
- createIndex(entityClass, indexName, binName, indexType, IndexCollectionType.DEFAULT);
- }
-
- @Override
- public void createIndex(Class entityClass, String indexName,
- String binName, IndexType indexType, IndexCollectionType indexCollectionType) {
- Assert.notNull(entityClass, "Class must not be null!");
- createIndex(entityClass, indexName, binName, indexType, indexCollectionType, new CTX[0]);
- }
-
- @Override
- public void createIndex(Class entityClass, String indexName,
- String binName, IndexType indexType, IndexCollectionType indexCollectionType,
- CTX... ctx) {
- Assert.notNull(entityClass, "Class must not be null!");
- createIndex(getSetName(entityClass), indexName, binName, indexType, indexCollectionType, ctx);
- }
-
- @Override
- public void createIndex(String setName, String indexName,
- String binName, IndexType indexType) {
- createIndex(setName, indexName, binName, indexType, IndexCollectionType.DEFAULT);
- }
-
- @Override
- public void createIndex(String setName, String indexName, String binName, IndexType indexType,
- IndexCollectionType indexCollectionType) {
- createIndex(setName, indexName, binName, indexType, indexCollectionType, new CTX[0]);
- }
-
- @Override
- public void createIndex(String setName, String indexName, String binName,
- IndexType indexType, IndexCollectionType indexCollectionType, CTX... ctx) {
- Assert.notNull(setName, "Set name type must not be null!");
- Assert.notNull(indexName, "Index name must not be null!");
- Assert.notNull(binName, "Bin name must not be null!");
- Assert.notNull(indexType, "Index type must not be null!");
- Assert.notNull(indexCollectionType, "Index collection type must not be null!");
- Assert.notNull(ctx, "Ctx must not be null!");
-
- try {
- IndexTask task = client.createIndex(null, this.namespace,
- setName, indexName, binName, indexType, indexCollectionType, ctx);
- if (task != null) {
- task.waitTillComplete();
- }
- refreshIndexesCache();
- } catch (AerospikeException e) {
- throw translateError(e);
- }
- }
-
@Override
public void refreshIndexesCache() {
indexRefresher.refreshIndexes();
}
- @Override
- public void deleteIndex(Class entityClass, String indexName) {
- Assert.notNull(entityClass, "Class must not be null!");
- deleteIndex(getSetName(entityClass), indexName);
- }
-
- @Override
- public void deleteIndex(String setName, String indexName) {
- Assert.notNull(setName, "Set name must not be null!");
- Assert.notNull(indexName, "Index name must not be null!");
-
- try {
- IndexTask task = client.dropIndex(null, this.namespace, setName, indexName);
- if (task != null) {
- task.waitTillComplete();
- }
- refreshIndexesCache();
- } catch (AerospikeException e) {
- throw translateError(e);
- }
- }
-
- @Override
- public boolean indexExists(String indexName) {
- Assert.notNull(indexName, "Index name must not be null!");
-
- try {
- Node[] nodes = client.getNodes();
- for (Node node : nodes) {
- String response = Info.request(node, "sindex-exists:ns=" + namespace + ";indexname=" + indexName);
- if (response == null) throw new AerospikeException("Null node response");
-
- if (response.equalsIgnoreCase("true")) {
- return true;
- } else if (response.equalsIgnoreCase("false")) {
- return false;
- } else {
- Matcher matcher = INDEX_EXISTS_REGEX_PATTERN.matcher(response);
- if (matcher.matches()) {
- int reason;
- try {
- reason = Integer.parseInt(matcher.group(1));
- } catch (NumberFormatException e) {
- throw new AerospikeException("Unexpected node response, unable to parse ResultCode: " +
- response);
- }
-
- // as for Server ver. >= 6.1.0.1 the response containing ResultCode.INVALID_NAMESPACE
- // means that the request should be sent to another node
- if (reason != ResultCode.INVALID_NAMESPACE) {
- throw new AerospikeException(reason);
- }
- } else {
- throw new AerospikeException("Unexpected node response: " + response);
- }
- }
- }
- } catch (AerospikeException e) {
- throw translateError(e);
- }
- return false;
- }
-
@Override
public void save(T document) {
Assert.notNull(document, "Document must not be null!");
@@ -305,25 +186,6 @@ private void checkForErrorsAndUpdateVersion(List> batchWri
}
}
- @Override
- public void persist(T document, WritePolicy policy) {
- Assert.notNull(document, "Document must not be null!");
- Assert.notNull(policy, "Policy must not be null!");
- persist(document, policy, getSetName(document));
- }
-
- @Override
- public void persist(T document, WritePolicy policy, String setName) {
- Assert.notNull(document, "Document must not be null!");
- Assert.notNull(policy, "Policy must not be null!");
- Assert.notNull(setName, "Set name must not be null!");
-
- AerospikeWriteData data = writeData(document, setName);
-
- Operation[] operations = operations(data.getBinsAsArray(), Operation::put);
- doPersistAndHandleError(data, policy, operations);
- }
-
@Override
public void insert(T document) {
Assert.notNull(document, "Document must not be null!");
@@ -376,6 +238,25 @@ public void insertAll(Iterable extends T> documents, String setName) {
checkForErrorsAndUpdateVersion(batchWriteDataList, batchWriteRecords, "insert");
}
+ @Override
+ public void persist(T document, WritePolicy policy) {
+ Assert.notNull(document, "Document must not be null!");
+ Assert.notNull(policy, "Policy must not be null!");
+ persist(document, policy, getSetName(document));
+ }
+
+ @Override
+ public void persist(T document, WritePolicy policy, String setName) {
+ Assert.notNull(document, "Document must not be null!");
+ Assert.notNull(policy, "Policy must not be null!");
+ Assert.notNull(setName, "Set name must not be null!");
+
+ AerospikeWriteData data = writeData(document, setName);
+
+ Operation[] operations = operations(data.getBinsAsArray(), Operation::put);
+ doPersistAndHandleError(data, policy, operations);
+ }
+
@Override
public void update(T document) {
Assert.notNull(document, "Document must not be null!");
@@ -476,17 +357,20 @@ public boolean delete(Object id, Class entityClass) {
}
@Override
- public void deleteAll(Class entityClass) {
- Assert.notNull(entityClass, "Class must not be null!");
- deleteAll(getSetName(entityClass));
+ public boolean delete(T document) {
+ Assert.notNull(document, "Document must not be null!");
+ return delete(document, getSetName(document));
}
@Override
- public void deleteAll(String setName) {
+ public boolean delete(T document, String setName) {
+ Assert.notNull(document, "Document must not be null!");
Assert.notNull(setName, "Set name must not be null!");
try {
- client.truncate(null, getNamespace(), setName, null);
+ AerospikeWriteData data = writeData(document, setName);
+
+ return this.client.delete(ignoreGenerationDeletePolicy(), data.getKey());
} catch (AerospikeException e) {
throw translateError(e);
}
@@ -512,26 +396,6 @@ public boolean deleteById(Object id, String setName) {
}
}
- @Override
- public boolean delete(T document) {
- Assert.notNull(document, "Document must not be null!");
- return delete(document, getSetName(document));
- }
-
- @Override
- public boolean delete(T document, String setName) {
- Assert.notNull(document, "Document must not be null!");
- Assert.notNull(setName, "Set name must not be null!");
-
- try {
- AerospikeWriteData data = writeData(document, setName);
-
- return this.client.delete(ignoreGenerationDeletePolicy(), data.getKey());
- } catch (AerospikeException e) {
- throw translateError(e);
- }
- }
-
@Override
public void deleteByIds(Iterable> ids, Class entityClass) {
Assert.notNull(ids, "List of ids must not be null!");
@@ -544,18 +408,18 @@ public void deleteByIds(Iterable> ids, String setName) {
Assert.notNull(ids, "List of ids must not be null!");
Assert.notNull(setName, "Set name must not be null!");
- deleteByIdsInternal(IterableConverter.toList(ids), setName);
+ deleteByIds(IterableConverter.toList(ids), setName);
}
@Override
- public void deleteByIdsInternal(Collection> ids, Class entityClass) {
+ public void deleteByIds(Collection> ids, Class entityClass) {
Assert.notNull(ids, "List of ids must not be null!");
Assert.notNull(entityClass, "Class must not be null!");
- deleteByIdsInternal(ids, getSetName(entityClass));
+ deleteByIds(ids, getSetName(entityClass));
}
@Override
- public void deleteByIdsInternal(Collection> ids, String setName) {
+ public void deleteByIds(Collection> ids, String setName) {
Assert.notNull(ids, "List of ids must not be null!");
Assert.notNull(setName, "Set name must not be null!");
@@ -567,25 +431,7 @@ public void deleteByIdsInternal(Collection> ids, String setName) {
.map(id -> getKey(id, setName))
.toArray(Key[]::new);
- checkForErrors(client, keys);
- }
-
- private void checkForErrors(IAerospikeClient client, Key[] keys) {
- BatchResults results;
- try {
- // requires server ver. >= 6.0.0
- results = client.delete(null, null, keys);
- } catch (AerospikeException e) {
- throw translateError(e);
- }
-
- for (int i = 0; i < results.records.length; i++) {
- BatchRecord record = results.records[i];
- if (batchRecordFailed(record)) {
- throw new AerospikeException.BatchRecordArray(results.records,
- new AerospikeException("Errors during batch delete"));
- }
- }
+ deleteAndHandleErrors(client, keys);
}
@Override
@@ -594,190 +440,245 @@ public void deleteByIds(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys.getEntitiesKeys(), "Entities keys must not be null!");
Assert.notEmpty(groupedKeys.getEntitiesKeys(), "Entities keys must not be empty!");
- deleteEntitiesByIdsInternal(groupedKeys);
+ deleteGroupedEntitiesByGroupedKeys(groupedKeys);
}
- private void deleteEntitiesByIdsInternal(GroupedKeys groupedKeys) {
+ private void deleteGroupedEntitiesByGroupedKeys(GroupedKeys groupedKeys) {
EntitiesKeys entitiesKeys = EntitiesKeys.of(toEntitiesKeyMap(groupedKeys));
- checkForErrors(client, entitiesKeys.getKeys());
+ deleteAndHandleErrors(client, entitiesKeys.getKeys());
}
@Override
- public boolean exists(Object id, Class entityClass) {
+ public void deleteAll(Class entityClass) {
Assert.notNull(entityClass, "Class must not be null!");
- return exists(id, getSetName(entityClass));
+ deleteAll(getSetName(entityClass));
}
@Override
- public boolean exists(Object id, String setName) {
- Assert.notNull(id, "Id must not be null!");
+ public void deleteAll(String setName) {
Assert.notNull(setName, "Set name must not be null!");
try {
- Key key = getKey(id, setName);
-
- Record aeroRecord = this.client.operate(null, key, Operation.getHeader());
- return aeroRecord != null;
+ client.truncate(null, getNamespace(), setName, null);
} catch (AerospikeException e) {
throw translateError(e);
}
}
- @Override
- public Stream findAll(Class entityClass) {
- Assert.notNull(entityClass, "Entity class must not be null!");
+ private void deleteAndHandleErrors(IAerospikeClient client, Key[] keys) {
+ BatchResults results;
+ try {
+ // requires server ver. >= 6.0.0
+ results = client.delete(null, null, keys);
+ } catch (AerospikeException e) {
+ throw translateError(e);
+ }
- return findAll(entityClass, getSetName(entityClass));
+ for (int i = 0; i < results.records.length; i++) {
+ BatchRecord record = results.records[i];
+ if (batchRecordFailed(record)) {
+ throw new AerospikeException.BatchRecordArray(results.records,
+ new AerospikeException("Errors during batch delete"));
+ }
+ }
}
@Override
- public Stream findAll(Class entityClass, Class targetClass) {
- Assert.notNull(entityClass, "Entity class must not be null!");
- Assert.notNull(targetClass, "Target class must not be null!");
-
- return findAll(targetClass, getSetName(entityClass));
+ public T add(T document, Map values) {
+ return add(document, getSetName(document), values);
}
@Override
- public Stream findAll(Class targetClass, String setName) {
- Assert.notNull(targetClass, "Target class must not be null!");
+ public T add(T document, String setName, Map values) {
+ Assert.notNull(document, "Document must not be null!");
Assert.notNull(setName, "Set name must not be null!");
+ Assert.notNull(values, "Values must not be null!");
- return findAllUsingQuery(targetClass, setName, null, null);
- }
+ try {
+ AerospikeWriteData data = writeData(document, setName);
+ Operation[] ops = operations(values, Operation.Type.ADD, Operation.get());
- @Override
- public T findById(Object id, Class entityClass) {
- Assert.notNull(id, "Id must not be null!");
- Assert.notNull(entityClass, "Class must not be null!");
- return findById(id, entityClass, getSetName(entityClass));
- }
+ WritePolicy writePolicy = WritePolicyBuilder.builder(client.getWritePolicyDefault())
+ .expiration(data.getExpiration())
+ .build();
- @Override
- public T findById(Object id, Class entityClass, String setName) {
- Assert.notNull(id, "Id must not be null!");
- Assert.notNull(entityClass, "Class must not be null!");
- return findById(id, entityClass, null, setName);
+ Record aeroRecord = this.client.operate(writePolicy, data.getKey(), ops);
+
+ return mapToEntity(data.getKey(), getEntityClass(document), aeroRecord);
+ } catch (AerospikeException e) {
+ throw translateError(e);
+ }
}
@Override
- public S findById(Object id, Class entityClass, Class targetClass) {
- Assert.notNull(id, "Id must not be null!");
- Assert.notNull(entityClass, "Class must not be null!");
- return findById(id, entityClass, targetClass, getSetName(entityClass));
+ public T add(T document, String binName, long value) {
+ return add(document, getSetName(document), binName, value);
}
- @SuppressWarnings("unchecked")
@Override
- public S findById(Object id, Class entityClass, Class targetClass, String setName) {
- Assert.notNull(id, "Id must not be null!");
- Assert.notNull(entityClass, "Class must not be null!");
- return (S) findByIdInternal(id, entityClass, targetClass, setName);
+ public