1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.dao;
20
21 import org.apache.commons.lang3.BooleanUtils;
22 import org.apache.commons.lang3.StringUtils;
23 import org.apache.commons.lang3.tuple.Pair;
24 import org.apache.syncope.common.lib.types.AttrSchemaType;
25 import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
26 import org.apache.syncope.core.persistence.api.entity.AnyUtils;
27 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
28 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
29
30 public class OJPAJSONAnyDAO extends AbstractJPAJSONAnyDAO {
31
32 public OJPAJSONAnyDAO(final PlainSchemaDAO plainSchemaDAO) {
33 super(plainSchemaDAO);
34 }
35
36 @Override
37 protected String queryBegin(final String table) {
38 return "SELECT DISTINCT id FROM " + view(table) + ' ';
39 }
40
41 @Override
42 protected Object getAttrValue(
43 final PlainSchema schema,
44 final PlainAttrValue attrValue,
45 final boolean ignoreCaseMatch) {
46
47 return schema.getType() == AttrSchemaType.Boolean
48 ? BooleanUtils.toStringTrueFalse(attrValue.getBooleanValue())
49 : schema.getType() == AttrSchemaType.String && ignoreCaseMatch
50 ? StringUtils.lowerCase(attrValue.getStringValue())
51 : attrValue.getValue();
52 }
53
54 @Override
55 protected String attrValueMatch(
56 final AnyUtils anyUtils,
57 final PlainSchema schema,
58 final PlainAttrValue attrValue,
59 final boolean ignoreCaseMatch) {
60
61 StringBuilder query = new StringBuilder("plainSchema = ? AND ");
62
63 Pair<String, Boolean> schemaInfo = schemaInfo(schema.getType(), ignoreCaseMatch);
64 query.append(schemaInfo.getRight() ? "LOWER(" : "");
65
66 if (schema.isUniqueConstraint()) {
67 query.append("u").append(schemaInfo.getLeft());
68 } else {
69 query.append("JSON_VALUE(").append(schemaInfo.getLeft()).append(", '$[*]')");
70 }
71
72 query.append(schemaInfo.getRight() ? ")" : "").
73 append(" = ").
74 append(schemaInfo.getRight() ? "LOWER(" : "").
75 append('?').append(schemaInfo.getRight() ? ")" : "");
76
77 return query.toString();
78 }
79 }