Search in sources :

Example 1 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class ElideCustomSerdeRegistrationTest method testRegisterCustomSerde.

@Test
public void testRegisterCustomSerde() {
    // Create a fake Elide.  Don't actually bind any entities.
    HashMapDataStore wrapped = new HashMapDataStore(DefaultClassScanner.getInstance(), String.class.getPackage());
    InMemoryDataStore store = new InMemoryDataStore(wrapped);
    ElideSettings elideSettings = new ElideSettingsBuilder(store).withEntityDictionary(EntityDictionary.builder().build()).build();
    Elide elide = new Elide(elideSettings);
    elide.doScans();
    assertNotNull(CoerceUtil.lookup(Dummy.class));
    assertNotNull(CoerceUtil.lookup(DummyTwo.class));
    assertNotNull(CoerceUtil.lookup(DummyThree.class));
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) ElideSettings(com.yahoo.elide.ElideSettings) Elide(com.yahoo.elide.Elide) InMemoryDataStore(com.yahoo.elide.core.datastore.inmemory.InMemoryDataStore) Test(org.junit.jupiter.api.Test)

Example 2 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class MetaDataStore method getMetaData.

/**
 * Get all metadata of a specific metadata class.
 *
 * @param cls metadata class
 * @param <T> metadata class
 * @return all metadata of given class
 */
public <T> Set<T> getMetaData(Type<T> cls) {
    String version = EntityDictionary.getModelVersion(cls);
    HashMapDataStore hashMapDataStore = hashMapDataStores.computeIfAbsent(version, SERVER_ERROR);
    return hashMapDataStore.get(cls).values().stream().map(obj -> (T) obj).collect(Collectors.toSet());
}
Also used : HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) Getter(lombok.Getter) IS_FIELD_HIDDEN(com.yahoo.elide.datastores.aggregation.AggregationDataStore.IS_FIELD_HIDDEN) Include(com.yahoo.elide.annotation.Include) Dimension(com.yahoo.elide.datastores.aggregation.metadata.models.Dimension) HashMap(java.util.HashMap) Function(java.util.function.Function) HashSet(java.util.HashSet) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Pair(org.apache.commons.lang3.tuple.Pair) DEFAULT_NAMESPACE(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT_NAMESPACE) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) Map(java.util.Map) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) InternalServerErrorException(com.yahoo.elide.core.exceptions.InternalServerErrorException) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) Entity(javax.persistence.Entity) ApiVersion(com.yahoo.elide.annotation.ApiVersion) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) TableSource(com.yahoo.elide.datastores.aggregation.metadata.models.TableSource) DEFAULT(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) Collection(java.util.Collection) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) TimeDimensionGrain(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimensionGrain) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Subselect(org.hibernate.annotations.Subselect) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) List(java.util.List) Versioned(com.yahoo.elide.datastores.aggregation.metadata.models.Versioned) TypeHelper.getClassType(com.yahoo.elide.core.utils.TypeHelper.getClassType) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) EMPTY(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.EMPTY) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) Metric(com.yahoo.elide.datastores.aggregation.metadata.models.Metric) DEFAULT(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)

Example 3 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class MultiplexManagerTest method partialCommitFailure.

@Test
public void partialCommitFailure() throws IOException {
    final EntityDictionary entityDictionary = EntityDictionary.builder().build();
    final HashMapDataStore ds1 = new HashMapDataStore(DefaultClassScanner.getInstance(), FirstBean.class.getPackage());
    final DataStore ds2 = new TestDataStore(OtherBean.class.getPackage());
    final MultiplexManager multiplexManager = new MultiplexManager(ds1, ds2);
    multiplexManager.populateEntityDictionary(entityDictionary);
    assertEquals(ds1, multiplexManager.getSubManager(ClassType.of(FirstBean.class)));
    assertEquals(ds2, multiplexManager.getSubManager(ClassType.of(OtherBean.class)));
    try (DataStoreTransaction t = ds1.beginTransaction()) {
        assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
        FirstBean firstBean = FirstBean.class.newInstance();
        firstBean.setName("name");
        t.createObject(firstBean, null);
        // t.save(firstBean);
        assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
        t.commit(null);
    } catch (InstantiationException | IllegalAccessException e) {
        log.error("", e);
    }
    try (DataStoreTransaction t = multiplexManager.beginTransaction()) {
        FirstBean firstBean = (FirstBean) t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().next();
        firstBean.setName("update");
        t.save(firstBean, null);
        OtherBean otherBean = OtherBean.class.newInstance();
        t.createObject(otherBean, null);
        // t.save(firstBean);
        assertThrows(TransactionException.class, () -> t.commit(null));
    } catch (InstantiationException | IllegalAccessException e) {
        log.error("", e);
    }
    // verify state
    try (DataStoreTransaction t = ds1.beginTransaction()) {
        Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
        assertNotNull(beans);
        ArrayList<Object> list = Lists.newArrayList(beans.iterator());
        assertEquals(list.size(), 1);
        assertEquals(((FirstBean) list.get(0)).getName(), "name");
    }
}
Also used : OtherBean(com.yahoo.elide.example.other.OtherBean) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) FirstBean(com.yahoo.elide.example.beans.FirstBean) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Example 4 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class MultiplexManagerTest method setup.

@BeforeAll
public void setup() {
    ClassScanner scanner = DefaultClassScanner.getInstance();
    entityDictionary = EntityDictionary.builder().build();
    final HashMapDataStore inMemoryDataStore1 = new HashMapDataStore(scanner, FirstBean.class.getPackage());
    final HashMapDataStore inMemoryDataStore2 = new HashMapDataStore(scanner, OtherBean.class.getPackage());
    multiplexManager = new MultiplexManager(inMemoryDataStore1, inMemoryDataStore2);
    multiplexManager.populateEntityDictionary(entityDictionary);
}
Also used : ClassScanner(com.yahoo.elide.core.utils.ClassScanner) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) FirstBean(com.yahoo.elide.example.beans.FirstBean) OtherBean(com.yahoo.elide.example.other.OtherBean) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with HashMapDataStore

use of com.yahoo.elide.core.datastore.inmemory.HashMapDataStore in project elide by yahoo.

the class AsyncAPICancelRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    cancelThread = new AsyncAPICancelRunnable(7, elide, asyncAPIDao);
    transactionRegistry = elide.getTransactionRegistry();
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)15 Elide (com.yahoo.elide.Elide)11 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)10 HashMap (java.util.HashMap)9 Check (com.yahoo.elide.core.security.checks.Check)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 RequestScope (com.yahoo.elide.core.RequestScope)5 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)4 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)3 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 User (com.yahoo.elide.core.security.User)3 AsyncAPIInlineChecks (com.yahoo.elide.async.models.security.AsyncAPIInlineChecks)2 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)2 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)2 DataStore (com.yahoo.elide.core.datastore.DataStore)2 DuplicateMappingException (com.yahoo.elide.core.exceptions.DuplicateMappingException)2 ClassScanner (com.yahoo.elide.core.utils.ClassScanner)2 FirstBean (com.yahoo.elide.example.beans.FirstBean)2