forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaoBase.java
More file actions
73 lines (56 loc) · 1.59 KB
/
DaoBase.java
File metadata and controls
73 lines (56 loc) · 1.59 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package act.db;
import act.app.security.SecurityContext;
import act.util.ActContext;
import javax.enterprise.context.ApplicationScoped;
import java.lang.annotation.Annotation;
public abstract class DaoBase<ID_TYPE, MODEL_TYPE, QUERY_TYPE extends Dao.Query<MODEL_TYPE, QUERY_TYPE>>
implements Dao<ID_TYPE, MODEL_TYPE, QUERY_TYPE> {
private ActContext appCtx;
private SecurityContext secCtx;
private boolean destroyed;
protected Class<MODEL_TYPE> modelType;
protected Class<ID_TYPE> idType;
public DaoBase(Class<ID_TYPE> idType, Class<MODEL_TYPE> modelType) {
this.idType = idType;
this.modelType = modelType;
}
@Override
public void setAppContext(ActContext context) {
appCtx = context;
}
@Override
public void destroy() {
if (destroyed) return;
destroyed = true;
releaseResources();
appCtx = null;
secCtx = null;
}
@Override
public Class<ID_TYPE> idType() {
return idType;
}
@Override
public Class<MODEL_TYPE> modelType() {
return modelType;
}
@Override
public boolean isDestroyed() {
return destroyed;
}
@Override
public void setSecurityContext(SecurityContext context) {
secCtx = context;
}
protected void releaseResources() {}
@Override
public Class<? extends Annotation> scope() {
return ApplicationScoped.class;
}
protected final ActContext appContext() {
return appCtx;
}
protected final SecurityContext securityContext() {
return secCtx;
}
}