use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleRepoBaseTest method extKey.
@NotNull
private String extKey(Containerable extContainer, String itemName, MExtItemHolderType holder) {
PrismContainerValue<?> pcv = extContainer.asPrismContainerValue();
ItemDefinition<?> def = pcv.getDefinition().findItemDefinition(new ItemName(itemName));
MExtItem.Key key = MExtItem.keyFrom(def, holder);
try (JdbcSession jdbcSession = startReadOnlyTransaction()) {
QExtItem ei = QExtItem.DEFAULT;
return jdbcSession.newQuery().from(ei).where(ei.itemName.eq(key.itemName).and(ei.valueType.eq(key.valueType)).and(ei.holderType.eq(key.holderType)).and(ei.cardinality.eq(key.cardinality))).select(ei.id).fetchFirst().toString();
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleRepoBaseTest method refreshOrgClosureForce.
protected void refreshOrgClosureForce() {
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.executeStatement("CALL m_refresh_org_closure(true)");
jdbcSession.commit();
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleRepoSearchIterativeTest method test125SearchIterativeWithCustomOrdering.
@Test
public void test125SearchIterativeWithCustomOrdering() throws Exception {
OperationResult operationResult = createOperationResult();
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
pm.clearGlobalPerformanceInformation();
given("query with custom ordering");
ObjectQuery query = prismContext.queryFor(UserType.class).asc(UserType.F_COST_CENTER).maxSize(// see the limit below
47).build();
when("calling search iterative");
SearchResultMetadata metadata = searchObjectsIterative(query, operationResult);
then("result metadata is not null and reports partial result (because of the break)");
assertThatOperationResult(operationResult).isSuccess();
assertThat(metadata).isNotNull();
assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
// everything was processed
assertThat(metadata.isPartialResults()).isFalse();
and("search operations were called");
assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
assertTypicalPageOperationCount(metadata);
and("all objects were processed in proper order");
QUser u = aliasFor(QUser.class);
try (JdbcSession jdbcSession = startReadOnlyTransaction()) {
List<String> result = jdbcSession.newQuery().from(u).orderBy(u.costCenter.asc(), u.oid.asc()).select(u.employeeNumber).limit(// must match the maxSize above
47).fetch();
for (int i = 1; i < result.size(); i++) {
// order matches
assertThat(result.get(i)).isEqualTo(getTestNumber() + "-" + i);
}
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test952ReindexFixingColumnsOutOfSync.
@Test
public void test952ReindexFixingColumnsOutOfSync() throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
OperationResult result = createOperationResult();
given("user existing in the repository");
String name = "user" + getTestNumber();
UserType user = new UserType(prismContext).name(name).emailAddress(name + "@goodmail.com").subtype("subtype-1").subtype("subtype-2").assignment(new AssignmentType(prismContext).order(1));
String oid = repositoryService.addObject(user.asPrismObject(), null, result);
and("object aggregate is modified in the DB (simulating out-of-sync data)");
QAssignment<MObject> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
UUID oidUuid = UUID.fromString(oid);
try (JdbcSession jdbcSession = startTransaction()) {
jdbcSession.newInsert(a).set(a.ownerOid, oidUuid).set(a.cid, -1L).set(a.containerType, MContainerType.ASSIGNMENT).set(a.ownerType, MObjectType.USER).set(a.orderValue, // test number, hopefully unique
952).execute();
QUser u = QUserMapping.getUserMapping().defaultAlias();
jdbcSession.newUpdate(u).set(u.emailAddress, "bad@badmail.com").set(u.subtypes, new String[] { "subtype-952" }).set(u.costCenter, "invasive value").where(u.oid.eq(oidUuid)).execute();
jdbcSession.commit();
}
and("search provides obviously bad results");
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_EMAIL_ADDRESS).eq(name + "@goodmail.com").build(), result)).isEmpty();
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_COST_CENTER).eq("invasive value").build(), result)).hasSize(// can find by bad value, that's wrong
1);
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_ASSIGNMENT, AssignmentType.F_ORDER).eq(952).build(), result)).hasSize(// can find by wrong assignment
1);
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_SUBTYPE).eq("subtype-952").build(), result)).hasSize(// can find by wrong subtype
1);
when("reindex is called to fix it");
repositoryService.modifyObject(UserType.class, oid, Collections.emptyList(), RepoModifyOptions.createForceReindex(), result);
then("the searches work as expected");
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_EMAIL_ADDRESS).eq(name + "@goodmail.com").build(), result)).hasSize(1).extracting(o -> o.getOid()).containsExactlyInAnyOrder(// can find by the original mail, that's good!
oid);
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_COST_CENTER).eq("invasive value").build(), result)).isEmpty();
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_ASSIGNMENT, AssignmentType.F_ORDER).eq(952).build(), result)).isEmpty();
assertThat(repositorySearchObjects(UserType.class, prismContext.queryFor(UserType.class).item(UserType.F_ASSIGNMENT, AssignmentType.F_ORDER).eq(1).build(), result)).extracting(o -> o.getOid()).contains(// good, can have more results, but our user is there too
oid);
and("database values are as good as new");
MUser userRow = selectObjectByOid(QUser.class, oid);
// tested by search above as well
assertThat(userRow.emailAddress).isEqualTo(name + "@goodmail.com");
assertThat(userRow.costCenter).isNull();
assertThat(userRow.subtypes).containsExactlyInAnyOrder("subtype-1", "subtype-2");
List<MAssignment> assRows = select(a, a.ownerOid.eq(oidUuid));
// single row with proper order is returned, wrong row is gone
assertThat(assRows).hasSize(1);
assertThat(assRows.get(0).orderValue).isEqualTo(1);
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SequenceConcurrencyTest method concurrencyUniversal.
private void concurrencyUniversal(long duration, WorkerThread[] workerThreads, boolean alwaysOrder) throws Exception {
try (JdbcSession jdbcSession = startTransaction()) {
System.out.println(">>>>" + jdbcSession.connection().getTransactionIsolation());
}
OperationResult result = createOperationResult();
String oid = repositoryService.addObject(new SequenceType(prismContext).name(getTestNameShort()).counter(0L).maxUnusedValues(10).asPrismObject(), null, result);
display("*** Object added: " + oid + " ***");
display("*** Starting modifier threads ***");
for (WorkerThread t : workerThreads) {
t.setOid(oid);
t.start();
}
display("*** Waiting " + duration + " ms ***");
Thread.sleep(duration);
for (WorkerThread t : workerThreads) {
t.stop = true;
}
long endTime = System.currentTimeMillis() + STOP_TIMEOUT;
for (; ; ) {
long remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
for (WorkerThread t : workerThreads) {
t.join(remaining);
remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
}
}
for (WorkerThread t : workerThreads) {
display("Worker thread " + t.id + " finished after " + t.counter + " iterations with result: " + (t.threadResult != null ? t.threadResult : "OK"));
}
for (WorkerThread t : workerThreads) {
if (t.threadResult != null) {
throw new AssertionError("Worker thread " + t.id + " finished with an exception: " + t.threadResult, t.threadResult);
}
}
List<Long> allValues = new ArrayList<>();
for (WorkerThread t : workerThreads) {
allValues.addAll(t.values);
}
if (alwaysOrder || workerThreads.length > 1) {
Collections.sort(allValues);
}
logger.trace("Checking a list of {} values", allValues.size());
for (int i = 0; i < allValues.size(); i++) {
if (allValues.get(i) != i) {
logger.error("Incorrect value at position {}: {}", i, allValues.get(i));
for (WorkerThread t : workerThreads) {
display("Thread " + t.id + ": " + t.values);
}
fail("Incorrect value at position " + i + ": " + allValues.get(i));
}
}
}
Aggregations