Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ public RealmSearchDAO realmSearchDAO(
public PlainSchemaRepoExt plainSchemaRepoExt(
final AnyUtilsFactory anyUtilsFactory,
final @Lazy ExternalResourceDAO resourceDAO,
final @Lazy PlainSchemaDAO plainSchemaDAO,
final EntityManager entityManager) {

return new OraclePlainSchemaRepoExtImpl(anyUtilsFactory, resourceDAO, plainSchemaDAO, entityManager);
return new OraclePlainSchemaRepoExtImpl(anyUtilsFactory, resourceDAO, entityManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import jakarta.persistence.Query;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
import org.apache.syncope.core.persistence.api.dao.NotFoundException;
import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
import org.apache.syncope.core.persistence.api.entity.AnyUtils;
import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
Expand All @@ -37,39 +35,51 @@ public class OraclePlainSchemaRepoExtImpl extends AbstractPlainSchemaRepoExt {
protected static final String HAS_ATTRS_QUERY = "SELECT COUNT(id) AS counts FROM %TABLE% "
+ "WHERE JSON_EXISTS(plainAttrs, '$[*]?(@.schema == \"%SCHEMA%\")')";

protected final PlainSchemaDAO plainSchemaDAO;

public OraclePlainSchemaRepoExtImpl(
final AnyUtilsFactory anyUtilsFactory,
final ExternalResourceDAO resourceDAO,
final PlainSchemaDAO plainSchemaDAO,
final EntityManager entityManager) {

super(anyUtilsFactory, resourceDAO, entityManager);
this.plainSchemaDAO = plainSchemaDAO;
}

@Override
public boolean hasAttrs(final PlainSchema schema) {
return hasAttrs(schema, HAS_ATTRS_QUERY, StringUtils.EMPTY);
}

protected boolean existsPlainAttrUniqueValue(
final String table,
final PlainSchema schema,
final String attrValue,
final String attrKey) {

String queryString = new StringBuilder("SELECT COUNT(id) FROM ").append(table).
append(" WHERE ").
append("JSON_EXISTS(plainAttrs, '$[*]?(@.schema == \"").append(schema.getKey()).append("\" ").
append("&& @.uniqueValue.").append(OracleJPAAnySearchDAO.key(schema.getType())).append(" == $value)' ").
append("PASSING ?1 AS \"value\") AND id <> ?2").
toString();

Query query = entityManager.createNativeQuery(queryString);

query.setParameter(1, attrValue);
query.setParameter(2, attrKey);

return ((Number) query.getSingleResult()).longValue() > 0;
}

@Override
public boolean existsPlainAttrUniqueValue(
final String realmKey,
final PlainSchema schema,
final PlainAttrValue attrValue) {

Query query = entityManager.createNativeQuery(
"SELECT COUNT(id) FROM "
+ JPARealm.TABLE + ","
+ OracleJPAAnySearchDAO.from(plainSchemaDAO.findById(schema.getKey()).
orElseThrow(() -> new NotFoundException("PlainSchema " + schema.getKey())))
+ " WHERE " + schema.getKey() + ".uniqueValue=?1 AND id <> ?2");
query.setParameter(1, attrValue.getValue());
query.setParameter(2, realmKey);

return ((Number) query.getSingleResult()).longValue() > 0;
return existsPlainAttrUniqueValue(
JPARealm.TABLE,
schema,
attrValue.getValue().toString(),
realmKey);
}

@Override
Expand All @@ -79,15 +89,10 @@ public boolean existsPlainAttrUniqueValue(
final PlainSchema schema,
final PlainAttrValue attrValue) {

Query query = entityManager.createNativeQuery(
"SELECT COUNT(id) FROM "
+ new SearchSupport(anyUtils.anyTypeKind()).table().name() + ","
+ OracleJPAAnySearchDAO.from(plainSchemaDAO.findById(schema.getKey()).
orElseThrow(() -> new NotFoundException("PlainSchema " + schema.getKey())))
+ " WHERE " + schema.getKey() + ".uniqueValue=?1 AND id <> ?2");
query.setParameter(1, attrValue.getValue());
query.setParameter(2, anyKey);

return ((Number) query.getSingleResult()).longValue() > 0;
return existsPlainAttrUniqueValue(
new SearchSupport(anyUtils.anyTypeKind()).table().name(),
schema,
attrValue.getValue().toString(),
anyKey);
}
}