Formatter: one more level: writeStartBatch() + writeEndBatch() which allows multiple databases on output
1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Sat Dec 28 19:54:03 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Sat Dec 28 20:24:51 2013 +0100
1.3 @@ -47,17 +47,21 @@
1.4 }
1.5
1.6 public void executeQuery(SQLCommand sqlCommand, Formatter formatter) throws SQLException {
1.7 + formatter.writeStartBatch();
1.8 formatter.writeStartDatabase(databaseDefinition);
1.9 processCommand(sqlCommand, formatter);
1.10 formatter.writeEndDatabase();
1.11 + formatter.writeEndBatch();
1.12 }
1.13
1.14 public void executeBatch(Batch batch, Formatter formatter) throws SQLException {
1.15 + formatter.writeStartBatch();
1.16 formatter.writeStartDatabase(databaseDefinition);
1.17 while (batch.hasNext()) {
1.18 processCommand(batch.next(), formatter);
1.19 }
1.20 formatter.writeEndDatabase();
1.21 + formatter.writeEndBatch();
1.22 }
1.23
1.24 private void processCommand(SQLCommand sqlCommand, Formatter formatter) throws SQLException {
2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 28 19:54:03 2013 +0100
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 28 20:24:51 2013 +0100
2.3 @@ -67,6 +67,7 @@
2.4 case FORMATTERS:
2.5 case TYPES:
2.6 formatter = getFormatter();
2.7 + formatter.writeStartBatch();
2.8 formatter.writeStartDatabase(new DatabaseDefinition());
2.9 }
2.10 }
2.11 @@ -77,6 +78,7 @@
2.12
2.13 if (formatter != null) {
2.14 formatter.writeEndDatabase();
2.15 + formatter.writeEndBatch();
2.16 }
2.17 }
2.18
3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java Sat Dec 28 19:54:03 2013 +0100
3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java Sat Dec 28 20:24:51 2013 +0100
3.3 @@ -44,21 +44,23 @@
3.4
3.5 /*
3.6 * root
3.7 - * .database
3.8 - * ..resultSet
3.9 - * ...@query
3.10 - * ...@parameters
3.11 - * ...@columnsHeader
3.12 - * ...row
3.13 - * ....@columnValue
3.14 - * ..updatesResult
3.15 - * ...@query
3.16 - * ...@parameters
3.17 - * ...@updatedRowsCount
3.18 + * .batch
3.19 + * ..database
3.20 + * ...resultSet
3.21 + * ....@query
3.22 + * ....@parameters
3.23 + * ....@columnsHeader
3.24 + * ....row
3.25 + * .....@columnValue
3.26 + * ...updatesResult
3.27 + * ....@query
3.28 + * ....@parameters
3.29 + * ....@updatedRowsCount
3.30 */
3.31 protected enum State {
3.32
3.33 ROOT,
3.34 + BATCH,
3.35 DATABASE,
3.36 RESULT_SET,
3.37 ROW,
3.38 @@ -120,13 +122,23 @@
3.39 }
3.40
3.41 @Override
3.42 + public void writeStartBatch() {
3.43 + pushState(State.BATCH, EnumSet.of(State.ROOT));
3.44 + }
3.45 +
3.46 + @Override
3.47 + public void writeEndBatch() {
3.48 + popState(EnumSet.of(State.ROOT));
3.49 + }
3.50 +
3.51 + @Override
3.52 public void writeStartDatabase(DatabaseDefinition databaseDefinition) {
3.53 - pushState(State.DATABASE, EnumSet.of(State.ROOT));
3.54 + pushState(State.DATABASE, EnumSet.of(State.BATCH));
3.55 }
3.56
3.57 @Override
3.58 public void writeEndDatabase() {
3.59 - popState(EnumSet.of(State.ROOT));
3.60 + popState(EnumSet.of(State.BATCH));
3.61 }
3.62
3.63 @Override
4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java Sat Dec 28 19:54:03 2013 +0100
4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java Sat Dec 28 20:24:51 2013 +0100
4.3 @@ -27,6 +27,8 @@
4.4 */
4.5 public interface Formatter {
4.6
4.7 + void writeStartBatch();
4.8 +
4.9 void writeStartDatabase(DatabaseDefinition databaseDefinition);
4.10
4.11 void writeEndDatabase();
4.12 @@ -52,4 +54,6 @@
4.13 void writeUpdatedRowsCount(int updatedRowsCount);
4.14
4.15 void writeEndUpdatesResult();
4.16 +
4.17 + void writeEndBatch();
4.18 }