Search in sources :

Example 1 with TransactionalCachedView

use of cz.o2.proxima.direct.transaction.TransactionalCachedView in project proxima-platform by O2-Czech-Republic.

the class DirectDataOperator method getCachedView.

/**
 * Retrieve {@link CachedView} for given {@link AttributeDescriptor}s.
 *
 * @param attrs the attributes to find cached view for
 * @return optional cached view
 */
public Optional<CachedView> getCachedView(Collection<AttributeDescriptor<?>> attrs) {
    boolean hasTransactions = attrs.stream().anyMatch(a -> a.getTransactionMode() != TransactionMode.NONE);
    Optional<CachedView> view = getFamilyForAttributes(attrs, DirectAttributeFamilyDescriptor::hasCachedView).flatMap(DirectAttributeFamilyDescriptor::getCachedView);
    if (hasTransactions) {
        return view.map(v -> new TransactionalCachedView(this, v));
    }
    return view;
}
Also used : TransactionalCachedView(cz.o2.proxima.direct.transaction.TransactionalCachedView) CachedView(cz.o2.proxima.direct.view.CachedView) TransactionalCachedView(cz.o2.proxima.direct.transaction.TransactionalCachedView)

Example 2 with TransactionalCachedView

use of cz.o2.proxima.direct.transaction.TransactionalCachedView in project proxima-platform by O2-Czech-Republic.

the class TransactionalCachedViewTest method testInvariants.

@Test
public void testInvariants() {
    try (CachedView view = Optionals.get(direct.getCachedView(status, device))) {
        Factory factory = view.asFactory();
        try (CachedView newView = factory.apply(repo)) {
            assertTrue(newView instanceof TransactionalCachedView);
        }
        assertEquals(Type.ONLINE, view.getType());
        assertSame(view, view.online());
    }
}
Also used : CachedView(cz.o2.proxima.direct.view.CachedView) ConfigFactory(com.typesafe.config.ConfigFactory) Factory(cz.o2.proxima.direct.view.CachedView.Factory) Test(org.junit.Test)

Aggregations

CachedView (cz.o2.proxima.direct.view.CachedView)2 ConfigFactory (com.typesafe.config.ConfigFactory)1 TransactionalCachedView (cz.o2.proxima.direct.transaction.TransactionalCachedView)1 Factory (cz.o2.proxima.direct.view.CachedView.Factory)1 Test (org.junit.Test)1