Cassandra 用于执行cql3脚本的Gradle插件

Cassandra 用于执行cql3脚本的Gradle插件,cassandra,gradle,cql3,Cassandra,Gradle,Cql3,我需要通过Gradle执行CQL3脚本,我们有什么要求吗 Gradle的cassandra插件也可以这么做,还是有其他方法可以 在构建过程中执行CQL3脚本。请建议 Dawood您可以将Cassandra客户端(如Astyanax)添加到buildscript类路径中,然后直接在Gradle脚本中使用它。e、 g buildscript { repositories { mavenCentral() } dependencies { com

我需要通过Gradle执行CQL3脚本,我们有什么要求吗 Gradle的cassandra插件也可以这么做,还是有其他方法可以 在构建过程中执行CQL3脚本。请建议


Dawood

您可以将Cassandra客户端(如Astyanax)添加到buildscript类路径中,然后直接在Gradle脚本中使用它。e、 g

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        compile 'com.netflix.astyanax:astyanax-cassandra:1.56.42'
    }
}

task(doCql) << {
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
        .forCluster("ClusterName")
        .forKeyspace("KeyspaceName")
        .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
            .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
            .setCqlVersion("3.0.0")
            .setTargetCassandraVersion("1.2")
        )
        .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
            .setPort(9160)
            .setMaxConnsPerHost(1)
            .setSeeds("127.0.0.1:9160")
        )
       .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
       .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    Keyspace keyspace = context.getClient();
    result = keyspace
        .prepareQuery(CQL3_CF)
        .withCql("SELECT * FROM employees WHERE empId='111';")
        .execute();

    for (Row<Integer, String> row : result.getResult().getRows()) {
        LOG.info("CQL Key: " + row.getKey());

        ColumnList<String> columns = row.getColumns();

        LOG.info("   first_name : " + columns.getStringValue ("first_name", null));
        LOG.info("   last_name  : " + columns.getStringValue ("last_name",  null));
    }
}