Search in sources :

Example 1 with Provider

use of org.elasticsearch.common.inject.Provider in project crate by crate.

the class DocIndexMetaDataTest method getDocIndexMetaDataFromStatement.

private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
    Statement statement = SqlParser.createStatement(stmt);
    ClusterService clusterService = new NoopClusterService();
    final TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
    Provider<TransportPutIndexTemplateAction> indexTemplateActionProvider = new Provider<TransportPutIndexTemplateAction>() {

        @Override
        public TransportPutIndexTemplateAction get() {
            return transportPutIndexTemplateAction;
        }
    };
    DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(functions, new IndexNameExpressionResolver(Settings.EMPTY), indexTemplateActionProvider, executorService);
    DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DEFAULT_SCHEMA_NAME, clusterService, docTableInfoFactory);
    CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(new Schemas(Settings.EMPTY, ImmutableMap.<String, SchemaInfo>of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory)), new FulltextAnalyzerResolver(clusterService, new IndicesAnalysisService(Settings.EMPTY)), functions, new NumberOfShards(clusterService));
    Analysis analysis = new Analysis(SessionContext.SYSTEM_SESSION, ParameterContext.EMPTY, ParamTypeHints.EMPTY);
    CreateTableAnalyzedStatement analyzedStatement = analyzer.analyze((CreateTable) statement, analysis.parameterContext(), analysis.sessionContext());
    Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
    IndexMetaData indexMetaData = IndexMetaData.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
    return newMeta(indexMetaData, analyzedStatement.tableIdent().name());
}
Also used : IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) Statement(io.crate.sql.tree.Statement) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Provider(org.elasticsearch.common.inject.Provider) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Settings(org.elasticsearch.common.settings.Settings) SchemaInfo(io.crate.metadata.table.SchemaInfo)

Example 2 with Provider

use of org.elasticsearch.common.inject.Provider in project elasticsearch by elastic.

the class ProviderMethodsModule method createProviderMethod.

<T> ProviderMethod<T> createProviderMethod(Binder binder, final Method method) {
    binder = binder.withSource(method);
    Errors errors = new Errors(method);
    // prepare the parameter providers
    Set<Dependency<?>> dependencies = new HashSet<>();
    List<Provider<?>> parameterProviders = new ArrayList<>();
    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]);
        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);
    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 ProviderMethod<>(key, method, delegate, unmodifiableSet(dependencies), parameterProviders, scopeAnnotation);
}
Also used : Message(org.elasticsearch.common.inject.spi.Message) ArrayList(java.util.ArrayList) Dependency(org.elasticsearch.common.inject.spi.Dependency) Provider(org.elasticsearch.common.inject.Provider) TypeLiteral(org.elasticsearch.common.inject.TypeLiteral) HashSet(java.util.HashSet)

Aggregations

Provider (org.elasticsearch.common.inject.Provider)2 SchemaInfo (io.crate.metadata.table.SchemaInfo)1 Statement (io.crate.sql.tree.Statement)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TransportPutIndexTemplateAction (org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)1 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)1 TypeLiteral (org.elasticsearch.common.inject.TypeLiteral)1 Dependency (org.elasticsearch.common.inject.spi.Dependency)1 Message (org.elasticsearch.common.inject.spi.Message)1 Settings (org.elasticsearch.common.settings.Settings)1 IndicesAnalysisService (org.elasticsearch.indices.analysis.IndicesAnalysisService)1 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)1