java/sql-dk/src/info/globalcode/sql/dk/formatting/SingleValueFormatter.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 07 Jan 2014 21:54:59 +0100
branchv_0
changeset 142 da1e38386d84
parent 79 e19a13ed19a9
permissions -rw-r--r--
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
franta-hg@60
     1
/**
franta-hg@60
     2
 * SQL-DK
franta-hg@60
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@60
     4
 *
franta-hg@60
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@60
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@60
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@60
     8
 * (at your option) any later version.
franta-hg@60
     9
 *
franta-hg@60
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@60
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@60
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@60
    13
 * GNU General Public License for more details.
franta-hg@60
    14
 *
franta-hg@60
    15
 * You should have received a copy of the GNU General Public License
franta-hg@60
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@60
    17
 */
franta-hg@60
    18
package info.globalcode.sql.dk.formatting;
franta-hg@60
    19
franta-hg@60
    20
import java.io.PrintWriter;
franta-hg@60
    21
franta-hg@60
    22
/**
franta-hg@60
    23
 * Prints just the value without any formatting. If the result set contains multiple records or
franta-hg@60
    24
 * columns, the values are simply concatenate without any separators. If updates result is returned,
franta-hg@60
    25
 * the updated records count is printed.
franta-hg@60
    26
 *
franta-hg@60
    27
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@60
    28
 */
franta-hg@60
    29
public class SingleValueFormatter extends AbstractFormatter {
franta-hg@60
    30
franta-hg@79
    31
	public static final String NAME = "single"; // bash-completion:formatter
franta-hg@60
    32
	private PrintWriter out;
franta-hg@60
    33
franta-hg@60
    34
	public SingleValueFormatter(FormatterContext formatterContext) {
franta-hg@60
    35
		super(formatterContext);
franta-hg@60
    36
		this.out = new PrintWriter(formatterContext.getOutputStream());
franta-hg@60
    37
	}
franta-hg@60
    38
franta-hg@60
    39
	@Override
franta-hg@60
    40
	public void writeColumnValue(Object value) {
franta-hg@60
    41
		super.writeColumnValue(value);
franta-hg@60
    42
		out.print(String.valueOf(value));
franta-hg@60
    43
		out.flush();
franta-hg@60
    44
	}
franta-hg@60
    45
franta-hg@60
    46
	@Override
franta-hg@142
    47
	public void writeUpdatesResult(int updatedRowsCount) {
franta-hg@142
    48
		super.writeUpdatesResult(updatedRowsCount);
franta-hg@60
    49
		out.print(updatedRowsCount);
franta-hg@60
    50
		out.flush();
franta-hg@60
    51
	}
franta-hg@60
    52
}