当前位置: 首页>>代码示例>>Java>>正文


Java SimpleStatement类代码示例

本文整理汇总了Java中com.datastax.driver.core.SimpleStatement的典型用法代码示例。如果您正苦于以下问题:Java SimpleStatement类的具体用法?Java SimpleStatement怎么用?Java SimpleStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleStatement类属于com.datastax.driver.core包,在下文中一共展示了SimpleStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryForLastWriteTimes

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
@Override
public DBResult queryForLastWriteTimes()
{
	if (cluster == null)
		return null;

	try (Session session = cluster.newSession())
	{
		Statement statement = new SimpleStatement(String.format("SELECT WRITETIME (%s) FROM %s.%s;", columnName, keyspace, tableName));
		statement.setConsistencyLevel(ConsistencyLevel.ALL);
		ResultSet results = session.execute(statement);
		List<Row> allRows = results.all();

		// sort all of the rows accordingly
		allRows.sort(new RowComparator());

		// gather the information we need
		long startTime = allRows.get(0).getLong(0) / 1000;
		long endTime = allRows.get(allRows.size() - 1).getLong(0) / 1000;
		int totalCount = allRows.size();
		return new DBResult(startTime, endTime, totalCount);
	}
}
 
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:24,代码来源:CassandraClient.java

示例2: primeAndExecuteQueries

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
private void primeAndExecuteQueries(String[] primed, String[] queries) throws Exception {
  SuccessResult result = getSampleSuccessResult();
  for (String primeQuery : primed) {
    server.prime(when(primeQuery).then(result));
  }

  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder(server.getCluster())
          .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
          .build()) {
    Session session = driverCluster.connect();
    server.getCluster().clearLogs();
    for (String executeQuery : queries) {
      SimpleStatement stmt = new SimpleStatement(executeQuery);
      stmt.setDefaultTimestamp(100);
      session.execute(stmt);
    }
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:20,代码来源:ActivityLogIntegrationTest.java

示例3: executePut

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
public void executePut(String query, String consistency){
	logger.debug("in data store handle, executing put:"+query);
	long start = System.currentTimeMillis();
	Statement statement = new SimpleStatement(query);
	if(consistency.equalsIgnoreCase("critical")){
		logger.info("Executing critical put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
	}
	else if (consistency.equalsIgnoreCase("eventual")){
		logger.info("Executing normal put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.ONE);
	}
	session.execute(statement); 
	long end = System.currentTimeMillis();
	logger.debug("Time taken for actual put in cassandra:"+(end-start));
}
 
开发者ID:att,项目名称:music,代码行数:17,代码来源:MusicDataStore.java

示例4: getHostStatementMatcher

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
private ArgumentMatcher<Statement> getHostStatementMatcher(final Host host, final String query)
        throws Exception {
    return new ArgumentMatcher<Statement>() {
        @Override
        public boolean matches(Object argument) {
            SelectedHostStatement statement = (SelectedHostStatement) argument;

            return ((SimpleStatement)statement.getStatement()).getQueryString().equals(query) &&
                    Objects.equals(statement.getHostCordinator().getAddress(), host.getAddress());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(format("query:%s host:%s", query, host.getAddress().toString()));
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:ClusterHintsPollerTest.java

示例5: should_generate_simple_statement

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
@Test
public void should_generate_simple_statement() throws Exception {
    //Given
    String input = "SELECT * FROM users LIMIT 10;";
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty());

    //When
    final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options, intrContext);

    //Then
    assertThat(actual).isNotNull();
    assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;");
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:19,代码来源:InterpreterLogicTest.java

示例6: should_generate_batch_statement

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
@Test
public void should_generate_batch_statement() throws Exception {
    //Given
    Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
    Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
    Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty());

    //When
    BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));

    //Then
    assertThat(actual).isNotNull();
    final List<Statement> statements = new ArrayList<>(actual.getStatements());
    assertThat(statements).hasSize(3);
    assertThat(statements.get(0)).isSameAs(st1);
    assertThat(statements.get(1)).isSameAs(st2);
    assertThat(statements.get(2)).isSameAs(st3);
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:25,代码来源:InterpreterLogicTest.java

示例7: buildSchema

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
/**
 * Build schema programmatically
 * <p>
 * DDL equivalent:
 * 
 * <pre>
 * CREATE TABLE messages (
 *   sessionId uuid,
 *   seqNo bigint,
 *   message blob,
 *   PRIMARY KEY  (sessionId, seqNo ) );
 * </pre>
 * 
 * @throws StoreException if the store is not open
 *
 */
public void buildSchema() throws StoreException {
  if (session != null) {
    // Appropriate for a local test only
    session.execute(new SimpleStatement("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE_NAME
        + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"));
    System.out.format("Keyspace %s available\n", KEYSPACE_NAME);

    Create create = SchemaBuilder.createTable(KEYSPACE_NAME, TABLE_NAME).ifNotExists()
        .addPartitionKey(SESSION_ID_COLNAME, DataType.uuid())
        .addClusteringColumn(SEQ_NO_COLNAME, DataType.bigint())
        .addColumn(MESSAGE_COLNAME, DataType.blob());

    ResultSet resultSet = session.execute(create);
    System.out.format("Table %s available\n", TABLE_NAME);
  } else {
    throw new StoreException("Schema not created; store not open");
  }
}
 
开发者ID:FIXTradingCommunity,项目名称:silverflash,代码行数:35,代码来源:CassandraMessageStore.java

示例8: should_generate_simple_statement

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
@Test
public void should_generate_simple_statement() throws Exception {
    //Given
    String input = "SELECT * FROM users LIMIT 10;";
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty(),
            Option.empty());

    //When
    final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options, intrContext);

    //Then
    assertThat(actual).isNotNull();
    assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;");
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:20,代码来源:InterpreterLogicTest.java

示例9: should_generate_batch_statement

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
@Test
public void should_generate_batch_statement() throws Exception {
    //Given
    Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
    Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
    Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty(),
            Option.empty());

    //When
    BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));

    //Then
    assertThat(actual).isNotNull();
    final List<Statement> statements = new ArrayList<>(actual.getStatements());
    assertThat(statements).hasSize(3);
    assertThat(statements.get(0)).isSameAs(st1);
    assertThat(statements.get(1)).isSameAs(st2);
    assertThat(statements.get(2)).isSameAs(st3);
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:26,代码来源:InterpreterLogicTest.java

示例10: load

import com.datastax.driver.core.SimpleStatement; //导入依赖的package包/类
static void load(SessionContext sessionContext, List<String> cqlStatements) {
    if (!cqlStatements.isEmpty()) {
        sessionContext.checkClusterHealth();
    }
    try {
        cqlStatements.stream()
                .map(stringStatement -> new SimpleStatement(stringStatement).setConsistencyLevel(sessionContext.getWriteConsistencyLevel()))
                .forEach(statement -> {
                    LOGGER.debug("Executing cql statement {}", statement);
                    sessionContext.getSession().execute(statement);
                });
    } catch (DriverException e) {
        LOGGER.error("Failed to execute cql statements {}: {}", cqlStatements, e.getMessage());
        throw e;
    }
}
 
开发者ID:sky-uk,项目名称:cqlmigrate,代码行数:17,代码来源:CqlLoader.java

示例11: 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;
  }
 
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:23,代码来源:CassandraStatement.java

示例12: 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;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:20,代码来源:CassandraHandler.java

示例13: 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;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:CassandraHandler.java

示例14: 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;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:26,代码来源:CassandraHandler.java

示例15: 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;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:CassandraHandler.java


注:本文中的com.datastax.driver.core.SimpleStatement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。