casser concept
This commit is contained in:
parent
e224051645
commit
398b9f8b65
15 changed files with 253 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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
|
||||
|
|
32
src/casser/Example.java
Normal file
32
src/casser/Example.java
Normal file
|
@ -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<String, Integer> 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
20
src/casser/User.java
Normal file
20
src/casser/User.java
Normal file
|
@ -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);
|
||||
|
||||
}
|
20
src/casser/core/Casser.java
Normal file
20
src/casser/core/Casser.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package casser.core;
|
||||
|
||||
import casser.operation.SessionOperation;
|
||||
|
||||
|
||||
public final class Casser {
|
||||
|
||||
public static SessionOperation connect() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <E> E dsl(Class<E> dsl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <E> E pojo(Class<E> dsl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
32
src/casser/core/Session.java
Normal file
32
src/casser/core/Session.java
Normal file
|
@ -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 <V1> SelectOperation<Tuple1<V1>> select(Getter<V1> getter1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <V1, V2> SelectOperation<Tuple2<V1, V2>> select(Getter<V1> getter1, Getter<V2> getter2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <V1, V2, V3> SelectOperation<Tuple3<V1, V2, V3>> select(Getter<V1> getter1, Getter<V2> getter2, Getter<V3> getter3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <V1> UpdateOperation update(Setter<V1> setter1, V1 v1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
7
src/casser/dsl/Getter.java
Normal file
7
src/casser/dsl/Getter.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package casser.dsl;
|
||||
|
||||
public interface Getter<V> {
|
||||
|
||||
V get();
|
||||
|
||||
}
|
7
src/casser/dsl/Setter.java
Normal file
7
src/casser/dsl/Setter.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package casser.dsl;
|
||||
|
||||
public interface Setter<V> {
|
||||
|
||||
void set(V val);
|
||||
|
||||
}
|
16
src/casser/mapping/Table.java
Normal file
16
src/casser/mapping/Table.java
Normal file
|
@ -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 "";
|
||||
|
||||
}
|
17
src/casser/operation/AbstractOperation.java
Normal file
17
src/casser/operation/AbstractOperation.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package casser.operation;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractOperation<E> {
|
||||
|
||||
public Stream<E> sync() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Future<Stream<E>> async() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
18
src/casser/operation/SelectOperation.java
Normal file
18
src/casser/operation/SelectOperation.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package casser.operation;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import casser.dsl.Getter;
|
||||
|
||||
|
||||
public class SelectOperation<E> extends AbstractOperation<E> {
|
||||
|
||||
public <V> SelectOperation<E> where(Getter<V> getter, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <R> SelectOperation<R> map(Function<E, R> fn) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
29
src/casser/operation/SessionOperation.java
Normal file
29
src/casser/operation/SessionOperation.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
12
src/casser/operation/UpdateOperation.java
Normal file
12
src/casser/operation/UpdateOperation.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package casser.operation;
|
||||
|
||||
import casser.dsl.Getter;
|
||||
|
||||
public class UpdateOperation extends AbstractOperation<Object> {
|
||||
|
||||
public <V> UpdateOperation where(Getter<V> getter, V val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
12
src/casser/tuple/Tuple1.java
Normal file
12
src/casser/tuple/Tuple1.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package casser.tuple;
|
||||
|
||||
public final class Tuple1<V1> {
|
||||
|
||||
public final V1 v1;
|
||||
|
||||
public Tuple1(V1 v1) {
|
||||
this.v1 = v1;
|
||||
}
|
||||
|
||||
|
||||
}
|
13
src/casser/tuple/Tuple2.java
Normal file
13
src/casser/tuple/Tuple2.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package casser.tuple;
|
||||
|
||||
public final class Tuple2<V1, V2> {
|
||||
|
||||
public final V1 v1;
|
||||
public final V2 v2;
|
||||
|
||||
public Tuple2(V1 v1, V2 v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
}
|
||||
|
||||
}
|
15
src/casser/tuple/Tuple3.java
Normal file
15
src/casser/tuple/Tuple3.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package casser.tuple;
|
||||
|
||||
public final class Tuple3<V1, V2, V3> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue