-
Notifications
You must be signed in to change notification settings - Fork 0
/
LookupBean.groovy
40 lines (36 loc) · 896 Bytes
/
LookupBean.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.lang.annotation.*
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Entity {
String table();
}
@Entity(table = 'user')
class User {}
class LookupBeanService {
enum LookupType {
Create, Find, Delete
}
LookupType cmd
Class type
Map<String, String> params
def "find some records"(v) {
cmd = LookupType.Find
this
}
def of(Class type) {
this.type = type
this
}
def given(params) {
this.params = params
_lookup()
}
private def _lookup() {
def where = params.collect { k, v -> "$k = '$v'" }.join(' and ')
def table = this.type.getAnnotation(Entity).table()
"select * from $table where $where"
}
}
new LookupBeanService().with {
"find some records" of(User) given([name: "Dan Woods", twitter: "@danveloper"])
}