本文整理汇总了Java中me.prettyprint.cassandra.serializers.StringSerializer类的典型用法代码示例。如果您正苦于以下问题:Java StringSerializer类的具体用法?Java StringSerializer怎么用?Java StringSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringSerializer类属于me.prettyprint.cassandra.serializers包,在下文中一共展示了StringSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryStringIndex
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
private Iterable<String> queryStringIndex(final String key) {
SliceQuery<String, String, String> sliceQuery =
HFactory.createSliceQuery(m_keyspace, StringSerializer.get(), StringSerializer.get(),
StringSerializer.get());
sliceQuery.setColumnFamily(CF_STRING_INDEX);
sliceQuery.setKey(key);
ColumnSliceIterator<String, String, String> columnIterator =
new ColumnSliceIterator<String, String, String>(sliceQuery, "", (String) null, false, m_singleRowReadSize);
List<String> ret = new ArrayList<String>();
while (columnIterator.hasNext()) {
ret.add(columnIterator.next().getName());
}
return ret;
}
示例2: getSerializer
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Class<?> valueClass) {
Serializer serializer = null;
if (valueClass.equals(Utf8.class) || valueClass.equals(CharSequence.class)) {
serializer = CharSequenceSerializer.get();
} else if (valueClass.equals(Boolean.class) || valueClass.equals(boolean.class)) {
serializer = BooleanSerializer.get();
} else if (valueClass.equals(ByteBuffer.class)) {
serializer = ByteBufferSerializer.get();
} else if (valueClass.equals(Double.class) || valueClass.equals(double.class)) {
serializer = DoubleSerializer.get();
} else if (valueClass.equals(Float.class) || valueClass.equals(float.class)) {
serializer = FloatSerializer.get();
} else if (valueClass.equals(Integer.class) || valueClass.equals(int.class)) {
serializer = IntegerSerializer.get();
} else if (valueClass.equals(Long.class) || valueClass.equals(long.class)) {
serializer = LongSerializer.get();
} else if (valueClass.equals(String.class)) {
serializer = StringSerializer.get();
} else {
serializer = SerializerTypeInferer.getSerializer(valueClass);
}
return serializer;
}
示例3: executeSuper
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
public List<SuperRow<K, String, ByteBuffer, ByteBuffer>> executeSuper(CassandraQuery<K, T> cassandraQuery, String family) {
String[] columnNames = cassandraQuery.getColumns(family);
Query<K, T> query = cassandraQuery.getQuery();
int limit = (int) query.getLimit();
if (limit < 1) {
limit = Integer.MAX_VALUE;
}
K startKey = query.getStartKey();
K endKey = query.getEndKey();
RangeSuperSlicesQuery<K, String, ByteBuffer, ByteBuffer> rangeSuperSlicesQuery = HFactory.createRangeSuperSlicesQuery
(this.keyspace, this.keySerializer, StringSerializer.get(), ByteBufferSerializer.get(), ByteBufferSerializer.get());
rangeSuperSlicesQuery.setColumnFamily(family);
rangeSuperSlicesQuery.setKeys(startKey, endKey);
rangeSuperSlicesQuery.setRange("", "", false, GoraRecordReader.BUFFER_LIMIT_READ_VALUE);
rangeSuperSlicesQuery.setRowCount(limit);
rangeSuperSlicesQuery.setColumnNames(columnNames);
QueryResult<OrderedSuperRows<K, String, ByteBuffer, ByteBuffer>> queryResult = rangeSuperSlicesQuery.execute();
OrderedSuperRows<K, String, ByteBuffer, ByteBuffer> orderedRows = queryResult.get();
return orderedRows.getList();
}
示例4: doGetUserListOfRole
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
/**
* Get the list of users mapped to a role.
*/
@Override
public String[] doGetUserListOfRole(String roleName, String filter) throws UserStoreException {
List<String> usersList = new ArrayList<String>();
Composite key = new Composite();
key.addComponent(roleName, stringSerializer);
key.addComponent(tenantIdString, stringSerializer);
SliceQuery<Composite, String, String> query = HFactory
.createSliceQuery(keyspace, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
.setKey(key).setColumnFamily(CFConstants.UM_ROLE_USER_INDEX);
ColumnSliceIterator<Composite, String, String> iterator = new ColumnSliceIterator<Composite, String, String>(
query, null, "\uFFFF", false);
while (iterator.hasNext()) {
HColumn<String, String> column = iterator.next();
usersList.add(column.getValue());
}
return usersList.toArray(new String[usersList.size()]);
}
示例5: doGetExternalRoleListOfUser
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
/**
* Gets the external role list of a user.
*/
@Override
public String[] doGetExternalRoleListOfUser(String userName, String filter) throws UserStoreException {
List<String> roles = new ArrayList<String>();
int arrayLength = 0;
Composite key = new Composite();
key.addComponent(userName, stringSerializer);
key.addComponent(tenantIdString, stringSerializer);
SliceQuery<Composite, String, String> query = HFactory
.createSliceQuery(keyspace, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
.setKey(key).setColumnFamily(CFConstants.UM_USER_ROLE);
ColumnSliceIterator<Composite, String, String> iterator = new ColumnSliceIterator<Composite, String, String>(
query, null, "\uFFFF", false);
while (iterator.hasNext()) {
HColumn<String, String> column = iterator.next();
roles.add(column.getValue());
}
return roles.toArray(new String[arrayLength]);
}
示例6: createKeyspace
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的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);
}
示例7: updateColumnNameBasedSecondaryIndices
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
private void updateColumnNameBasedSecondaryIndices(K key, List<String> secondaryIndexByColumnNameChanges, Map<String, Integer> ttls) {
final Mutator<String> secondaryIndexMutator = HFactory.createMutator(keysp, StringSerializer.get());
String secondaryIndexCF = secondaryIndexedColumnFamilyTemplate.getColumnFamily();
boolean ttlsDefined = MapUtils.isNotEmpty(ttls);
for (String secondaryIndexByColumnName : secondaryIndexByColumnNameChanges) {
int ttl = -1;
if (ttlsDefined && ttls.get(secondaryIndexByColumnName) != null) {
ttl = ttls.get(secondaryIndexByColumnName);
}
HColumn<K, K> hColumn;
if (ttl > 0) {
hColumn = HFactory.createColumn(key, key, keysp.createClock(), ttl, keySerializer, keySerializer);
} else {
hColumn = HFactory.createColumn(key, key, keysp.createClock(), keySerializer, keySerializer);
}
secondaryIndexMutator.addInsertion(getSecondaryIndexKey(secondaryIndexByColumnName, ""), secondaryIndexCF, hColumn);
}
MutationResult execute = secondaryIndexMutator.execute();
log.debug(secondaryIndexByColumnNameChanges.size() + " secondary Indexes got updated for the key " + key.toString() +
". Exec Time = " + execute.getExecutionTimeMicro() + ", Host used = " + execute.getHostUsed());
}
示例8: readColumnSlice
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Override
public CassandraResultSet<K, String> readColumnSlice(K key, String start, String end, boolean reversed, int count) {
SliceQuery<K, String, String> sliceQuery = HFactory.createSliceQuery(keysp, keySerializer,
StringSerializer.get(),
StringSerializer.get()).setColumnFamily(
columnFamily).setRange(start, end, reversed, count).setKey(key);
QueryResult<ColumnSlice<String, String>> queriedResult = sliceQuery.execute();
if (isClientAdapterDebugMessagesEnabled) {
log.info("ColumnSlice retrieved from Cassandra. Exec Time = " + queriedResult.getExecutionTimeMicro() +
", Host used = " + queriedResult.getHostUsed() + ", Key = " + key);
}
return new HectorColumnSliceResultSet<K, String, String>(queriedResult);
}
示例9: configureOurColumnFamilyTemplatePool
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
public void configureOurColumnFamilyTemplatePool(String[] splittedPorts, String[] splittedLocationURLs) {
final CassandraHostConfigurator cassandraHostConfigurator = createCassandraConfigurator();
for (int index = 0; index < splittedLocationURLs.length; index++) {
String locationURL = splittedLocationURLs[index];
String port = "";
if (index < splittedPorts.length) {
port = splittedPorts[index];
}
if (port == null || "".equals(port)) {
port = "9160";
}
cassandraHostConfigurator.setHosts(locationURL + ":" + port);
cluster = HFactory.getOrCreateCluster(clusterName, cassandraHostConfigurator);
keysp = HFactory.createKeyspace(keyspace, cluster, consistencyLevel);
columnFamilyTemplates.add(new ThriftColumnFamilyTemplate<K, String>(keysp, columnFamily, keySerializer,
StringSerializer.get()));
}
}
示例10: setUp
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Override
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
super.setUp();
Serializer<String> keySerializer = StringSerializer.get();
Serializer<String> supercolumnSerializer = StringSerializer.get();
Serializer<String> columnNameSerializer = StringSerializer.get();
Serializer<Object> valueSerializer = StructureSerializer.get();
SuperColumnFamilyOperations<String,String,String,Object> operations = new SuperColumnFamilyTemplate<String,String,String,Object>(
keyspace,
columnFamily,
keySerializer,
supercolumnSerializer,
columnNameSerializer,
valueSerializer);
dao = new ThriftSuperStructuredDataSupport<String>(operations);
}
示例11: testWriteColumn
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Test(groups={"unit"})
public void testWriteColumn() {
String propertyValue = columnValue;
//=========================
superColumnFamilyTestDao.writeColumn(rowKey, superColumnName, columnName, propertyValue, txnContext);
//=========================
HColumn<String,String> column = HFactory.createColumn(columnName,
columnValue,
StringSerializer.get(),
StringSerializer.get());
HSuperColumn<String,String,String> superColumn = HFactory.createSuperColumn(superColumnName,
Arrays.asList(column),
StringSerializer.get(),
StringSerializer.get(),
StringSerializer.get());
ArgumentCaptor<HSuperColumn> superColumnCaptor = ArgumentCaptor.forClass(HSuperColumn.class);
verify(mutator).addInsertion(eq(rowKey), eq(columnFamily), superColumnCaptor.capture());
HSuperColumn actualSuperColumn = superColumnCaptor.getValue();
assertTrue(areSuperColumnsEqual(actualSuperColumn, superColumn));
}
示例12: testDeleteColumns
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Test(groups={"unit"})
public void testDeleteColumns() {
//=========================
superColumnFamilyTestDao.deleteColumns(rowKey, superColumnName, columnNames, txnContext);
//=========================
for (String colName : columnNames) {
verify(mutator).addSubDelete(rowKey,
columnFamily,
superColumnName,
colName,
StringSerializer.get(),
StringSerializer.get());
}
}
示例13: testWriteColumn
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Test(groups = {"unit"})
public void testWriteColumn() throws Exception {
String propertyValue = columnValue;
//=========================
columnFamilyTestDao.writeColumn(rowKey, columnName, propertyValue, txnContext);
//=========================
HColumn<String,String> column = HFactory.createColumn(columnName,
columnValue,
StringSerializer.get(),
StringSerializer.get());
ArgumentCaptor<HColumn> columnCaptor = ArgumentCaptor.forClass(HColumn.class);
verify(mutator).addInsertion(eq(rowKey), eq(columnFamily), columnCaptor.capture());
HColumn actualColumn = columnCaptor.getValue();
assertTrue(areColumnsEqual(actualColumn, column));
}
示例14: testWriteColumns
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Test(groups = {"unit"})
public void testWriteColumns() throws Exception {
Map<String,String> properties = new HashMap<String,String>();
Iterator<String> itr = columnValues.iterator();
for (String columnName : columnNames) {
properties.put(columnName, itr.next());
}
//=========================
columnFamilyTestDao.writeColumns(rowKey, properties, txnContext);
//=========================
HColumn column1 = HFactory.createColumn(columnNames.get(0),
columnValues.get(0),
StringSerializer.get(),
StringSerializer.get());
HColumn column2 = HFactory.createColumn(columnNames.get(1),
columnValues.get(1),
StringSerializer.get(),
StringSerializer.get());
ArgumentCaptor<HColumn> columnCaptor = ArgumentCaptor.forClass(HColumn.class);
verify(mutator, times(2)).addInsertion(eq(rowKey), eq(columnFamily), columnCaptor.capture());
List<HColumn> actualColumns = columnCaptor.getAllValues();
assertTrue(areColumnsEqual(actualColumns.get(0), column1));
assertTrue(areColumnsEqual(actualColumns.get(1), column2));
}
示例15: shouldDeleteColumnSlice
import me.prettyprint.cassandra.serializers.StringSerializer; //导入依赖的package包/类
@Test(groups = {"unit"})
public void shouldDeleteColumnSlice() throws Exception {
ColumnFamilyOperations<String,String,String> spy = spy(columnFamilyTestDao);
doReturn(Arrays.asList("a", "b", "c")).when(spy).readColumns(eq(rowKey), eq("start"), eq(
"finish"), eq(Integer.MAX_VALUE), eq(false), mapperCaptor.capture());
//=========================
spy.deleteColumns(rowKey, "start", "finish", txnContext);
//=========================
verify(mutator).addDeletion(rowKey, columnFamily, "a", StringSerializer.get());
verify(mutator).addDeletion(rowKey, columnFamily, "a", StringSerializer.get());
verify(mutator).addDeletion(rowKey, columnFamily, "a", StringSerializer.get());
verify(mutator, never()).execute();
}