From 398b9f8b65d2bc8d3c0fe6585abbd90862df5a57 Mon Sep 17 00:00:00 2001 From: Alex Shvid Date: Wed, 11 Mar 2015 20:01:14 -0700 Subject: [PATCH] casser concept --- .gitignore | 3 ++ src/casser/Example.java | 32 +++++++++++++++++++++ src/casser/User.java | 20 +++++++++++++ src/casser/core/Casser.java | 20 +++++++++++++ src/casser/core/Session.java | 32 +++++++++++++++++++++ src/casser/dsl/Getter.java | 7 +++++ src/casser/dsl/Setter.java | 7 +++++ src/casser/mapping/Table.java | 16 +++++++++++ src/casser/operation/AbstractOperation.java | 17 +++++++++++ src/casser/operation/SelectOperation.java | 18 ++++++++++++ src/casser/operation/SessionOperation.java | 29 +++++++++++++++++++ src/casser/operation/UpdateOperation.java | 12 ++++++++ src/casser/tuple/Tuple1.java | 12 ++++++++ src/casser/tuple/Tuple2.java | 13 +++++++++ src/casser/tuple/Tuple3.java | 15 ++++++++++ 15 files changed, 253 insertions(+) create mode 100644 src/casser/Example.java create mode 100644 src/casser/User.java create mode 100644 src/casser/core/Casser.java create mode 100644 src/casser/core/Session.java create mode 100644 src/casser/dsl/Getter.java create mode 100644 src/casser/dsl/Setter.java create mode 100644 src/casser/mapping/Table.java create mode 100644 src/casser/operation/AbstractOperation.java create mode 100644 src/casser/operation/SelectOperation.java create mode 100644 src/casser/operation/SessionOperation.java create mode 100644 src/casser/operation/UpdateOperation.java create mode 100644 src/casser/tuple/Tuple1.java create mode 100644 src/casser/tuple/Tuple2.java create mode 100644 src/casser/tuple/Tuple3.java diff --git a/.gitignore b/.gitignore index 32858aa..4aa400e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/bin +/.project +/.classpath diff --git a/src/casser/Example.java b/src/casser/Example.java new file mode 100644 index 0000000..fe4b225 --- /dev/null +++ b/src/casser/Example.java @@ -0,0 +1,32 @@ +package casser; + +import casser.core.Casser; +import casser.core.Session; +import casser.tuple.Tuple2; + +public class Example { + + User userDsl = Casser.dsl(User.class); + + Session session = Casser.connect().update(userDsl).get(); + + public static User mapUser(Tuple2 t) { + User user = Casser.pojo(User.class); + user.setName(t.v1); + user.setAge(t.v2); + return user; + } + + public void test() { + + String nameAndAge = session.select(userDsl::getName, userDsl::getAge).where(userDsl::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(); + + session.update(userDsl::setAge, 10).where(userDsl::getId, 100L).async(); + + } + +} diff --git a/src/casser/User.java b/src/casser/User.java new file mode 100644 index 0000000..d00348c --- /dev/null +++ b/src/casser/User.java @@ -0,0 +1,20 @@ +package casser; + +import casser.mapping.Table; + +@Table("user") +public interface User { + + Long getId(); + + void setId(Long id); + + String getName(); + + void setName(String name); + + Integer getAge(); + + void setAge(Integer age); + +} diff --git a/src/casser/core/Casser.java b/src/casser/core/Casser.java new file mode 100644 index 0000000..02acad3 --- /dev/null +++ b/src/casser/core/Casser.java @@ -0,0 +1,20 @@ +package casser.core; + +import casser.operation.SessionOperation; + + +public final class Casser { + + public static SessionOperation connect() { + return null; + } + + public static E dsl(Class dsl) { + return null; + } + + public static E pojo(Class dsl) { + return null; + } + +} diff --git a/src/casser/core/Session.java b/src/casser/core/Session.java new file mode 100644 index 0000000..478eddb --- /dev/null +++ b/src/casser/core/Session.java @@ -0,0 +1,32 @@ +package casser.core; + +import casser.dsl.Getter; +import casser.dsl.Setter; +import casser.operation.SelectOperation; +import casser.operation.UpdateOperation; +import casser.tuple.Tuple1; +import casser.tuple.Tuple2; +import casser.tuple.Tuple3; + +public class Session { + + public SelectOperation> select(Getter getter1) { + return null; + } + + public SelectOperation> select(Getter getter1, Getter getter2) { + return null; + } + + public SelectOperation> select(Getter getter1, Getter getter2, Getter getter3) { + return null; + } + + public UpdateOperation update(Setter setter1, V1 v1) { + return null; + } + + public void close() { + + } +} diff --git a/src/casser/dsl/Getter.java b/src/casser/dsl/Getter.java new file mode 100644 index 0000000..cb81d4b --- /dev/null +++ b/src/casser/dsl/Getter.java @@ -0,0 +1,7 @@ +package casser.dsl; + +public interface Getter { + + V get(); + +} diff --git a/src/casser/dsl/Setter.java b/src/casser/dsl/Setter.java new file mode 100644 index 0000000..2b175c2 --- /dev/null +++ b/src/casser/dsl/Setter.java @@ -0,0 +1,7 @@ +package casser.dsl; + +public interface Setter { + + void set(V val); + +} diff --git a/src/casser/mapping/Table.java b/src/casser/mapping/Table.java new file mode 100644 index 0000000..2f334cc --- /dev/null +++ b/src/casser/mapping/Table.java @@ -0,0 +1,16 @@ +package casser.mapping; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +public @interface Table { + + String value() default ""; + +} diff --git a/src/casser/operation/AbstractOperation.java b/src/casser/operation/AbstractOperation.java new file mode 100644 index 0000000..2582032 --- /dev/null +++ b/src/casser/operation/AbstractOperation.java @@ -0,0 +1,17 @@ +package casser.operation; + +import java.util.concurrent.Future; +import java.util.stream.Stream; + +public abstract class AbstractOperation { + + public Stream sync() { + return null; + } + + public Future> async() { + return null; + } + + +} diff --git a/src/casser/operation/SelectOperation.java b/src/casser/operation/SelectOperation.java new file mode 100644 index 0000000..902a108 --- /dev/null +++ b/src/casser/operation/SelectOperation.java @@ -0,0 +1,18 @@ +package casser.operation; + +import java.util.function.Function; + +import casser.dsl.Getter; + + +public class SelectOperation extends AbstractOperation { + + public SelectOperation where(Getter getter, V val) { + return this; + } + + public SelectOperation map(Function fn) { + return null; + } + +} diff --git a/src/casser/operation/SessionOperation.java b/src/casser/operation/SessionOperation.java new file mode 100644 index 0000000..e35d1f7 --- /dev/null +++ b/src/casser/operation/SessionOperation.java @@ -0,0 +1,29 @@ +package casser.operation; + +import casser.core.Session; + +public class SessionOperation { + + public SessionOperation validate(Object... dsls) { + return this; + } + + public SessionOperation update(Object... dsls) { + return this; + } + + public SessionOperation create(Object... dsls) { + return this; + } + + public SessionOperation createDrop(Object... dsls) { + return this; + } + + public Session get() { + return null; + } + + + +} diff --git a/src/casser/operation/UpdateOperation.java b/src/casser/operation/UpdateOperation.java new file mode 100644 index 0000000..3107987 --- /dev/null +++ b/src/casser/operation/UpdateOperation.java @@ -0,0 +1,12 @@ +package casser.operation; + +import casser.dsl.Getter; + +public class UpdateOperation extends AbstractOperation { + + public UpdateOperation where(Getter getter, V val) { + return this; + } + + +} diff --git a/src/casser/tuple/Tuple1.java b/src/casser/tuple/Tuple1.java new file mode 100644 index 0000000..480cacf --- /dev/null +++ b/src/casser/tuple/Tuple1.java @@ -0,0 +1,12 @@ +package casser.tuple; + +public final class Tuple1 { + + public final V1 v1; + + public Tuple1(V1 v1) { + this.v1 = v1; + } + + +} diff --git a/src/casser/tuple/Tuple2.java b/src/casser/tuple/Tuple2.java new file mode 100644 index 0000000..bdd77e3 --- /dev/null +++ b/src/casser/tuple/Tuple2.java @@ -0,0 +1,13 @@ +package casser.tuple; + +public final class Tuple2 { + + public final V1 v1; + public final V2 v2; + + public Tuple2(V1 v1, V2 v2) { + this.v1 = v1; + this.v2 = v2; + } + +} diff --git a/src/casser/tuple/Tuple3.java b/src/casser/tuple/Tuple3.java new file mode 100644 index 0000000..1446b4d --- /dev/null +++ b/src/casser/tuple/Tuple3.java @@ -0,0 +1,15 @@ +package casser.tuple; + +public final class Tuple3 { + + public final V1 v1; + public final V2 v2; + public final V3 v3; + + public Tuple3(V1 v1, V2 v2, V3 v3) { + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + } + +}