author | František Kučera <franta-hg@frantovo.cz> |
Sun, 21 Jun 2015 16:21:51 +0200 | |
branch | v_0 |
changeset 202 | 01078e09b85b |
parent 142 | java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleValueFormatter.java@da1e38386d84 |
child 206 | e2f24eea8543 |
permissions | -rw-r--r-- |
60 | 1 |
/** |
2 |
* SQL-DK |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
3 |
* Copyright © 2015 František Kučera (frantovo.cz) |
60 | 4 |
* |
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. |
|
9 |
* |
|
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. |
|
14 |
* |
|
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/>. |
|
17 |
*/ |
|
18 |
package info.globalcode.sql.dk.formatting; |
|
19 |
||
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
20 |
import info.globalcode.sql.dk.ColorfulPrintWriter; |
60 | 21 |
|
22 |
/** |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
23 |
* Formatter intended for printing one record (or few records) with many columns. |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
24 |
* Prints each colum name and its value on separate line. |
60 | 25 |
* |
26 |
* @author Ing. František Kučera (frantovo.cz) |
|
27 |
*/ |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
28 |
public class SingleRecordFormatter extends AbstractFormatter { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
29 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
30 |
public static final String NAME = "record"; // bash-completion:formatter |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
31 |
public static final String PROPERTY_COLORFUL = "color"; |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
32 |
private final ColorfulPrintWriter out; |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
33 |
private boolean firstResult = true; |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
34 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
35 |
public SingleRecordFormatter(FormatterContext formatterContext) { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
36 |
super(formatterContext); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
37 |
out = new ColorfulPrintWriter(formatterContext.getOutputStream()); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
38 |
out.setColorful(formatterContext.getProperties().getBoolean(PROPERTY_COLORFUL, true)); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
39 |
} |
60 | 40 |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
41 |
@Override |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
42 |
public void writeStartResultSet(ColumnsHeader header) { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
43 |
super.writeStartResultSet(header); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
44 |
printResultSeparator(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
45 |
} |
60 | 46 |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
47 |
@Override |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
48 |
public void writeStartRow() { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
49 |
super.writeStartRow(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
50 |
printRecordSeparator(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
51 |
out.print(ColorfulPrintWriter.TerminalColor.Red, "Record: "); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
52 |
out.print(getCurrentRowCount()); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
53 |
println(); |
60 | 54 |
} |
55 |
||
56 |
@Override |
|
57 |
public void writeColumnValue(Object value) { |
|
58 |
super.writeColumnValue(value); |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
59 |
String columnName = getCurrentColumnsHeader().getColumnDescriptors().get(getCurrentColumnsCount() - 1).getLabel(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
60 |
out.print(ColorfulPrintWriter.TerminalColor.Green, columnName + ": "); |
60 | 61 |
out.print(String.valueOf(value)); |
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
62 |
println(); |
60 | 63 |
} |
64 |
||
65 |
@Override |
|
142
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
66 |
public void writeUpdatesResult(int updatedRowsCount) { |
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
67 |
super.writeUpdatesResult(updatedRowsCount); |
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
68 |
printResultSeparator(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
69 |
out.print(ColorfulPrintWriter.TerminalColor.Red, "Updated records: "); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
70 |
out.println(updatedRowsCount); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
71 |
printBellAndFlush(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
72 |
} |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
73 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
74 |
private void printBellAndFlush() { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
75 |
out.bell(); |
60 | 76 |
out.flush(); |
77 |
} |
|
202
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
78 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
79 |
private void println() { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
80 |
out.println(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
81 |
printBellAndFlush(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
82 |
} |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
83 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
84 |
private void printRecordSeparator() { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
85 |
if (getCurrentRowCount() > 1) { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
86 |
println(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
87 |
} |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
88 |
} |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
89 |
|
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
90 |
private void printResultSeparator() { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
91 |
if (firstResult) { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
92 |
firstResult = false; |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
93 |
} else { |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
94 |
println(); |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
95 |
} |
01078e09b85b
SingleRecordFormatter: Formatter intended for printing one record (or few records) with many columns.Prints each colum name and its value on separate line.
František Kučera <franta-hg@frantovo.cz>
parents:
142
diff
changeset
|
96 |
} |
60 | 97 |
} |