2015-03-26 03:33:19 +00:00
|
|
|
# casser ![build](https://travis-ci.org/noorq/casser.svg?branch=master)
|
2015-03-28 03:25:59 +00:00
|
|
|
Cutting edge Java 8 Cassandra Client
|
2015-03-12 08:08:42 +00:00
|
|
|
|
2015-03-26 06:00:46 +00:00
|
|
|
Current status: Active development
|
|
|
|
|
2015-03-18 03:17:44 +00:00
|
|
|
### Features
|
|
|
|
|
|
|
|
* Leverages Java 8 language capabilities to build CQL queries
|
2015-03-28 03:25:59 +00:00
|
|
|
* Simple function-style stream API
|
|
|
|
* Reactive asynchronous and synchronous API
|
|
|
|
* Provides Java mapping for Tables and User Defined Types
|
2015-03-18 03:17:44 +00:00
|
|
|
|
2015-03-12 08:08:42 +00:00
|
|
|
### Requirements
|
|
|
|
|
|
|
|
* Only JVM 8
|
2015-03-28 03:25:59 +00:00
|
|
|
* Latest Datastax Driver 2.1.5
|
|
|
|
* Latest Cassandra
|
2015-03-12 08:08:42 +00:00
|
|
|
* Maven
|
|
|
|
|
2015-03-24 04:38:53 +00:00
|
|
|
### Example
|
|
|
|
|
2015-03-24 04:42:56 +00:00
|
|
|
Entity definition:
|
2015-03-24 04:38:53 +00:00
|
|
|
```
|
2015-03-24 04:42:56 +00:00
|
|
|
@Table("timelines")
|
|
|
|
public interface Timeline {
|
|
|
|
|
|
|
|
@PartitionKey
|
2015-03-27 20:12:36 +00:00
|
|
|
UUID userId();
|
2015-03-24 04:42:56 +00:00
|
|
|
|
|
|
|
@ClusteringColumn
|
|
|
|
@DataTypeName(Name.TIMEUUID)
|
2015-03-27 20:12:36 +00:00
|
|
|
Date timestamp();
|
2015-03-24 04:42:56 +00:00
|
|
|
|
|
|
|
@Column
|
2015-03-27 20:12:36 +00:00
|
|
|
String text();
|
2015-03-24 04:42:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Session initialization:
|
|
|
|
```
|
|
|
|
Timeline timeline = Casser.dsl(Timeline.class);
|
2015-03-25 04:58:58 +00:00
|
|
|
CasserSession session = Casser.init(getSession()).showCql().add(Timeline.class).autoCreateDrop().get();
|
2015-03-24 04:42:56 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Select information:
|
|
|
|
```
|
2015-03-27 20:12:36 +00:00
|
|
|
session.select(timeline::userId, timeline::timestamp, timeline::text)
|
|
|
|
.where(timeline::userId, Operator.EQ, userId)
|
|
|
|
.orderBy(timeline::timestamp, "desc").limit(5).sync()
|
2015-03-24 04:42:56 +00:00
|
|
|
.forEach(System.out::println);
|
|
|
|
```
|
|
|
|
|
|
|
|
Insert information:
|
|
|
|
```
|
2015-03-27 20:12:36 +00:00
|
|
|
TimelineImpl post = new TimelineImpl();
|
|
|
|
post.userId=userId;
|
|
|
|
post.timestamp=new Date(postTime+1000L*i);
|
|
|
|
post.text="hello";
|
2015-03-24 04:42:56 +00:00
|
|
|
session.upsert(post).sync();
|
2015-03-24 04:38:53 +00:00
|
|
|
```
|