DATACASS-305 - Polishing.
Add generics to list of specifications. Extract CQL generation in own method. Add author tag. Original pull request: #70.
This commit is contained in:
@@ -63,6 +63,7 @@ import com.datastax.driver.core.policies.RetryPolicy;
|
||||
* @author Jorge Davison
|
||||
* @author John Blum
|
||||
* @author Mark Paluch
|
||||
* @author Stefan Birkner
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
@@ -267,20 +268,18 @@ public class CassandraCqlClusterFactoryBean
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeSpecsAndScripts(@SuppressWarnings("rawtypes") List specs, List<String> scripts) {
|
||||
protected void executeSpecsAndScripts(List<? extends KeyspaceActionSpecification<?>> specifications, List<String> scripts) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(specifications) || !CollectionUtils.isEmpty(scripts)) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(specs) || !CollectionUtils.isEmpty(scripts)) {
|
||||
Session session = cluster.connect();
|
||||
|
||||
try {
|
||||
|
||||
CqlTemplate template = new CqlTemplate(session);
|
||||
|
||||
for (Object spec : specs) {
|
||||
String cql = (spec instanceof CreateKeyspaceSpecification)
|
||||
? new CreateKeyspaceCqlGenerator((CreateKeyspaceSpecification) spec).toCql()
|
||||
: new DropKeyspaceCqlGenerator((DropKeyspaceSpecification) spec).toCql();
|
||||
|
||||
template.execute(cql);
|
||||
for (KeyspaceActionSpecification<?> spec : specifications) {
|
||||
template.execute(toCql(spec));
|
||||
}
|
||||
|
||||
for (String script : scripts) {
|
||||
@@ -294,6 +293,15 @@ public class CassandraCqlClusterFactoryBean
|
||||
}
|
||||
}
|
||||
|
||||
private String toCql(KeyspaceActionSpecification<?> spec) {
|
||||
|
||||
if(spec instanceof CreateKeyspaceSpecification) {
|
||||
return new CreateKeyspaceCqlGenerator((CreateKeyspaceSpecification) spec).toCql();
|
||||
}
|
||||
|
||||
return new DropKeyspaceCqlGenerator((DropKeyspaceSpecification) spec).toCql();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a comma-delimited string of the contact points (hosts) to connect to. Default is {@code localhost}, see
|
||||
* {@link #DEFAULT_CONTACT_POINTS}.
|
||||
|
||||
Reference in New Issue
Block a user