首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于执行cql3脚本的Gradle插件

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

Stack Overflow用户
提问于 2013-09-03 20:27:11
回答 1查看 532关注 0票数 0

我有一个通过Gradle执行CQL3脚本的需求,我们有没有任何用于Gradle的cassandra插件来做同样的事情,或者有没有其他方法可以在构建过程中执行CQL3脚本。请提个建议。

达伍德

EN

回答 1

Stack Overflow用户

发布于 2013-09-04 12:51:55

您可以将Astyanax之类的Cassandra客户端添加到buildscript类路径中,然后直接在Gradle脚本中使用它。例如:

代码语言:javascript
复制
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));
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18592332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档