make universal where operator
This commit is contained in:
parent
0297778d05
commit
019dafbf79
6 changed files with 49 additions and 10 deletions
|
@ -1,2 +1,9 @@
|
|||
# casser
|
||||
Yet Another Cassandra Client
|
||||
|
||||
### Requirements
|
||||
|
||||
* Only JVM 8
|
||||
* Datastax Driver
|
||||
* Maven
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import casser.tuple.Tuple2;
|
|||
|
||||
public class Example {
|
||||
|
||||
User userDsl = Casser.dsl(User.class);
|
||||
static final User _user = Casser.dsl(User.class);
|
||||
|
||||
Session session = Casser.connect("localhost").update(userDsl).get();
|
||||
Session session = Casser.connect("localhost").update(_user).get();
|
||||
|
||||
public static User mapUser(Tuple2<String, Integer> t) {
|
||||
User user = Casser.pojo(User.class);
|
||||
|
@ -25,15 +25,15 @@ public class Example {
|
|||
newUser.setAge(34);
|
||||
session.upsert(newUser);
|
||||
|
||||
String nameAndAge = session.select(userDsl::getName, userDsl::getAge).where(userDsl::getId, 100L).sync().findFirst().map(t -> {
|
||||
String nameAndAge = session.select(_user::getName, _user::getAge).where(_user::getId, "==", 100L).sync().findFirst().map(t -> {
|
||||
return t.v1 + ":" + t.v2;
|
||||
}).get();
|
||||
|
||||
User user = session.select(userDsl::getName, userDsl::getAge).where(userDsl::getId, 100L).map(Example::mapUser).sync().findFirst().get();
|
||||
User user = session.select(_user::getName, _user::getAge).where(_user::getId, "==", 100L).map(Example::mapUser).sync().findFirst().get();
|
||||
|
||||
session.update(userDsl::setAge, 10).where(userDsl::getId, 100L).async();
|
||||
session.update(_user::setAge, 10).where(_user::getId, "==", 100L).async();
|
||||
|
||||
session.delete().where(userDsl::getId, 100L).async();
|
||||
session.delete().where(_user::getId, "==", 100L).async();
|
||||
|
||||
}
|
||||
|
||||
|
|
20
src/casser/core/SupportedOperators.java
Normal file
20
src/casser/core/SupportedOperators.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package casser.core;
|
||||
|
||||
public final class SupportedOperators {
|
||||
|
||||
public static final String EQUAL = "==";
|
||||
|
||||
public static final String NOT_EQUAL = "!=";
|
||||
|
||||
public static final String GREATER = ">";
|
||||
|
||||
public static final String LESS = "<";
|
||||
|
||||
public static final String GREATER_OR_EQUAL = ">=";
|
||||
|
||||
public static final String LESS_OR_EQUAL = "<=";
|
||||
|
||||
private SupportedOperators() {
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,12 @@ import casser.dsl.Getter;
|
|||
|
||||
public class DeleteOperation extends AbstractOperation<Object> {
|
||||
|
||||
public <V> DeleteOperation where(Getter<V> getter, V val) {
|
||||
public <V> DeleteOperation where(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> DeleteOperation and(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,11 @@ import casser.dsl.Getter;
|
|||
|
||||
public class SelectOperation<E> extends AbstractStreamOperation<E> {
|
||||
|
||||
public <V> SelectOperation<E> where(Getter<V> getter, V val) {
|
||||
public <V> SelectOperation<E> where(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> SelectOperation<E> and(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,12 @@ import casser.dsl.Getter;
|
|||
|
||||
public class UpdateOperation extends AbstractOperation<Object> {
|
||||
|
||||
public <V> UpdateOperation where(Getter<V> getter, V val) {
|
||||
public <V> UpdateOperation where(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> UpdateOperation and(Getter<V> getter, String operator, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue