Search in sources :

Example 16 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect in project doma by domaframework.

the class BatchModifyCommand method prepareStatement.

protected PreparedStatement prepareStatement(Connection connection, PreparedSql sql) {
    if (query.isAutoGeneratedKeysSupported()) {
        Config config = query.getConfig();
        Dialect dialect = config.getDialect();
        switch(dialect.getAutoGeneratedKeysType()) {
            case FIRST_COLUMN:
                return JdbcUtil.prepareStatementForAutoGeneratedKeysOfFirstColumn(connection, sql);
            case DEFAULT:
                return JdbcUtil.prepareStatementForAutoGeneratedKeys(connection, sql);
        }
    }
    return JdbcUtil.prepareStatement(connection, sql);
}
Also used : Config(org.seasar.doma.jdbc.Config) Dialect(org.seasar.doma.jdbc.dialect.Dialect)

Example 17 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect in project doma by domaframework.

the class BatchModifyCommand method execute.

@Override
public int[] execute() {
    if (!query.isExecutable()) {
        JdbcLogger logger = query.getConfig().getJdbcLogger();
        logger.logSqlExecutionSkipping(query.getClassName(), query.getMethodName(), query.getSqlExecutionSkipCause());
        return new int[] {};
    }
    Connection connection = JdbcUtil.getConnection(query.getConfig().getDataSource());
    try {
        PreparedSql sql = query.getSql();
        PreparedStatement preparedStatement = prepareStatement(connection, sql);
        try {
            setupOptions(preparedStatement);
            return executeInternal(preparedStatement, query.getSqls());
        } catch (SQLException e) {
            Dialect dialect = query.getConfig().getDialect();
            throw new BatchSqlExecutionException(query.getConfig().getExceptionSqlLogType(), sql, e, dialect.getRootCause(e));
        } finally {
            JdbcUtil.close(preparedStatement, query.getConfig().getJdbcLogger());
        }
    } finally {
        JdbcUtil.close(connection, query.getConfig().getJdbcLogger());
    }
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) JdbcLogger(org.seasar.doma.jdbc.JdbcLogger) BatchSqlExecutionException(org.seasar.doma.jdbc.BatchSqlExecutionException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Dialect(org.seasar.doma.jdbc.dialect.Dialect) PreparedStatement(java.sql.PreparedStatement)

Example 18 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect in project doma by domaframework.

the class ModifyCommand method executeUpdate.

protected int executeUpdate(PreparedStatement preparedStatement) throws SQLException {
    try {
        int updatedRows = preparedStatement.executeUpdate();
        validateRows(updatedRows);
        return updatedRows;
    } catch (SQLException e) {
        Dialect dialect = query.getConfig().getDialect();
        if (dialect.isUniqueConstraintViolated(e)) {
            throw new UniqueConstraintException(query.getConfig().getExceptionSqlLogType(), sql, e);
        }
        throw e;
    }
}
Also used : UniqueConstraintException(org.seasar.doma.jdbc.UniqueConstraintException) SQLException(java.sql.SQLException) Dialect(org.seasar.doma.jdbc.dialect.Dialect)

Example 19 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect in project doma by domaframework.

the class ModifyCommand method execute.

@Override
public Integer execute() {
    if (!query.isExecutable()) {
        JdbcLogger logger = query.getConfig().getJdbcLogger();
        logger.logSqlExecutionSkipping(query.getClassName(), query.getMethodName(), query.getSqlExecutionSkipCause());
        return 0;
    }
    Connection connection = JdbcUtil.getConnection(query.getConfig().getDataSource());
    try {
        PreparedStatement preparedStatement = prepareStatement(connection);
        try {
            log();
            setupOptions(preparedStatement);
            bindParameters(preparedStatement);
            return executeInternal(preparedStatement);
        } catch (SQLException e) {
            Dialect dialect = query.getConfig().getDialect();
            throw new SqlExecutionException(query.getConfig().getExceptionSqlLogType(), sql, e, dialect.getRootCause(e));
        } finally {
            JdbcUtil.close(preparedStatement, query.getConfig().getJdbcLogger());
        }
    } finally {
        JdbcUtil.close(connection, query.getConfig().getJdbcLogger());
    }
}
Also used : SqlExecutionException(org.seasar.doma.jdbc.SqlExecutionException) JdbcLogger(org.seasar.doma.jdbc.JdbcLogger) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Dialect(org.seasar.doma.jdbc.dialect.Dialect) PreparedStatement(java.sql.PreparedStatement)

Example 20 with Dialect

use of org.seasar.doma.jdbc.dialect.Dialect in project doma by domaframework.

the class ModuleCommand method execute.

@Override
public RESULT execute() {
    Connection connection = JdbcUtil.getConnection(query.getConfig().getDataSource());
    try {
        CallableStatement callableStatement = JdbcUtil.prepareCall(connection, sql);
        try {
            log();
            setupOptions(callableStatement);
            bindParameters(callableStatement);
            return executeInternal(callableStatement);
        } catch (SQLException e) {
            Dialect dialect = query.getConfig().getDialect();
            throw new SqlExecutionException(query.getConfig().getExceptionSqlLogType(), sql, e, dialect.getRootCause(e));
        } finally {
            JdbcUtil.close(callableStatement, query.getConfig().getJdbcLogger());
        }
    } finally {
        JdbcUtil.close(connection, query.getConfig().getJdbcLogger());
    }
}
Also used : SqlExecutionException(org.seasar.doma.jdbc.SqlExecutionException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) Dialect(org.seasar.doma.jdbc.dialect.Dialect)

Aggregations

Dialect (org.seasar.doma.jdbc.dialect.Dialect)32 Test (org.junit.jupiter.api.Test)11 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)11 Naming (org.seasar.doma.jdbc.Naming)10 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)8 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)8 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)8 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)8 Mssql2008Dialect (org.seasar.doma.jdbc.dialect.Mssql2008Dialect)8 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)8 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)8 PreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder)6 StandardDialect (org.seasar.doma.jdbc.dialect.StandardDialect)6 SQLException (java.sql.SQLException)5 PreparedSql (org.seasar.doma.jdbc.PreparedSql)5 Connection (java.sql.Connection)4 Method (java.lang.reflect.Method)3 PreparedStatement (java.sql.PreparedStatement)3 Test (org.junit.Test)3 SqlExecutionException (org.seasar.doma.jdbc.SqlExecutionException)3