Search in sources :

Example 6 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.

the class StringListTest method shouldFailFastIfCollectionTypeIsAmbiguous.

@Test
void shouldFailFastIfCollectionTypeIsAmbiguous() throws Exception {
    try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/stringlist/mybatis-config-invalid.xml")) {
        new SqlSessionFactoryBuilder().build(reader);
        fail("Should throw exception when collection type is unresolvable.");
    } catch (PersistenceException e) {
        assertTrue(e.getMessage().contains("Ambiguous collection type for property 'groups'. You must specify 'javaType' or 'resultMap'."));
    }
}
Also used : PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.jupiter.api.Test) BaseDataTest(org.apache.ibatis.BaseDataTest)

Example 7 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project sonarqube by SonarSource.

the class ThreadLocalSettingsTest method getProperties_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache.

@Test
public void getProperties_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache() {
    SettingLoader settingLoaderMock = mock(SettingLoader.class);
    PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
    doThrow(toBeThrown).when(settingLoaderMock).loadAll();
    underTest = new ThreadLocalSettings(new PropertyDefinitions(system), new Properties(), settingLoaderMock);
    underTest.load();
    assertThat(underTest.getProperties()).isEmpty();
}
Also used : CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class ClassificationQueryImpl method list.

@Override
public List<ClassificationSummary> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<ClassificationSummary> result = null;
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        result = taskanaEngine.getSqlSession().selectList(LINK_TO_SUMMARYMAPPER, this, rowBounds);
        return result;
    } catch (Exception e) {
        if (e instanceof PersistenceException) {
            if (e.getMessage().contains("ERRORCODE=-4470")) {
                TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
                ex.setStackTrace(e.getStackTrace());
                throw ex;
            }
        }
        throw e;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException)

Example 9 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class WorkbasketAccessItemQueryImpl method list.

@Override
public List<WorkbasketAccessItem> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<WorkbasketAccessItem> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        List<WorkbasketAccessItemImpl> foundAccessItms = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
        result.addAll(foundAccessItms);
        return result;
    } catch (PersistenceException e) {
        if (e.getMessage().contains("ERRORCODE=-4470")) {
            TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
        throw e;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException)

Example 10 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class WorkbasketQueryImpl method list.

@Override
public List<WorkbasketSummary> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<WorkbasketSummary> workbaskets = null;
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        handleCallerRolesAndAccessIds();
        workbaskets = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
        return workbaskets;
    } catch (PersistenceException e) {
        if (e.getMessage().contains("ERRORCODE=-4470")) {
            TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
        throw e;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(workbaskets));
        }
    }
}
Also used : PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Aggregations

PersistenceException (org.apache.ibatis.exceptions.PersistenceException)17 BaseDataTest (org.apache.ibatis.BaseDataTest)6 Test (org.junit.jupiter.api.Test)6 Properties (java.util.Properties)5 RowBounds (org.apache.ibatis.session.RowBounds)5 SqlSession (org.apache.ibatis.session.SqlSession)5 Test (org.junit.Test)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 CorePropertyDefinitions (org.sonar.core.config.CorePropertyDefinitions)5 TaskanaRuntimeException (pro.taskana.exceptions.TaskanaRuntimeException)5 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)2 ClassificationSummary (pro.taskana.ClassificationSummary)2 Duration (java.time.Duration)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Attachment (pro.taskana.Attachment)1 TaskSummary (pro.taskana.TaskSummary)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketSummary (pro.taskana.WorkbasketSummary)1