use of org.jdbi.v3.core.argument.Arguments in project jdbi by jdbi.
the class Handle method execute.
/**
* Execute a SQL statement, and return the number of rows affected by the statement.
*
* @param sql the SQL statement to execute, using positional parameters (if any)
* @param args positional arguments
*
* @return the number of rows affected
*/
public int execute(String sql, Object... args) {
Update stmt = createUpdate(sql);
int position = 0;
for (Object arg : args) {
stmt.bind(position++, arg);
}
return stmt.execute();
}
use of org.jdbi.v3.core.argument.Arguments in project jdbi by jdbi.
the class DefineListFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
final DefineList d = (DefineList) annotation;
final String name = ParameterUtil.findParameterName(d.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @DefineList parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> {
List<?> argsList;
if (arg instanceof List) {
argsList = (List<?>) arg;
} else if (arg instanceof Object[]) {
argsList = Arrays.asList((Object[]) arg);
} else if (arg == null) {
throw new IllegalArgumentException("A null object was passed as a @DefineList parameter. " + "@DefineList is only supported on List and array arguments");
} else {
throw new IllegalArgumentException("A " + arg.getClass() + " object was passed as a @DefineList " + "parameter. @DefineList is only supported on List and array arguments");
}
if (argsList.isEmpty()) {
throw new IllegalArgumentException("An empty list was passed as a @DefineList parameter. Can't define " + "an empty attribute.");
}
if (argsList.contains(null)) {
throw new IllegalArgumentException("A @DefineList parameter was passed a list with null values in it.");
}
stmt.defineList(name, argsList);
};
}
use of org.jdbi.v3.core.argument.Arguments in project jdbi by jdbi.
the class Handle method select.
/**
* Convenience method which creates a query with the given positional arguments
* @param sql SQL or named statement
* @param args arguments to bind positionally
* @return query object
*/
public Query select(String sql, Object... args) {
Query query = this.createQuery(sql);
int position = 0;
for (Object arg : args) {
query.bind(position++, arg);
}
return query;
}
use of org.jdbi.v3.core.argument.Arguments in project jdbi by jdbi.
the class RegisterObjectArgumentFactoryImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
RegisterObjectArgumentFactory registerObjectArgumentFactory = (RegisterObjectArgumentFactory) annotation;
Arguments arguments = registry.get(Arguments.class);
Class<?> clazz = registerObjectArgumentFactory.value();
int sqlType = registerObjectArgumentFactory.sqlType();
if (sqlType == Integer.MIN_VALUE) {
arguments.register(ObjectArgumentFactory.create(clazz));
} else {
arguments.register(ObjectArgumentFactory.create(clazz, sqlType));
}
}
use of org.jdbi.v3.core.argument.Arguments in project jdbi by jdbi.
the class RegisterArgumentFactoryImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
RegisterArgumentFactory raf = (RegisterArgumentFactory) annotation;
Arguments arguments = registry.get(Arguments.class);
try {
arguments.register(raf.value().newInstance());
} catch (Exception e) {
throw new IllegalStateException("unable to instantiate specified argument factory", e);
}
}
Aggregations