Java 获取cassandra查询中的所有列
我的cql3表如下Java 获取cassandra查询中的所有列,java,astyanax,cassandra-2.0,Java,Astyanax,Cassandra 2.0,我的cql3表如下 CREATE TABLE customer_details ( customer_id int, uuid text, creation_time timestamp, agent text, address text, PRIMARY KEY (customer_id, uuid) ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' A
CREATE TABLE customer_details (
customer_id int,
uuid text,
creation_time timestamp,
agent text,
address text,
PRIMARY KEY (customer_id, uuid)
) WITH
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
index_interval=128 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
default_time_to_live=0 AND
speculative_retry='NONE' AND
memtable_flush_period_in_ms=0 AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'LZ4Compressor'};
public class CustomerCF {
private static String columnFamilyName = "customer";
@Component(ordinal = 0)
private String uuid;
@Component(ordinal = 1)
private String columnName;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public static String getColumnFamilyName() {
return columnFamilyName;
}
}
我在cql3中查询:
select * from customer_details where customer_id=1 and uuid='0xxiyj';
customer_id | uuid | creation_time | agent | address
-------------+---------------+--------------------------+----------------------+----------
11 | 0xxiyj | 1970-01-01 05:30:00+0530 | My agent | india
我一直在尝试在astyanax中实现ORM等效
我能接近的马克斯是
AnnotatedCompositeSerializer<CustomerCF> recordEntitySerializer = new AnnotatedCompositeSerializer<CustomerCF>(CustomerCF.class);
ColumnFamily<Integer,CustomerCF> recordColumnFamily = this.buildColumnFamily(CustomerCF.getColumnFamilyName(), customerId, recordEntitySerializer);
try {
//OperationResult<ColumnList<CustomerCF>> result = astyanaxKeyspace.prepareQuery(recordColumnFamily).getKey(customerId).withColumnRange(recordEntitySerializer.buildRange()
// .withPrefix('0xxiyj')).execute();
CustomerCF recordCF = new CustomerCF();
recordCF.setUuid('0xxiyj');
recordCF.setColumnName("address");
CustomerCF recordCF1 = new CustomerCF();
recordCF.setUuid('0xxiyj');
recordCF1.setColumnName("agent");
List<CustomerCF> list = new ArrayList<CustomerCF>();
list.add(recordCF);list.add(recordCF1);
OperationResult<ColumnList<CustomerCF>> result = astyanaxKeyspace.prepareQuery(recordColumnFamily).getKey(customerId).withColumnSlice(list).execute();
for (Column<CustomerCF> row : result.getResult()) {
System.out.println(row.getName().getColumnName()+" "+row.getStringValue());
}
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
我如何写ORM等价物
select * from customer_details where customer_id=1 and uuid='0xxiyj';
还有一个最重要的问题:如果在上述情况下,主键是customer_id、uuid、agent、address,我如何查询
select agent,address from customer_details where customer_id=1 and uuid='0xxiyj';
在ORM中,您可以使用昆德拉。 它使用起来非常简单 你可以在下面的链接中找到它 你也可以参考
谢谢……但我已经用astyanax编程了90%的项目,所以我必须坚持下去。
select agent,address from customer_details where customer_id=1 and uuid='0xxiyj';