提交 191dc4dc 编写于 作者: O o2sword

存入缓存的jpa对象要与jpa解绑

上级 fd5a4718
......@@ -41,8 +41,8 @@ public abstract class ElementFactory extends AbstractFactory {
t = this.entityManagerContainer().flag(flag, clz);
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
CacheManager.put(cacheCategory, cacheKey, t );
}
CacheManager.put(cacheCategory, cacheKey, t );
}
return t;
}
......@@ -65,8 +65,8 @@ public abstract class ElementFactory extends AbstractFactory {
appInfo.getId());
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
CacheManager.put(cacheCategory, cacheKey, t );
}
CacheManager.put(cacheCategory, cacheKey, t );
}
return t;
}
......@@ -102,4 +102,4 @@ public abstract class ElementFactory extends AbstractFactory {
return list;
}
}
\ No newline at end of file
}
......@@ -129,6 +129,7 @@ public class ScriptFactory extends ElementFactory {
List<Script> list = em.createQuery( cq.where(p) ).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
script = list.get(0);
em.detach(script);
CacheManager.put(cacheCategory, cacheKey, script );
}
}
......
......@@ -28,10 +28,10 @@ public abstract class ElementFactory extends AbstractFactory {
t = this.entityManagerContainer().flag(flag, clz);
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
CacheManager.put(cacheCategory, cacheKey, t );
}
CacheManager.put(cacheCategory, cacheKey, t );
}
return t;
}
}
\ No newline at end of file
}
......@@ -134,6 +134,7 @@ public class Business {
}else{
config = this.entityManagerContainer().firstEqual(FileConfig.class, FileConfig.person_FIELDNAME, Business.SYSTEM_CONFIG);
if(config != null){
this.entityManagerContainer().get(FileConfig.class).detach(config);
CacheManager.put(cacheCategory, cacheKey, config);
}
}
......
......@@ -50,6 +50,7 @@ abstract class BaseAction extends StandardJaxrsAction {
}else{
config = business.entityManagerContainer().firstEqual(FileConfig.class, FileConfig.person_FIELDNAME, Business.SYSTEM_CONFIG);
if(config != null){
business.entityManagerContainer().get(FileConfig.class).detach(config);
CacheManager.put(cacheCategory, cacheKey, config);
}
}
......
......@@ -50,8 +50,8 @@ public abstract class AbstractFactory {
t = this.entityManagerContainer().flag(flag, clz);
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
CacheManager.put(cacheCategory, cacheKey, t);
}
CacheManager.put(cacheCategory, cacheKey, t);
}
return t;
}
......@@ -71,6 +71,7 @@ public abstract class AbstractFactory {
} else {
T t = this.entityManagerContainer().flag(flag, clz);
if (null != t) {
this.entityManagerContainer().get(clz).detach(t);
list.add(t);
CacheManager.put(cacheCategory, cacheKey, t);
}
......@@ -78,4 +79,4 @@ public abstract class AbstractFactory {
}
return list;
}
}
\ No newline at end of file
}
......@@ -36,9 +36,10 @@ public class BeginFactory extends ElementFactory {
} else {
o = this.entityManagerContainer().firstEqual(Begin.class, Activity.process_FIELDNAME, process.getId());
if (null != o) {
this.entityManagerContainer().get(Begin.class).detach(o);
CacheManager.put(cacheCategory, cacheKey, o);
}
}
return o;
}
}
\ No newline at end of file
}
......@@ -78,6 +78,9 @@ public class ScriptFactory extends ElementFactory {
if (null == script) {
script = this.getWithApplicationWithName(application, uniqueName);
}
if(script != null){
this.entityManagerContainer().get(Script.class).detach(script);
}
return script;
}
......@@ -122,4 +125,4 @@ public class ScriptFactory extends ElementFactory {
}
return null;
}
}
\ No newline at end of file
}
......@@ -92,6 +92,7 @@ public class ElementFactory extends AbstractFactory {
} else {
t = this.entityManagerContainer().find(id, clz);
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
CacheManager.put(cacheCategory, cacheKey, t);
}
}
......@@ -194,7 +195,10 @@ public class ElementFactory extends AbstractFactory {
begin = (Begin) optional.get();
} else {
begin = this.entityManagerContainer().firstEqual(Begin.class, Activity.process_FIELDNAME, id);
CacheManager.put(cacheCategory, cacheKey, begin);
if(begin != null) {
this.entityManagerContainer().get(Begin.class).detach(begin);
CacheManager.put(cacheCategory, cacheKey, begin);
}
}
return begin;
}
......@@ -216,6 +220,9 @@ public class ElementFactory extends AbstractFactory {
Root<Route> root = cq.from(Route.class);
Predicate p = root.get(Route_.id).in(choice.getRouteList());
list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList();
for (Route route : list){
em.detach(route);
}
CacheManager.put(cacheCategory, cacheKey, list);
}
}
......@@ -239,6 +246,9 @@ public class ElementFactory extends AbstractFactory {
Root<Route> root = cq.from(Route.class);
Predicate p = root.get(Route_.id).in(manual.getRouteList());
list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList();
for (Route route : list){
em.detach(route);
}
CacheManager.put(cacheCategory, cacheKey, list);
}
}
......@@ -262,6 +272,9 @@ public class ElementFactory extends AbstractFactory {
Root<Route> root = cq.from(Route.class);
Predicate p = root.get(Route_.id).in(parallel.getRouteList());
list = em.createQuery(cq.where(p).orderBy(cb.asc(root.get(Route_.orderNumber)))).getResultList();
for (Route route : list){
em.detach(route);
}
CacheManager.put(cacheCategory, cacheKey, list);
}
}
......@@ -284,9 +297,12 @@ public class ElementFactory extends AbstractFactory {
List<String> loops = new ArrayList<>();
for (String name : names) {
Script o = this.getScriptWithApplicationWithUniqueName(applicationId, name);
if ((null != o) && (!list.contains(o))) {
list.add(o);
loops.addAll(o.getDependScriptList());
if(null != o){
this.entityManagerContainer().get(Script.class).detach(o);
if(!list.contains(o)){
list.add(o);
loops.addAll(o.getDependScriptList());
}
}
}
names = loops;
......@@ -418,6 +434,9 @@ public class ElementFactory extends AbstractFactory {
p = cb.and(p, cb.or(cb.equal(root.get(Mapping_.process), process), cb.equal(root.get(Mapping_.process), ""),
cb.isNull(root.get(Mapping_.process))));
List<Mapping> os = em.createQuery(cq.where(p)).getResultList();
for (Mapping mapping : os){
em.detach(mapping);
}
os.stream().collect(Collectors.groupingBy(o -> o.getApplication() + o.getTableName()))
.forEach((k, v) -> list.add(v.stream().filter(i -> StringUtils.isNotEmpty(i.getProcess()))
.findFirst().orElse(v.get(0))));
......
......@@ -123,6 +123,7 @@ abstract class BaseAction extends StandardJaxrsAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Invoke invoke = emc.flag(flag, Invoke.class);
if (null != invoke) {
emc.get(Invoke.class).detach(invoke);
CacheManager.put(cacheCategory, cacheKey, invoke);
}
return invoke;
......
......@@ -34,8 +34,8 @@ public class QueryFactory extends AbstractFactory {
list.add((Query) optional.get());
} else {
Query o = this.pickObject(str);
CacheManager.put(cache, cacheKey, o);
if (null != o) {
CacheManager.put(cache, cacheKey, o);
list.add(o);
}
}
......@@ -54,7 +54,9 @@ public class QueryFactory extends AbstractFactory {
o = (Query) optional.get();
} else {
o = this.pickObject(flag);
CacheManager.put(cache, cacheKey, o);
if(o != null) {
CacheManager.put(cache, cacheKey, o);
}
}
return o;
}
......@@ -79,4 +81,4 @@ public class QueryFactory extends AbstractFactory {
}
}
\ No newline at end of file
}
......@@ -78,6 +78,7 @@ class ActionExecute extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
statement = emc.flag(flag, Statement.class);
if (null != statement) {
emc.get(Statement.class).detach(statement);
CacheManager.put(cache, cacheKey, statement);
}
}
......
......@@ -34,8 +34,8 @@ public class QueryFactory extends AbstractFactory {
list.add((Query) optional.get());
} else {
Query o = this.pickObject(str);
CacheManager.put(cache, cacheKey, o);
if (null != o) {
CacheManager.put(cache, cacheKey, o);
list.add(o);
}
}
......@@ -54,7 +54,9 @@ public class QueryFactory extends AbstractFactory {
o = (Query) optional.get();
} else {
o = this.pickObject(flag);
CacheManager.put(cache, cacheKey, o);
if(o != null) {
CacheManager.put(cache, cacheKey, o);
}
}
return o;
}
......@@ -79,4 +81,4 @@ public class QueryFactory extends AbstractFactory {
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册