SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
3 * Copyright © 2015 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk.formatting;
20 import info.globalcode.sql.dk.ColorfulPrintWriter;
23 * Formatter intended for printing one record (or few records) with many columns.
24 * Prints each colum name and its value on separate line.
26 * @author Ing. František Kučera (frantovo.cz)
28 public class SingleRecordFormatter extends AbstractFormatter {
30 public static final String NAME = "record"; // bash-completion:formatter
31 public static final String PROPERTY_COLORFUL = "color";
32 private final ColorfulPrintWriter out;
33 private boolean firstResult = true;
35 public SingleRecordFormatter(FormatterContext formatterContext) {
36 super(formatterContext);
37 out = new ColorfulPrintWriter(formatterContext.getOutputStream());
38 out.setColorful(formatterContext.getProperties().getBoolean(PROPERTY_COLORFUL, true));
42 public void writeStartResultSet(ColumnsHeader header) {
43 super.writeStartResultSet(header);
44 printResultSeparator();
48 public void writeStartRow() {
49 super.writeStartRow();
50 printRecordSeparator();
51 out.print(ColorfulPrintWriter.TerminalColor.Red, "Record: ");
52 out.print(getCurrentRowCount());
57 public void writeColumnValue(Object value) {
58 super.writeColumnValue(value);
59 String columnName = getCurrentColumnsHeader().getColumnDescriptors().get(getCurrentColumnsCount() - 1).getLabel();
60 out.print(ColorfulPrintWriter.TerminalColor.Green, columnName + ": ");
61 out.print(String.valueOf(value));
66 public void writeUpdatesResult(int updatedRowsCount) {
67 super.writeUpdatesResult(updatedRowsCount);
68 printResultSeparator();
69 out.print(ColorfulPrintWriter.TerminalColor.Red, "Updated records: ");
70 out.println(updatedRowsCount);
74 private void printBellAndFlush() {
79 private void println() {
84 private void printRecordSeparator() {
85 if (getCurrentRowCount() > 1) {
90 private void printResultSeparator() {