DATACASS-305 - Improve readability of CassandraCqlClusterFactoryBean.executeSpecsAndScripts.

We now check first whether any CQL statements need to be executed. This makes the code simpler because we don't have to check whether the session has already been created. Rename the Session variable system to session to omit confusion. Remove CQL logging here as CQL statements are logged inside the CqlTemplate.

Original pull request: #70.
This commit is contained in:
Stefan Birkner
2016-06-19 22:54:10 +02:00
committed by Mark Paluch
parent 570d71a905
commit 5154d2b531

View File

@@ -269,43 +269,27 @@ public class CassandraCqlClusterFactoryBean
protected void executeSpecsAndScripts(@SuppressWarnings("rawtypes") List specs, List<String> scripts) {
Session system = null;
if (!CollectionUtils.isEmpty(specs) || !CollectionUtils.isEmpty(scripts)) {
Session session = cluster.connect();
try {
if (!CollectionUtils.isEmpty(specs)) {
system = cluster.connect();
CqlTemplate template = new CqlTemplate(system);
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();
if (log.isDebugEnabled()) {
log.debug("executing raw CQL [{}]", cql);
}
template.execute(cql);
}
}
if (!CollectionUtils.isEmpty(scripts)) {
system = (system != null ? system : cluster.connect());
CqlTemplate template = new CqlTemplate(system);
for (String script : scripts) {
if (log.isDebugEnabled()) {
log.debug("executing raw CQL [{}]", script);
}
template.execute(script);
}
}
} finally {
if (system != null) {
system.close();
} finally {
if (session != null) {
session.close();
}
}
}
}