use of com.google.inject.TypeLiteral in project presto by prestodb.
the class VerifierModule method setup.
protected final void setup(Binder binder) {
configBinder(binder).bindConfig(VerifierConfig.class);
configBinder(binder).bindConfig(DeterminismAnalyzerConfig.class);
configBinder(binder).bindConfig(QueryConfigurationOverridesConfig.class, ForControl.class, "control");
configBinder(binder).bindConfig(QueryConfigurationOverridesConfig.class, ForTest.class, "test");
binder.bind(QueryConfigurationOverrides.class).annotatedWith(ForControl.class).to(Key.get(QueryConfigurationOverridesConfig.class, ForControl.class)).in(SINGLETON);
binder.bind(QueryConfigurationOverrides.class).annotatedWith(ForTest.class).to(Key.get(QueryConfigurationOverridesConfig.class, ForTest.class)).in(SINGLETON);
for (Class<? extends Predicate<SourceQuery>> customQueryFilterClass : customQueryFilterClasses) {
binder.bind(customQueryFilterClass).in(SINGLETON);
}
// block encoding
binder.bind(BlockEncodingSerde.class).to(BlockEncodingManager.class).in(Scopes.SINGLETON);
newSetBinder(binder, BlockEncoding.class);
// catalog
binder.bind(CatalogManager.class).in(Scopes.SINGLETON);
// function
binder.bind(FunctionAndTypeManager.class).in(SINGLETON);
// handle resolver
binder.install(new HandleJsonModule());
// parser
binder.bind(SqlParserOptions.class).toInstance(sqlParserOptions);
binder.bind(SqlParser.class).in(SINGLETON);
// transaction
configBinder(binder).bindConfig(TransactionManagerConfig.class);
// type
configBinder(binder).bindConfig(FeaturesConfig.class);
binder.bind(TypeManager.class).to(FunctionAndTypeManager.class).in(SINGLETON);
newSetBinder(binder, Type.class);
// verifier
install(new VerificationQueryRewriterModule());
install(FailureResolverModule.BUILT_IN);
binder.bind(VerificationManager.class).in(SINGLETON);
binder.bind(VerificationFactory.class).in(SINGLETON);
binder.bind(ChecksumValidator.class).in(SINGLETON);
MapBinder<Category, ColumnValidator> columnValidatorBinder = MapBinder.newMapBinder(binder, Category.class, ColumnValidator.class);
columnValidatorBinder.addBinding(SIMPLE).to(SimpleColumnValidator.class).in(SINGLETON);
columnValidatorBinder.addBinding(FLOATING_POINT).to(FloatingPointColumnValidator.class).in(SINGLETON);
columnValidatorBinder.addBinding(ARRAY).to(ArrayColumnValidator.class).in(SINGLETON);
columnValidatorBinder.addBinding(ROW).to(RowColumnValidator.class).in(SINGLETON);
columnValidatorBinder.addBinding(MAP).to(MapColumnValidator.class).in(SINGLETON);
binder.bind(new TypeLiteral<List<Predicate<SourceQuery>>>() {
}).toProvider(new CustomQueryFilterProvider(customQueryFilterClasses));
}
use of com.google.inject.TypeLiteral in project presto by prestodb.
the class RedisConnectorFactory method create.
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
requireNonNull(catalogName, "catalogName is null");
requireNonNull(config, "config is null");
try {
Bootstrap app = new Bootstrap(new JsonModule(), new RedisConnectorModule(), binder -> {
binder.bind(RedisConnectorId.class).toInstance(new RedisConnectorId(catalogName));
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
if (tableDescriptionSupplier.isPresent()) {
binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {
}).toInstance(tableDescriptionSupplier.get());
} else {
binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {
}).to(RedisTableDescriptionSupplier.class).in(Scopes.SINGLETON);
}
});
Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
return injector.getInstance(RedisConnector.class);
} catch (Exception e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
use of com.google.inject.TypeLiteral in project guice by google.
the class CheckedProviderMethodsModule method createProviderMethod.
<T> CheckedProviderMethod<T> createProviderMethod(Binder binder, final Method method, CheckedProvides checkedProvides) {
// Class literal uses rawtypes.
@SuppressWarnings("rawtypes") Class<? extends CheckedProvider> throwingProvider = checkedProvides.value();
binder = binder.withSource(method);
Errors errors = new Errors(method);
// prepare the parameter providers
List<Dependency<?>> dependencies = Lists.newArrayList();
List<Provider<?>> parameterProviders = Lists.newArrayList();
List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
for (int i = 0; i < parameterTypes.size(); i++) {
Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
if (key.equals(LOGGER_KEY)) {
// If it was a Logger, change the key to be unique & bind it to a
// provider that provides a logger with a proper name.
// This solves issue 482 (returning a new anonymous logger on every call exhausts memory)
Key<Logger> loggerKey = Key.get(Logger.class, UniqueAnnotations.create());
binder.bind(loggerKey).toProvider(new LogProvider(method));
key = loggerKey;
}
dependencies.add(Dependency.get(key));
parameterProviders.add(binder.getProvider(key));
}
// Define T as the method's return type.
@SuppressWarnings("unchecked") TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
List<TypeLiteral<?>> exceptionTypes = typeLiteral.getExceptionTypes(method);
Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations());
for (Message message : errors.getMessages()) {
binder.addError(message);
}
return new CheckedProviderMethod<T>(key, method, delegate, ImmutableSet.copyOf(dependencies), parameterProviders, scopeAnnotation, throwingProvider, exceptionTypes, checkedProvides.scopeExceptions());
}
use of com.google.inject.TypeLiteral in project guice by google.
the class MapBinderTest method testMapBinderMatching.
@Marker
public void testMapBinderMatching() throws Exception {
Method m = MapBinderTest.class.getDeclaredMethod("testMapBinderMatching");
assertNotNull(m);
final Annotation marker = m.getAnnotation(Marker.class);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
MapBinder<Integer, Integer> mb1 = MapBinder.newMapBinder(binder(), Integer.class, Integer.class, Marker.class);
MapBinder<Integer, Integer> mb2 = MapBinder.newMapBinder(binder(), Integer.class, Integer.class, marker);
mb1.addBinding(1).toInstance(1);
mb2.addBinding(2).toInstance(2);
// This assures us that the two binders are equivalent, so we expect the instance added to
// each to have been added to one set.
assertEquals(mb1, mb2);
}
});
TypeLiteral<Map<Integer, Integer>> t = new TypeLiteral<Map<Integer, Integer>>() {
};
Map<Integer, Integer> s1 = injector.getInstance(Key.get(t, Marker.class));
Map<Integer, Integer> s2 = injector.getInstance(Key.get(t, marker));
// This assures us that the two sets are in fact equal. They may not be same set (as in Java
// object identical), but we shouldn't expect that, since probably Guice creates the set each
// time in case the elements are dependent on scope.
assertEquals(s1, s2);
// This ensures that MultiBinder is internally using the correct set name --
// making sure that instances of marker annotations have the same set name as
// MarkerAnnotation.class.
Map<Integer, Integer> expected = new HashMap<>();
expected.put(1, 1);
expected.put(2, 2);
assertEquals(expected, s1);
}
use of com.google.inject.TypeLiteral in project guice by google.
the class MoreTypesTest method testGetRawType_wildcard.
public <T> void testGetRawType_wildcard() throws Exception {
WildcardType wildcard = (WildcardType) ((ParameterizedType) new TypeLiteral<List<?>>() {
}.getType()).getActualTypeArguments()[0];
assertEquals(Object.class, MoreTypes.getRawType(wildcard));
}
Aggregations