获取cassandra查询中的所有列

时间:2014-05-22 06:53:33

标签: 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='' 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;

相当于

select address, agent from customer_details where customer_id=1 and uuid='0xxiyj';

我如何编写ORM等效的

select * from customer_details where customer_id=1 and uuid='0xxiyj';

还有1个&amp;大多数人问题:如果在上述情况下主键是(customer_id,uuid,agent,address),我如何查询等效的

select agent,address from customer_details where customer_id=1 and uuid='0xxiyj';
ORM中的

1 个答案:

答案 0 :(得分:0)

你可以使用昆德拉。 它的使用非常简单。

您可以在以下链接中找到它 https://github.com/impetus-opensource/Kundera

你也可以参考 https://github.com/impetus-opensource/Kundera/wiki/Getting-Started-in-5-minutes