Search in sources :

Example 1 with ResultMappingException

use of org.seasar.doma.jdbc.ResultMappingException in project doma-spring-boot by domaframework.

the class DomaPersistenceExceptionTranslator method translateExceptionIfPossible.

@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (!(ex instanceof JdbcException)) {
        // Fallback to other translators if not JdbcException
        return null;
    }
    if (ex instanceof OptimisticLockException) {
        return new OptimisticLockingFailureException(ex.getMessage(), ex);
    } else if (ex instanceof UniqueConstraintException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    } else if (ex instanceof NonUniqueResultException || ex instanceof NonSingleColumnException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    } else if (ex instanceof NoResultException) {
        return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
    } else if (ex instanceof UnknownColumnException || ex instanceof ResultMappingException) {
        return new TypeMismatchDataAccessException(ex.getMessage(), ex);
    }
    if (ex.getCause() instanceof SQLException) {
        SQLException e = (SQLException) ex.getCause();
        String sql = null;
        if (ex instanceof SqlExecutionException) {
            sql = ((SqlExecutionException) ex).getRawSql();
        }
        DataAccessException dae = translator.translate(ex.getMessage(), sql, e);
        return (dae != null ? dae : new UncategorizedSQLException(ex.getMessage(), sql, e));
    }
    return new UncategorizedDataAccessException(ex.getMessage(), ex) {
    };
}
Also used : NonUniqueResultException(org.seasar.doma.jdbc.NonUniqueResultException) NonSingleColumnException(org.seasar.doma.jdbc.NonSingleColumnException) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) NoResultException(org.seasar.doma.jdbc.NoResultException) ResultMappingException(org.seasar.doma.jdbc.ResultMappingException) JdbcException(org.seasar.doma.jdbc.JdbcException) TypeMismatchDataAccessException(org.springframework.dao.TypeMismatchDataAccessException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) UncategorizedDataAccessException(org.springframework.dao.UncategorizedDataAccessException) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) UnknownColumnException(org.seasar.doma.jdbc.UnknownColumnException) SqlExecutionException(org.seasar.doma.jdbc.SqlExecutionException) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) UniqueConstraintException(org.seasar.doma.jdbc.UniqueConstraintException) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) DataAccessException(org.springframework.dao.DataAccessException) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) TypeMismatchDataAccessException(org.springframework.dao.TypeMismatchDataAccessException) UncategorizedDataAccessException(org.springframework.dao.UncategorizedDataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 2 with ResultMappingException

use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.

the class AutoFunctionTest method testResultSet_check.

@Test
@Run(unless = { Dbms.MYSQL, Dbms.SQLSERVER })
public void testResultSet_check(Config config) throws Exception {
    FunctionDao dao = new FunctionDaoImpl(config);
    try {
        dao.func_resultset_check(Integer.valueOf(1));
        fail();
    } catch (ResultMappingException ignored) {
        System.err.println(ignored);
    }
}
Also used : FunctionDaoImpl(org.seasar.doma.it.dao.FunctionDaoImpl) ResultMappingException(org.seasar.doma.jdbc.ResultMappingException) FunctionDao(org.seasar.doma.it.dao.FunctionDao) Test(org.junit.jupiter.api.Test) Run(org.seasar.doma.it.Run)

Example 3 with ResultMappingException

use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.

the class AutoProcedureTest method testResultSet_check.

@Test
public void testResultSet_check(Config config) throws Exception {
    ProcedureDao dao = new ProcedureDaoImpl(config);
    List<Employee> employees = new ArrayList<>();
    try {
        dao.proc_resultset_check(employees, 1);
        fail();
    } catch (ResultMappingException ignored) {
        System.err.println(ignored);
    }
}
Also used : ProcedureDao(org.seasar.doma.it.dao.ProcedureDao) Employee(org.seasar.doma.it.entity.Employee) ProcedureDaoImpl(org.seasar.doma.it.dao.ProcedureDaoImpl) ArrayList(java.util.ArrayList) ResultMappingException(org.seasar.doma.jdbc.ResultMappingException) Test(org.junit.jupiter.api.Test)

Example 4 with ResultMappingException

use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.

the class SqlFileSelectTest method testEnsureResultMappping_true.

@Test
public void testEnsureResultMappping_true(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    try {
        dao.selectOnlyNameWithMappingCheck();
        fail();
    } catch (ResultMappingException expected) {
        System.err.print(expected);
    }
}
Also used : EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) ResultMappingException(org.seasar.doma.jdbc.ResultMappingException) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 5 with ResultMappingException

use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.

the class EntityProvider method throwResultMappingException.

protected void throwResultMappingException(Set<EntityPropertyType<ENTITY, ?>> unmappedPropertySet) {
    Naming naming = query.getConfig().getNaming();
    int size = unmappedPropertySet.size();
    List<String> unmappedPropertyNames = new ArrayList<>(size);
    List<String> expectedColumnNames = new ArrayList<>(size);
    for (EntityPropertyType<ENTITY, ?> propertyType : unmappedPropertySet) {
        unmappedPropertyNames.add(propertyType.getName());
        expectedColumnNames.add(propertyType.getColumnName(naming::apply));
    }
    Sql<?> sql = query.getSql();
    throw new ResultMappingException(query.getConfig().getExceptionSqlLogType(), entityType.getEntityClass().getName(), unmappedPropertyNames, expectedColumnNames, sql.getKind(), sql.getRawSql(), sql.getFormattedSql(), sql.getSqlFilePath());
}
Also used : ArrayList(java.util.ArrayList) Naming(org.seasar.doma.jdbc.Naming) ResultMappingException(org.seasar.doma.jdbc.ResultMappingException)

Aggregations

ResultMappingException (org.seasar.doma.jdbc.ResultMappingException)5 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 SQLException (java.sql.SQLException)1 Run (org.seasar.doma.it.Run)1 EmployeeDao (org.seasar.doma.it.dao.EmployeeDao)1 EmployeeDaoImpl (org.seasar.doma.it.dao.EmployeeDaoImpl)1 FunctionDao (org.seasar.doma.it.dao.FunctionDao)1 FunctionDaoImpl (org.seasar.doma.it.dao.FunctionDaoImpl)1 ProcedureDao (org.seasar.doma.it.dao.ProcedureDao)1 ProcedureDaoImpl (org.seasar.doma.it.dao.ProcedureDaoImpl)1 Employee (org.seasar.doma.it.entity.Employee)1 JdbcException (org.seasar.doma.jdbc.JdbcException)1 Naming (org.seasar.doma.jdbc.Naming)1 NoResultException (org.seasar.doma.jdbc.NoResultException)1 NonSingleColumnException (org.seasar.doma.jdbc.NonSingleColumnException)1 NonUniqueResultException (org.seasar.doma.jdbc.NonUniqueResultException)1 OptimisticLockException (org.seasar.doma.jdbc.OptimisticLockException)1 SqlExecutionException (org.seasar.doma.jdbc.SqlExecutionException)1 UniqueConstraintException (org.seasar.doma.jdbc.UniqueConstraintException)1