Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ghsby
o2oa
提交
38257d69
o2oa
项目概览
ghsby
/
o2oa
落后 Fork 源项目 2880 个版本
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
38257d69
编写于
9月 10, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
x_base_core_project fixed
上级
85107334
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
94 deletion
+15
-94
o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java
...ava/com/x/base/core/container/EntityManagerContainer.java
+10
-15
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/StandardJaxrsAction.java
...va/com/x/base/core/project/jaxrs/StandardJaxrsAction.java
+5
-79
未找到文件。
o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java
浏览文件 @
38257d69
...
...
@@ -10,6 +10,7 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Map.Entry
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
javax.persistence.EntityManager
;
import
javax.persistence.Query
;
...
...
@@ -244,7 +245,8 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
CriteriaQuery
<
T
>
cq
=
cb
.
createQuery
(
cls
);
Root
<
T
>
root
=
cq
.
from
(
cls
);
Predicate
p
=
cb
.
equal
(
root
.
get
(
field
.
getName
()),
flag
);
List
<
T
>
list
=
em
.
createQuery
(
cq
.
select
(
root
).
where
(
p
).
distinct
(
true
)).
setMaxResults
(
2
).
getResultList
();
List
<
T
>
list
=
em
.
createQuery
(
cq
.
select
(
root
).
where
(
p
)).
setMaxResults
(
2
).
getResultList
().
stream
().
distinct
()
.
collect
(
Collectors
.
toList
());
switch
(
list
.
size
())
{
case
0
:
break
;
...
...
@@ -252,7 +254,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
t
=
list
.
get
(
0
);
break
out
;
case
2
:
throw
new
Exception
(
"flag get multiple entity flag:"
+
flag
+
", class:"
+
cls
.
getName
()
throw
new
IllegalState
Exception
(
"flag get multiple entity flag:"
+
flag
+
", class:"
+
cls
.
getName
()
+
", attribute:"
+
field
.
getName
()
+
"."
);
}
}
...
...
@@ -265,7 +267,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
private
<
T
extends
JpaObject
>
List
<
T
>
flag
(
List
<
String
>
FLAGS
,
Class
<
T
>
cls
,
List
<
Field
>
fields
)
throws
Exception
{
if
(
ListTools
.
isEmpty
(
fields
))
{
throw
new
Exception
(
"attributes can not be empty."
);
throw
new
IllegalState
Exception
(
"attributes can not be empty."
);
}
List
<
T
>
list
=
new
ArrayList
<>();
if
(
ListTools
.
isEmpty
(
FLAGS
))
{
...
...
@@ -582,9 +584,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
CriteriaQuery
<
T
>
cq
=
cb
.
createQuery
(
cls
);
Root
<
T
>
root
=
cq
.
from
(
cls
);
cq
.
select
(
root
).
where
(
cb
.
isMember
(
root
.
get
(
attribute
),
cb
.
literal
(
values
)));
List
<
T
>
os
=
em
.
createQuery
(
cq
.
distinct
(
true
)).
getResultList
();
List
<
T
>
list
=
new
ArrayList
<>(
os
);
return
list
;
return
new
ArrayList
<>(
em
.
createQuery
(
cq
).
getResultList
().
stream
().
distinct
().
collect
(
Collectors
.
toList
()));
}
public
<
T
extends
JpaObject
>
List
<
T
>
listIsMember
(
Class
<
T
>
cls
,
String
attribute
,
Object
value
)
throws
Exception
{
...
...
@@ -888,9 +888,8 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
CriteriaQuery
<
String
>
cq
=
cb
.
createQuery
(
String
.
class
);
Root
<
T
>
root
=
cq
.
from
(
cls
);
cq
.
select
(
root
.
get
(
JpaObject
.
id_FIELDNAME
)).
where
(
cb
.
isMember
(
root
.
get
(
attribute
),
cb
.
literal
(
values
)));
List
<
String
>
os
=
em
.
createQuery
(
cq
.
distinct
(
true
)).
getResultList
();
List
<
String
>
list
=
new
ArrayList
<>(
os
);
return
list
;
return
new
ArrayList
<>(
em
.
createQuery
(
cq
).
getResultList
().
stream
().
distinct
().
collect
(
Collectors
.
toList
()));
}
public
<
T
extends
JpaObject
,
W
extends
Object
>
List
<
String
>
idsNotIn
(
Class
<
T
>
cls
,
String
attribute
,
...
...
@@ -900,9 +899,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
CriteriaQuery
<
String
>
cq
=
cb
.
createQuery
(
String
.
class
);
Root
<
T
>
root
=
cq
.
from
(
cls
);
cq
.
select
(
root
.
get
(
JpaObject
.
id_FIELDNAME
)).
where
(
cb
.
not
(
root
.
get
(
attribute
).
in
(
values
)));
List
<
String
>
os
=
em
.
createQuery
(
cq
.
distinct
(
true
)).
getResultList
();
List
<
String
>
list
=
new
ArrayList
<>(
os
);
return
list
;
return
new
ArrayList
<>(
em
.
createQuery
(
cq
).
getResultList
().
stream
().
distinct
().
collect
(
Collectors
.
toList
()));
}
public
<
T
extends
JpaObject
,
W
extends
Object
>
List
<
String
>
idsEqualAndNotIn
(
Class
<
T
>
cls
,
String
attribute
,
...
...
@@ -914,9 +911,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
Predicate
p
=
cb
.
not
(
root
.
get
(
attribute
).
in
(
values
));
p
=
cb
.
and
(
p
,
cb
.
equal
(
root
.
get
(
otherAttribute
),
otherValue
));
cq
.
select
(
root
.
get
(
JpaObject
.
id_FIELDNAME
)).
where
(
p
);
List
<
String
>
os
=
em
.
createQuery
(
cq
.
distinct
(
true
)).
getResultList
();
List
<
String
>
list
=
new
ArrayList
<>(
os
);
return
list
;
return
new
ArrayList
<>(
em
.
createQuery
(
cq
).
getResultList
().
stream
().
distinct
().
collect
(
Collectors
.
toList
()));
}
public
<
T
extends
JpaObject
>
List
<
String
>
idsIsMember
(
Class
<
T
>
cls
,
String
attribute
,
Object
value
)
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/StandardJaxrsAction.java
浏览文件 @
38257d69
...
...
@@ -624,7 +624,7 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
ListOrderedMap
<
String
,
Collection
<?>>
notIns
,
ListOrderedMap
<
String
,
Object
>
members
,
ListOrderedMap
<
String
,
Object
>
notMembers
,
boolean
andJoin
,
String
order
)
throws
Exception
{
EntityManager
em
=
emc
.
get
(
cls
);
String
str
=
"SELECT count(
distinct
o) FROM "
+
cls
.
getCanonicalName
()
+
" o"
;
String
str
=
"SELECT count(o) FROM "
+
cls
.
getCanonicalName
()
+
" o"
;
/* 预编译的SQL语句的参数序号,必须由1开始 */
Integer
index
=
1
;
List
<
String
>
ps
=
new
ArrayList
<>();
...
...
@@ -696,80 +696,6 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
return
(
Long
)
query
.
getSingleResult
()
+
1
;
}
// private <T extends JpaObject> Long count(EntityManagerContainer emc, Class<T>
// cls, EqualsTerms equals,
// NotEqualsTerms notEquals, LikeTerms likes, InTerms ins, NotInTerms notIns,
// MemberTerms members,
// NotMemberTerms notMembers, boolean andJoin) throws Exception {
// EntityManager em = emc.get(cls);
// String str = "SELECT count(distinct o) FROM " + cls.getCanonicalName() + "
// o";
// /* 预编译的SQL语句的参数序号,必须由1开始 */
// Integer index = 1;
// List<String> ps = new ArrayList<>();
// List<Object> vs = new ArrayList<>();
// if (null != equals && (!equals.isEmpty())) {
// for (Entry<String, Object> en : equals.entrySet()) {
// ps.add("o." + en.getKey() + (" = ?" + index));
// vs.add(en.getValue());
// index++;
// }
// }
// if (null != notEquals && (!notEquals.isEmpty())) {
// for (Entry<String, Object> en : notEquals.entrySet()) {
// ps.add("(o." + en.getKey() + (" <> ?" + index) + " or o." + en.getKey() + "
// is null)");
// vs.add(en.getValue());
// index++;
// }
// }
// if (null != likes && (!likes.isEmpty())) {
// List<String> ors = new ArrayList<>();
// for (Entry<String, Object> en : likes.entrySet()) {
// ors.add("o." + en.getKey() + (" Like ?" + index));
// vs.add("%" + en.getValue() + "%");
// index++;
// }
// ps.add("(" + StringUtils.join(ors, " or ") + ")");
// }
// if (null != ins && (!ins.isEmpty())) {
// for (Entry<String, Collection<?>> en : ins.entrySet()) {
// ps.add("o." + en.getKey() + (" in ?" + index));
// vs.add(en.getValue());
// index++;
// }
// }
// if (null != notIns && (!notIns.isEmpty())) {
// for (Entry<String, Collection<?>> en : notIns.entrySet()) {
// ps.add("o." + en.getKey() + (" not in ?" + index));
// vs.add(en.getValue());
// index++;
// }
// }
// if (null != members && (!members.isEmpty())) {
// for (Entry<String, Object> en : members.entrySet()) {
// ps.add(("?" + index) + (" member of o." + en.getKey()));
// vs.add(en.getValue());
// index++;
// }
// }
// if (null != notMembers && (!notMembers.isEmpty())) {
// for (Entry<String, Object> en : notMembers.entrySet()) {
// ps.add(("?" + index) + (" not member of o." + en.getKey()));
// vs.add(en.getValue());
// index++;
// }
// }
// if (!ps.isEmpty()) {
// str += " where " + StringUtils.join(ps, (andJoin ? " and " : " or "));
// }
// Query query = em.createQuery(str, cls);
// for (int i = 0; i < vs.size(); i++) {
// query.setParameter(i + 1, vs.get(i));
// }
// return (Long) query.getSingleResult();
// }
private
<
T
extends
JpaObject
>
Long
count
(
EntityManagerContainer
emc
,
Class
<
T
>
cls
,
EqualsTerms
equals
,
NotEqualsTerms
notEquals
,
LikeTerms
likes
,
InTerms
ins
,
NotInTerms
notIns
,
MemberTerms
members
,
NotMemberTerms
notMembers
,
boolean
andJoin
)
throws
Exception
{
...
...
@@ -1121,7 +1047,7 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
selections
.
add
(
root
.
get
(
field
));
}
List
<
Tuple
>
os
=
em
.
createQuery
(
cq
.
multiselect
(
selections
)
.
distinct
(
true
)
)
List
<
Tuple
>
os
=
em
.
createQuery
(
cq
.
multiselect
(
selections
))
.
setMaxResults
(
Math
.
max
(
Math
.
min
(
count
,
list_max
),
list_min
)).
getResultList
();
List
<
W
>
ws
=
new
ArrayList
<
W
>();
...
...
@@ -1181,7 +1107,7 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
selections
.
add
(
root
.
get
(
field
));
}
List
<
Tuple
>
os
=
em
.
createQuery
(
cq
.
multiselect
(
selections
)
.
distinct
(
true
)
)
List
<
Tuple
>
os
=
em
.
createQuery
(
cq
.
multiselect
(
selections
))
.
setMaxResults
(
Math
.
max
(
Math
.
min
(
count
,
list_max
),
list_min
)).
getResultList
();
List
<
W
>
ws
=
new
ArrayList
<
W
>();
...
...
@@ -1236,8 +1162,8 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
cq
.
orderBy
(
cb
.
asc
(
root
.
get
(
sequenceField
)));
}
List
<
T
>
os
=
em
.
createQuery
(
cq
.
select
(
root
)
.
distinct
(
true
))
.
setMaxResults
(
Math
.
max
(
Math
.
min
(
count
,
list_max
),
list_min
)).
getResultList
();
List
<
T
>
os
=
em
.
createQuery
(
cq
.
select
(
root
)
).
setMaxResults
(
Math
.
max
(
Math
.
min
(
count
,
list_max
),
list_min
))
.
getResultList
();
ActionResult
<
List
<
T
>>
result
=
new
ActionResult
<>();
result
.
setData
(
new
ArrayList
<
T
>(
os
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录