Search in sources :

Example 1 with DomaNullPointerException

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

the class BatchDeleteExecutor method execute.

/**
 * Executes SQL DELETE 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 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 BatchDeleteCommand(query));
}
Also used : BatchDeleteCommand(org.seasar.doma.jdbc.command.BatchDeleteCommand) DomaNullPointerException(org.seasar.doma.DomaNullPointerException)

Example 2 with DomaNullPointerException

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

the class BatchInsertExecutor method execute.

/**
 * Executes SQL INSERT 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 BatchInsertCommand(query));
}
Also used : BatchInsertCommand(org.seasar.doma.jdbc.command.BatchInsertCommand) DomaNullPointerException(org.seasar.doma.DomaNullPointerException)

Example 3 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException 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);
}
Also used : SQLException(java.sql.SQLException) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Savepoint(java.sql.Savepoint) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 4 with DomaNullPointerException

use of org.seasar.doma.DomaNullPointerException 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;
}
Also used : DomaNullPointerException(org.seasar.doma.DomaNullPointerException) SelectForUpdateType(org.seasar.doma.jdbc.SelectForUpdateType) JdbcException(org.seasar.doma.jdbc.JdbcException) JdbcMappingHint(org.seasar.doma.jdbc.JdbcMappingHint) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 5 with DomaNullPointerException

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

the class EntityTypeFactory method getEntityType.

/**
 * Creates the entity description.
 *
 * @param <E> the entity type
 * @param entityClass the entity class
 * @param classHelper the class helper
 * @return the entity description
 * @throws DomaNullPointerException if any arguments are {@code null}
 * @throws DomaIllegalArgumentException if the entity class is not annotated with the {@link
 *     Entity} annotation
 * @throws EntityTypeNotFoundException if the entity description is not found
 */
public static <E> EntityType<E> getEntityType(Class<E> entityClass, ClassHelper classHelper) {
    if (entityClass == null) {
        throw new DomaNullPointerException("entityClass");
    }
    if (classHelper == null) {
        throw new DomaNullPointerException("classHelper");
    }
    if (!entityClass.isAnnotationPresent(Entity.class)) {
        throw new DomaIllegalArgumentException("entityClass", Message.DOMA2206.getMessage("entityClass"));
    }
    String entityTypeClassName = ClassNames.newEntityTypeClassName(entityClass.getName()).toString();
    try {
        Class<E> clazz = classHelper.forName(entityTypeClassName);
        Method method = ClassUtil.getMethod(clazz, "getSingletonInternal");
        return MethodUtil.invoke(method, null);
    } catch (Exception e) {
        throw new EntityTypeNotFoundException(e.getCause(), entityClass.getName(), entityTypeClassName);
    }
}
Also used : Entity(org.seasar.doma.Entity) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Method(java.lang.reflect.Method) DomaIllegalArgumentException(org.seasar.doma.DomaIllegalArgumentException) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) DomaIllegalArgumentException(org.seasar.doma.DomaIllegalArgumentException)

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