org.jdbi.v3.core.config.ConfigRegistry Java Examples
The following examples show how to use
org.jdbi.v3.core.config.ConfigRegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SfmRowMapperFactory.java From SimpleFlatMapper with MIT License | 6 votes |
@Override public Optional<RowMapper<?>> build(Type type, ConfigRegistry configRegistry) { if (acceptsPredicate.test(type, configRegistry)) { RowMapper<?> rowMapper = cache.get(type); if (rowMapper == null) { ContextualSourceMapper<ResultSet, ?> resultSetMapper = mapperFactory.newInstance(type); rowMapper = toRowMapper(resultSetMapper); RowMapper<?> cachedMapper = cache.putIfAbsent(type, rowMapper); if (cachedMapper != null) { rowMapper = cachedMapper; } } return Optional.of(rowMapper); } return Optional.empty(); }
Example #2
Source File: PropertiesArgumentFactory.java From irontest with Apache License 2.0 | 5 votes |
@Override protected Argument build(Properties value, ConfigRegistry config) { return (position, statement, ctx) -> { try { statement.setString(position, new ObjectMapper().writeValueAsString(value)); } catch (JsonProcessingException e) { throw new RuntimeException("Fail to serialize the Properties object."); } }; }
Example #3
Source File: RosettaRowMapperFactory.java From Rosetta with Apache License 2.0 | 5 votes |
@Override public Optional<RowMapper<?>> build(Type type, ConfigRegistry config) { if (accepts(type, config)) { return Optional.of((rs, ctx) -> { ObjectMapper objectMapper = ctx.getConfig(RosettaObjectMapper.class).getObjectMapper(); String tableName = SqlTableNameExtractor.extractTableName(ctx.getParsedSql().getSql()); final RosettaMapper mapper = new RosettaMapper(type, objectMapper, tableName); return mapper.mapRow(rs); }); } else { return Optional.empty(); } }
Example #4
Source File: RosettaRowMapperFactory.java From Rosetta with Apache License 2.0 | 5 votes |
private static boolean accepts(Type type, ConfigRegistry config) { Class<?> rawType = GenericTypes.getErasedType(type); if (rawType.isPrimitive() || rawType.isArray() || rawType.isAnnotation()) { return false; } else if (rawType == Optional.class) { Optional<Type> optionalType = GenericTypes.findGenericParameter(type, Optional.class); // TODO we currently return false if we can't infer the type of the Optional, should we reverse that? return optionalType.isPresent() && accepts(optionalType.get(), config); } else { return !hasBuiltInMapper(type, config); } }
Example #5
Source File: RosettaObjectMapperTest.java From Rosetta with Apache License 2.0 | 5 votes |
private static void registerSerializer(ConfigRegistry config, JsonSerializer<TestObject> serializer) { ObjectMapper objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.setSerializers(new SimpleSerializers(Collections.singletonList(serializer))); objectMapper.registerModule(module); config.get(RosettaObjectMapper.class).setObjectMapper(objectMapper); }
Example #6
Source File: RosettaObjectMapperTest.java From Rosetta with Apache License 2.0 | 5 votes |
private static void registerDeserializer(ConfigRegistry config, JsonDeserializer<TestObject> deserializer) { ObjectMapper objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.setDeserializers(new SimpleDeserializers(Collections.singletonMap(TestObject.class, deserializer))); objectMapper.registerModule(module); config.get(RosettaObjectMapper.class).setObjectMapper(objectMapper); }
Example #7
Source File: SfmRowMapperFactory.java From SimpleFlatMapper with MIT License | 4 votes |
@Override public boolean test(Type type, ConfigRegistry configRegistry) { return true; }
Example #8
Source File: SfmRowMapperFactory.java From SimpleFlatMapper with MIT License | 4 votes |
public SfmRowMapperFactory(BiPredicate<Type, ConfigRegistry> acceptsPredicate, UnaryFactory<Type, ContextualSourceMapper<ResultSet, ?>> mapperFactory) { this.mapperFactory = mapperFactory; this.acceptsPredicate = acceptsPredicate; }
Example #9
Source File: RosettaRowMapperFactory.java From Rosetta with Apache License 2.0 | 4 votes |
private static boolean hasBuiltInMapper(Type type, ConfigRegistry config) { return config.get(ColumnMappers.class).findFor(type).isPresent(); }