Search in sources :

Example 6 with ConnectionDetails

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails in project elide by yahoo.

the class ElideStandaloneSettings method getQueryEngine.

/**
 * Gets the QueryEngine for elide.
 * @param metaDataStore MetaDataStore object.
 * @param defaultConnectionDetails default DataSource Object and SQLDialect Object.
 * @param dynamicConfiguration Optional dynamic config.
 * @param dataSourceConfiguration DataSource Configuration.
 * @param dbPasswordExtractor Password Extractor Implementation.
 * @return QueryEngine object initialized.
 */
default QueryEngine getQueryEngine(MetaDataStore metaDataStore, ConnectionDetails defaultConnectionDetails, Optional<DynamicConfiguration> dynamicConfiguration, DataSourceConfiguration dataSourceConfiguration, DBPasswordExtractor dbPasswordExtractor) {
    if (dynamicConfiguration.isPresent()) {
        Map<String, ConnectionDetails> connectionDetailsMap = new HashMap<>();
        dynamicConfiguration.get().getDatabaseConfigurations().forEach(dbConfig -> connectionDetailsMap.put(dbConfig.getName(), new ConnectionDetails(dataSourceConfiguration.getDataSource(dbConfig, dbPasswordExtractor), SQLDialectFactory.getDialect(dbConfig.getDialect()))));
        Function<String, ConnectionDetails> connectionDetailsLookup = (name) -> {
            if (StringUtils.isEmpty(name)) {
                return defaultConnectionDetails;
            }
            return Optional.ofNullable(connectionDetailsMap.get(name)).orElseThrow(() -> new IllegalStateException("ConnectionDetails undefined for connection: " + name));
        };
        return new SQLQueryEngine(metaDataStore, connectionDetailsLookup, new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()));
    }
    return new SQLQueryEngine(metaDataStore, (unused) -> defaultConnectionDetails);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Arrays(java.util.Arrays) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Role(com.yahoo.elide.core.security.checks.prefab.Role) StringUtils(org.apache.commons.lang3.StringUtils) ClassType(com.yahoo.elide.core.type.ClassType) DataSourceConfiguration(com.yahoo.elide.datastores.aggregation.queryengines.sql.DataSourceConfiguration) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) Map(java.util.Map) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) JsonApiMapper(com.yahoo.elide.jsonapi.JsonApiMapper) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) TableExport(com.yahoo.elide.async.models.TableExport) TemplateConfigValidator(com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator) SQLDialectFactory(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) TimeZone(java.util.TimeZone) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) CaffeineCache(com.yahoo.elide.datastores.aggregation.cache.CaffeineCache) Set(java.util.Set) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) List(java.util.List) EntityManagerFactory(javax.persistence.EntityManagerFactory) DataStore(com.yahoo.elide.core.datastore.DataStore) SwaggerBuilder(com.yahoo.elide.swagger.SwaggerBuilder) Optional(java.util.Optional) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) ErrorMapper(com.yahoo.elide.core.exceptions.ErrorMapper) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Swagger(io.swagger.models.Swagger) Session(org.hibernate.Session) HashMap(java.util.HashMap) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) HashSet(java.util.HashSet) DBPasswordExtractor(com.yahoo.elide.modelconfig.DBPasswordExtractor) Injector(com.yahoo.elide.core.dictionary.Injector) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) ElideSettings(com.yahoo.elide.ElideSettings) Slf4jQueryLogger(com.yahoo.elide.datastores.aggregation.core.Slf4jQueryLogger) QueryEngine(com.yahoo.elide.datastores.aggregation.QueryEngine) DEFAULT_LOGGER(com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER) Check(com.yahoo.elide.core.security.checks.Check) Properties(java.util.Properties) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) IOException(java.io.IOException) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityManager(javax.persistence.EntityManager) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) Consumer(java.util.function.Consumer) AuditLogger(com.yahoo.elide.core.audit.AuditLogger) Type(com.yahoo.elide.core.type.Type) Collections(java.util.Collections) DocEndpoint(com.yahoo.elide.swagger.resources.DocEndpoint) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) HashMap(java.util.HashMap) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)

Aggregations

ConnectionDetails (com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails)6 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)4 ClassType (com.yahoo.elide.core.type.ClassType)4 Type (com.yahoo.elide.core.type.Type)4 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)4 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 DataSource (javax.sql.DataSource)4 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)3 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)3 CoerceUtil (com.yahoo.elide.core.utils.coerce.CoerceUtil)3 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)3 QueryEngine (com.yahoo.elide.datastores.aggregation.QueryEngine)3 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)3 SQLDialect (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect)3 SQLDialectFactory (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory)3 HikariConfig (com.zaxxer.hikari.HikariConfig)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 Properties (java.util.Properties)3