use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.
the class TnQueryInsertDynamicCommand method execute.
// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
// analyze arguments
final Entity entity = extractEntityWithCheck(args);
final ConditionBean intoCB = extractIntoConditionBeanWithCheck(args);
final ConditionBean resourceCB = extractResourceConditionBeanWithCheck(args);
final InsertOption<ConditionBean> option = extractInsertOptionWithCheck(args);
prepareStatementConfigOnThreadIfExists(option);
// arguments for execution (not contains an option)
final String[] argNames = new String[] { "entity", "pmb" };
final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), resourceCB.getClass() };
final Object[] realArgs = new Object[] { entity, resourceCB };
// prepare context
final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
final CommandContext context;
{
final String twoWaySql = buildQueryInsertTwoWaySql(entity, intoCB, resourceCB, option, boundPropTypeList);
context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
}
// execute
final TnCommandContextHandler handler = createCommandContextHandler(context);
handler.setExceptionMessageSqlArgs(context.getBindVariables());
final boolean identityDisabled = option != null && option.isPrimaryKeyIdentityDisabled();
if (identityDisabled) {
disableIdentityGeneration(entity);
}
final int rows;
RuntimeException sqlEx = null;
try {
rows = handler.execute(realArgs);
} catch (RuntimeException e) {
sqlEx = e;
throw e;
} finally {
if (identityDisabled) {
try {
enableIdentityGeneration(entity);
} catch (RuntimeException e) {
if (sqlEx == null) {
throw e;
}
// ignore the exception when main SQL fails
// not to close the main exception
}
}
}
return Integer.valueOf(rows);
}
use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.
the class TnAbstractQueryDynamicCommand method createCommandContextHandler.
// ===================================================================================
// CommandContext Handler
// ======================
protected TnCommandContextHandler createCommandContextHandler(CommandContext context) {
final String executedSql = filterSqlStringByCallbackFilter(context.getSql());
final TnCommandContextHandler handler = newCommandContextHandler(executedSql, context);
handler.setUpdateSQLFailureProcessTitle(getUpdateSQLFailureProcessTitle());
return handler;
}
use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.
the class TnQueryDeleteDynamicCommand method execute.
// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
// analyze arguments
final ConditionBean cb = extractConditionBeanWithCheck(args);
final DeleteOption<ConditionBean> option = extractUpdateOptionWithCheck(args);
prepareStatementConfigOnThreadIfExists(option);
// arguments for execution (not contains an option)
final String[] argNames = new String[] { "pmb" };
final Class<?>[] argTypes = new Class<?>[] { cb.getClass() };
final Object[] realArgs = new Object[] { cb };
// prepare context
final CommandContext context;
{
final String twoWaySql = buildQueryDeleteTwoWaySql(cb, option);
context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
}
// execute
final TnCommandContextHandler handler = createCommandContextHandler(context);
handler.setExceptionMessageSqlArgs(context.getBindVariables());
final int rows = handler.execute(realArgs);
return Integer.valueOf(rows);
}
use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.
the class TnQueryUpdateDynamicCommand method execute.
// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
// analyze arguments
final Entity entity = extractEntityWithCheck(args);
final ConditionBean cb = extractConditionBeanWithCheck(args);
final UpdateOption<ConditionBean> option = extractUpdateOptionWithCheck(args);
prepareStatementConfigOnThreadIfExists(option);
// arguments for execution (not contains an option)
final String[] argNames = new String[] { "entity", "pmb" };
final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), cb.getClass() };
final Object[] realArgs = new Object[] { entity, cb };
// prepare context
final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
final CommandContext context;
{
final String twoWaySql = buildQueryUpdateTwoWaySql(entity, cb, option, boundPropTypeList);
if (twoWaySql == null) {
// non execute
return 0;
}
context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
}
// execute
final TnCommandContextHandler handler = createCommandContextHandler(context);
handler.setExceptionMessageSqlArgs(context.getBindVariables());
handler.setFirstBoundPropTypeList(boundPropTypeList);
final int rows = handler.execute(realArgs);
return Integer.valueOf(rows);
}
Aggregations