# HG changeset patch # User František Kučera # Date 1388258691 -3600 # Node ID 43e8d52091d510f41f45145e0b9118e03250b77e # Parent ce2b7576ab67cdf8e3e526d281f7b5ffa1baa9cc Formatter: one more level: writeStartBatch() + writeEndBatch() which allows multiple databases on output diff -r ce2b7576ab67 -r 43e8d52091d5 java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Sat Dec 28 19:54:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Sat Dec 28 20:24:51 2013 +0100 @@ -47,17 +47,21 @@ } public void executeQuery(SQLCommand sqlCommand, Formatter formatter) throws SQLException { + formatter.writeStartBatch(); formatter.writeStartDatabase(databaseDefinition); processCommand(sqlCommand, formatter); formatter.writeEndDatabase(); + formatter.writeEndBatch(); } public void executeBatch(Batch batch, Formatter formatter) throws SQLException { + formatter.writeStartBatch(); formatter.writeStartDatabase(databaseDefinition); while (batch.hasNext()) { processCommand(batch.next(), formatter); } formatter.writeEndDatabase(); + formatter.writeEndBatch(); } private void processCommand(SQLCommand sqlCommand, Formatter formatter) throws SQLException { diff -r ce2b7576ab67 -r 43e8d52091d5 java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 28 19:54:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 28 20:24:51 2013 +0100 @@ -67,6 +67,7 @@ case FORMATTERS: case TYPES: formatter = getFormatter(); + formatter.writeStartBatch(); formatter.writeStartDatabase(new DatabaseDefinition()); } } @@ -77,6 +78,7 @@ if (formatter != null) { formatter.writeEndDatabase(); + formatter.writeEndBatch(); } } diff -r ce2b7576ab67 -r 43e8d52091d5 java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java Sat Dec 28 19:54:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java Sat Dec 28 20:24:51 2013 +0100 @@ -44,21 +44,23 @@ /* * root - * .database - * ..resultSet - * ...@query - * ...@parameters - * ...@columnsHeader - * ...row - * ....@columnValue - * ..updatesResult - * ...@query - * ...@parameters - * ...@updatedRowsCount + * .batch + * ..database + * ...resultSet + * ....@query + * ....@parameters + * ....@columnsHeader + * ....row + * .....@columnValue + * ...updatesResult + * ....@query + * ....@parameters + * ....@updatedRowsCount */ protected enum State { ROOT, + BATCH, DATABASE, RESULT_SET, ROW, @@ -120,13 +122,23 @@ } @Override + public void writeStartBatch() { + pushState(State.BATCH, EnumSet.of(State.ROOT)); + } + + @Override + public void writeEndBatch() { + popState(EnumSet.of(State.ROOT)); + } + + @Override public void writeStartDatabase(DatabaseDefinition databaseDefinition) { - pushState(State.DATABASE, EnumSet.of(State.ROOT)); + pushState(State.DATABASE, EnumSet.of(State.BATCH)); } @Override public void writeEndDatabase() { - popState(EnumSet.of(State.ROOT)); + popState(EnumSet.of(State.BATCH)); } @Override diff -r ce2b7576ab67 -r 43e8d52091d5 java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java Sat Dec 28 19:54:03 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java Sat Dec 28 20:24:51 2013 +0100 @@ -27,6 +27,8 @@ */ public interface Formatter { + void writeStartBatch(); + void writeStartDatabase(DatabaseDefinition databaseDefinition); void writeEndDatabase(); @@ -52,4 +54,6 @@ void writeUpdatedRowsCount(int updatedRowsCount); void writeEndUpdatesResult(); + + void writeEndBatch(); }