Search in sources :

Example 1 with JpaDataStore

use of com.yahoo.elide.datastores.jpa.JpaDataStore in project elide by yahoo.

the class AggregationDataStoreTestHarness method getDataStore.

@Override
public DataStore getDataStore() {
    AggregationDataStore.AggregationDataStoreBuilder aggregationDataStoreBuilder = AggregationDataStore.builder();
    ClassScanner scanner = DefaultClassScanner.getInstance();
    MetaDataStore metaDataStore;
    if (validator != null) {
        metaDataStore = new MetaDataStore(scanner, validator.getElideTableConfig().getTables(), validator.getElideNamespaceConfig().getNamespaceconfigs(), true);
        aggregationDataStoreBuilder.dynamicCompiledClasses(metaDataStore.getDynamicTypes());
    } else {
        metaDataStore = new MetaDataStore(scanner, true);
    }
    AggregationDataStore aggregationDataStore = aggregationDataStoreBuilder.queryEngine(new SQLQueryEngine(metaDataStore, (name) -> connectionDetailsMap.getOrDefault(name, defaultConnectionDetails), new HashSet<>(Arrays.asList(new AggregateBeforeJoinOptimizer(metaDataStore))), new DefaultQueryPlanMerger(metaDataStore), new DefaultQueryValidator(metaDataStore.getMetadataDictionary()))).queryLogger(new Slf4jQueryLogger()).build();
    Consumer<EntityManager> txCancel = em -> em.unwrap(Session.class).cancelQuery();
    DataStore jpaStore = new JpaDataStore(() -> entityManagerFactory.createEntityManager(), em -> new NonJtaTransaction(em, txCancel));
    return new MultiplexManager(jpaStore, metaDataStore, aggregationDataStore);
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Arrays(java.util.Arrays) SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Session(org.hibernate.Session) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) HashSet(java.util.HashSet) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) Map(java.util.Map) DataSource(javax.sql.DataSource) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) Slf4jQueryLogger(com.yahoo.elide.datastores.aggregation.core.Slf4jQueryLogger) SQLDialectFactory(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) EntityManager(javax.persistence.EntityManager) DataStoreTestHarness(com.yahoo.elide.core.datastore.test.DataStoreTestHarness) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) Consumer(java.util.function.Consumer) EntityManagerFactory(javax.persistence.EntityManagerFactory) DataStore(com.yahoo.elide.core.datastore.DataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) DefaultQueryValidator(com.yahoo.elide.datastores.aggregation.DefaultQueryValidator) Slf4jQueryLogger(com.yahoo.elide.datastores.aggregation.core.Slf4jQueryLogger) EntityManager(javax.persistence.EntityManager) AggregateBeforeJoinOptimizer(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) HashSet(java.util.HashSet) Session(org.hibernate.Session)

Example 2 with JpaDataStore

use of com.yahoo.elide.datastores.jpa.JpaDataStore in project elide by yahoo.

the class ElideStandaloneSettings method getDataStore.

/**
 * Gets the DataStore for elide.
 * @param metaDataStore MetaDataStore object.
 * @param aggregationDataStore AggregationDataStore object.
 * @param entityManagerFactory EntityManagerFactory object.
 * @return DataStore object initialized.
 */
default DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore aggregationDataStore, EntityManagerFactory entityManagerFactory) {
    List<DataStore> stores = new ArrayList<>();
    DataStore jpaDataStore = new JpaDataStore(() -> entityManagerFactory.createEntityManager(), em -> new NonJtaTransaction(em, TXCANCEL, DEFAULT_LOGGER, true, true));
    stores.add(jpaDataStore);
    if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
        stores.add(new ConfigDataStore(getAnalyticProperties().getDynamicConfigPath(), new TemplateConfigValidator(getClassScanner(), getAnalyticProperties().getDynamicConfigPath())));
    }
    stores.add(metaDataStore);
    stores.add(aggregationDataStore);
    return new MultiplexManager(stores.toArray(new DataStore[0]));
}
Also used : JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) TemplateConfigValidator(com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) ArrayList(java.util.ArrayList) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager)

