diff --git a/README.md b/README.md index 61b3b57..3965041 100644 --- a/README.md +++ b/README.md @@ -23,20 +23,15 @@ Entity definition: public interface Timeline { @PartitionKey - UUID getUserId(); - - void setUserId(UUID uid); + UUID userId(); @ClusteringColumn @DataTypeName(Name.TIMEUUID) - Date getTimestamp(); - - void setTimestamp(Date ts); + Date timestamp(); @Column - String getText(); + String text(); - void setText(String text); } ``` @@ -48,17 +43,17 @@ CasserSession session = Casser.init(getSession()).showCql().add(Timeline.class). Select information: ``` -session.select(timeline::getUserId, timeline::getTimestamp, timeline::getText) - .where(timeline::getUserId, "==", userId) - .orderBy(timeline::getTimestamp, "desc").limit(5).sync() +session.select(timeline::userId, timeline::timestamp, timeline::text) + .where(timeline::userId, Operator.EQ, userId) + .orderBy(timeline::timestamp, "desc").limit(5).sync() .forEach(System.out::println); ``` Insert information: ``` -Timeline post = Casser.pojo(Timeline.class); -post.setUserId(userId); -post.setTimestamp(new Date(postTime+1000L*i)); -post.setText("hello"); +TimelineImpl post = new TimelineImpl(); +post.userId=userId; +post.timestamp=new Date(postTime+1000L*i); +post.text="hello"; session.upsert(post).sync(); ``` diff --git a/src/main/java/casser/core/Filter.java b/src/main/java/casser/core/Filter.java index f148dfa..30fa4ae 100644 --- a/src/main/java/casser/core/Filter.java +++ b/src/main/java/casser/core/Filter.java @@ -28,18 +28,18 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; public final class Filter { private final CasserMappingProperty property; - private final FilterOperator operation; + private final Operator operation; private final V value; private final V[] values; - private Filter(CasserMappingProperty prop, FilterOperator op, V value) { + private Filter(CasserMappingProperty prop, Operator op, V value) { this.property = prop; this.operation = op; this.value = value; this.values = null; } - private Filter(CasserMappingProperty prop, FilterOperator op, V[] values) { + private Filter(CasserMappingProperty prop, Operator op, V[] values) { this.property = prop; this.operation = op; this.value = null; @@ -50,7 +50,7 @@ public final class Filter { return property; } - public FilterOperator getOperation() { + public Operator getOperation() { return operation; } @@ -62,7 +62,7 @@ public final class Filter { switch(operation) { - case EQUAL: + case EQ: return QueryBuilder.eq(property.getColumnName(), valuePreparer.prepareColumnValue(value, property)); @@ -73,16 +73,16 @@ public final class Filter { } return QueryBuilder.in(property.getColumnName(), preparedValues); - case LESSER: + case LT: return QueryBuilder.lt(property.getColumnName(), valuePreparer.prepareColumnValue(value, property)); - case LESSER_OR_EQUAL: + case LTE: return QueryBuilder.lte(property.getColumnName(), valuePreparer.prepareColumnValue(value, property)); - case GREATER: + case GT: return QueryBuilder.gt(property.getColumnName(), valuePreparer.prepareColumnValue(value, property)); - case GREATER_OR_EQUAL: + case GTE: return QueryBuilder.gte(property.getColumnName(), valuePreparer.prepareColumnValue(value, property)); default: @@ -92,7 +92,7 @@ public final class Filter { } public static Filter equal(Getter getter, V val) { - return create(getter, FilterOperator.EQUAL, val); + return create(getter, Operator.EQ, val); } public static Filter in(Getter getter, V[] vals) { @@ -109,29 +109,29 @@ public final class Filter { CasserMappingProperty prop = MappingUtil.resolveMappingProperty(getter); - return new Filter(prop, FilterOperator.IN, vals); + return new Filter(prop, Operator.IN, vals); } public static Filter greater(Getter getter, V val) { - return create(getter, FilterOperator.GREATER, val); + return create(getter, Operator.GT, val); } public static Filter less(Getter getter, V val) { - return create(getter, FilterOperator.LESSER, val); + return create(getter, Operator.LT, val); } public static Filter greaterOrEqual(Getter getter, V val) { - return create(getter, FilterOperator.GREATER_OR_EQUAL, val); + return create(getter, Operator.GTE, val); } public static Filter lessOrEqual(Getter getter, V val) { - return create(getter, FilterOperator.LESSER_OR_EQUAL, val); + return create(getter, Operator.LTE, val); } public static Filter create(Getter getter, String operator, V val) { Objects.requireNonNull(operator, "empty operator"); - FilterOperator fo = FilterOperator.findByOperator(operator); + Operator fo = Operator.findByOperator(operator); if (fo == null) { throw new CasserMappingException("invalid operator " + operator); @@ -140,12 +140,12 @@ public final class Filter { return create(getter, fo, val); } - public static Filter create(Getter getter, FilterOperator op, V val) { + public static Filter create(Getter getter, Operator op, V val) { Objects.requireNonNull(getter, "empty getter"); Objects.requireNonNull(op, "empty op"); Objects.requireNonNull(val, "empty value"); - if (op == FilterOperator.IN) { + if (op == Operator.IN) { throw new IllegalArgumentException("invalid usage of the 'in' operator, use Filter.in() static method"); } diff --git a/src/main/java/casser/core/FilterOperator.java b/src/main/java/casser/core/Operator.java similarity index 70% rename from src/main/java/casser/core/FilterOperator.java rename to src/main/java/casser/core/Operator.java index c519c05..9f41dd4 100644 --- a/src/main/java/casser/core/FilterOperator.java +++ b/src/main/java/casser/core/Operator.java @@ -18,31 +18,31 @@ package casser.core; import java.util.HashMap; import java.util.Map; -public enum FilterOperator { +public enum Operator { - EQUAL("=="), + EQ("=="), IN("in"), - GREATER(">"), + GT(">"), - LESSER("<"), + LT("<"), - GREATER_OR_EQUAL(">="), + GTE(">="), - LESSER_OR_EQUAL("<="); + LTE("<="); private final String name; - private final static Map indexByName = new HashMap(); + private final static Map indexByName = new HashMap(); static { - for (FilterOperator fo : FilterOperator.values()) { + for (Operator fo : Operator.values()) { indexByName.put(fo.getName(), fo); } } - private FilterOperator(String name) { + private Operator(String name) { this.name = name; } @@ -50,7 +50,7 @@ public enum FilterOperator { return name; } - public static FilterOperator findByOperator(String name) { + public static Operator findByOperator(String name) { return indexByName.get(name); } diff --git a/src/main/java/casser/core/operation/AbstractFilterOperation.java b/src/main/java/casser/core/operation/AbstractFilterOperation.java index e8bbb6b..e6b65fb 100644 --- a/src/main/java/casser/core/operation/AbstractFilterOperation.java +++ b/src/main/java/casser/core/operation/AbstractFilterOperation.java @@ -20,7 +20,7 @@ import java.util.List; import casser.core.AbstractSessionOperations; import casser.core.Filter; -import casser.core.FilterOperator; +import casser.core.Operator; import casser.core.Getter; public abstract class AbstractFilterOperation> extends AbstractEntityOperation { @@ -38,7 +38,7 @@ public abstract class AbstractFilterOperation O where(Getter getter, FilterOperator operator, V val) { + public O where(Getter getter, Operator operator, V val) { addFilter(Filter.create(getter, operator, val)); @@ -59,7 +59,7 @@ public abstract class AbstractFilterOperation O and(Getter getter, FilterOperator operator, V val) { + public O and(Getter getter, Operator operator, V val) { addFilter(Filter.create(getter, operator, val)); diff --git a/src/main/java/casser/core/operation/AbstractFilterStreamOperation.java b/src/main/java/casser/core/operation/AbstractFilterStreamOperation.java index aa908f1..f4e2d96 100644 --- a/src/main/java/casser/core/operation/AbstractFilterStreamOperation.java +++ b/src/main/java/casser/core/operation/AbstractFilterStreamOperation.java @@ -20,7 +20,7 @@ import java.util.List; import casser.core.AbstractSessionOperations; import casser.core.Filter; -import casser.core.FilterOperator; +import casser.core.Operator; import casser.core.Getter; public abstract class AbstractFilterStreamOperation> extends AbstractStreamOperation { @@ -38,7 +38,7 @@ public abstract class AbstractFilterStreamOperation O where(Getter getter, FilterOperator operator, V val) { + public O where(Getter getter, Operator operator, V val) { addFilter(Filter.create(getter, operator, val)); @@ -59,7 +59,7 @@ public abstract class AbstractFilterStreamOperation O and(Getter getter, FilterOperator operator, V val) { + public O and(Getter getter, Operator operator, V val) { addFilter(Filter.create(getter, operator, val)); diff --git a/src/test/java/casser/test/integration/core/simple/SimpleUserTest.java b/src/test/java/casser/test/integration/core/simple/SimpleUserTest.java index 6034121..e7cd3d9 100644 --- a/src/test/java/casser/test/integration/core/simple/SimpleUserTest.java +++ b/src/test/java/casser/test/integration/core/simple/SimpleUserTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import casser.core.Casser; import casser.core.CasserSession; -import casser.core.FilterOperator; +import casser.core.Operator; import casser.test.integration.build.AbstractEmbeddedCassandraTest; public class SimpleUserTest extends AbstractEmbeddedCassandraTest { @@ -73,7 +73,7 @@ public class SimpleUserTest extends AbstractEmbeddedCassandraTest { session.update(user::name, "albert").set(user::age, 35) .where(user::id, "==", 123L).sync(); - long cnt = session.count(user).where(user::id, FilterOperator.EQUAL, 123L).sync(); + long cnt = session.count(user).where(user::id, Operator.EQ, 123L).sync(); Assert.assertEquals(1L, cnt); String name = session.select(user::name)