DATACASS-32 : Completed : Refactoring completed after code review.
This commit is contained in:
@@ -690,7 +690,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe
|
||||
* @param q
|
||||
* @param optionsByName
|
||||
*/
|
||||
protected static void addQueryOptions(Query q, QueryOptions options) {
|
||||
public static void addQueryOptions(Query q, QueryOptions options) {
|
||||
|
||||
if (options == null) {
|
||||
return;
|
||||
@@ -714,7 +714,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe
|
||||
* @param q
|
||||
* @param optionsByName
|
||||
*/
|
||||
protected static void addPreparedStatementOptions(PreparedStatement s, QueryOptions options) {
|
||||
public static void addPreparedStatementOptions(PreparedStatement s, QueryOptions options) {
|
||||
|
||||
if (options == null) {
|
||||
return;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
@@ -122,22 +121,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T insert(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> T insert(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T insert(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given list of objects to the table by annotation table name.
|
||||
*
|
||||
@@ -163,14 +146,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -179,14 +154,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -209,14 +176,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -225,14 +184,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -255,14 +206,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -271,14 +214,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -301,14 +236,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T update(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T update(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -317,14 +244,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T update(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T update(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -347,14 +266,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -363,14 +274,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -393,14 +296,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -409,14 +304,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -439,14 +326,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -455,14 +334,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -485,13 +356,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void delete(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void delete(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -499,13 +363,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void delete(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void delete(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -528,13 +385,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void delete(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void delete(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -542,13 +392,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void delete(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void delete(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -563,13 +406,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -577,13 +413,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Removes the given object from the given table.
|
||||
*
|
||||
@@ -614,13 +443,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -628,13 +450,6 @@ public interface CassandraDataOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param optionsByName
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Returns the underlying {@link CassandraConverter}.
|
||||
*
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.cassandra.core.CassandraTemplate;
|
||||
@@ -78,8 +77,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
/*
|
||||
* Required elements for successful Template Operations. These can be set with the Constructor, or wired in
|
||||
* later.
|
||||
*
|
||||
* TODO - DW - Discuss Autowiring these.
|
||||
*/
|
||||
private String keyspace;
|
||||
private CassandraConverter cassandraConverter;
|
||||
@@ -150,16 +147,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
delete(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
delete(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -176,19 +163,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
@Override
|
||||
public <T> void delete(List<T> entities, String tableName) {
|
||||
|
||||
delete(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
doBatchDelete(tableName, entities, optionsByName, false);
|
||||
delete(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -196,7 +171,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(List<T> entities, String tableName, QueryOptions options) {
|
||||
delete(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
doBatchDelete(tableName, entities, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -209,16 +187,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
delete(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entity.getClass());
|
||||
Assert.notNull(tableName);
|
||||
delete(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -234,19 +202,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(T entity, String tableName) {
|
||||
|
||||
delete(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#delete(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
doDelete(tableName, entity, optionsByName, false);
|
||||
delete(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -254,7 +210,9 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void delete(T entity, String tableName, QueryOptions options) {
|
||||
delete(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
doDelete(tableName, entity, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -267,16 +225,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
deleteAsynchronously(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
deleteAsynchronously(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -292,20 +240,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(List<T> entities, String tableName) {
|
||||
|
||||
insertAsynchronously(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
doBatchDelete(tableName, entities, optionsByName, true);
|
||||
deleteAsynchronously(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -313,7 +248,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(List<T> entities, String tableName, QueryOptions options) {
|
||||
deleteAsynchronously(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
doBatchDelete(tableName, entities, options, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -326,16 +264,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
deleteAsynchronously(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entity.getClass());
|
||||
Assert.notNull(tableName);
|
||||
deleteAsynchronously(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -351,19 +279,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(T entity, String tableName) {
|
||||
|
||||
deleteAsynchronously(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#deleteAsynchronously(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
doDelete(tableName, entity, optionsByName, true);
|
||||
deleteAsynchronously(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -371,7 +287,9 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> void deleteAsynchronously(T entity, String tableName, QueryOptions options) {
|
||||
deleteAsynchronously(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
doDelete(tableName, entity, options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,16 +337,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return insert(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insert(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
return insert(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -444,20 +352,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insert(List<T> entities, String tableName) {
|
||||
|
||||
return insert(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insert(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doBatchInsert(tableName, entities, optionsByName, false);
|
||||
return insert(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -465,7 +360,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insert(List<T> entities, String tableName, QueryOptions options) {
|
||||
return insert(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
return doBatchInsert(tableName, entities, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -478,16 +376,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return insert(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T insert(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = determineTableName(entity);
|
||||
Assert.notNull(tableName);
|
||||
return insert(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -503,19 +391,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T insert(T entity, String tableName) {
|
||||
|
||||
return insert(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insert(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T insert(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
ensureNotIterable(entity);
|
||||
return doInsert(tableName, entity, optionsByName, false);
|
||||
return insert(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -523,7 +399,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T insert(T entity, String tableName, QueryOptions options) {
|
||||
return insert(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
ensureNotIterable(entity);
|
||||
return doInsert(tableName, entity, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -536,16 +415,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return insertAsynchronously(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insertAsynchronously(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
return insertAsynchronously(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -561,20 +430,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insertAsynchronously(List<T> entities, String tableName) {
|
||||
|
||||
return insertAsynchronously(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insertAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doBatchInsert(tableName, entities, optionsByName, true);
|
||||
return insertAsynchronously(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -582,7 +438,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> insertAsynchronously(List<T> entities, String tableName, QueryOptions options) {
|
||||
return insertAsynchronously(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
return doBatchInsert(tableName, entities, options, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -595,16 +454,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return insertAsynchronously(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T insertAsynchronously(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = determineTableName(entity);
|
||||
Assert.notNull(tableName);
|
||||
return insertAsynchronously(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -620,22 +469,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T insertAsynchronously(T entity, String tableName) {
|
||||
|
||||
return insertAsynchronously(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#insertAsynchronously(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T insertAsynchronously(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
|
||||
ensureNotIterable(entity);
|
||||
|
||||
return doInsert(tableName, entity, optionsByName, true);
|
||||
return insertAsynchronously(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -643,7 +477,12 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T insertAsynchronously(T entity, String tableName, QueryOptions options) {
|
||||
return insertAsynchronously(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
|
||||
ensureNotIterable(entity);
|
||||
|
||||
return doInsert(tableName, entity, options, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -688,16 +527,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return update(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> update(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
return update(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -713,20 +542,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> update(List<T> entities, String tableName) {
|
||||
|
||||
return update(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> update(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doBatchUpdate(tableName, entities, optionsByName, false);
|
||||
return update(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -734,7 +550,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> update(List<T> entities, String tableName, QueryOptions options) {
|
||||
return update(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
return doBatchUpdate(tableName, entities, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -747,16 +566,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return update(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T update(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entity.getClass());
|
||||
Assert.notNull(tableName);
|
||||
return update(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -772,19 +581,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T update(T entity, String tableName) {
|
||||
|
||||
return update(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#update(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T update(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doUpdate(tableName, entity, optionsByName, false);
|
||||
return update(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -792,7 +589,9 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T update(T entity, String tableName, QueryOptions options) {
|
||||
return update(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
return doUpdate(tableName, entity, options, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -805,16 +604,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return updateAsynchronously(entities, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> updateAsynchronously(List<T> entities, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entities.get(0).getClass());
|
||||
Assert.notNull(tableName);
|
||||
return updateAsynchronously(entities, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.util.List, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -830,20 +619,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> updateAsynchronously(List<T> entities, String tableName) {
|
||||
|
||||
return updateAsynchronously(entities, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.util.List, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> updateAsynchronously(List<T> entities, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doBatchUpdate(tableName, entities, optionsByName, true);
|
||||
return updateAsynchronously(entities, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -851,7 +627,10 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> updateAsynchronously(List<T> entities, String tableName, QueryOptions options) {
|
||||
return updateAsynchronously(entities, tableName, options.toMap());
|
||||
Assert.notNull(entities);
|
||||
Assert.notEmpty(entities);
|
||||
Assert.notNull(tableName);
|
||||
return doBatchUpdate(tableName, entities, options, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -864,16 +643,6 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
return updateAsynchronously(entity, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.lang.Object, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T updateAsynchronously(T entity, Map<String, Object> optionsByName) {
|
||||
String tableName = getTableName(entity.getClass());
|
||||
Assert.notNull(tableName);
|
||||
return updateAsynchronously(entity, tableName, optionsByName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.lang.Object, org.springframework.data.cassandra.core.QueryOptions)
|
||||
*/
|
||||
@@ -890,18 +659,7 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
@Override
|
||||
public <T> T updateAsynchronously(T entity, String tableName) {
|
||||
|
||||
return updateAsynchronously(entity, tableName, Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations#updateAsynchronously(java.lang.Object, java.lang.String, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public <T> T updateAsynchronously(T entity, String tableName, Map<String, Object> optionsByName) {
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
Assert.notNull(optionsByName);
|
||||
return doUpdate(tableName, entity, optionsByName, true);
|
||||
return updateAsynchronously(entity, tableName, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -909,7 +667,9 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
*/
|
||||
@Override
|
||||
public <T> T updateAsynchronously(T entity, String tableName, QueryOptions options) {
|
||||
return updateAsynchronously(entity, tableName, options.toMap());
|
||||
Assert.notNull(entity);
|
||||
Assert.notNull(tableName);
|
||||
return doUpdate(tableName, entity, options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1026,14 +786,14 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param tableName
|
||||
* @param objectToRemove
|
||||
*/
|
||||
protected <T> void doBatchDelete(final String tableName, final List<T> entities, Map<String, Object> optionsByName,
|
||||
protected <T> void doBatchDelete(final String tableName, final List<T> entities, final QueryOptions options,
|
||||
final boolean deleteAsynchronously) {
|
||||
|
||||
Assert.notEmpty(entities);
|
||||
|
||||
try {
|
||||
|
||||
final Batch b = CqlUtils.toDeleteBatchQuery(keyspace, tableName, entities, optionsByName, cassandraConverter);
|
||||
final Batch b = CqlUtils.toDeleteBatchQuery(keyspace, tableName, entities, options, cassandraConverter);
|
||||
logger.info(b.toString());
|
||||
|
||||
doExecute(new SessionCallback<Object>() {
|
||||
@@ -1067,14 +827,14 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param insertAsychronously
|
||||
* @return
|
||||
*/
|
||||
protected <T> List<T> doBatchInsert(final String tableName, final List<T> entities,
|
||||
Map<String, Object> optionsByName, final boolean insertAsychronously) {
|
||||
protected <T> List<T> doBatchInsert(final String tableName, final List<T> entities, final QueryOptions options,
|
||||
final boolean insertAsychronously) {
|
||||
|
||||
Assert.notEmpty(entities);
|
||||
|
||||
try {
|
||||
|
||||
final Batch b = CqlUtils.toInsertBatchQuery(keyspace, tableName, entities, optionsByName, cassandraConverter);
|
||||
final Batch b = CqlUtils.toInsertBatchQuery(keyspace, tableName, entities, options, cassandraConverter);
|
||||
logger.info(b.getQueryString());
|
||||
|
||||
return doExecute(new SessionCallback<List<T>>() {
|
||||
@@ -1108,14 +868,14 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param updateAsychronously
|
||||
* @return
|
||||
*/
|
||||
protected <T> List<T> doBatchUpdate(final String tableName, final List<T> entities,
|
||||
Map<String, Object> optionsByName, final boolean updateAsychronously) {
|
||||
protected <T> List<T> doBatchUpdate(final String tableName, final List<T> entities, final QueryOptions options,
|
||||
final boolean updateAsychronously) {
|
||||
|
||||
Assert.notEmpty(entities);
|
||||
|
||||
try {
|
||||
|
||||
final Batch b = CqlUtils.toUpdateBatchQuery(keyspace, tableName, entities, optionsByName, cassandraConverter);
|
||||
final Batch b = CqlUtils.toUpdateBatchQuery(keyspace, tableName, entities, options, cassandraConverter);
|
||||
logger.info(b.toString());
|
||||
|
||||
return doExecute(new SessionCallback<List<T>>() {
|
||||
@@ -1146,12 +906,12 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param tableName
|
||||
* @param objectToRemove
|
||||
*/
|
||||
protected <T> void doDelete(final String tableName, final T objectToRemove, Map<String, Object> optionsByName,
|
||||
protected <T> void doDelete(final String tableName, final T objectToRemove, final QueryOptions options,
|
||||
final boolean deleteAsynchronously) {
|
||||
|
||||
try {
|
||||
|
||||
final Query q = CqlUtils.toDeleteQuery(keyspace, tableName, objectToRemove, optionsByName, cassandraConverter);
|
||||
final Query q = CqlUtils.toDeleteQuery(keyspace, tableName, objectToRemove, options, cassandraConverter);
|
||||
logger.info(q.toString());
|
||||
|
||||
doExecute(new SessionCallback<Object>() {
|
||||
@@ -1201,12 +961,12 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param tableName
|
||||
* @param entity
|
||||
*/
|
||||
protected <T> T doInsert(final String tableName, final T entity, final Map<String, Object> optionsByName,
|
||||
protected <T> T doInsert(final String tableName, final T entity, final QueryOptions options,
|
||||
final boolean insertAsychronously) {
|
||||
|
||||
try {
|
||||
|
||||
final Query q = CqlUtils.toInsertQuery(keyspace, tableName, entity, optionsByName, cassandraConverter);
|
||||
final Query q = CqlUtils.toInsertQuery(keyspace, tableName, entity, options, cassandraConverter);
|
||||
|
||||
logger.info(q.toString());
|
||||
if (q.getConsistencyLevel() != null) {
|
||||
@@ -1248,12 +1008,12 @@ public class CassandraDataTemplate extends CassandraTemplate implements Cassandr
|
||||
* @param updateAsychronously
|
||||
* @return
|
||||
*/
|
||||
protected <T> T doUpdate(final String tableName, final T entity, final Map<String, Object> optionsByName,
|
||||
protected <T> T doUpdate(final String tableName, final T entity, final QueryOptions options,
|
||||
final boolean updateAsychronously) {
|
||||
|
||||
try {
|
||||
|
||||
final Query q = CqlUtils.toUpdateQuery(keyspace, tableName, entity, optionsByName, cassandraConverter);
|
||||
final Query q = CqlUtils.toUpdateQuery(keyspace, tableName, entity, options, cassandraConverter);
|
||||
logger.info(q.toString());
|
||||
|
||||
return doExecute(new SessionCallback<T>() {
|
||||
|
||||
@@ -2,15 +2,11 @@ package org.springframework.data.cassandra.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.ConsistencyLevel;
|
||||
import org.springframework.cassandra.core.ConsistencyLevelResolver;
|
||||
import org.springframework.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.core.RetryPolicyResolver;
|
||||
import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
@@ -155,7 +151,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static Query toInsertQuery(String keyspaceName, String tableName, final Object objectToSave,
|
||||
Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
QueryOptions options, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
|
||||
final Insert q = QueryBuilder.insertInto(keyspaceName, tableName);
|
||||
|
||||
@@ -167,13 +163,13 @@ public abstract class CqlUtils {
|
||||
/*
|
||||
* Add Query Options
|
||||
*/
|
||||
addQueryOptions(q, optionsByName);
|
||||
CassandraTemplate.addQueryOptions(q, options);
|
||||
|
||||
/*
|
||||
* Add TTL to Insert object
|
||||
*/
|
||||
if (optionsByName.get(QueryOptions.QueryOptionMapKeys.TTL) != null) {
|
||||
q.using(QueryBuilder.ttl((Integer) optionsByName.get(QueryOptions.QueryOptionMapKeys.TTL)));
|
||||
if (options != null && options.getTtl() != null) {
|
||||
q.using(QueryBuilder.ttl(options.getTtl()));
|
||||
}
|
||||
|
||||
return q;
|
||||
@@ -193,7 +189,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static Query toUpdateQuery(String keyspaceName, String tableName, final Object objectToSave,
|
||||
Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
QueryOptions options, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
|
||||
final Update q = QueryBuilder.update(keyspaceName, tableName);
|
||||
|
||||
@@ -205,13 +201,13 @@ public abstract class CqlUtils {
|
||||
/*
|
||||
* Add Query Options
|
||||
*/
|
||||
addQueryOptions(q, optionsByName);
|
||||
CassandraTemplate.addQueryOptions(q, options);
|
||||
|
||||
/*
|
||||
* Add TTL to Insert object
|
||||
*/
|
||||
if (optionsByName.get(QueryOptions.QueryOptionMapKeys.TTL) != null) {
|
||||
q.using(QueryBuilder.ttl((Integer) optionsByName.get(QueryOptions.QueryOptionMapKeys.TTL)));
|
||||
if (options != null && options.getTtl() != null) {
|
||||
q.using(QueryBuilder.ttl(options.getTtl()));
|
||||
}
|
||||
|
||||
return q;
|
||||
@@ -231,7 +227,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static <T> Batch toUpdateBatchQuery(final String keyspaceName, final String tableName,
|
||||
final List<T> objectsToSave, Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter)
|
||||
final List<T> objectsToSave, QueryOptions options, EntityWriter<Object, Object> entityWriter)
|
||||
throws EntityWriterException {
|
||||
|
||||
/*
|
||||
@@ -241,11 +237,14 @@ public abstract class CqlUtils {
|
||||
|
||||
for (final T objectToSave : objectsToSave) {
|
||||
|
||||
b.add((Statement) toUpdateQuery(keyspaceName, tableName, objectToSave, optionsByName, entityWriter));
|
||||
b.add((Statement) toUpdateQuery(keyspaceName, tableName, objectToSave, options, entityWriter));
|
||||
|
||||
}
|
||||
|
||||
addQueryOptions(b, optionsByName);
|
||||
/*
|
||||
* Add Query Options
|
||||
*/
|
||||
CassandraTemplate.addQueryOptions(b, options);
|
||||
|
||||
return b;
|
||||
|
||||
@@ -264,7 +263,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static <T> Batch toInsertBatchQuery(final String keyspaceName, final String tableName,
|
||||
final List<T> objectsToSave, Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter)
|
||||
final List<T> objectsToSave, QueryOptions options, EntityWriter<Object, Object> entityWriter)
|
||||
throws EntityWriterException {
|
||||
|
||||
/*
|
||||
@@ -274,11 +273,14 @@ public abstract class CqlUtils {
|
||||
|
||||
for (final T objectToSave : objectsToSave) {
|
||||
|
||||
b.add((Statement) toInsertQuery(keyspaceName, tableName, objectToSave, optionsByName, entityWriter));
|
||||
b.add((Statement) toInsertQuery(keyspaceName, tableName, objectToSave, options, entityWriter));
|
||||
|
||||
}
|
||||
|
||||
addQueryOptions(b, optionsByName);
|
||||
/*
|
||||
* Add Query Options
|
||||
*/
|
||||
CassandraTemplate.addQueryOptions(b, options);
|
||||
|
||||
return b;
|
||||
|
||||
@@ -296,7 +298,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static Query toDeleteQuery(String keyspace, String tableName, final Object objectToRemove,
|
||||
Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
QueryOptions options, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
|
||||
final Delete.Selection ds = QueryBuilder.delete();
|
||||
final Delete q = ds.from(keyspace, tableName);
|
||||
@@ -307,7 +309,7 @@ public abstract class CqlUtils {
|
||||
*/
|
||||
entityWriter.write(objectToRemove, w);
|
||||
|
||||
addQueryOptions(q, optionsByName);
|
||||
CassandraTemplate.addQueryOptions(q, options);
|
||||
|
||||
return q;
|
||||
|
||||
@@ -363,7 +365,7 @@ public abstract class CqlUtils {
|
||||
* @throws EntityWriterException
|
||||
*/
|
||||
public static <T> Batch toDeleteBatchQuery(String keyspaceName, String tableName, List<T> entities,
|
||||
Map<String, Object> optionsByName, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
QueryOptions options, EntityWriter<Object, Object> entityWriter) throws EntityWriterException {
|
||||
|
||||
/*
|
||||
* Return variable is a Batch statement
|
||||
@@ -372,40 +374,14 @@ public abstract class CqlUtils {
|
||||
|
||||
for (final T objectToSave : entities) {
|
||||
|
||||
b.add((Statement) toDeleteQuery(keyspaceName, tableName, objectToSave, optionsByName, entityWriter));
|
||||
b.add((Statement) toDeleteQuery(keyspaceName, tableName, objectToSave, options, entityWriter));
|
||||
|
||||
}
|
||||
|
||||
addQueryOptions(b, optionsByName);
|
||||
CassandraTemplate.addQueryOptions(b, options);
|
||||
|
||||
return b;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add common Query options for all types of queries.
|
||||
*
|
||||
* @param q
|
||||
* @param optionsByName
|
||||
*/
|
||||
private static void addQueryOptions(Query q, Map<String, Object> optionsByName) {
|
||||
|
||||
if (optionsByName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add Query Options
|
||||
*/
|
||||
if (optionsByName.get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL) != null) {
|
||||
q.setConsistencyLevel(ConsistencyLevelResolver.resolve((ConsistencyLevel) optionsByName
|
||||
.get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL)));
|
||||
}
|
||||
if (optionsByName.get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY) != null) {
|
||||
q.setRetryPolicy(RetryPolicyResolver.resolve((RetryPolicy) optionsByName
|
||||
.get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.CassandraCQLUnit;
|
||||
@@ -33,6 +31,7 @@ import org.cassandraunit.dataset.yaml.ClassPathYamlDataSet;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -128,22 +127,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.insert(b3, "book", options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b4 = new Book();
|
||||
b4.setIsbn("123456-4");
|
||||
b4.setTitle("Spring Data Cassandra Guide");
|
||||
b4.setAuthor("Cassandra Guru");
|
||||
b4.setPages(465);
|
||||
|
||||
Map<String, Object> optionsByName = new HashMap<String, Object>();
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL, ConsistencyLevel.ALL);
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.RETRY_POLICY, RetryPolicy.FALLTHROUGH);
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.TTL, 30);
|
||||
|
||||
cassandraDataTemplate.insert(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -155,17 +138,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.insert(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
b6.setTitle("Spring Data Cassandra Guide");
|
||||
b6.setAuthor("Cassandra Guru");
|
||||
b6.setPages(465);
|
||||
|
||||
cassandraDataTemplate.insert(b6, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,13 +186,6 @@ public class CassandraDataOperationsTest {
|
||||
b4.setAuthor("Cassandra Guru");
|
||||
b4.setPages(465);
|
||||
|
||||
Map<String, Object> optionsByName = new HashMap<String, Object>();
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL, ConsistencyLevel.ALL);
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.RETRY_POLICY, RetryPolicy.FALLTHROUGH);
|
||||
optionsByName.put(QueryOptions.QueryOptionMapKeys.TTL, 30);
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -232,17 +197,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
b6.setTitle("Spring Data Cassandra Guide");
|
||||
b6.setAuthor("Cassandra Guru");
|
||||
b6.setPages(465);
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(b6, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,16 +227,8 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -313,16 +259,8 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insertAsynchronously(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,17 +327,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.update(b3, "book", options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b4 = new Book();
|
||||
b4.setIsbn("123456-4");
|
||||
b4.setTitle("Spring Data Cassandra Book");
|
||||
b4.setAuthor("Cassandra Guru");
|
||||
b4.setPages(465);
|
||||
|
||||
cassandraDataTemplate.update(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -411,17 +338,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.update(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
b6.setTitle("Spring Data Cassandra Book");
|
||||
b6.setAuthor("Cassandra Guru");
|
||||
b6.setPages(465);
|
||||
|
||||
cassandraDataTemplate.update(b6, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -468,17 +384,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(b3, "book", options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b4 = new Book();
|
||||
b4.setIsbn("123456-4");
|
||||
b4.setTitle("Spring Data Cassandra Book");
|
||||
b4.setAuthor("Cassandra Guru");
|
||||
b4.setPages(465);
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -490,17 +395,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
b6.setTitle("Spring Data Cassandra Book");
|
||||
b6.setAuthor("Cassandra Guru");
|
||||
b6.setPages(465);
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(b6, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -543,28 +437,12 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, "book", optionsByName);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.update(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.update(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, optionsByName);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.update(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -607,28 +485,12 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, "book", optionsByName);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, optionsByName);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraDataTemplate.updateAsynchronously(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,14 +539,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.delete(b3, "book", options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b4 = new Book();
|
||||
b4.setIsbn("123456-4");
|
||||
|
||||
cassandraDataTemplate.delete(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -693,14 +547,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.delete(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
|
||||
cassandraDataTemplate.delete(b6, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -737,14 +583,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(b3, "book", options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b4 = new Book();
|
||||
b4.setIsbn("123456-4");
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(b4, "book", optionsByName);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
@@ -753,13 +591,6 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(b5, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b6 = new Book();
|
||||
b6.setIsbn("123456-6");
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(b6, optionsByName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -796,22 +627,10 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, "book", optionsByName);
|
||||
|
||||
cassandraDataTemplate.delete(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, options);
|
||||
|
||||
cassandraDataTemplate.delete(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, optionsByName);
|
||||
|
||||
cassandraDataTemplate.delete(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -848,22 +667,10 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, "book", optionsByName);
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(books, "book", optionsByName);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, options);
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraDataTemplate.insert(books, optionsByName);
|
||||
|
||||
cassandraDataTemplate.deleteAsynchronously(books, optionsByName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user