Example 3 with JpaDataStore

use of com.yahoo.elide.datastores.jpa.JpaDataStore in project elide by yahoo.

the class ElideAutoConfiguration method buildDataStore.

/**
 * Creates the DataStore Elide.  Override to use a different store.
 * @param entityManagerFactory The JPA factory which creates entity managers.
 * @param scanner Class Scanner
 * @param queryEngine QueryEngine instance for aggregation data store.
 * @param settings Elide configuration settings.
 * @param cache Analytics query cache
 * @param querylogger Analytics query logger
 * @return An instance of a JPA DataStore.
 */
@Bean
@ConditionalOnMissingBean
@Scope(SCOPE_PROTOTYPE)
public DataStore buildDataStore(EntityManagerFactory entityManagerFactory, ClassScanner scanner, @Autowired(required = false) QueryEngine queryEngine, ElideConfigProperties settings, @Autowired(required = false) Cache cache, @Autowired(required = false) QueryLogger querylogger) {
    List<DataStore> stores = new ArrayList<>();
    JpaDataStore jpaDataStore = new JpaDataStore(entityManagerFactory::createEntityManager, em -> new NonJtaTransaction(em, txCancel, DEFAULT_LOGGER, settings.getJpaStore().isDelegateToInMemoryStore(), true));
    stores.add(jpaDataStore);
    if (isAggregationStoreEnabled(settings)) {
        AggregationDataStore.AggregationDataStoreBuilder aggregationDataStoreBuilder = AggregationDataStore.builder().queryEngine(queryEngine);
        if (isDynamicConfigEnabled(settings)) {
            aggregationDataStoreBuilder.dynamicCompiledClasses(queryEngine.getMetaDataStore().getDynamicTypes());
            if (settings.getDynamicConfig().isConfigApiEnabled()) {
                stores.add(new ConfigDataStore(settings.getDynamicConfig().getPath(), new TemplateConfigValidator(scanner, settings.getDynamicConfig().getPath())));
            }
        }
        aggregationDataStoreBuilder.cache(cache);
        aggregationDataStoreBuilder.queryLogger(querylogger);
        AggregationDataStore aggregationDataStore = aggregationDataStoreBuilder.build();
        stores.add(queryEngine.getMetaDataStore());
        stores.add(aggregationDataStore);
        // meta data store needs to be put at first to populate meta data models
        return new MultiplexManager(stores.toArray(new DataStore[0]));
    }
    return jpaDataStore;
}
Also used : JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) TemplateConfigValidator(com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) JpaDataStore(com.yahoo.elide.datastores.jpa.JpaDataStore) ConfigDataStore(com.yahoo.elide.modelconfig.store.ConfigDataStore) ArrayList(java.util.ArrayList) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) NonJtaTransaction(com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction) MultiplexManager(com.yahoo.elide.datastores.multiplex.MultiplexManager) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DataStore (com.yahoo.elide.core.datastore.DataStore)3 AggregationDataStore (com.yahoo.elide.datastores.aggregation.AggregationDataStore)3 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)3 JpaDataStore (com.yahoo.elide.datastores.jpa.JpaDataStore)3 NonJtaTransaction (com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction)3 MultiplexManager (com.yahoo.elide.datastores.multiplex.MultiplexManager)3 TemplateConfigValidator (com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator)2 ConfigDataStore (com.yahoo.elide.modelconfig.store.ConfigDataStore)2 ArrayList (java.util.ArrayList)2 DataStoreTestHarness (com.yahoo.elide.core.datastore.test.DataStoreTestHarness)1 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)1 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)1 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)1 Slf4jQueryLogger (com.yahoo.elide.datastores.aggregation.core.Slf4jQueryLogger)1 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)1 ConnectionDetails (com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails)1 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)1 SQLDialectFactory (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory)1 AggregateBeforeJoinOptimizer (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.AggregateBeforeJoinOptimizer)1 DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)1