/** * Creates an instance of {@link CassandraTemplate} initialized with the given {@link SessionFactory} and * {@link CassandraConverter}. * * @param sessionFactory {@link SessionFactory} used to interact with Cassandra; must not be {@literal null}. * @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be * {@literal null}. * @see CassandraConverter * @see SessionFactory */ public CassandraTemplate(SessionFactory sessionFactory, CassandraConverter converter) { this(new CqlTemplate(sessionFactory), converter); }
CqlOperations newCqlOperations(Session session) { return new CqlTemplate(session); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(session, "Session must not be null"); this.template = new CqlTemplate(session); }
/** * Creates a {@link CqlTemplate} configured with {@link #sessionFactory()}. * * @return the {@link CqlTemplate}. * @see #sessionFactory() */ @Bean public CqlTemplate cqlTemplate() { return new CqlTemplate(sessionFactory()); } }
private void executeSpecsAndScripts(List<? extends KeyspaceActionSpecification> keyspaceActionSpecifications, List<String> scripts, Cluster cluster) { if (!CollectionUtils.isEmpty(keyspaceActionSpecifications) || !CollectionUtils.isEmpty(scripts)) { Session session = cluster.connect(); try { CqlTemplate template = new CqlTemplate(session); keyspaceActionSpecifications .forEach(keyspaceActionSpecification -> template.execute(toCql(keyspaceActionSpecification))); scripts.forEach(template::execute); } finally { if (session != null) { session.close(); } } } }