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-04-25 17:23:22 +00:00
|
|
|
Current status: First application is using in production!
|
2015-03-26 06:00:46 +00:00
|
|
|
|
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
|
2015-04-28 03:52:55 +00:00
|
|
|
* Provides Java mapping for Tables, Tuples, UDFs (User Defined Types), Collections, UDT Collections, Tuple Collections
|
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
|
2015-04-28 03:52:55 +00:00
|
|
|
* Latest Cassandra 2.1.4
|
2015-03-12 08:08:42 +00:00
|
|
|
* Maven
|
|
|
|
|
2015-03-30 19:49:44 +00:00
|
|
|
### Maven
|
|
|
|
|
2015-04-28 03:52:55 +00:00
|
|
|
Latest release dependency:
|
|
|
|
```
|
|
|
|
<dependencies>
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.noorq.casser</groupId>
|
|
|
|
<artifactId>casser-core</artifactId>
|
|
|
|
<version>1.0.0</version>
|
|
|
|
</dependency>
|
|
|
|
</dependencies>
|
|
|
|
```
|
|
|
|
|
2015-03-30 19:49:44 +00:00
|
|
|
Active development dependency:
|
|
|
|
```
|
2015-03-30 19:52:45 +00:00
|
|
|
<dependencies>
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.noorq.casser</groupId>
|
|
|
|
<artifactId>casser-core</artifactId>
|
2015-04-28 03:50:16 +00:00
|
|
|
<version>1.1.0-SNAPSHOT</version>
|
2015-03-30 19:52:45 +00:00
|
|
|
</dependency>
|
|
|
|
</dependencies>
|
|
|
|
|
|
|
|
<repositories>
|
|
|
|
<repository>
|
|
|
|
<id>oss-sonatype</id>
|
|
|
|
<name>oss-sonatype</name>
|
|
|
|
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
|
|
|
<snapshots>
|
|
|
|
<enabled>true</enabled>
|
|
|
|
</snapshots>
|
|
|
|
</repository>
|
|
|
|
</repositories>
|
2015-03-30 19:49:44 +00:00
|
|
|
```
|
|
|
|
|
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
|
2015-04-16 23:54:30 +00:00
|
|
|
@Types.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)
|
2015-04-09 21:28:54 +00:00
|
|
|
.where(timeline::userId, Query.eq(userId))
|
|
|
|
.orderBy(Query.desc(timeline::timestamp)).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
|
|
|
```
|