use of io.helidon.common.GenericType in project helidon by oracle.
the class JdbcStatementQuery method createMetadata.
static Map<Long, DbColumn> createMetadata(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
Map<Long, DbColumn> byNumbers = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
String name = metaData.getColumnLabel(i);
String sqlType = metaData.getColumnTypeName(i);
Class<?> javaClass = classByName(metaData.getColumnClassName(i));
DbColumn column = new DbColumn() {
@Override
public <T> T as(Class<T> type) {
return null;
}
@Override
public <T> T as(GenericType<T> type) {
return null;
}
@Override
public Class<?> javaType() {
return javaClass;
}
@Override
public String dbType() {
return sqlType;
}
@Override
public String name() {
return name;
}
};
byNumbers.put((long) i, column);
}
return byNumbers;
}
use of io.helidon.common.GenericType in project helidon by oracle.
the class BuilderImpl method addMapper.
@Override
public <T> Config.Builder addMapper(GenericType<T> type, Function<Config, T> mappingFunction) {
Objects.requireNonNull(type);
Objects.requireNonNull(mappingFunction);
addMapper(new ConfigMapperProvider() {
@Override
public Map<Class<?>, Function<Config, ?>> mappers() {
return Map.of();
}
@Override
public Map<GenericType<?>, BiFunction<Config, ConfigMapper, ?>> genericTypeMappers() {
return Map.of(type, (config, aMapper) -> mappingFunction.apply(config));
}
});
return this;
}
use of io.helidon.common.GenericType in project helidon by oracle.
the class MockZipkinService method mockZipkin.
private void mockZipkin(final ServerRequest request, final ServerResponse response) {
request.queryParams().all("serviceName").forEach(s -> System.out.println(">>>" + s));
request.content().registerReader(new MessageBodyStreamReader<JsonValue>() {
@Override
public PredicateResult accept(final GenericType<?> type, final MessageBodyReaderContext context) {
return PredicateResult.COMPATIBLE;
}
@Override
@SuppressWarnings("unchecked")
public <U extends JsonValue> Flow.Publisher<U> read(final Flow.Publisher<DataChunk> publisher, final GenericType<U> type, final MessageBodyReaderContext context) {
return (Flow.Publisher<U>) Multi.create(publisher).map(d -> ByteBuffer.wrap(d.bytes())).reduce((buf, buf2) -> ByteBuffer.allocate(buf.capacity() + buf2.capacity()).put(buf.array()).put(buf2.array())).flatMap(b -> {
try (ByteArrayInputStream bais = new ByteArrayInputStream(b.array());
GZIPInputStream gzipInputStream = new GZIPInputStream(bais)) {
return Single.just(Json.createReader(new StringReader(new String(gzipInputStream.readAllBytes()))).readArray());
} catch (EOFException e) {
// ignore
return Multi.empty();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).flatMap(a -> Multi.create(a.stream()));
}
}).asStream(JsonValue.class).map(JsonValue::asJsonObject).filter(json -> TAGS_POINTER.containsValue(json) && COMPONENT_POINTER.containsValue(json) && filteredComponents.stream().anyMatch(s -> s.equals(((JsonString) COMPONENT_POINTER.getValue(json)).getString()))).onError(Throwable::printStackTrace).onError(t -> response.status(500).send(t)).onComplete(response::send).peek(json -> LOGGER.info(json.toString())).forEach(e -> next.getAndSet(new CompletableFuture<>()).complete(e));
}
use of io.helidon.common.GenericType in project helidon by oracle.
the class CacheExtension method addBeans.
/*
* create EmbeddedStorageManager beans
*/
private void addBeans(@Observes final AfterBeanDiscovery event, final BeanManager beanManager) {
if (event != null && beanManager != null) {
if (!this.cacheBeans.isEmpty()) {
for (final Descriptor entry : this.cacheBeans) {
assert entry != null;
// create Microstream Cache bean
final Set<Annotation> qualifiers = entry.getAnnotations();
assert qualifiers != null;
assert !qualifiers.isEmpty();
ParameterizedType types = entry.getTypes();
GenericType<?> keyType = GenericType.create(types.getActualTypeArguments()[0]);
GenericType<?> valueType = GenericType.create(types.getActualTypeArguments()[1]);
String name = getName(qualifiers);
event.<Cache<?, ?>>addBean().qualifiers(qualifiers).scope(ApplicationScoped.class).addTransitiveTypeClosure(Cache.class).addTypes(types).createWith(cc -> {
return CacheBuilder.create(name, getConfigNode(qualifiers), keyType.rawType(), valueType.rawType());
}).destroyWith((cache, context) -> cache.close());
}
}
}
}
use of io.helidon.common.GenericType in project helidon by oracle.
the class TestJsonBindingSupport method genericType.
@Test
public void genericType() throws Exception {
GenericType<List<Person>> personsType = new GenericType<>() {
};
final Routing routing = Routing.builder().post("/foo", (req, res) -> {
req.content().as(personsType).thenAccept(res::send);
}).build();
final String personsJson = "[{\"name\":\"Frank\"},{\"name\":\"John\"}]";
final TestResponse response = TestClient.create(routing, JsonbSupport.create()).path("/foo").post(MediaPublisher.create(MediaType.APPLICATION_JSON.withCharset("UTF-8"), personsJson));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), is(MediaType.APPLICATION_JSON.toString()));
final String json = response.asString().get(10, TimeUnit.SECONDS);
assertThat(json, is(personsJson));
}
Aggregations