Search in sources :

Example 1 with SessionFactory

use of org.springframework.data.cassandra.SessionFactory in project spring-data-cassandra by spring-projects.

the class AsyncCqlTemplate method getCurrentSession.

private CqlSession getCurrentSession() {
    SessionFactory sessionFactory = getSessionFactory();
    Assert.state(sessionFactory != null, "SessionFactory is null");
    return sessionFactory.getSession();
}
Also used : SessionFactory(org.springframework.data.cassandra.SessionFactory)

Example 2 with SessionFactory

use of org.springframework.data.cassandra.SessionFactory in project spring-data-cassandra by spring-projects.

the class CqlTemplate method getCurrentSession.

private CqlSession getCurrentSession() {
    SessionFactory sessionFactory = getSessionFactory();
    Assert.state(sessionFactory != null, "SessionFactory is null");
    return sessionFactory.getSession();
}
Also used : SessionFactory(org.springframework.data.cassandra.SessionFactory)

Example 3 with SessionFactory

use of org.springframework.data.cassandra.SessionFactory in project spring-data-cassandra by spring-projects.

the class BeanFactorySessionFactoryLookupUnitTests method shouldResolveSessionFactoryFromBeanFactory.

// DATACASS-330
@Test
void shouldResolveSessionFactoryFromBeanFactory() throws Exception {
    when(beanFactory.getBean("factory", SessionFactory.class)).thenReturn(sessionFactory);
    BeanFactorySessionFactoryLookup lookup = new BeanFactorySessionFactoryLookup();
    lookup.setBeanFactory(beanFactory);
    SessionFactory result = lookup.getSessionFactory("factory");
    assertThat(result).isSameAs(sessionFactory);
}
Also used : SessionFactory(org.springframework.data.cassandra.SessionFactory) BeanFactorySessionFactoryLookup(org.springframework.data.cassandra.core.cql.session.lookup.BeanFactorySessionFactoryLookup) Test(org.junit.jupiter.api.Test)

Example 4 with SessionFactory

use of org.springframework.data.cassandra.SessionFactory in project spring-data-cassandra by spring-projects.

the class AbstractRoutingSessionFactory method determineTargetSessionFactory.

/**
 * Retrieve the current target {@link SessionFactory}. Determines the {@link #determineCurrentLookupKey() current
 * lookup key}, performs a lookup in the {@link #setTargetSessionFactories(Map)} map, falls back to the specified
 * {@link #setDefaultTargetSessionFactory default target SessionFactory} if necessary.
 *
 * @see #determineCurrentLookupKey()
 */
protected SessionFactory determineTargetSessionFactory() {
    Assert.notNull(this.resolvedSessionFactories, "SessionFactory router not initialized");
    Object lookupKey = determineCurrentLookupKey();
    SessionFactory sessionFactory = this.resolvedSessionFactories.get(lookupKey);
    if (sessionFactory == null && (this.lenientFallback || lookupKey == null)) {
        sessionFactory = this.resolvedDefaultSessionFactory;
    }
    if (sessionFactory == null) {
        throw new IllegalStateException(String.format("Cannot determine target SessionFactory for lookup key [%s]", lookupKey));
    }
    return sessionFactory;
}
Also used : SessionFactory(org.springframework.data.cassandra.SessionFactory)

Example 5 with SessionFactory

use of org.springframework.data.cassandra.SessionFactory in project spring-data-cassandra by spring-projects.

the class SingleSessionFactoryLookupUnitTests method shouldResolveSessionFactory.

// DATACASS-330
@Test
void shouldResolveSessionFactory() {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    SessionFactory result = new SingleSessionFactoryLookup(sessionFactory).getSessionFactory("any");
    assertThat(result).isSameAs(sessionFactory);
}
Also used : SessionFactory(org.springframework.data.cassandra.SessionFactory) SingleSessionFactoryLookup(org.springframework.data.cassandra.core.cql.session.lookup.SingleSessionFactoryLookup) Test(org.junit.jupiter.api.Test)

Aggregations

SessionFactory (org.springframework.data.cassandra.SessionFactory)7 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BeanFactorySessionFactoryLookup (org.springframework.data.cassandra.core.cql.session.lookup.BeanFactorySessionFactoryLookup)1 SingleSessionFactoryLookup (org.springframework.data.cassandra.core.cql.session.lookup.SingleSessionFactoryLookup)1