Search in sources :

Example 26 with JdbcSession

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

the class TestSqaleRepositoryBeanConfig method clearDatabase.

/**
 * Taken from `SqaleRepoBaseTest#clearDatabase()` - this is the new repo version of
 * TestSqlRepositoryBeanPostProcessor.
 * No need to clean up the cache tables, only the main and audit tables are cleared.
 */
public void clearDatabase(SqaleRepoContext sqlRepoContext) {
    LOGGER.info("Postprocessing session factory - removing everything from database if necessary.");
    try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
        // Truncate cascades to sub-rows of the "object aggregate" - if FK points to m_object table hierarchy.
        jdbcSession.executeStatement("TRUNCATE m_object CASCADE;");
        // But truncate does not run ON DELETE trigger, many refs/container tables are not cleaned,
        // because their FK references OID pool table. After truncating m_object_oid it cleans all the tables.
        jdbcSession.executeStatement("TRUNCATE m_object_oid CASCADE;");
        jdbcSession.executeStatement("TRUNCATE ma_audit_event CASCADE;");
        jdbcSession.commit();
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession)

Example 27 with JdbcSession

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

the class AddObjectContext method execute.

/**
 * Inserts the object provided to the constructor and returns its OID.
 */
public String execute() throws SchemaException, ObjectAlreadyExistsException {
    try (JdbcSession jdbcSession = repositoryContext.newJdbcSession().startTransaction()) {
        String oid = execute(jdbcSession);
        jdbcSession.commit();
        return oid;
    } catch (QueryException e) {
        // Querydsl exception, not ours
        Throwable cause = e.getCause();
        if (cause instanceof PSQLException) {
            SqaleUtils.handlePostgresException((PSQLException) cause);
        }
        throw e;
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) QueryException(com.querydsl.core.QueryException) PSQLException(org.postgresql.util.PSQLException)

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