本文整理汇总了Java中com.netflix.astyanax.Keyspace.createKeyspace方法的典型用法代码示例。如果您正苦于以下问题:Java Keyspace.createKeyspace方法的具体用法?Java Keyspace.createKeyspace怎么用?Java Keyspace.createKeyspace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.astyanax.Keyspace
的用法示例。
在下文中一共展示了Keyspace.createKeyspace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupCassandraKeySpace
import com.netflix.astyanax.Keyspace; //导入方法依赖的package包/类
public static void setupCassandraKeySpace(String cassandraConnectionString, String keySpaceName,
String columnFamily) throws ConnectionException {
try {
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(keySpaceName)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setMaxConnsPerHost(1)
.setSeeds(cassandraConnectionString)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
Keyspace keyspace = context.getClient();
// Using simple strategy
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
.put("strategy_options", ImmutableMap.<String, Object>builder()
.put("replication_factor", "1")
.build())
.put("strategy_class", "SimpleStrategy")
.build()
);
ColumnFamily<String, String> CF_STANDARD1 = ColumnFamily.newColumnFamily(columnFamily,
StringSerializer.get(), StringSerializer.get());
keyspace.createColumnFamily(CF_STANDARD1, null);
context.shutdown();
} catch(BadRequestException e) {
LOG.warn("could not setup cassandra keyspace , assuming keyspace already exists.", e);
}
}
示例2: initKeyspace
import com.netflix.astyanax.Keyspace; //导入方法依赖的package包/类
@Override
public void initKeyspace(Keyspace keyspace) throws ConnectionException {
try {
keyspace.describeKeyspace();
} catch (ConnectionException e) {
Map<String, Object> options = ImmutableMap.<String, Object>builder()
.put("name", keyspace.getKeyspaceName())
.put("strategy_class", "SimpleStrategy")
.put("strategy_options", ImmutableMap.of("replication_factor", "1"))
.build();
keyspace.createKeyspace(options);
}
}
示例3: createModel
import com.netflix.astyanax.Keyspace; //导入方法依赖的package包/类
public static void createModel() throws ConnectionException {
final Keyspace keyspace = CassandraUtils.getConnection();
// CREATE COLUMN FAMILY storage WITH comparator = UTF8Type AND key_validation_class=UTF8Type
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
.put("strategy_options", ImmutableMap.<String, Object>builder()
.put("replication_factor", "1")
.build())
.put("strategy_class", "SimpleStrategy")
.build()
);
keyspace
.prepareQuery(CassandraUtils.CQL3_CF)
.withCql("CREATE TABLE directory(pathId uuid, child varchar, childId uuid, PRIMARY KEY (pathId, child)) WITH COMPACT STORAGE;")
.asPreparedStatement()
.execute();
keyspace
.prepareQuery(CassandraUtils.CQL3_CF)
.withCql("CREATE TABLE file(file uuid PRIMARY KEY, size bigint, storageType varchar, storageData varchar);")
.asPreparedStatement()
.execute();
keyspace
.prepareQuery(CassandraUtils.CQL3_CF)
.withCql("insert into directory(pathid, child, childid) VALUES (?, '.', ?);")
.asPreparedStatement()
.withUUIDValue(CassandraUtils.ROOT_UUID)
.withUUIDValue(CassandraUtils.ROOT_UUID)
.execute();
final ColumnFamily<String, String> cf = ColumnFamily.newColumnFamily("storage", StringSerializer.get(), StringSerializer.get());
keyspace.createColumnFamily(cf, ImmutableMap.<String, Object>builder()
.put("key_validation_class", "UTF8Type")
.put("comparator", "UTF8Type")
.build());
}
示例4: createKeyspace
import com.netflix.astyanax.Keyspace; //导入方法依赖的package包/类
public static void createKeyspace(String keyspacename) throws ConnectionException {
AstyanaxContext<Keyspace> ctx = builder.forKeyspace(keyspacename).buildKeyspace(ThriftFamilyFactory.getInstance());
ctx.start();
Keyspace keyspace = ctx.getClient();
keyspace.createKeyspace(ImmutableMap.<String, Object> builder()
.put("strategy_options",
ImmutableMap.<String, Object> builder().put("replication_factor", String.valueOf(Configuration.global.getValue("cassandra", "default_replication_factor", 1))).build())
.put("strategy_class", "SimpleStrategy").build());
cluster.getKeyspace(keyspacename).describeKeyspace();
Loggers.Cassandra.info("Create Keyspace " + keyspacename);
}