org.elasticsearch.common.inject.AbstractModule Java Examples

The following examples show how to use org.elasticsearch.common.inject.AbstractModule. 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: Elements.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private RecordingBinder(Stage stage) {
    this.stage = stage;
    this.modules = Sets.newHashSet();
    this.elements = new ArrayList<>();
    this.source = null;
    this.sourceProvider = new SourceProvider().plusSkippedClasses(
            Elements.class, RecordingBinder.class, AbstractModule.class,
            ConstantBindingBuilderImpl.class, AbstractBindingBuilder.class, BindingBuilder.class);
    this.parent = null;
    this.privateElements = null;
}
 
Example #2
Source File: FactoryProvider2.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a child injector that binds the args, and returns the binding for the method's result.
 */
public Binding<?> getBindingFromNewInjector(final Method method, final Object[] args) {
    checkState(injector != null,
            "Factories.create() factories cannot be used until they're initialized by Guice.");

    final Key<?> returnType = returnTypesByMethod.get(method);

    Module assistedModule = new AbstractModule() {
        @Override
        @SuppressWarnings("unchecked") // raw keys are necessary for the args array and return value
        protected void configure() {
            Binder binder = binder().withSource(method);

            int p = 0;
            for (Key<?> paramKey : paramTypes.get(method)) {
                // Wrap in a Provider to cover null, and to prevent Guice from injecting the parameter
                binder.bind((Key) paramKey).toProvider(Providers.of(args[p++]));
            }

            if (producedType != null && !returnType.equals(producedType)) {
                binder.bind(returnType).to((Key) producedType);
            } else {
                binder.bind(returnType);
            }
        }
    };

    Injector forCreate = injector.createChildInjector(assistedModule);
    return forCreate.getBinding(returnType);
}
 
Example #3
Source File: Elements.java    From crate with Apache License 2.0 5 votes vote down vote up
private RecordingBinder(Stage stage) {
    this.stage = stage;
    this.modules = new HashSet<>();
    this.elements = new ArrayList<>();
    this.source = null;
    this.sourceProvider = new SourceProvider().plusSkippedClasses(
            Elements.class, RecordingBinder.class, AbstractModule.class,
            ConstantBindingBuilderImpl.class, AbstractBindingBuilder.class, BindingBuilder.class);
    this.parent = null;
    this.privateElements = null;
}
 
Example #4
Source File: SqlExpressions.java    From crate with Apache License 2.0 5 votes vote down vote up
public SqlExpressions(Map<RelationName, AnalyzedRelation> sources,
                      @Nullable FieldResolver fieldResolver,
                      User user,
                      AbstractModule... additionalModules) {
    ModulesBuilder modulesBuilder = new ModulesBuilder()
        .add(new SessionSettingModule())
        .add(new OperatorModule())
        .add(new AggregationImplModule())
        .add(new ScalarFunctionModule())
        .add(new WindowFunctionModule())
        .add(new TableFunctionModule())
        .add(new PredicateModule());
    if (additionalModules != null) {
        for (AbstractModule module : additionalModules) {
            modulesBuilder.add(module);
        }
    }
    injector = modulesBuilder.createInjector();
    functions = injector.getInstance(Functions.class);
    coordinatorTxnCtx = new CoordinatorTxnCtx(new SessionContext(Option.NONE, user));
    expressionAnalyzer = new ExpressionAnalyzer(
        functions,
        coordinatorTxnCtx,
        ParamTypeHints.EMPTY,
        new FullQualifiedNameFieldProvider(
            sources,
            ParentRelations.NO_PARENTS,
            coordinatorTxnCtx.sessionContext().searchPath().currentSchema()),
        new SubqueryAnalyzer(
            new RelationAnalyzer(functions, mock(Schemas.class)),
            new StatementAnalysisContext(ParamTypeHints.EMPTY, Operation.READ, coordinatorTxnCtx)
        )
    );
    normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, null, fieldResolver);
    expressionAnalysisCtx = new ExpressionAnalysisContext();
}
 
Example #5
Source File: AbstractWindowFunctionTest.java    From crate with Apache License 2.0 4 votes vote down vote up
public AbstractWindowFunctionTest(AbstractModule... additionalModules) {
    this.additionalModules = additionalModules;
}