add show cql parameter
This commit is contained in:
parent
496cf2c34b
commit
c05d3e2737
4 changed files with 33 additions and 6 deletions
|
@ -9,16 +9,22 @@ import com.datastax.driver.core.Session;
|
|||
|
||||
public abstract class AbstractSessionOperations {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
abstract Session currentSession();
|
||||
|
||||
abstract boolean isShowCql();
|
||||
|
||||
void doExecute(String cql) {
|
||||
|
||||
try {
|
||||
|
||||
logger.info("Execute query " + cql);
|
||||
|
||||
if (isShowCql() && cql != null) {
|
||||
System.out.println(cql);
|
||||
}
|
||||
|
||||
currentSession().execute(cql);
|
||||
}
|
||||
catch(RuntimeException e) {
|
||||
|
|
|
@ -21,10 +21,12 @@ import com.datastax.driver.core.schemabuilder.SchemaBuilder;
|
|||
public class CasserSession extends AbstractSessionOperations implements Closeable {
|
||||
|
||||
private final Session session;
|
||||
private final boolean showCql;
|
||||
private final Set<CasserMappingEntity<?>> dropEntitiesOnClose;
|
||||
|
||||
CasserSession(Session session, Set<CasserMappingEntity<?>> dropEntitiesOnClose) {
|
||||
CasserSession(Session session, boolean showCql, Set<CasserMappingEntity<?>> dropEntitiesOnClose) {
|
||||
this.session = session;
|
||||
this.showCql = showCql;
|
||||
this.dropEntitiesOnClose = dropEntitiesOnClose;
|
||||
}
|
||||
|
||||
|
@ -33,6 +35,11 @@ public class CasserSession extends AbstractSessionOperations implements Closeabl
|
|||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isShowCql() {
|
||||
return showCql;
|
||||
}
|
||||
|
||||
public <V1> SelectOperation<Tuple1<V1>> select(Getter<V1> getter1) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.datastax.driver.core.schemabuilder.SchemaBuilder;
|
|||
public class SessionInitializer extends AbstractSessionOperations {
|
||||
|
||||
private final Session session;
|
||||
private boolean showCql = false;
|
||||
private Set<CasserMappingEntity<?>> dropEntitiesOnClose = null;
|
||||
|
||||
SessionInitializer(Session session) {
|
||||
|
@ -35,6 +36,21 @@ public class SessionInitializer extends AbstractSessionOperations {
|
|||
return session;
|
||||
}
|
||||
|
||||
public SessionInitializer showCql() {
|
||||
this.showCql = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SessionInitializer showCql(boolean enabled) {
|
||||
this.showCql = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isShowCql() {
|
||||
return showCql;
|
||||
}
|
||||
|
||||
public SessionInitializer validate(Object... dsls) {
|
||||
process(AutoDslType.VALIDATE, dsls);
|
||||
return this;
|
||||
|
@ -61,7 +77,7 @@ public class SessionInitializer extends AbstractSessionOperations {
|
|||
}
|
||||
|
||||
public CasserSession get() {
|
||||
return new CasserSession(session, dropEntitiesOnClose);
|
||||
return new CasserSession(session, showCql, dropEntitiesOnClose);
|
||||
}
|
||||
|
||||
private enum AutoDslType {
|
||||
|
@ -190,8 +206,6 @@ public class SessionInitializer extends AbstractSessionOperations {
|
|||
|
||||
String cql = create.getQueryString();
|
||||
|
||||
System.out.println("cql = " + cql);
|
||||
|
||||
doExecute(cql);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class FlatObjectTest extends AbstractEmbeddedCassandraTest {
|
|||
|
||||
user = Casser.dsl(User.class);
|
||||
|
||||
session = Casser.init(getSession()).create(User.class).get();
|
||||
session = Casser.init(getSession()).showCql().create(User.class).get();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue