本文整理汇总了Java中me.prettyprint.hector.api.ddl.KeyspaceDefinition类的典型用法代码示例。如果您正苦于以下问题:Java KeyspaceDefinition类的具体用法?Java KeyspaceDefinition怎么用?Java KeyspaceDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyspaceDefinition类属于me.prettyprint.hector.api.ddl包,在下文中一共展示了KeyspaceDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSchema
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private void createSchema(int replicationFactor)
{
List<ColumnFamilyDefinition> cfDef = new ArrayList<ColumnFamilyDefinition>();
cfDef.add(HFactory.createColumnFamilyDefinition(
m_keyspaceName, CF_DATA_POINTS, ComparatorType.BYTESTYPE));
cfDef.add(HFactory.createColumnFamilyDefinition(
m_keyspaceName, CF_ROW_KEY_INDEX, ComparatorType.BYTESTYPE));
cfDef.add(HFactory.createColumnFamilyDefinition(
m_keyspaceName, CF_STRING_INDEX, ComparatorType.UTF8TYPE));
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(
m_keyspaceName, ThriftKsDef.DEF_STRATEGY_CLASS,
replicationFactor, cfDef);
m_cluster.addKeyspace(newKeyspace, true);
}
示例2: createRequiredSchemaEntities
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
@Override
public void createRequiredSchemaEntities() throws DataAccessLayerException {
final String keyspaceName = _keyspace.getKeyspaceName();
KeyspaceDefinition ksdef = _factory.getCluster().describeKeyspace(keyspaceName);
if (!hasColumnFamily(ksdef, _cf_name)) {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspaceName, _cf_name);
cfDef.setKeyValidationClass(ComparatorType.UTF8TYPE.getClassName());
cfDef.setComparatorType(ComparatorType.UTF8TYPE);
cfDef.setCompactionStrategy("LeveledCompactionStrategy");
cfDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
cfDef.setColumnType(ColumnType.STANDARD);
_factory.getCluster().addColumnFamily(cfDef, true);
}
setDefaultValue(-1L);
}
示例3: createKeyspace
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
/** Creates the keyspace. */
private void createKeyspace(Cluster cluster) {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
KEYSPACE_NAME, COLUMN_FAMILY_NAME, ComparatorType.BYTESTYPE);
cfDef.setGcGraceSeconds(1);
cfDef.setCompactionStrategy("LeveledCompactionStrategy");
BasicColumnDefinition column = new BasicColumnDefinition();
column.setName(StringSerializer.get().toByteBuffer(COLUMN_NAME));
column.setValidationClass(ComparatorType.BYTESTYPE.getClassName());
cfDef.addColumnDefinition(column);
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(
KEYSPACE_NAME, ThriftKsDef.DEF_STRATEGY_CLASS, 1,
Arrays.asList(cfDef));
cluster.addKeyspace(newKeyspace, true);
}
示例4: createLinksTable
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private static void createLinksTable() {
// column family l
final String CF_LINKS = "l";
final String QF_URL = "u";
ColumnFamilyDefinition cfLinks = HFactory.createColumnFamilyDefinition(
LINKS, CF_LINKS, ComparatorType.UTF8TYPE);
cfLinks.setKeyValidationClass(ComparatorType.UTF8TYPE.getTypeName());
List<ColumnDefinition> linksMetaData = new ArrayList<ColumnDefinition>();
BasicColumnDefinition twLinks = new BasicColumnDefinition();
twLinks.setName(StringSerializer.get().toByteBuffer(QF_URL));
twLinks.setValidationClass(ComparatorType.UTF8TYPE.getClassName());
linksMetaData.add(twLinks);
cfLinks.addColumnDefinition(twLinks);
List<ColumnFamilyDefinition> cfDefs = new ArrayList<ColumnFamilyDefinition>();
cfDefs.add(cfLinks);
KeyspaceDefinition linksDef = HFactory.createKeyspaceDefinition(LINKS,
SIMPLESTRATEGY, replFactor, cfDefs);
cluster.addKeyspace(linksDef);
}
示例5: cfExists
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
/** Return true if the column family exists */
public boolean cfExists( String keyspace, String cfName ) {
KeyspaceDefinition ksDef = cluster.describeKeyspace( keyspace );
if ( ksDef == null ) {
return false;
}
for ( ColumnFamilyDefinition cf : ksDef.getCfDefs() ) {
if ( cfName.equals( cf.getName() ) ) {
return true;
}
}
return false;
}
示例6: getOrCreateKeyspace
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
@Override public Keyspace getOrCreateKeyspace(String keyspaceName, int replicationFactor, Cluster cluster) {
KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspaceName);
List<ColumnFamilyDefinition> cfDefs = new LinkedList<ColumnFamilyDefinition>();
// If keyspace does not exist create it without CFs.
if (keyspaceDef == null) {
keyspaceDef = HFactory.createKeyspaceDefinition(keyspaceName, ThriftKsDef.DEF_STRATEGY_CLASS, replicationFactor, cfDefs);
cluster.addKeyspace(keyspaceDef);
}
Keyspace keyspace = HFactory.createKeyspace(keyspaceName, cluster);
ConfigurableConsistencyLevel consistencyLevel = new ConfigurableConsistencyLevel();
consistencyLevel.setDefaultReadConsistencyLevel(HConsistencyLevel.QUORUM);
consistencyLevel.setDefaultWriteConsistencyLevel(HConsistencyLevel.QUORUM);
keyspace.setConsistencyLevelPolicy(consistencyLevel);
return keyspace;
}
示例7: createKeyspaceDefinition
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
/**
* Creates the CumulusRDF keyspace.
*
* @param keyspaceName the keyspace name.
* @return the keyspace definition.
*/
protected KeyspaceDefinition createKeyspaceDefinition(final String keyspaceName) {
return HFactory.createKeyspaceDefinition(
keyspaceName,
"org.apache.cassandra.locator.SimpleStrategy",
_dataAccessLayerFactory.getReplication(),
createColumnFamiliyDefinitions());
}
示例8: createRequiredSchemaEntities
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
@Override
public void createRequiredSchemaEntities() throws DataAccessLayerException {
final String keyspace_name = _keyspace.getKeyspaceName();
final KeyspaceDefinition ksdef = _factory.getCluster().describeKeyspace(keyspace_name);
if (!hasColumnFamily(ksdef, _cf_name)) {
final ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace_name, _cf_name);
final Map<String, String> compressionOptions = new HashMap<String, String>();
compressionOptions.put("sstable_compression", "SnappyCompressor");
cfDef.setCompressionOptions(compressionOptions);
cfDef.setColumnType(ColumnType.STANDARD);
cfDef.setKeyValidationClass(ComparatorType.BYTESTYPE.getClassName());
cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName());
cfDef.setCompactionStrategy("LeveledCompactionStrategy");
if (_isBidirectional) {
BasicColumnDefinition colDef = new BasicColumnDefinition();
colDef.setName(BytesArraySerializer.get().toByteBuffer(COLUMN_NAME));
colDef.setValidationClass(ComparatorType.BYTESTYPE.getClassName());
colDef.setIndexType(ColumnIndexType.KEYS);
colDef.setIndexName(_cf_name + "_val_idx");
cfDef.addColumnDefinition(colDef);
}
_factory.getCluster().addColumnFamily(new ThriftCfDef(cfDef), true);
}
}
示例9: hasColumnFamily
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
/**
* Returns true if a given keyspace has a column family.
*
* @param ksdef the keyspace.
* @param cfname the column family name.
* @return true if the keyspace has the column family, false otherwise.
*/
public static boolean hasColumnFamily(final KeyspaceDefinition ksdef, final String cfname) {
for (final ColumnFamilyDefinition cfdef : ksdef.getCfDefs()) {
if (cfdef.getName().equals(cfname)) {
return true;
}
}
return false;
}
示例10: getColumnFamilies
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
public List<ColumnFamilyDefinition> getColumnFamilies(String keyspaceName) throws SummarizerException {
KeyspaceDefinition keyspaceDefinition = newConnection().describeKeyspace(keyspaceName);
if (keyspaceDefinition != null && !keyspaceDefinition.equals("")) {
return keyspaceDefinition.getCfDefs();
} else {
Exception e = null;
log.error("There are no key spaces in the server yet");
throw new SummarizerException("There are no key spaces in the server yet", e);
}
}
示例11: main
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Properties prop = new Properties();
replFactor = 1;
try {
prop.load(Schema.class.getClassLoader().getResourceAsStream("config.properties"));
replFactor = Integer.valueOf(prop.getProperty("REPL_FACTOR"));
host = String.valueOf(prop.getProperty("HOST"));
clusterName = String.valueOf(prop.getProperty("CLUSTERNAME"));
System.out.println("Replication factor: " + replFactor);
System.out.println("Host: " + host);
System.out.println("Cluster name: " + clusterName);
} catch (Exception ex) {
ex.printStackTrace();
}
cluster = HFactory.getOrCreateCluster(clusterName, host);
KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(TWEETS);
if (keyspaceDef == null) {
createTweetsTable();
}
keyspaceDef = cluster.describeKeyspace(LINKS);
if (keyspaceDef == null) {
createLinksTable();
}
}
示例12: createTweetsTable
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private static void createTweetsTable() {
final String QF_ID = "id";
// Column Family tweets
final String CF_TWEET = "t";
final String QF_TEXT = "txt";
ColumnFamilyDefinition cfTweet = HFactory.createColumnFamilyDefinition(
TWEETS, CF_TWEET, ComparatorType.UTF8TYPE);
cfTweet.setKeyValidationClass(ComparatorType.LONGTYPE.getTypeName());
List<ColumnDefinition> tweetMetaData = new ArrayList<ColumnDefinition>();
BasicColumnDefinition t_txt = new BasicColumnDefinition();
t_txt.setName(StringSerializer.get().toByteBuffer(QF_TEXT));
t_txt.setValidationClass(ComparatorType.UTF8TYPE.getClassName());
tweetMetaData.add(t_txt);
cfTweet.addColumnDefinition(t_txt);
List<ColumnFamilyDefinition> cfDefs = new ArrayList<ColumnFamilyDefinition>();
cfDefs.add(cfTweet);
KeyspaceDefinition tweetsDef = HFactory.createKeyspaceDefinition(
TWEETS, SIMPLESTRATEGY, replFactor, cfDefs);
cluster.addKeyspace(tweetsDef);
}
示例13: createSchema
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private void createSchema(Cluster cluster, String keyspace) {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace,
COLUMN_FAMILY_NAME,
ComparatorType.BYTESTYPE);
KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspace,
ThriftKsDef.DEF_STRATEGY_CLASS,
1,
Arrays.asList(cfDef));
cluster.addKeyspace(newKeyspace, true);
}
示例14: createKeyspace
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private void createKeyspace() {
Cluster cluster = newCluster();
KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(KEYSPACE_NAME);
if (keyspaceDefinition == null) {
keyspaceDefinition = HFactory.createKeyspaceDefinition(KEYSPACE_NAME);
String keyspaceId = cluster.addKeyspace(keyspaceDefinition, true);
System.out.println("Result of addKeyspace: " + keyspaceId);
} else {
System.out.println("Keyspace already exists with name: " + keyspaceDefinition.getName());
}
}
示例15: describeKeySpace
import me.prettyprint.hector.api.ddl.KeyspaceDefinition; //导入依赖的package包/类
private void describeKeySpace() {
List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
for (KeyspaceDefinition kd : keyspaces) {
if (kd.getName().equals(KEYSPACE_NAME)) {
System.out.println("Name: " + kd.getName());
System.out.println("RF: " + kd.getReplicationFactor());
System.out.println("strategy class: " + kd.getStrategyClass());
List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
ColumnFamilyDefinition def = cfDefs.get(0);
System.out.println(" CF Name: " + def.getName());
System.out.println(" CF Metadata: " + def.getColumnMetadata());
}
}
}