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);
}
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());
}
}
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;
}
}
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());
}
}
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());
}
}
Aggregations