Search in sources :

Example 6 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException in project doma by domaframework.

the class DaoImplSupportTest method testConstructorParameter1.

@SuppressWarnings("ConstantConditions")
@Test
public void testConstructorParameter1() {
    Config config = null;
    try {
        new DaoImplSupport(config) {
        };
        fail();
    } catch (DomaNullPointerException expected) {
        assertEquals("config", expected.getParameterName());
    }
}
Also used : Config(org.seasar.doma.jdbc.Config) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Test(org.junit.jupiter.api.Test)

Example 7 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException in project doma by domaframework.

the class DaoImplSupportTest method testConstructorParameter3.

@SuppressWarnings("ConstantConditions")
@Test
public void testConstructorParameter3() {
    Config config = mock(Config.class);
    Connection connection = null;
    try {
        new DaoImplSupport(config, connection) {
        };
        fail();
    } catch (DomaNullPointerException expected) {
        assertEquals("connection", expected.getParameterName());
    }
}
Also used : Config(org.seasar.doma.jdbc.Config) Connection(java.sql.Connection) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Test(org.junit.jupiter.api.Test)

Example 8 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException in project doma by domaframework.

the class BatchUpdateExecutor method execute.

/**
 * Executes SQL UPDATE statements.
 *
 * @param <P> the parameter type
 * @param params the parameters
 * @param buildConsumer the code block that builds SQL statements
 * @return the array whose each element contains affected rows count. The array length is equal to
 *     the {@code parameter} size.
 * @throws DomaNullPointerException if {@code params} or {@code buildConsumer} is {@code null}
 * @throws UniqueConstraintException if an unique constraint violation occurs
 * @throws JdbcException if a JDBC related error occurs
 */
public <P> int[] execute(Iterable<P> params, BiConsumer<P, BatchBuilder> buildConsumer) {
    if (params == null) {
        throw new DomaNullPointerException("params");
    }
    if (buildConsumer == null) {
        throw new DomaNullPointerException("buildConsumer");
    }
    if (query.getMethodName() == null) {
        query.setCallerMethodName("execute");
    }
    BatchBuilder builder = BatchBuilder.newInstance(query);
    for (P p : params) {
        buildConsumer.accept(p, builder);
        builder = builder.fixSql();
    }
    return builder.execute(() -> new BatchUpdateCommand(query));
}
Also used : DomaNullPointerException(org.seasar.doma.DomaNullPointerException) BatchUpdateCommand(org.seasar.doma.jdbc.command.BatchUpdateCommand)

Example 9 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException in project doma by domaframework.

the class LocalTransaction method rollback.

/**
 * Undoes all changes made after the given save point.
 *
 * @param savepointName the name of the save point
 * @throws DomaNullPointerException if the {@code savepointName} is {@code null}
 * @throws SavepointNotFoundException if the save point is not found
 * @throws TransactionNotYetBegunException if this transaction is not yet begun
 * @throws JdbcException if a JDBC related error occurs
 */
public void rollback(String savepointName) {
    if (savepointName == null) {
        rollbackInternal("rollback");
        throw new DomaNullPointerException("savepointName");
    }
    LocalTransactionContext context = localTxContextHolder.get();
    if (!isActiveInternal(context)) {
        throw new TransactionNotYetBegunException(Message.DOMA2062, savepointName);
    }
    String id = context.getId();
    Savepoint savepoint = context.getSavepoint(savepointName);
    if (savepoint == null) {
        rollbackInternal("rollback");
        throw new SavepointNotFoundException(savepointName);
    }
    LocalTransactionConnection connection = context.getConnection();
    try {
        connection.rollback(savepoint);
    } catch (SQLException e) {
        rollbackInternal("rollback");
        throw new JdbcException(Message.DOMA2052, e, savepointName, e);
    }
    jdbcLogger.logTransactionSavepointRolledback(className, "rollback", id, savepointName);
}
Also used : SQLException(java.sql.SQLException) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Savepoint(java.sql.Savepoint) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 10 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException in project doma by domaframework.

the class LocalTransaction method setSavepoint.

/**
 * Creates a save point with the specified name.
 *
 * @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 SavepointAlreadyExistsException if the save point already exists
 * @throws JdbcException if a JDBC related error occurs
 */
public void setSavepoint(String savepointName) {
    if (savepointName == null) {
        rollbackInternal("setSavepoint");
        throw new DomaNullPointerException("savepointName");
    }
    LocalTransactionContext context = localTxContextHolder.get();
    if (!isActiveInternal(context)) {
        throw new TransactionNotYetBegunException(Message.DOMA2053, savepointName);
    }
    String id = context.getId();
    Savepoint savepoint = context.getSavepoint(savepointName);
    if (savepoint != null) {
        rollbackInternal("setSavepoint");
        throw new SavepointAlreadyExistsException(savepointName);
    }
    LocalTransactionConnection connection = context.getConnection();
    try {
        savepoint = connection.setSavepoint(savepointName);
    } catch (SQLException e) {
        rollbackInternal("setSavepoint");
        throw new JdbcException(Message.DOMA2051, e, savepointName, e);
    }
    context.addSavepoint(savepointName, savepoint);
    jdbcLogger.logTransactionSavepointCreated(className, "setSavepoint", id, savepointName);
}
Also used : SQLException(java.sql.SQLException) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Savepoint(java.sql.Savepoint) JdbcException(org.seasar.doma.jdbc.JdbcException)

Aggregations

DomaNullPointerException (org.seasar.doma.DomaNullPointerException)16 Test (org.junit.jupiter.api.Test)5 Config (org.seasar.doma.jdbc.Config)5 SQLException (java.sql.SQLException)4 JdbcException (org.seasar.doma.jdbc.JdbcException)4 Method (java.lang.reflect.Method)3 Savepoint (java.sql.Savepoint)3 DomaIllegalArgumentException (org.seasar.doma.DomaIllegalArgumentException)3 Connection (java.sql.Connection)2 DataSource (javax.sql.DataSource)2 WrapException (org.seasar.doma.internal.WrapException)2 Entity (org.seasar.doma.Entity)1 JdbcMappingHint (org.seasar.doma.jdbc.JdbcMappingHint)1 SelectForUpdateType (org.seasar.doma.jdbc.SelectForUpdateType)1 SqlNode (org.seasar.doma.jdbc.SqlNode)1 BatchDeleteCommand (org.seasar.doma.jdbc.command.BatchDeleteCommand)1 BatchInsertCommand (org.seasar.doma.jdbc.command.BatchInsertCommand)1 BatchUpdateCommand (org.seasar.doma.jdbc.command.BatchUpdateCommand)1