This is an automated email from the ASF dual-hosted git repository.
fmartelli pushed a commit to branch SYNCOPE-1400_SYNCOPE-1401
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/SYNCOPE-1400_SYNCOPE-1401 by
this push:
new f9ad5d0 [SYNCOPE-1401] fix json search DAO for mysql
f9ad5d0 is described below
commit f9ad5d0d7799c4f3a56279cf49d50d543d958b57
Author: fmartelli <[email protected]>
AuthorDate: Thu Jan 24 17:55:22 2019 +0100
[SYNCOPE-1401] fix json search DAO for mysql
---
.../persistence/jpa/dao/MyJPAJSONAnySearchDAO.java | 19 ++++++++++++-------
.../persistence/jpa/dao/PGJPAJSONAnySearchDAO.java | 8 ++++----
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/MyJPAJSONAnySearchDAO.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/MyJPAJSONAnySearchDAO.java
index d33701f..a4fa998 100644
---
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/MyJPAJSONAnySearchDAO.java
+++
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/MyJPAJSONAnySearchDAO.java
@@ -61,20 +61,25 @@ public class MyJPAJSONAnySearchDAO extends
AbstractJPAJSONAnySearchDAO {
} else {
attrWhere.append(" OR ");
}
- attrWhere.append("JSON_CONTAINS(plainAttrs,
'[{\"schema\":\"").append(field).append("\"}]'");
+ attrWhere.append("JSON_CONTAINS(plainAttrs,
'[{\"schema\":\"").append(field).append("\"}]')");
nullAttrWhere.append(" UNION SELECT DISTINCT
any_id,").append(svs.table().alias).append(".*, ").
- append("JSON('{\"schema\": \"").
- append(field).
- append("\"})' as attrs, JSON('{}') as
attrValues").
+
append("\"").append(field).append("\"").append(" AS plainShema, ").
+ append("null AS binaryValue, ").
+ append("null AS booleanValue, ").
+ append("null AS dateValue, ").
+ append("null AS doubleValue, ").
+ append("null AS longValue, ").
+ append("null AS stringValue, ").
+ append("null AS attrUniqueValue").
append(" FROM
").append(svs.table().name).append(" ").append(svs.table().alias).
append(", ").append(svs.field().name).
- append(" WHERE ").
- append("any_id NOT IN ").
+ append(" WHERE
any_id=").append(svs.table().alias).append(".id").
+ append(" AND any_id NOT IN ").
append("(SELECT distinct any_id FROM ").
append(svs.field().name).
append(" WHERE
").append(svs.table().alias).append(".id=any_id AND ").
- append("JSON_CONTAINS(plainAttrs,
'[{\"schema\":\"").append(field).append("\"}]')");
+ append("JSON_CONTAINS(plainAttrs,
'[{\"schema\":\"").append(field).append("\"}]'))");
});
where.append(attrWhere).append(nullAttrWhere);
}
diff --git
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
index bd29bf3..b715bc0 100644
---
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
+++
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
@@ -127,10 +127,6 @@ public class PGJPAJSONAnySearchDAO extends
AbstractJPAJSONAnySearchDAO {
fillAttrQuery(anyUtils, query, attrValue, schema, cond, false,
parameters, svs);
query.append(")");
} else {
- String key = key(schema.getType());
- boolean lower = (schema.getType() == AttrSchemaType.String ||
schema.getType() == AttrSchemaType.Enum)
- && (cond.getType() == AttributeCond.Type.IEQ ||
cond.getType() == AttributeCond.Type.ILIKE);
-
if (!not && cond.getType() == AttributeCond.Type.EQ) {
PlainAttr<?> container = anyUtils.newPlainAttr();
container.setSchema(schema);
@@ -144,6 +140,10 @@ public class PGJPAJSONAnySearchDAO extends
AbstractJPAJSONAnySearchDAO {
append(POJOHelper.serialize(Arrays.asList(container))).
append("'::jsonb");
} else {
+ String key = key(schema.getType());
+ boolean lower = (schema.getType() == AttrSchemaType.String ||
schema.getType() == AttrSchemaType.Enum)
+ && (cond.getType() == AttributeCond.Type.IEQ ||
cond.getType() == AttributeCond.Type.ILIKE);
+
query.append("attrs ->> 'schema' =
?").append(setParameter(parameters, cond.getSchema())).
append(" AND ").
append(lower ? "LOWER(" : "").