本文整理汇总了Java中com.datastax.driver.core.SimpleStatement.setConsistencyLevel方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleStatement.setConsistencyLevel方法的具体用法?Java SimpleStatement.setConsistencyLevel怎么用?Java SimpleStatement.setConsistencyLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.SimpleStatement
的用法示例。
在下文中一共展示了SimpleStatement.setConsistencyLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeBatch
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public int[] executeBatch() throws SQLException
{
int[] returnCounts= new int[batchQueries.size()];
List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>();
if (logger.isTraceEnabled() || this.connection.debugMode) logger.debug("CQL statements: "+ batchQueries.size());
for(String q:batchQueries){
if (logger.isTraceEnabled() || this.connection.debugMode) logger.debug("CQL: "+ q);
SimpleStatement stmt = new SimpleStatement(q);
stmt.setConsistencyLevel(this.connection.defaultConsistencyLevel);
ResultSetFuture resultSetFuture = this.connection.getSession().executeAsync(stmt);
futures.add(resultSetFuture);
}
int i=0;
for (ResultSetFuture future : futures){
future.getUninterruptibly();
returnCounts[i]=1;
i++;
}
return returnCounts;
}
示例2: getRows
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public ResultSet getRows(String keyspace, String table, int limit,
String startKey, ConsistencyLevel level) {
StringBuilder command = new StringBuilder();
command.append("SELECT * from ").append(keyspace).append(".")
.append(table);
if (startKey != null) {
command.append(" WHERE token(key)>token('").append(startKey)
.append("')");
}
if (limit > 0) {
command.append(" LIMIT ").append(Integer.toString(limit));
}
command.append(";");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
ResultSet result = executeQuery(ss);
return result;
}
示例3: getColumnFromRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public ResultSet getColumnFromRow(String keyspace, String tableName,
String key, String column, ConsistencyLevel level) {
StringBuilder command = new StringBuilder();
// Build SELECT query
command.append("SELECT ").append(column).append(" FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ").append(KEY)
.append(" = '").append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
ResultSet result = executeQuery(ss);
return result;
}
示例4: getColumnsFromRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public ResultSet getColumnsFromRow(String keyspace, String tableName,
String key, ArrayList<String> columns, ConsistencyLevel level) {
StringBuilder command = new StringBuilder();
StringBuilder cols = new StringBuilder();
// Build column list
cols.append(columns.get(0));
for (int i = 1; i < columns.size(); i++) {
cols.append(",").append(columns.get(i));
}
// Build SELECT query
command.append("SELECT ").append(cols.toString()).append(" FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ").append(KEY)
.append(" = '").append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
ResultSet result = executeQuery(ss);
return result;
}
示例5: getRowByVersion
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public ResultSet getRowByVersion(String keyspace, String tableName,
int version, ConsistencyLevel level) {
Long start = System.nanoTime();
StringBuilder command = new StringBuilder();
command.append("SELECT * FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ")
.append(VERSION).append(" = ").append(version).append(";");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
ResultSet result = executeQuery(ss);
IOStats.getRowByVersion(((double) System.nanoTime() - (double) start) / 1000000);
return result;
}
示例6: markDeleted
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public void markDeleted(String keyspace, String tableName, String key,
int version, ConsistencyLevel level) {
Long start = System.nanoTime();
StringBuilder command = new StringBuilder();
command.append("UPDATE ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" USING TIMESTAMP ")
.append(++this.counter).append(" SET ").append(DELETED)
.append(" = true,").append(VERSION).append(" = ")
.append(version).append(" WHERE ").append(KEY).append(" = '")
.append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
executeQuery(ss);
IOStats.markDelRow(((double) System.nanoTime() - (double) start) / 1000000);
}
示例7: deleteColumnsFromRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public void deleteColumnsFromRow(String keyspace, String tableName,
String key, List<String> columns, ConsistencyLevel level) {
StringBuilder command = new StringBuilder();
command.append("DELETE ");
String col = columns.get(0);
command.append(col);
for (int i = 1; i < columns.size(); i++) {
col = columns.get(i);
command.append(",").append(col);
}
command.append(" FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ").append(KEY)
.append(" = '").append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
executeQuery(ss);
}
示例8: deleteRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public void deleteRow(String keyspace, String tableName, String key,
ConsistencyLevel level) {
Long start = System.nanoTime();
StringBuilder command = new StringBuilder();
command.append("DELETE FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ").append(KEY)
.append(" = '").append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
executeQuery(ss);
IOStats.delRow(((double) System.nanoTime() - (double) start) / 1000000);
}
示例9: execute
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public ResultSet execute() {
if (session == null)
init();
// Select selectQuery = QueryBuilder.select().all().from(HiveCassandraUtils.getKeyspace(conf), HiveCassandraUtils.getColumnFamily(this.conf));
StringBuilder sb = new StringBuilder();
sb.append("SELECT * FROM ");
sb.append(HiveCassandraUtils.getKeyspace(conf));
sb.append(".");
sb.append(HiveCassandraUtils.getColumnFamily(conf));
String whereClause = HiveCassandraUtils.getWhereClause(conf);
if (!Strings.isNullOrEmpty(whereClause)) {
sb.append(" WHERE ");
sb.append(getWhereClause(conf));
}
SimpleStatement selectQuery = new SimpleStatement(sb.toString());
selectQuery.setConsistencyLevel(ConsistencyLevel.valueOf(HiveCassandraUtils.getInputConsistencyLevel(conf)));
return session.execute(selectQuery);
}
示例10: get
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @param key
* @param fields
* @return
*/
@Override
public Persistent get(Object key, String[] fields) {
if (fields == null) {
fields = getFields();
}
String cqlQuery = CassandraQueryFactory.getSelectObjectWithFieldsQuery(mapping, fields);
SimpleStatement statement = new SimpleStatement(cqlQuery, key);
if (readConsistencyLevel != null) {
statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel));
}
ResultSet results = client.getSession().execute(statement);
Result<T> objects = mapper.map(results);
List<T> objectList = objects.all();
if (objectList != null) {
LOG.debug("Object is found for key : {}", key);
return objectList.get(0);
}
LOG.debug("Object is not found for key : {}", key);
return null;
}
示例11: get
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @param key
* @param fields
* @return
*/
@Override
public Persistent get(Object key, String[] fields) {
if (fields == null) {
fields = getFields();
}
ArrayList<String> cassandraKeys = new ArrayList<>();
ArrayList<Object> cassandraValues = new ArrayList<>();
AvroCassandraUtils.processKeys(mapping, key, cassandraKeys, cassandraValues);
String cqlQuery = CassandraQueryFactory.getSelectObjectWithFieldsQuery(mapping, fields, cassandraKeys);
SimpleStatement statement = new SimpleStatement(cqlQuery, cassandraValues.toArray());
if (readConsistencyLevel != null) {
statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel));
}
ResultSet resultSet = this.client.getSession().execute(statement);
Iterator<Row> iterator = resultSet.iterator();
ColumnDefinitions definitions = resultSet.getColumnDefinitions();
T obj = null;
if (iterator.hasNext()) {
obj = cassandraDataStore.newPersistent();
AbstractGettableData row = (AbstractGettableData) iterator.next();
populateValuesToPersistent(row, definitions, obj, fields);
}
return obj;
}
示例12: main
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public static void main(String[] args) {
Session session = Connection.connect();
SimpleStatement statement1 = new SimpleStatement("insert into user (id, name, age) values (?, ?, ?)",
UUIDs.timeBased(), "user01", 30);
statement1.setConsistencyLevel(ConsistencyLevel.ONE);
try {
ResultSet rs = session.execute(statement1);
System.out.println(rs);
} catch (Exception ex) {
ex.printStackTrace();
}
SimpleStatement statement2 = new SimpleStatement("select id, name, age from user");
ResultSet rs2 = session.execute(statement2);
System.out.println(rs2);
for (Row row : rs2) {
System.out.printf("id: %s, name: %s, age: %d\n", row.get(0, UUID.class),
row.getString(1), row.getInt(2));
}
Connection.close();
}
示例13: putRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public void putRow(String keyspace, String tableName, String rowKey,
Integer version, List<ColumnData> values, ConsistencyLevel level) {
Long start = System.nanoTime();
LOG.debug("PUT ROW START\n");
StringBuilder command = new StringBuilder();
StringBuilder vals = new StringBuilder();
command.append("INSERT INTO ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" (").append(KEY)
.append(",").append(VERSION).append(",").append(DELETED)
.append(",");
ColumnData pair = values.get(0);
command.append(pair.getColumn());
vals.append(pair.getValue());
for (int i = 1; i < values.size(); i++) {
pair = values.get(i);
command.append(",").append(pair.getColumn());
vals.append(",").append(pair.getValue());
}
command.append(") VALUES (").append("'" + rowKey + "',")
.append(version + ",").append("false,").append(vals.toString())
.append(") USING TIMESTAMP ").append(++this.counter)
.append(";");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
LOG.debug(ss.toString());
executeQuery(ss);
LOG.debug("PUT ROW END\n\n");
IOStats.putRow(((double) System.nanoTime() - (double) start) / 1000000);
}
示例14: deleteColumnFromRow
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
public void deleteColumnFromRow(String keyspace, String tableName,
String key, String column, ConsistencyLevel level) {
StringBuilder command = new StringBuilder();
command.append("DELETE ").append(column).append(" FROM ")
.append((keyspace == null) ? keyspaceName : keyspace)
.append(".").append(tableName).append(" WHERE ").append(KEY)
.append(" = '").append(key).append("';");
SimpleStatement ss = new SimpleStatement(command.toString());
ss.setConsistencyLevel(level);
executeQuery(ss);
}
示例15: delete
import com.datastax.driver.core.SimpleStatement; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @param key
* @return
*/
@Override
public boolean delete(Object key) {
ArrayList<String> cassandraKeys = new ArrayList<>();
ArrayList<Object> cassandraValues = new ArrayList<>();
AvroCassandraUtils.processKeys(mapping, key, cassandraKeys, cassandraValues);
String cqlQuery = CassandraQueryFactory.getDeleteDataQuery(mapping, cassandraKeys);
SimpleStatement statement = new SimpleStatement(cqlQuery, cassandraValues.toArray());
if (writeConsistencyLevel != null) {
statement.setConsistencyLevel(ConsistencyLevel.valueOf(writeConsistencyLevel));
}
ResultSet resultSet = client.getSession().execute(statement);
return resultSet.wasApplied();
}