switched from *Template to *Operations in C*TemplateFactoryBean

This commit is contained in:
Matthew Adams
2013-12-10 14:27:21 -06:00
parent ffdeaa9fe8
commit 4045f52e6f
5 changed files with 12 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ public abstract class AbstractCassandraConfiguration {
/**
* The name of the keyspace to connect to. If {@literal null} or empty, then the system keyspace will be used.
*/
protected abstract String getKeyspace();
protected abstract String getKeyspaceName();
/**
* The {@link Cluster} instance to connect to. Must not be null.
@@ -51,19 +51,15 @@ public abstract class AbstractCassandraConfiguration {
*/
@Bean
public Session session() {
String keyspace = getKeyspace();
if (StringUtils.hasText(keyspace)) {
return cluster().connect(keyspace);
} else {
return cluster().connect();
}
String keyspaceName = getKeyspaceName();
return StringUtils.hasText(keyspaceName) ? cluster().connect(keyspaceName) : cluster().connect();
}
/**
* A {@link CassandraTemplate} created from the {@link Session} returned by {@link #session()}.
*/
@Bean
public CassandraOperations cassandraTemplate() {
public CassandraOperations template() {
return new CassandraTemplate(session());
}
}

View File

@@ -19,6 +19,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cassandra.core.CassandraOperations;
import org.springframework.cassandra.core.CassandraTemplate;
import com.datastax.driver.core.Session;
@@ -28,20 +29,19 @@ import com.datastax.driver.core.Session;
*
* @author Matthew T. Adams
*/
public class CassandraTemplateFactoryBean implements FactoryBean<CassandraTemplate>, InitializingBean {
public class CassandraTemplateFactoryBean implements FactoryBean<CassandraOperations>, InitializingBean {
private static final Logger log = LoggerFactory.getLogger(CassandraTemplateFactoryBean.class);
private CassandraTemplate template;
private Session session;
public CassandraTemplate getObject() {
public CassandraOperations getObject() {
return template;
}
public Class<? extends CassandraTemplate> getObjectType() {
return CassandraTemplate.class;
public Class<? extends CassandraOperations> getObjectType() {
return CassandraOperations.class;
}
public boolean isSingleton() {

View File

@@ -21,7 +21,7 @@ public abstract class AbstractKeyspaceCreatingConfiguration extends AbstractInte
}
protected void createKeyspaceIfNecessary() {
String keyspace = getKeyspace();
String keyspace = getKeyspaceName();
if (!StringUtils.hasText(keyspace)) {
return;
}

View File

@@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
public class Config extends AbstractIntegrationTestConfiguration {
@Override
protected String getKeyspace() {
protected String getKeyspaceName() {
return null;
}
}

View File

@@ -8,7 +8,7 @@ public class KeyspaceCreatingConfig extends AbstractKeyspaceCreatingConfiguratio
public static final String KEYSPACE = "kcc";
@Override
protected String getKeyspace() {
protected String getKeyspaceName() {
return KEYSPACE;
}
}