use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class AutoBatchInsertTest method testIdNotAssigned.
@Test
public void testIdNotAssigned(Config config) throws Exception {
DepartmentDao dao = new DepartmentDaoImpl(config);
Department department = new Department();
department.setDepartmentNo(99);
department.setDepartmentName("hoge");
Department department2 = new Department();
department2.setDepartmentNo(98);
department2.setDepartmentName("hoge");
try {
dao.insert(Arrays.asList(department, department2));
fail();
} catch (JdbcException expected) {
assertEquals(Message.DOMA2020, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class MssqlPagingTransformer method visitSelectStatementNode.
@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
if (processed) {
return node;
}
processed = true;
if (!forceOffsetFetch && offset <= 0) {
return super.appendTopNode(node);
}
OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
if (originalOrderBy == null) {
throw new JdbcException(Message.DOMA2201);
}
OrderByClauseNode orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
for (SqlNode child : originalOrderBy.getChildren()) {
orderBy.appendNode(child);
}
String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
orderBy.appendNode(new FragmentNode(" offset "));
orderBy.appendNode(new FragmentNode(offset));
orderBy.appendNode(new FragmentNode(" rows"));
if (this.limit > 0) {
orderBy.appendNode(new FragmentNode(" fetch next "));
orderBy.appendNode(new FragmentNode(String.valueOf(this.limit)));
orderBy.appendNode(new FragmentNode(" rows only"));
}
SelectStatementNode result = new SelectStatementNode();
result.setSelectClauseNode(node.getSelectClauseNode());
result.setFromClauseNode(node.getFromClauseNode());
result.setWhereClauseNode(node.getWhereClauseNode());
result.setGroupByClauseNode(node.getGroupByClauseNode());
result.setHavingClauseNode(node.getHavingClauseNode());
result.setOrderByClauseNode(orderBy);
result.setForUpdateClauseNode(node.getForUpdateClauseNode());
result.setOptionClauseNode(node.getOptionClauseNode());
return result;
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class LocalTransaction method commit.
/**
* Commits this transaction.
*
* @throws TransactionNotYetBegunException if this transaction is not yet begun
* @throws JdbcException if a JDBC related error occurs
*/
public void commit() {
LocalTransactionContext context = localTxContextHolder.get();
if (!isActiveInternal(context)) {
throw new TransactionNotYetBegunException(Message.DOMA2046);
}
if (context.hasConnection()) {
LocalTransactionConnection connection = context.getConnection();
try {
connection.commit();
jdbcLogger.logTransactionCommitted(className, "commit", context.getId());
} catch (SQLException e) {
rollbackInternal("commit");
throw new JdbcException(Message.DOMA2043, e, e);
} finally {
end("commit");
}
} else {
end("commit");
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class LocalTransaction method releaseSavepoint.
/**
* Removes the specified save point and subsequent save points from this transaction.
*
* @param savepointName the name of the save point
* @throws DomaNullPointerException if the {@code savepointName} is {@code null}
* @throws TransactionNotYetBegunException if this transaction is not yet begun
* @throws JdbcException if a JDBC related error occurs
*/
public void releaseSavepoint(String savepointName) {
if (savepointName == null) {
rollbackInternal("releaseSavepoint");
throw new DomaNullPointerException("savepointName");
}
LocalTransactionContext context = localTxContextHolder.get();
if (!isActiveInternal(context)) {
throw new TransactionNotYetBegunException(Message.DOMA2061, savepointName);
}
String id = context.getId();
Savepoint savepoint = context.releaseAndGetSavepoint(savepointName);
if (savepoint == null) {
rollbackInternal("releaseSavepoint");
throw new SavepointNotFoundException(savepointName);
}
LocalTransactionConnection connection = context.getConnection();
try {
connection.releaseSavepoint(savepoint);
} catch (SQLException e) {
rollbackInternal("releaseSavepoint");
throw new JdbcException(Message.DOMA2060, e, savepointName, e);
}
jdbcLogger.logTransactionSavepointReleased(className, "releaseSavepoint", id, savepointName);
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class StandardDialect method transformSelectSqlNode.
@Override
public SqlNode transformSelectSqlNode(SqlNode sqlNode, SelectOptions options) {
if (sqlNode == null) {
throw new DomaNullPointerException("sqlNode");
}
if (options == null) {
throw new DomaNullPointerException("options");
}
SqlNode transformed = sqlNode;
if (SelectOptionsAccessor.isCount(options)) {
transformed = toCountCalculatingSqlNode(sqlNode);
}
long offset = SelectOptionsAccessor.getOffset(options);
long limit = SelectOptionsAccessor.getLimit(options);
if (offset >= 0 || limit >= 0) {
transformed = toPagingSqlNode(transformed, offset, limit);
}
SelectForUpdateType forUpdateType = SelectOptionsAccessor.getForUpdateType(options);
if (forUpdateType != null) {
String[] aliases = SelectOptionsAccessor.getAliases(options);
if (!supportsSelectForUpdate(forUpdateType, false)) {
switch(forUpdateType) {
case NORMAL:
throw new JdbcException(Message.DOMA2023, getName());
case WAIT:
throw new JdbcException(Message.DOMA2079, getName());
case NOWAIT:
throw new JdbcException(Message.DOMA2080, getName());
default:
AssertionUtil.assertUnreachable();
}
}
if (aliases.length > 0) {
if (!supportsSelectForUpdate(forUpdateType, true)) {
switch(forUpdateType) {
case NORMAL:
throw new JdbcException(Message.DOMA2024, getName());
case WAIT:
throw new JdbcException(Message.DOMA2081, getName());
case NOWAIT:
throw new JdbcException(Message.DOMA2082, getName());
default:
AssertionUtil.assertUnreachable();
}
}
}
int waitSeconds = SelectOptionsAccessor.getWaitSeconds(options);
transformed = toForUpdateSqlNode(transformed, forUpdateType, waitSeconds, aliases);
}
return transformed;
}
Aggregations