Search in sources :

Example 1 with JdbcSession

use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.

the class SqaleRepoModifyObjectTest method test951ReindexAfterManualChangeOfFullObject.

@Test
public void test951ReindexAfterManualChangeOfFullObject() throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    OperationResult result = createOperationResult();
    UserType user = new UserType(prismContext).name("corrupted").beginAssignment().policySituation("kept").<UserType>end().beginAssignment().policySituation("removed").end();
    String oid = repositoryService.addObject(user.asPrismObject(), null, result);
    when("full object is modified in the database (indices are desynced from full object)");
    user = repositoryService.getObject(UserType.class, oid, null, result).asObjectable();
    // remove removed
    user.getAssignment().remove(1);
    user.beginAssignment().policySituation("added");
    QUserMapping mapping = QUserMapping.getUserMapping();
    byte[] fullObject = mapping.createFullObject(user);
    try (JdbcSession session = mapping.repositoryContext().newJdbcSession().startTransaction()) {
        session.newUpdate(mapping.defaultAlias()).set(mapping.defaultAlias().fullObject, fullObject).where(mapping.defaultAlias().oid.eq(SqaleUtils.oidToUUid(oid))).execute();
        session.commit();
    }
    assertPolicySituationFound("kept", 1, result);
    assertPolicySituationFound("removed", 1, result);
    assertPolicySituationFound("added", 0, result);
    given("object is reindexed");
    RepoModifyOptions options = RepoModifyOptions.createForceReindex();
    repositoryService.modifyObject(UserType.class, oid, Collections.emptyList(), options, result);
    then("indices are updated according new full object");
    assertPolicySituationFound("kept", 1, result);
    assertPolicySituationFound("removed", 0, result);
    assertPolicySituationFound("added", 1, result);
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QUserMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 2 with JdbcSession

use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.

the class BaseSQLRepoTest method select.

protected <S, Q extends FlexibleRelationalPathBase<R>, R> List<R> select(QueryTableMapping<S, Q, R> mapping, Predicate... conditions) {
    try (JdbcSession jdbcSession = createJdbcSession().startReadOnlyTransaction()) {
        Q alias = mapping.defaultAlias();
        SQLQuery<R> query = jdbcSession.newQuery().select(alias).from(alias).where(conditions);
        PrimaryKey<R> primaryKey = alias.getPrimaryKey();
        if (primaryKey != null) {
            for (Path<?> pkColumn : primaryKey.getLocalColumns()) {
                if (pkColumn instanceof ComparablePath) {
                    query.orderBy(((ComparablePath<?>) pkColumn).asc());
                }
            }
        }
        return query.fetch();
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) ComparablePath(com.querydsl.core.types.dsl.ComparablePath)

Example 3 with JdbcSession

use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.

the class SqaleQueryContext method beforeQuery.

@Override
public void beforeQuery() {
    if (containsOrgFilter) {
        try (JdbcSession jdbcSession = repositoryContext().newJdbcSession().startTransaction()) {
            jdbcSession.executeStatement("CALL m_refresh_org_closure()");
            jdbcSession.commit();
        }
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession)

Example 4 with JdbcSession

use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.

the class UriCache method retrieveUriFromDb.

private String retrieveUriFromDb(Integer id) {
    MUri row;
    try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startReadOnlyTransaction()) {
        row = jdbcSession.newQuery().select(QUri.DEFAULT).from(QUri.DEFAULT).where(QUri.DEFAULT.id.eq(id)).fetchOne();
    }
    if (row == null) {
        return null;
    }
    updateMaps(row);
    return row.uri;
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MUri(com.evolveum.midpoint.repo.sqale.qmodel.common.MUri)

Example 5 with JdbcSession

use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.

the class UriCache method retrieveIdFromDb.

private Integer retrieveIdFromDb(String uriString) {
    MUri row;
    try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startReadOnlyTransaction()) {
        row = jdbcSession.newQuery().select(QUri.DEFAULT).from(QUri.DEFAULT).where(QUri.DEFAULT.uri.eq(uriString)).fetchOne();
    }
    if (row == null) {
        return null;
    }
    updateMaps(row);
    return row.id;
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MUri(com.evolveum.midpoint.repo.sqale.qmodel.common.MUri)

Aggregations

JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)27 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)4 MExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem)4 QExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 NotNull (org.jetbrains.annotations.NotNull)4 MUri (com.evolveum.midpoint.repo.sqale.qmodel.common.MUri)3 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)3 Test (org.testng.annotations.Test)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 RepoModifyOptions (com.evolveum.midpoint.repo.api.RepoModifyOptions)2 Jsonb (com.evolveum.midpoint.repo.sqale.jsonb.Jsonb)2 QUri (com.evolveum.midpoint.repo.sqale.qmodel.common.QUri)2 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)2 QUserMapping (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping)2 Instant (java.time.Instant)2 QName (javax.xml.namespace.QName)2