use of org.dbflute.s2dao.metadata.TnProcedureParameterType in project dbflute-core by dbflute.
the class TnProcedureHandler method bindArgs.
protected void bindArgs(Connection conn, CallableStatement cs, Object dto) throws SQLException {
if (dto == null) {
return;
}
int i = 0;
for (TnProcedureParameterType ppt : _procedureMetaData.getBindParameterTypeList()) {
final ValueType valueType = ppt.getValueType();
final int bindIndex = (i + 1);
// if INOUT parameter, both are true
if (ppt.isOutType()) {
valueType.registerOutParameter(conn, cs, bindIndex);
}
if (ppt.isInType()) {
// bind as PreparedStatement
// because CallableStatement's setter might be unsupported
// (for example, PostgreSQL JDBC Driver for JDBC 3.0)
final Object value = ppt.getValue(dto);
valueType.bindValue(conn, cs, bindIndex, value);
}
// either must be true
++i;
}
}
use of org.dbflute.s2dao.metadata.TnProcedureParameterType in project dbflute-core by dbflute.
the class TnProcedureHandler method handleOutParameter.
/**
* Handle result set for out-parameter.
* @param conn The connection for the database. (NotNull)
* @param cs The statement of procedure. (NotNull)
* @param pmb The parameter bean from arguments. (NotNull)
* @param executed The return value of execute() that means whether the first result is a result set.
* @throws SQLException When it fails to handle the SQL.
*/
protected void handleOutParameter(Connection conn, CallableStatement cs, Object pmb, boolean executed) throws SQLException {
if (pmb == null) {
return;
}
int index = 0;
for (TnProcedureParameterType ppt : _procedureMetaData.getBindParameterTypeList()) {
final ValueType valueType = ppt.getValueType();
if (ppt.isOutType()) {
Object value = valueType.getValue(cs, index + 1);
if (value instanceof ResultSet) {
final ResultSet rs = wrapResultSetIfNeeds(pmb, (ResultSet) value);
final TnResultSetHandler handler = createResultSetHandler(pmb, ppt);
try {
value = handler.handle(rs);
} finally {
if (rs != null) {
rs.close();
}
}
}
ppt.setValue(pmb, value);
}
++index;
}
}
use of org.dbflute.s2dao.metadata.TnProcedureParameterType in project dbflute-core by dbflute.
the class TnProcedureHandler method handleNotParamResult.
/**
* Handle not-parameter result set, for example, MySQL, DB2 and (MS) SQLServer.
* @param conn The connection for the database. (NotNull)
* @param cs The statement of procedure. (NotNull)
* @param pmb The parameter bean from arguments. (NotNull)
* @param executed The return value of execute() that means whether the first result is a result set.
* @throws SQLException When it fails to handle the SQL.
*/
@SuppressWarnings("resource")
protected void handleNotParamResult(Connection conn, CallableStatement cs, Object pmb, boolean executed) throws SQLException {
if (pmb == null) {
return;
}
if (!executed) {
if (!cs.getMoreResults()) {
// just in case
return;
}
}
final List<TnProcedureParameterType> resultList = _procedureMetaData.getNotParamResultTypeList();
ResultSet rs = null;
for (TnProcedureParameterType ppt : resultList) {
try {
rs = cs.getResultSet();
if (rs == null) {
break;
}
rs = wrapResultSetIfNeeds(pmb, rs);
final TnResultSetHandler handler = createResultSetHandler(pmb, ppt);
final Object beanList = handler.handle(rs);
ppt.setValue(pmb, beanList);
if (!cs.getMoreResults()) {
break;
}
} finally {
if (rs != null) {
rs.close();
}
}
}
}
use of org.dbflute.s2dao.metadata.TnProcedureParameterType in project dbflute-core by dbflute.
the class TnProcedureHandler method buildDisplaySql.
// ===================================================================================
// DisplaySql
// ==========
@Override
protected String buildDisplaySql(String sql, Object[] args) {
// for procedure call
if (args == null) {
// basically no way, just in case
return sql;
}
final Object dto = getParameterBean(args);
if (dto == null) {
return sql;
}
final StringBuilder sb = new StringBuilder(100);
int pos = 0;
int pos2 = 0;
for (TnProcedureParameterType ppt : _procedureMetaData.getBindParameterTypeList()) {
if ((pos2 = sql.indexOf('?', pos)) < 0) {
break;
}
sb.append(sql.substring(pos, pos2));
pos = pos2 + 1;
if (ppt.isInType()) {
sb.append(getBindVariableText(ppt.getValue(dto)));
} else {
sb.append(sql.substring(pos2, pos));
}
}
sb.append(sql.substring(pos));
return sb.toString();
}
Aggregations