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