author | František Kučera <franta-hg@frantovo.cz> |
Sat, 28 Dec 2013 12:19:39 +0100 | |
branch | v_0 |
changeset 88 | 102ba0fcb07f |
parent 87 | 03bf24449c7a |
child 89 | 98d18e9a357b |
permissions | -rw-r--r-- |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* SQL-DK |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* (at your option) any later version. |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
*/ |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
package info.globalcode.sql.dk.formatting; |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
20 |
import info.globalcode.sql.dk.ColorfulPrintWriter; |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
21 |
import static info.globalcode.sql.dk.ColorfulPrintWriter.*; |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
22 |
import static info.globalcode.sql.dk.Functions.lpad; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
23 |
import static info.globalcode.sql.dk.Functions.rpad; |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
24 |
import static info.globalcode.sql.dk.Functions.repeat; |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
25 |
import java.util.Arrays; |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
26 |
import java.util.List; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
27 |
|
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
/** |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
* @author Ing. František Kučera (frantovo.cz) |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
*/ |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
public class TabularFormatter extends AbstractFormatter { |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
|
79
e19a13ed19a9
more bash completion tags
František Kučera <franta-hg@frantovo.cz>
parents:
76
diff
changeset
|
34 |
public static final String NAME = "tabular"; // bash-completion:formatter |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
35 |
private static final String HEADER_TYPE_PREFIX = " ("; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
36 |
private static final String HEADER_TYPE_SUFFIX = ")"; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
37 |
private ColorfulPrintWriter out; |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
38 |
private boolean firstResult = true; |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
39 |
private int[] columnWidth; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
40 |
/** |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
41 |
* use ASCII borders instead of unicode ones |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
42 |
*/ |
76
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
43 |
private final boolean asciiNostalgia = false; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
44 |
/** |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
45 |
* Trim values if they are longer than cell size |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
46 |
*/ |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
47 |
private final boolean trimValues = false; |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
|
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
public TabularFormatter(FormatterContext formatterContext) { |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
super(formatterContext); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
51 |
out = new ColorfulPrintWriter(formatterContext.getOutputStream()); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
52 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
53 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
54 |
@Override |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
55 |
public void writeStartResultSet() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
56 |
super.writeStartResultSet(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
57 |
printResultSeparator(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
58 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
59 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
60 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
61 |
public void writeColumnsHeader(ColumnsHeader header) { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
62 |
super.writeColumnsHeader(header); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
63 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
64 |
initColumnWidths(header.getColumnCount()); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
65 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
66 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
67 |
printTableBorder("╭"); |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
68 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
69 |
List<ColumnDescriptor> columnDescriptors = header.getColumnDescriptors(); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
70 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
71 |
for (ColumnDescriptor cd : columnDescriptors) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
72 |
// padding: make header cell at least same width as data cells in this column |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
73 |
int typeWidth = cd.getTypeName().length() + HEADER_TYPE_PREFIX.length() + HEADER_TYPE_SUFFIX.length(); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
74 |
cd.setLabel(rpad(cd.getLabel(), getColumnWidth(cd.getColumnNumber()) - typeWidth)); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
75 |
updateColumnWidth(cd.getColumnNumber(), cd.getLabel().length() + typeWidth); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
76 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
77 |
if (!cd.isFirstColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
78 |
printTableBorder("┬"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
79 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
80 |
printTableBorder(repeat('─', getColumnWidth(cd.getColumnNumber()) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
81 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
82 |
printTableBorder("╮"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
83 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
84 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
85 |
for (ColumnDescriptor cd : columnDescriptors) { |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
86 |
if (cd.isFirstColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
87 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
88 |
printTableBorder("│ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
89 |
} else { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
90 |
printTableBorder(" │ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
91 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
92 |
out.print(TerminalStyle.Bright, cd.getLabel()); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
93 |
out.print(HEADER_TYPE_PREFIX); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
94 |
out.print(cd.getTypeName()); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
95 |
out.print(HEADER_TYPE_SUFFIX); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
96 |
if (cd.isLastColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
97 |
printTableBorder(" │"); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
98 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
99 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
100 |
out.println(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
101 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
102 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
103 |
printTableBorder("├"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
104 |
for (int i = 1; i <= header.getColumnCount(); i++) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
105 |
if (i > 1) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
106 |
printTableBorder("┼"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
107 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
108 |
printTableBorder(repeat('─', getColumnWidth(i) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
109 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
110 |
printTableBorder("┤"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
111 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
112 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
113 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
114 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
115 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
116 |
/** |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
117 |
* Must be called before |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
118 |
* {@linkplain #updateColumnWidth(int, int)} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
119 |
* and {@linkplain #getColumnWidth(int)} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
120 |
* for each result set. |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
121 |
* |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
122 |
* @param columnCount number of columns in current result set |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
123 |
*/ |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
124 |
protected void initColumnWidths(int columnCount) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
125 |
if (columnWidth == null) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
126 |
columnWidth = new int[columnCount]; |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
127 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
128 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
129 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
130 |
protected void cleanColumnWidths() { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
131 |
columnWidth = null; |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
132 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
133 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
134 |
@Override |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
135 |
public void writeColumnValue(Object value) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
136 |
super.writeColumnValue(value); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
137 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
138 |
if (isCurrentColumnFirst()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
139 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
140 |
printTableBorder("│ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
141 |
} else { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
142 |
printTableBorder(" │ "); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
143 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
144 |
|
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
145 |
out.print(TerminalColor.Cyan, toString(value)); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
146 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
147 |
if (isCurrentColumnLast()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
148 |
printTableBorder(" │"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
149 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
150 |
|
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
151 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
152 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
153 |
private int getColumnWidth(int columnNumber) { |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
154 |
return columnWidth[columnNumber - 1]; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
155 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
156 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
157 |
private void setColumnWidth(int columnNumber, int width) { |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
158 |
columnWidth[columnNumber - 1] = width; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
159 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
160 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
161 |
protected void updateColumnWidth(int columnNumber, int width) { |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
162 |
int oldWidth = getColumnWidth(columnNumber); |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
163 |
setColumnWidth(columnNumber, Math.max(width, oldWidth)); |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
164 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
165 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
166 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
167 |
@Override |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
168 |
protected String toString(Object value) { |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
169 |
final int width = getColumnWidth(getCurrentColumnsCount()); |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
170 |
String result; |
43
2813d3409afd
TabularFormatter: also booleans will be aligned to the right
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
171 |
if (value instanceof Number || value instanceof Boolean) { |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
172 |
result = lpad(super.toString(value), width); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
173 |
} else { |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
174 |
result = rpad(super.toString(value), width); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
175 |
} |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
176 |
// ? value = (boolean) value ? "✔" : "✗"; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
177 |
|
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
178 |
if (trimValues && result.length() > width) { |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
179 |
result = result.substring(0, width - 1) + "…"; |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
180 |
} |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
181 |
|
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
182 |
return result; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
183 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
184 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
185 |
@Override |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
186 |
public void writeEndRow() { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
187 |
super.writeEndRow(); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
188 |
out.println(); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
189 |
out.flush(); |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
190 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
191 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
192 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
193 |
public void writeEndResultSet() { |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
194 |
int columnCount = getCurrentColumnsHeader().getColumnCount(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
195 |
super.writeEndResultSet(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
196 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
197 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
198 |
printTableBorder("╰"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
199 |
for (int i = 1; i <= columnCount; i++) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
200 |
if (i > 1) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
201 |
printTableBorder("┴"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
202 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
203 |
printTableBorder(repeat('─', getColumnWidth(i) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
204 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
205 |
printTableBorder("╯"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
206 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
207 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
208 |
cleanColumnWidths(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
209 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
210 |
out.print(TerminalColor.Yellow, "Record count: "); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
211 |
out.println(getCurrentRowCount()); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
212 |
out.bell(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
213 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
214 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
215 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
216 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
217 |
public void writeStartUpdatesResult() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
218 |
super.writeStartUpdatesResult(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
219 |
printResultSeparator(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
220 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
221 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
222 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
223 |
public void writeUpdatedRowsCount(int updatedRowsCount) { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
224 |
super.writeUpdatedRowsCount(updatedRowsCount); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
225 |
out.print(TerminalColor.Red, "Updated records: "); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
226 |
out.println(updatedRowsCount); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
227 |
out.bell(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
228 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
229 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
230 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
231 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
232 |
public void writeEndDatabase() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
233 |
super.writeEndDatabase(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
234 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
235 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
236 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
237 |
private void printResultSeparator() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
238 |
if (firstResult) { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
239 |
firstResult = false; |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
240 |
} else { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
241 |
out.println(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
242 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
243 |
} |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
244 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
245 |
private void printTableBorder(String border) { |
76
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
246 |
if (asciiNostalgia) { |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
247 |
border = border.replaceAll("─", "-"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
248 |
border = border.replaceAll("│", "|"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
249 |
border = border.replaceAll("[╭┬╮├┼┤╰┴╯]", "+"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
250 |
} |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
251 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
252 |
out.print(TerminalColor.Green, border); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
253 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
254 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
255 |
private void printTableIndent() { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
256 |
out.print(" "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
257 |
} |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
258 |
} |