TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
3 * Copyright © 2013 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.configuration;
20 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
21 import static info.globalcode.sql.dk.Functions.findByName;
22 import info.globalcode.sql.dk.formatting.SilentFormatter;
23 import info.globalcode.sql.dk.formatting.SingleValueFormatter;
24 import info.globalcode.sql.dk.formatting.TabularFormatter;
25 import info.globalcode.sql.dk.formatting.TabularPrefetchingFormatter;
26 import info.globalcode.sql.dk.formatting.XmlFormatter;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.List;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlRootElement;
33 import javax.xml.bind.annotation.XmlTransient;
37 * @author Ing. František Kučera (frantovo.cz)
39 @XmlRootElement(name = "configuration", namespace = CONFIGURATION)
40 public class Configuration {
42 private List<DatabaseDefinition> databases = new ArrayList<>();
43 private List<FormatterDefinition> formatters = new ArrayList<>();
45 * is used if no formatter is specified on CLI nor in user configuration
47 public static final String DEFAULT_FORMATTER = TabularFormatter.NAME;
48 private String defaultFormatter;
50 * Default list of formatters. Is used if particular name is not found in user configuration.
52 private static final Collection<FormatterDefinition> buildInFormatters;
55 Collection<FormatterDefinition> l = new ArrayList<>();
56 l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
57 l.add(new FormatterDefinition(SingleValueFormatter.NAME, SingleValueFormatter.class.getName()));
58 l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
59 l.add(new FormatterDefinition(TabularFormatter.NAME, TabularFormatter.class.getName()));
60 l.add(new FormatterDefinition(TabularPrefetchingFormatter.NAME, TabularPrefetchingFormatter.class.getName()));
61 buildInFormatters = Collections.unmodifiableCollection(l);
64 @XmlElement(name = "database", namespace = CONFIGURATION)
65 public List<DatabaseDefinition> getDatabases() {
69 public void setDatabases(List<DatabaseDefinition> databases) {
70 this.databases = databases;
74 * @throws ConfigurationException if no database with this name is configured
76 public DatabaseDefinition getDatabase(String name) throws ConfigurationException {
77 DatabaseDefinition dd = findByName(databases, name);
79 throw new ConfigurationException("Database is not configured: " + name);
86 * @return only configured formatters
87 * @see #getBuildInFormatters()
88 * @see #getAllFormatters()
90 @XmlElement(name = "formatter", namespace = CONFIGURATION)
91 public List<FormatterDefinition> getFormatters() {
95 public void setFormatters(List<FormatterDefinition> formatters) {
96 this.formatters = formatters;
100 * @param name name of desired formatter. Looking for this name in user configuration, then in
101 * buil-in formatters. If null, default from configuration or (if not configured) built-in
103 * @return formatter definition
104 * @throws ConfigurationException if no formatter with this name was found
106 public FormatterDefinition getFormatter(String name) throws ConfigurationException {
108 return defaultFormatter == null ? getFormatter(DEFAULT_FORMATTER) : getFormatter(defaultFormatter);
110 FormatterDefinition fd = findByName(formatters, name);
111 fd = fd == null ? findByName(buildInFormatters, name) : fd;
113 throw new ConfigurationException("Formatter is not configured: " + name);
121 * @return only built-in formatters
122 * @see #getAllFormatters()
123 * @see #getFormatters()
126 public Collection<FormatterDefinition> getBuildInFormatters() {
127 return buildInFormatters;
131 * @return built-in + configured formatters
132 * @see #getFormatters()
135 public Collection<FormatterDefinition> getAllFormatters() {
136 Collection<FormatterDefinition> allFormatters = new ArrayList<>();
137 allFormatters.addAll(buildInFormatters);
138 allFormatters.addAll(formatters);
139 return allFormatters;
143 * @return name of default formatter, is used if name is not specified on CLI
145 @XmlElement(name = "defaultFormatter", namespace = CONFIGURATION)
146 public String getDefaultFormatter() {
147 return defaultFormatter;
150 public void setDefaultFormatter(String defaultFormatter) {
151 this.defaultFormatter = defaultFormatter;