本文整理汇总了Java中com.datastax.driver.mapping.annotations.ClusteringColumn类的典型用法代码示例。如果您正苦于以下问题:Java ClusteringColumn类的具体用法?Java ClusteringColumn怎么用?Java ClusteringColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClusteringColumn类属于com.datastax.driver.mapping.annotations包,在下文中一共展示了ClusteringColumn类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generatePrimaryKey
import com.datastax.driver.mapping.annotations.ClusteringColumn; //导入依赖的package包/类
private static String generatePrimaryKey(Class<?> c) throws Exception {
Field[] fields = c.getFields();
List<PartitionKey> partitionKeys = new LinkedList<>();
Map<PartitionKey, String> partitionKeyToFieldName = new HashMap<>();
List<String> clusterColumns = new LinkedList<>();
for (Field f : fields) {
PartitionKey partitionKey = f.getAnnotation(PartitionKey.class);
ClusteringColumn clusterColumn = f.getAnnotation(ClusteringColumn.class);
if (partitionKey != null) {
partitionKeys.add(partitionKey);
partitionKeyToFieldName.put(partitionKey, getNameOfField(f));
// partitonKeys.
}
if (clusterColumn != null) {
clusterColumns.add(getNameOfField(f));
}
}
if (partitionKeys.size() == 0) {
throw new Exception("Partition key annotations are required!");
}
String partitonKey =
partitionKeys.stream().sorted((p1, p2) -> Integer.compare(p1.value(), p2.value()))
.map((p) -> partitionKeyToFieldName.get(p)).reduce((p1, p2) -> p1 + ", " + p2).get();
boolean multiPartitionKey = partitionKeys.size() > 1;
String result = "PRIMARY KEY (";
if (multiPartitionKey) {
result += "(";
}
result += partitonKey;
if (multiPartitionKey) {
result += ")";
}
if (clusterColumns != null) {
result += ", ";
result += clusterColumns.stream().reduce((c1, c2) -> c1 + ", " + c2).get();
}
result += ")";
return result;
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:56,代码来源:CassandraSchemaGenerator.java
示例2: getClusteringAnnotation
import com.datastax.driver.mapping.annotations.ClusteringColumn; //导入依赖的package包/类
/**
* Get the ClusteringColumn annotation for a Table field.
* @param position the order of the field in the partition key
* @return the annotation
*/
public static AnnotationSpec getClusteringAnnotation(int position) {
return AnnotationSpec.builder(ClusteringColumn.class).addMember("value", "$L", position).build();
}
开发者ID:jtruelove,项目名称:exovert,代码行数:9,代码来源:EntityGeneratorHelper.java
注:本文中的com.datastax.driver.mapping.annotations.ClusteringColumn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论