I kind of punted on out parameters for now, there is no out param per
se, and the return value must be either null or OutParameters. I'll
try to work out a decent mechanism for getting at out params and
putting them on the return value, and/or something like:
public void foo(@Out("waffle") Reference<Double> waffle)
which is grody, but works nicely in JNA and their ilk.
Assuming no one barfs on the code (
https://github.com/brianm/jdbi/commit/5aa2b4781f608e85bca2666d87bcdbe4a28a9e75
comments! ) I'll probably cut a release with it shortly.
-Brian
Hi Brian,Could you please give a sample code snippet on how to use the @SqlCall that returns an OutParameter.The TestSqlCall shows a stored proc call that does an insert.
Thanks in advance.RegardsSathish
On Monday, March 12, 2012 6:23:20 PM UTC-4, Brian McCallister wrote:I just checked in initial support for @SqlCall within the sql object APII kind of punted on out parameters for now, there is no out param per
se, and the return value must be either null or OutParameters. I'll
try to work out a decent mechanism for getting at out params and
putting them on the return value, and/or something like:public void foo(@Out("waffle") Reference<Double> waffle)
which is grody, but works nicely in JNA and their ilk.
Assuming no one barfs on the code (
https://github.com/brianm/jdbi/commit/5aa2b4781f608e85bca2666d87bcdbe4a28a9e75
comments! ) I'll probably cut a release with it shortly.-Brian
--
--
--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@SqlCall("BEGIN TEST.TOOLS.CREATE_NEW_WORKPLACE(:str_workplace, :n_new_workplace_id); END;")
@OutParameter(name = "n_new_workplace_id", sqlType = Types.BIGINT)OutParameters createNewWorkplace(@Bind("str_workplace") String workplaceName);OutParameters p = dao.createNewWorkplace(workplaceName);return p.getLong("n_new_workplace_id").longValue(); //$NON-NLS-1$
import java.lang.annotation.Annotation;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import java.lang.reflect.Method;import java.sql.SQLException;
import org.skife.jdbi.v2.Call;import org.skife.jdbi.v2.SQLStatement;import org.skife.jdbi.v2.sqlobject.SqlStatementCustomizer;import org.skife.jdbi.v2.sqlobject.SqlStatementCustomizerFactory;import org.skife.jdbi.v2.sqlobject.SqlStatementCustomizingAnnotation;
@SqlStatementCustomizingAnnotation(OutParameter.Factory.class)@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)public @interface OutParameter {
String name();
int sqlType();
static class Factory implements SqlStatementCustomizerFactory { @Override public SqlStatementCustomizer createForType(Annotation annotation, @SuppressWarnings("rawtypes") Class sqlObjectType) { throw new UnsupportedOperationException("Not allowed on Type"); //$NON-NLS-1$ }
@Override public SqlStatementCustomizer createForMethod(Annotation annotation, @SuppressWarnings("rawtypes") Class sqlObjectType, Method method) { final OutParameter outParam = (OutParameter) annotation; return new SqlStatementCustomizer() { @Override public void apply(@SuppressWarnings("rawtypes") SQLStatement q) throws SQLException { assert q instanceof Call; ((Call) q).registerOutParameter(outParam.name(), outParam.sqlType()); } }; }
@Override public SqlStatementCustomizer createForParameter(Annotation annotation, @SuppressWarnings("rawtypes") Class sqlObjectType, Method method, final Object arg) { throw new UnsupportedOperationException("Not defined for parameter"); //$NON-NLS-1$ } }
}