本文整理汇总了Java中org.skife.jdbi.v2.tweak.Argument类的典型用法代码示例。如果您正苦于以下问题:Java Argument类的具体用法?Java Argument怎么用?Java Argument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Argument类属于org.skife.jdbi.v2.tweak包,在下文中一共展示了Argument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locate
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public String locate(final String name, final StatementContext ctx) throws Exception {
// Rewrite create to createBac, createBin, createBiia, etc.
if ("create".equals(name)) {
final Binding binding = ctx.getBinding();
if (binding != null) {
final Argument tableNameArgument = binding.forName("tableName");
if (tableNameArgument != null) {
// Lame, rely on toString (tableNameArgument will be a org.skife.jdbi.v2.StringArgument)
final String tableName = CharMatcher.anyOf("'").removeFrom(tableNameArgument.toString());
final String newQueryName = name + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName);
return super.locate(newQueryName, ctx);
}
}
}
// Inspired from org.skife.jdbi.v2.ClasspathStatementLocator to allow real SQL to be executed
if (looksLikeSql(name)) {
return name;
} else {
return super.locate(name, ctx);
}
}
示例2: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, Value<?> value, StatementContext ctx) {
if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(jdbcDriver)) {
return new MsSqlValueArgument(value);
} else if ("oracle.jdbc.OracleDriver".equals(jdbcDriver)) {
return new DefaultValueArgument(value, Types.NULL);
}
return new DefaultValueArgument(value);
}
示例3: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, Option<?> value, StatementContext ctx) {
if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(jdbcDriver)) {
return new MsSqlOptionArgument(value);
} else if ("oracle.jdbc.OracleDriver".equals(jdbcDriver)) {
return new DefaultOptionArgument(value, Types.NULL);
}
return new DefaultOptionArgument(value);
}
示例4: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, final LongCollectionSqlType value, StatementContext ctx) {
return (int position, PreparedStatement statement, StatementContext ctx1) -> {
try {
Array sqlArray = ctx1.getConnection().createArrayOf("int", value.getValue().toArray());
statement.setArray(position, sqlArray);
} catch (SQLException e) {
// H2 DB feature not supported: "createArray" error
if (e.getErrorCode() != 50100) {
throw e;
}
statement.setObject(position, value.getValue().toArray());
}
};
}
示例5: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, final Collection<String> value, StatementContext ctx) {
return (int position, PreparedStatement statement, StatementContext ctx1) -> {
try {
Array sqlArray = ctx1.getConnection().createArrayOf("text", value.toArray());
statement.setArray(position, sqlArray);
} catch (SQLException e) {
// H2 DB feature not supported: "createArray" error
if (e.getErrorCode() != 50100) {
throw e;
}
statement.setObject(position, value.toArray());
}
};
}
示例6: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, Optional<Object> value, StatementContext ctx) {
if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(jdbcDriver)) {
return new MsSqlOptionalArgument(value);
} else if ("oracle.jdbc.OracleDriver".equals(jdbcDriver)) {
return new DefaultOptionalArgument(value, Types.NULL);
}
return new DefaultOptionalArgument(value);
}
示例7: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, final TenacityConfiguration value, StatementContext ctx) {
return (position, statement, ctx1) -> {
try {
statement.setObject(position, objectMapper.writeValueAsString(value));
} catch (JsonProcessingException err) {
LOGGER.warn("Could not write as json: {}", value, err);
throw new IllegalArgumentException(err);
}
};
}
示例8: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(Class<?> expectedType, Object value, StatementContext ctx) {
if (expectedType.equals(Instant.class)) {
return new InstantArgument((Instant) value);
} else if (expectedType.equals(Duration.class)) {
return new DurationArgument((Duration) value);
} else {
return ToStringArgument.of(value);
}
}
示例9: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(final Class<?> expectedType, final Optional<?> value,
final StatementContext sctx) {
return (pos, stmt, ctx) -> {
if (value.isPresent()) {
stmt.setObject(pos, value.get());
} else {
stmt.setNull(pos, Types.OTHER);
}
};
}
示例10: empty
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Test
public void empty() throws Exception {
new MockUnit(StatementContext.class, PreparedStatement.class)
.expect(unit -> {
PreparedStatement stmt = unit.get(PreparedStatement.class);
stmt.setNull(1, Types.OTHER);
})
.run(unit -> {
Argument arg = new OptionalArgumentFactory()
.build(Optional.class, Optional.empty(), unit.get(StatementContext.class));
assertNotNull(arg);
arg.apply(1, unit.get(PreparedStatement.class), unit.get(StatementContext.class));
});
}
示例11: value
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Test
public void value() throws Exception {
new MockUnit(StatementContext.class, PreparedStatement.class)
.expect(unit -> {
PreparedStatement stmt = unit.get(PreparedStatement.class);
stmt.setObject(1, "x");
})
.run(unit -> {
Argument arg = new OptionalArgumentFactory()
.build(Optional.class, Optional.of("x"), unit.get(StatementContext.class));
assertNotNull(arg);
arg.apply(1, unit.get(PreparedStatement.class), unit.get(StatementContext.class));
});
}
示例12: build
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Override
public Argument build(final Class<?> expectedType, final SqlArray<?> value, final StatementContext ctx) {
return (position, statement, ctx1) -> {
final Array elements = ctx.getConnection().createArrayOf(getTypeName(value), value.getElements());
statement.setArray(position, elements);
};
}
示例13: testBuildInteger
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Test
public void testBuildInteger() throws Exception {
Integer[] intArray = {1, 2, 3};
List<Integer> ints = Arrays.asList(intArray);
SqlArray<Integer> value = new SqlArray<>(Integer.class, ints);
given(connection.createArrayOf("integer", intArray)).willReturn(array);
Argument result = sut.build(Integer.class, value, ctx);
result.apply(1, preparedStatement, ctx);
verify(preparedStatement).setArray(1, array);
}
示例14: testBuildLong
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Test
public void testBuildLong() throws Exception {
Long[] longArray = {1L, 2L, 3L};
List<Long> longs = Arrays.asList(longArray);
SqlArray<Long> value = new SqlArray<>(Long.class, longs);
given(connection.createArrayOf("bigint", longArray)).willReturn(array);
Argument result = sut.build(Long.class, value, ctx);
result.apply(1, preparedStatement, ctx);
verify(preparedStatement).setArray(1, array);
}
示例15: testBuildFloat
import org.skife.jdbi.v2.tweak.Argument; //导入依赖的package包/类
@Test
public void testBuildFloat() throws Exception {
Float[] floatArray = {1.1F, 2.2F, 3.3F};
List<Float> floats = Arrays.asList(floatArray);
SqlArray<Float> value = new SqlArray<>(Float.class, floats);
given(connection.createArrayOf("float4", floatArray)).willReturn(array);
Argument result = sut.build(Float.class, value, ctx);
result.apply(1, preparedStatement, ctx);
verify(preparedStatement).setArray(1, array);
}