Cassandra,spring数据,如何添加行

时间:2015-07-31 12:31:10

标签: cassandra insert spring-data nosql

spring数据中的简单示例cassandra参考文档以SQL mappers的方式显示事物:

Insert insert = QueryBuilder.insertInto("person");
insert.setConsistencyLevel(ConsistencyLevel.ONE);
insert.value("id", "123123123");
insert.value("name", "Alison");
insert.value("age", 39);

cassandraOperations.execute(insert);

我对不同类型的例子感兴趣。

正如cassandra(或NONSQL)神学所声称的那样,我们需要通过查询获得模型数据,我们想要执行。

假设我有“对象”,称为“信息”。

我想按类别(分区键)查询它们。

有时按时间聚类, 有时按标签聚类。

我有2个表:

create table info_by_category_time(
  id uuid,
  title text,
  category text,
  subtitle text,
  authornick text,
  info text,
  link text,
  pic text,
  pic_title text,
  tag1 text,
  tag2 text,
  tag3 text,
  alltags text,
  language text,
  active boolean,
  creation_time timestamp,
  primary key (category, creation_time, tag1, tag2, tag3))
  with CLUSTERING ORDER BY (creation_time DESC, tag1 DESC, tag2 DESC, tag3 DESC)
;

create table info_by_category_tags(
  id uuid,
  title text,
  category text,
  subtitle text,
  authornick text,
  info text,
  link text,
  pic text,
  pic_title text,
  tag1 text,
  tag2 text,
  tag3 text,
  alltags text,
  language text,
  active boolean,
  creation_time timestamp,
  primary key (category, tag1, tag2, tag3, creation_time))
  with CLUSTERING ORDER BY (tag1 DESC, tag2 DESC, tag3 DESC, creation_time DESC)
;

表格相似,唯一的区别是 - 不同的聚类。

他们说:数据重复没有问题,您需要提供查询 - 这一点更为重要。

OK!

但是我应该如何使用spring数据将对象添加到cassandra?

我现在应该使用2个不同的Repository接口将它们添加到两个不同的表中吗?

我该怎么做?

感谢。

1 个答案:

答案 0 :(得分:0)

我发现有一个"用户定义的类型"在卡桑德拉。如果使用得当,那就是我需要的东西。它允许定义复杂类型并在不同的表中重用该定义。问题:Spring-data还没有支持这个UDT。我打算做的是:我将定义"可重复使用的"部分为BLOB。所以,我可以保存任何我想要的对象。因此,在不同的表中重用此对象。当然,这是一个糟糕的解决方法,我不确定我是否应该继续使用具有这种缺点的弹簧数据。