forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityMetaInfoRepo.java
More file actions
144 lines (118 loc) · 4.25 KB
/
EntityMetaInfoRepo.java
File metadata and controls
144 lines (118 loc) · 4.25 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package act.db.meta;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2018 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import act.app.App;
import act.app.AppServiceBase;
import act.db.CreatedAt;
import act.db.DB;
import act.db.LastModifiedAt;
import act.util.Stateless;
import org.osgl.inject.NamedProvider;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import static act.db.meta.EntityFieldMetaInfo.Trait.*;
/**
* Stores meta information about entity classes. At the moment there
* are two index table maintained in this class:
*
* * index field name by class name for {@link CreatedAt}
* * index field name by class name for {@link LastModifiedAt}
*/
public class EntityMetaInfoRepo extends AppServiceBase<EntityMetaInfoRepo> {
@Stateless
public static class Provider implements javax.inject.Provider<EntityMetaInfoRepo>, NamedProvider<EntityMetaInfoRepo> {
@Inject
private MasterEntityMetaInfoRepo masterRepo;
@Override
public EntityMetaInfoRepo get() {
return get(DB.DEFAULT);
}
@Override
public EntityMetaInfoRepo get(String s) {
return masterRepo.forDb(s);
}
}
Map<String, EntityClassMetaInfo> lookup = new HashMap<>();
Map<Class, EntityClassMetaInfo> lookup2 = new HashMap<>();
EntityMetaInfoRepo(final App app) {
super(app);
}
public void registerEntityOrMappedSuperClass(String className) {
getOrCreate(className);
}
public void registerEntityName(String className, String entityName) {
EntityClassMetaInfo info = getOrCreate(className);
info.entityName(entityName);
}
public void markEntityListenersFound(String className) {
EntityClassMetaInfo info = getOrCreate(className);
info.foundEntityListenersAnnotation();
}
public void registerCreatedField(String className, String fieldName) {
EntityClassMetaInfo info = getOrCreate(className);
info.getOrCreateFieldInfo(fieldName).trait(CREATED);
}
public void registerLastModifiedField(String className, String fieldName) {
EntityClassMetaInfo info = getOrCreate(className);
info.getOrCreateFieldInfo(fieldName).trait(LAST_MODIFIED);
}
public void registerIdField(String className, String fieldName) {
EntityClassMetaInfo info = getOrCreate(className);
info.getOrCreateFieldInfo(fieldName).trait(ID);
}
public void registerColumnName(String className, String fieldName, String columnName) {
EntityClassMetaInfo info = getOrCreate(className);
info.getOrCreateFieldInfo(fieldName).columnName(columnName);
}
public boolean isRegistered(String className) {
return lookup.containsKey(className);
}
public Set<Class> entityClasses() {
return lookup2.keySet();
}
public EntityClassMetaInfo classMetaInfo(Class<?> entityClass) {
return lookup2.get(entityClass);
}
public EntityClassMetaInfo classMetaInfo(String className) {
return lookup.get(className);
}
@Override
protected void releaseResources() {
for (EntityClassMetaInfo classInfo : lookup.values()) {
classInfo.clear();
}
lookup.clear();
}
void register(Class<?> entityClass, EntityClassMetaInfo info) {
lookup2.put(entityClass, info);
lookup.put(entityClass.getName(), info);
}
private EntityClassMetaInfo getOrCreate(String className) {
EntityClassMetaInfo info = lookup.get(className);
if (null == info) {
info = new EntityClassMetaInfo();
info.className(className);
lookup.put(className, info);
}
return info;
}
}