Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 07 Jan 2014 21:54:59 +0100
branchv_0
changeset 142da1e38386d84
parent 141 ecd17aad1178
child 143 1336bb9a4499
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleValueFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularPrefetchingFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularWrappingFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Tue Jan 07 21:53:24 2014 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Tue Jan 07 21:54:59 2014 +0100
     1.3 @@ -66,7 +66,11 @@
     1.4  	public void executeQuery(SQLCommand sqlCommand, Formatter formatter) throws SQLException {
     1.5  		formatter.writeStartBatch();
     1.6  		formatter.writeStartDatabase(databaseDefinition);
     1.7 +		formatter.writeStartStatement();
     1.8 +		formatter.writeQuery(sqlCommand.getQuery());
     1.9 +		formatter.writeParameters(sqlCommand.getParameters());
    1.10  		processCommand(sqlCommand, formatter);
    1.11 +		formatter.writeEndStatement();
    1.12  		formatter.writeEndDatabase();
    1.13  		formatter.writeEndBatch();
    1.14  	}
    1.15 @@ -75,7 +79,12 @@
    1.16  		formatter.writeStartBatch();
    1.17  		formatter.writeStartDatabase(databaseDefinition);
    1.18  		while (batch.hasNext()) {
    1.19 -			processCommand(batch.next(), formatter);
    1.20 +			SQLCommand sqlCommand = batch.next();
    1.21 +			formatter.writeStartStatement();
    1.22 +			formatter.writeQuery(sqlCommand.getQuery());
    1.23 +			formatter.writeParameters(sqlCommand.getParameters());
    1.24 +			processCommand(sqlCommand, formatter);
    1.25 +			formatter.writeEndStatement();
    1.26  		}
    1.27  		formatter.writeEndDatabase();
    1.28  		formatter.writeEndBatch();
    1.29 @@ -90,19 +99,19 @@
    1.30  			log.log(Level.FINE, "Statement executed");
    1.31  			if (isRS) {
    1.32  				try (ResultSet rs = ps.getResultSet()) {
    1.33 -					processResultSet(sqlCommand, rs, formatter);
    1.34 +					processResultSet(rs, formatter);
    1.35  				}
    1.36  			} else {
    1.37 -				processUpdateResult(sqlCommand, ps, formatter);
    1.38 +				processUpdateResult(ps, formatter);
    1.39  			}
    1.40  			logWarnings(ps);
    1.41  
    1.42  			while (ps.getMoreResults() || ps.getUpdateCount() > -1) {
    1.43  				ResultSet rs = ps.getResultSet();
    1.44  				if (rs == null) {
    1.45 -					processUpdateResult(sqlCommand, ps, formatter);
    1.46 +					processUpdateResult(ps, formatter);
    1.47  				} else {
    1.48 -					processResultSet(sqlCommand, rs, formatter);
    1.49 +					processResultSet(rs, formatter);
    1.50  					rs.close();
    1.51  				}
    1.52  				logWarnings(ps);
    1.53 @@ -110,26 +119,13 @@
    1.54  		}
    1.55  	}
    1.56  
    1.57 -	private void processUpdateResult(SQLCommand sqlCommand, PreparedStatement ps, Formatter formatter) throws SQLException {
    1.58 -		formatter.writeStartUpdatesResult();
    1.59 -		formatter.writeQuery(sqlCommand.getQuery());
    1.60 -		formatter.writeParameters(sqlCommand.getParameters());
    1.61 -		formatter.writeUpdatedRowsCount(ps.getUpdateCount());
    1.62 -		formatter.writeEndUpdatesResult();
    1.63 +	private void processUpdateResult(PreparedStatement ps, Formatter formatter) throws SQLException {
    1.64 +		formatter.writeUpdatesResult(ps.getUpdateCount());
    1.65  	}
    1.66  
    1.67 -	private void processResultSet(SQLCommand sqlCommand, ResultSet rs, Formatter formatter) throws SQLException {
    1.68 -		formatter.writeStartResultSet();
    1.69 -		formatter.writeQuery(sqlCommand.getQuery());
    1.70 -		formatter.writeParameters(sqlCommand.getParameters());
    1.71 +	private void processResultSet(ResultSet rs, Formatter formatter) throws SQLException {
    1.72 +		formatter.writeStartResultSet(new ColumnsHeader(rs.getMetaData()));
    1.73  
    1.74 -		processResultSetRows(rs, formatter);
    1.75 -
    1.76 -		formatter.writeEndResultSet();
    1.77 -	}
    1.78 -
    1.79 -	private void processResultSetRows(ResultSet rs, Formatter formatter) throws SQLException {
    1.80 -		formatter.writeColumnsHeader(new ColumnsHeader(rs.getMetaData()));
    1.81  		int columnCount = rs.getMetaData().getColumnCount();
    1.82  
    1.83  		while (rs.next()) {
    1.84 @@ -142,6 +138,7 @@
    1.85  			formatter.writeEndRow();
    1.86  		}
    1.87  
    1.88 +		formatter.writeEndResultSet();
    1.89  	}
    1.90  
    1.91  	private void logWarnings(PreparedStatement ps) throws SQLException {
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Tue Jan 07 21:53:24 2014 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Tue Jan 07 21:54:59 2014 +0100
     2.3 @@ -77,7 +77,9 @@
     2.4  				formatter = f;
     2.5  				formatter.writeStartBatch();
     2.6  				formatter.writeStartDatabase(new DatabaseDefinition());
     2.7 +				formatter.writeStartStatement();
     2.8  				showInfos(commands);
     2.9 +				formatter.writeEndStatement();
    2.10  				formatter.writeEndDatabase();
    2.11  				formatter.writeEndBatch();
    2.12  				formatter.close();
    2.13 @@ -201,8 +203,7 @@
    2.14  	}
    2.15  
    2.16  	private void printTable(Formatter formatter, ColumnsHeader header, List<Object[]> data) throws ConfigurationException, FormatterException {
    2.17 -		formatter.writeStartResultSet();
    2.18 -		formatter.writeColumnsHeader(header);
    2.19 +		formatter.writeStartResultSet(header);
    2.20  
    2.21  		for (Object[] row : data) {
    2.22  			formatter.writeStartRow();
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/AbstractFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     3.3 @@ -46,25 +46,22 @@
     3.4  	 * root
     3.5  	 * .batch
     3.6  	 * ..database
     3.7 -	 * ...resultSet
     3.8 +	 * ...statement
     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 +	 * ....resultSet
    3.19 +	 * .....row
    3.20 +	 * ......@columnValue
    3.21 +	 * ....@updatesResult
    3.22  	 */
    3.23  	protected enum State {
    3.24  
    3.25  		ROOT,
    3.26  		BATCH,
    3.27  		DATABASE,
    3.28 +		STATEMENT,
    3.29  		RESULT_SET,
    3.30 -		ROW,
    3.31 -		UPDATES_RESULT
    3.32 +		ROW
    3.33  	}
    3.34  
    3.35  	/**
    3.36 @@ -142,20 +139,31 @@
    3.37  	}
    3.38  
    3.39  	@Override
    3.40 -	public void writeStartResultSet() {
    3.41 -		pushState(State.RESULT_SET, EnumSet.of(State.DATABASE));
    3.42 +	public void writeStartStatement() {
    3.43 +		pushState(State.STATEMENT, EnumSet.of(State.DATABASE));
    3.44 +	}
    3.45 +
    3.46 +	@Override
    3.47 +	public void writeEndStatement() {
    3.48 +		popState(EnumSet.of(State.DATABASE));
    3.49 +	}
    3.50 +
    3.51 +	@Override
    3.52 +	public void writeStartResultSet(ColumnsHeader header) {
    3.53 +		pushState(State.RESULT_SET, EnumSet.of(State.STATEMENT));
    3.54  		currentRowCount = 0;
    3.55 +		currentColumnsHeader = header;
    3.56  	}
    3.57  
    3.58  	@Override
    3.59  	public void writeEndResultSet() {
    3.60 -		popState(EnumSet.of(State.DATABASE));
    3.61 +		popState(EnumSet.of(State.STATEMENT));
    3.62  		currentColumnsHeader = null;
    3.63  	}
    3.64  
    3.65  	@Override
    3.66  	public void writeQuery(String sql) {
    3.67 -		peekState(EnumSet.of(State.RESULT_SET, State.UPDATES_RESULT));
    3.68 +		peekState(EnumSet.of(State.STATEMENT));
    3.69  
    3.70  		if (currentColumnsHeader == null) {
    3.71  			currentQuery = sql;
    3.72 @@ -166,7 +174,7 @@
    3.73  
    3.74  	@Override
    3.75  	public void writeParameters(List<? extends Parameter> parameters) {
    3.76 -		peekState(EnumSet.of(State.RESULT_SET, State.UPDATES_RESULT));
    3.77 +		peekState(EnumSet.of(State.STATEMENT));
    3.78  
    3.79  		if (currentColumnsHeader != null) {
    3.80  			throw new IllegalStateException("Parameters '" + parameters + "' must be set before columns header – was already set: " + currentColumnsHeader);
    3.81 @@ -178,17 +186,6 @@
    3.82  	}
    3.83  
    3.84  	@Override
    3.85 -	public void writeColumnsHeader(ColumnsHeader header) {
    3.86 -		peekState(EnumSet.of(State.RESULT_SET));
    3.87 -
    3.88 -		if (currentColumnsHeader == null) {
    3.89 -			currentColumnsHeader = header;
    3.90 -		} else {
    3.91 -			throw new IllegalStateException("Columns header can be set only once per result set – was already set: " + currentColumnsHeader);
    3.92 -		}
    3.93 -	}
    3.94 -
    3.95 -	@Override
    3.96  	public void writeStartRow() {
    3.97  		pushState(State.ROW, EnumSet.of(State.RESULT_SET));
    3.98  		currentColumnsCount = 0;
    3.99 @@ -212,19 +209,8 @@
   3.100  	}
   3.101  
   3.102  	@Override
   3.103 -	public void writeStartUpdatesResult() {
   3.104 -		pushState(State.UPDATES_RESULT, EnumSet.of(State.DATABASE));
   3.105 -	}
   3.106 -
   3.107 -	@Override
   3.108 -	public void writeEndUpdatesResult() {
   3.109 -		popState(EnumSet.of(State.DATABASE));
   3.110 -		currentColumnsHeader = null;
   3.111 -	}
   3.112 -
   3.113 -	@Override
   3.114 -	public void writeUpdatedRowsCount(int updatedRowsCount) {
   3.115 -		peekState(EnumSet.of(State.UPDATES_RESULT));
   3.116 +	public void writeUpdatesResult(int updatedRowsCount) {
   3.117 +		peekState(EnumSet.of(State.STATEMENT));
   3.118  	}
   3.119  
   3.120  	@Override
     4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java	Tue Jan 07 21:53:24 2014 +0100
     4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/Formatter.java	Tue Jan 07 21:54:59 2014 +0100
     4.3 @@ -33,15 +33,17 @@
     4.4  
     4.5  	void writeEndDatabase();
     4.6  
     4.7 -	void writeStartResultSet();
     4.8 +	void writeStartStatement();
     4.9  
    4.10 -	void writeEndResultSet();
    4.11 +	void writeEndStatement();
    4.12  
    4.13  	void writeQuery(String sql);
    4.14  
    4.15  	void writeParameters(List<? extends Parameter> parameters);
    4.16  
    4.17 -	void writeColumnsHeader(ColumnsHeader header);
    4.18 +	void writeStartResultSet(ColumnsHeader header);
    4.19 +
    4.20 +	void writeEndResultSet();
    4.21  
    4.22  	void writeStartRow();
    4.23  
    4.24 @@ -49,11 +51,7 @@
    4.25  
    4.26  	void writeEndRow();
    4.27  
    4.28 -	void writeStartUpdatesResult();
    4.29 -
    4.30 -	void writeUpdatedRowsCount(int updatedRowsCount);
    4.31 -
    4.32 -	void writeEndUpdatesResult();
    4.33 +	void writeUpdatesResult(int updatedRowsCount);
    4.34  
    4.35  	void writeEndBatch();
    4.36  
     5.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleValueFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     5.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleValueFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     5.3 @@ -44,8 +44,8 @@
     5.4  	}
     5.5  
     5.6  	@Override
     5.7 -	public void writeUpdatedRowsCount(int updatedRowsCount) {
     5.8 -		super.writeUpdatedRowsCount(updatedRowsCount);
     5.9 +	public void writeUpdatesResult(int updatedRowsCount) {
    5.10 +		super.writeUpdatesResult(updatedRowsCount);
    5.11  		out.print(updatedRowsCount);
    5.12  		out.flush();
    5.13  	}
     6.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     6.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     6.3 @@ -57,14 +57,9 @@
     6.4  	}
     6.5  
     6.6  	@Override
     6.7 -	public void writeStartResultSet() {
     6.8 -		super.writeStartResultSet();
     6.9 +	public void writeStartResultSet(ColumnsHeader header) {
    6.10 +		super.writeStartResultSet(header);
    6.11  		printResultSeparator();
    6.12 -	}
    6.13 -
    6.14 -	@Override
    6.15 -	public void writeColumnsHeader(ColumnsHeader header) {
    6.16 -		super.writeColumnsHeader(header);
    6.17  
    6.18  		initColumnWidths(header.getColumnCount());
    6.19  
    6.20 @@ -227,14 +222,9 @@
    6.21  	}
    6.22  
    6.23  	@Override
    6.24 -	public void writeStartUpdatesResult() {
    6.25 -		super.writeStartUpdatesResult();
    6.26 +	public void writeUpdatesResult(int updatedRowsCount) {
    6.27 +		super.writeUpdatesResult(updatedRowsCount);
    6.28  		printResultSeparator();
    6.29 -	}
    6.30 -
    6.31 -	@Override
    6.32 -	public void writeUpdatedRowsCount(int updatedRowsCount) {
    6.33 -		super.writeUpdatedRowsCount(updatedRowsCount);
    6.34  		out.print(TerminalColor.Red, "Updated records: ");
    6.35  		out.println(updatedRowsCount);
    6.36  		out.bell();
     7.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularPrefetchingFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     7.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularPrefetchingFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     7.3 @@ -17,7 +17,6 @@
     7.4   */
     7.5  package info.globalcode.sql.dk.formatting;
     7.6  
     7.7 -import info.globalcode.sql.dk.Parameter;
     7.8  import java.util.ArrayList;
     7.9  import java.util.List;
    7.10  
    7.11 @@ -32,8 +31,6 @@
    7.12  public class TabularPrefetchingFormatter extends TabularFormatter {
    7.13  
    7.14  	public static final String NAME = "tabular-prefetching"; // bash-completion:formatter
    7.15 -	private String currentSql;
    7.16 -	private List<? extends Parameter> currentParameters;
    7.17  	private ColumnsHeader currentHeader;
    7.18  	private List<Object[]> currentResultSet;
    7.19  	private Object[] currentRow;
    7.20 @@ -54,22 +51,8 @@
    7.21  	}
    7.22  
    7.23  	@Override
    7.24 -	public void writeStartResultSet() {
    7.25 +	public void writeStartResultSet(ColumnsHeader header) {
    7.26  		currentResultSet = new ArrayList<>();
    7.27 -	}
    7.28 -
    7.29 -	@Override
    7.30 -	public void writeQuery(String sql) {
    7.31 -		currentSql = sql;
    7.32 -	}
    7.33 -
    7.34 -	@Override
    7.35 -	public void writeParameters(List<? extends Parameter> parameters) {
    7.36 -		currentParameters = parameters;
    7.37 -	}
    7.38 -
    7.39 -	@Override
    7.40 -	public void writeColumnsHeader(ColumnsHeader header) {
    7.41  		currentHeader = header;
    7.42  		initColumnWidths(header.getColumnCount());
    7.43  	}
    7.44 @@ -99,10 +82,7 @@
    7.45  	public void writeEndResultSet() {
    7.46  		prefetchDone = true;
    7.47  
    7.48 -		super.writeStartResultSet();
    7.49 -		super.writeQuery(currentSql);
    7.50 -		super.writeParameters(currentParameters);
    7.51 -		super.writeColumnsHeader(currentHeader);
    7.52 +		super.writeStartResultSet(currentHeader);
    7.53  
    7.54  		for (Object[] row : currentResultSet) {
    7.55  			super.writeStartRow();
    7.56 @@ -113,8 +93,6 @@
    7.57  		}
    7.58  
    7.59  		currentColumnsCount = 0;
    7.60 -		currentSql = null;
    7.61 -		currentParameters = null;
    7.62  		currentHeader = null;
    7.63  		currentRow = null;
    7.64  		currentResultSet = null;
     8.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularWrappingFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     8.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularWrappingFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     8.3 @@ -38,8 +38,8 @@
     8.4  	}
     8.5  
     8.6  	@Override
     8.7 -	public void writeColumnsHeader(ColumnsHeader header) {
     8.8 -		super.writeColumnsHeader(header);
     8.9 +	public void writeStartResultSet(ColumnsHeader header) {
    8.10 +		super.writeStartResultSet(header);
    8.11  		currentRow = new ArrayList<>(header.getColumnCount());
    8.12  	}
    8.13  
    8.14 @@ -48,7 +48,7 @@
    8.15  		boolean rightAlign = value instanceof Number || value instanceof Boolean;
    8.16  		String valueString = String.valueOf(value);
    8.17  		int columnWidth = getColumnWidth(getCurrentColumnsCount()) - 1;  // -1 = space for new line symbol
    8.18 -		currentRow.add(split(valueString, columnWidth, rightAlign));
    8.19 +		currentRow.add(wrapLines(valueString, columnWidth, rightAlign));
    8.20  	}
    8.21  
    8.22  	@Override
    8.23 @@ -99,7 +99,7 @@
    8.24  		// already done – wrapped row ends
    8.25  	}
    8.26  
    8.27 -	private static String[] split(String s, int width, boolean rightAlign) {
    8.28 +	private static String[] wrapLines(String s, int width, boolean rightAlign) {
    8.29  		String[] array = new String[(s.length() - 1) / width + 1];
    8.30  		for (int i = 0; i < array.length; i++) {
    8.31  			if (i == array.length - 1) {
     9.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java	Tue Jan 07 21:53:24 2014 +0100
     9.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XhtmlFormatter.java	Tue Jan 07 21:54:59 2014 +0100
     9.3 @@ -46,6 +46,7 @@
     9.4  	public static final String NAME = "xhtml"; // bash-completion:formatter
     9.5  	private static final String DOCTYPE = "html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\" \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\"";
     9.6  	private static final String CSS_FILE = "info/globalcode/sql/dk/formatter/XhtmlFormatter.css";
     9.7 +	private int statementCounter = 0;
     9.8  	private int resultSetCounter = 0;
     9.9  	private int updatesResultCounter = 0;
    9.10  
    9.11 @@ -115,7 +116,6 @@
    9.12  	@Override
    9.13  	public void writeQuery(String sql) {
    9.14  		super.writeQuery(sql);
    9.15 -		printTextElement(qname("h3"), null, "SQL:");
    9.16  		printTextElement(qname("pre"), null, sql);
    9.17  	}
    9.18  
    9.19 @@ -199,9 +199,11 @@
    9.20  	}
    9.21  
    9.22  	@Override
    9.23 -	public void writeColumnsHeader(ColumnsHeader header) {
    9.24 -		super.writeColumnsHeader(header);
    9.25 -		printTextElement(qname("h3"), null, "Data:");
    9.26 +	public void writeStartResultSet(ColumnsHeader header) {
    9.27 +		super.writeStartResultSet(header);
    9.28 +		resultSetCounter++;
    9.29 +		printEmptyElement(qname("hr"), null);
    9.30 +		printTextElement(qname("h3"), null, "Result set #" + resultSetCounter);
    9.31  		printStartElement(qname("table"));
    9.32  		printStartElement(qname("thead"));
    9.33  		printStartElement(qname("tr"));
    9.34 @@ -216,6 +218,14 @@
    9.35  	}
    9.36  
    9.37  	@Override
    9.38 +	public void writeEndResultSet() {
    9.39 +		super.writeEndResultSet();
    9.40 +		printEndElement();
    9.41 +		printEndElement();
    9.42 +		printTextElement(qname("p"), null, "Record count: " + getCurrentRowCount());
    9.43 +	}
    9.44 +
    9.45 +	@Override
    9.46  	public void writeStartRow() {
    9.47  		super.writeStartRow();
    9.48  		printStartElement(qname("tr"));
    9.49 @@ -234,33 +244,21 @@
    9.50  	}
    9.51  
    9.52  	@Override
    9.53 -	public void writeStartResultSet() {
    9.54 -		super.writeStartResultSet();
    9.55 -		resultSetCounter++;
    9.56 +	public void writeStartStatement() {
    9.57 +		super.writeStartStatement();
    9.58 +		statementCounter++;
    9.59  		printEmptyElement(qname("hr"), null);
    9.60 -		printTextElement(qname("h2"), null, "Result set #" + resultSetCounter);
    9.61 +		printTextElement(qname("h2"), null, "SQL statement #" + statementCounter);
    9.62 +		resultSetCounter = 0;
    9.63 +		updatesResultCounter = 0;
    9.64  	}
    9.65  
    9.66  	@Override
    9.67 -	public void writeEndResultSet() {
    9.68 -		super.writeEndResultSet();
    9.69 -		printEndElement();
    9.70 -		printEndElement();
    9.71 -
    9.72 -		printTextElement(qname("p"), null, "Record count: " + getCurrentRowCount());
    9.73 -	}
    9.74 -
    9.75 -	@Override
    9.76 -	public void writeStartUpdatesResult() {
    9.77 -		super.writeStartUpdatesResult();
    9.78 +	public void writeUpdatesResult(int updatedRowsCount) {
    9.79 +		super.writeUpdatesResult(updatedRowsCount);
    9.80  		updatesResultCounter++;
    9.81  		printEmptyElement(qname("hr"), null);
    9.82 -		printTextElement(qname("h2"), null, "Updates result #" + updatesResultCounter);
    9.83 -	}
    9.84 -
    9.85 -	@Override
    9.86 -	public void writeUpdatedRowsCount(int updatedRowsCount) {
    9.87 -		super.writeUpdatedRowsCount(updatedRowsCount);
    9.88 +		printTextElement(qname("h3"), null, "Updates result #" + updatesResultCounter);
    9.89  		printTextElement(qname("p"), null, "Updated rows: " + updatedRowsCount);
    9.90  	}
    9.91  }
    10.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Tue Jan 07 21:53:24 2014 +0100
    10.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Tue Jan 07 21:54:59 2014 +0100
    10.3 @@ -71,14 +71,14 @@
    10.4  	}
    10.5  
    10.6  	@Override
    10.7 -	public void writeStartResultSet() {
    10.8 -		super.writeStartResultSet();
    10.9 -		printStartElement(qname("resultSet"));
   10.10 +	public void writeStartStatement() {
   10.11 +		super.writeStartStatement();
   10.12 +		printStartElement(qname("statement"));
   10.13  	}
   10.14  
   10.15  	@Override
   10.16 -	public void writeEndResultSet() {
   10.17 -		super.writeEndResultSet();
   10.18 +	public void writeEndStatement() {
   10.19 +		super.writeEndStatement();
   10.20  		printEndElement();
   10.21  	}
   10.22  
   10.23 @@ -106,8 +106,9 @@
   10.24  	}
   10.25  
   10.26  	@Override
   10.27 -	public void writeColumnsHeader(ColumnsHeader header) {
   10.28 -		super.writeColumnsHeader(header);
   10.29 +	public void writeStartResultSet(ColumnsHeader header) {
   10.30 +		super.writeStartResultSet(header);
   10.31 +		printStartElement(qname("resultSet"));
   10.32  
   10.33  		for (ColumnDescriptor cd : header.getColumnDescriptors()) {
   10.34  			Map<QName, String> attributes = new LinkedHashMap<>(4);
   10.35 @@ -120,6 +121,12 @@
   10.36  	}
   10.37  
   10.38  	@Override
   10.39 +	public void writeEndResultSet() {
   10.40 +		super.writeEndResultSet();
   10.41 +		printEndElement();
   10.42 +	}
   10.43 +
   10.44 +	@Override
   10.45  	public void writeStartRow() {
   10.46  		super.writeStartRow();
   10.47  		printStartElement(qname("row"));
   10.48 @@ -145,23 +152,11 @@
   10.49  	}
   10.50  
   10.51  	@Override
   10.52 -	public void writeStartUpdatesResult() {
   10.53 -		super.writeStartUpdatesResult();
   10.54 -		printStartElement(qname("updatesResult"));
   10.55 -	}
   10.56 -
   10.57 -	@Override
   10.58 -	public void writeUpdatedRowsCount(int updatedRowsCount) {
   10.59 -		super.writeUpdatedRowsCount(updatedRowsCount);
   10.60 +	public void writeUpdatesResult(int updatedRowsCount) {
   10.61 +		super.writeUpdatesResult(updatedRowsCount);
   10.62  		printTextElement(qname("updatedRows"), null, String.valueOf(updatedRowsCount));
   10.63  	}
   10.64  
   10.65 -	@Override
   10.66 -	public void writeEndUpdatesResult() {
   10.67 -		super.writeEndUpdatesResult();
   10.68 -		printEndElement();
   10.69 -	}
   10.70 -
   10.71  	protected String toString(Object value) {
   10.72  		return String.valueOf(value);
   10.73  	}