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);
}
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();
}
}
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();
}
}
}
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;
}
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;
}
Aggregations