casser concept

This commit is contained in:
Alex Shvid 2015-03-11 20:01:14 -07:00
parent e224051645
commit 398b9f8b65
15 changed files with 253 additions and 0 deletions

3
.gitignore vendored
View file

@ -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
View 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
View 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);
}

View 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;
}
}

View 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() {
}
}

View file

@ -0,0 +1,7 @@
package casser.dsl;
public interface Getter<V> {
V get();
}

View file

@ -0,0 +1,7 @@
package casser.dsl;
public interface Setter<V> {
void set(V val);
}

View 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 "";
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View file

@ -0,0 +1,12 @@
package casser.tuple;
public final class Tuple1<V1> {
public final V1 v1;
public Tuple1(V1 v1) {
this.v1 = v1;
}
}

View 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;
}
}

View 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;
}
}