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();
}
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();
}
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);
}
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;
}
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);
}
Aggregations