[#7800] Let Record extend Formattable
- Also: [#7803] Add dummy implementations to ArrayRecordImpl
This commit is contained in:
parent
8f0deab2b0
commit
ae41800faa
@ -38,8 +38,6 @@
|
||||
|
||||
package org.jooq;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -48,10 +46,10 @@ import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.exception.IOException;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.impl.DefaultRecordMapper;
|
||||
import org.jooq.impl.DefaultRecordMapperProvider;
|
||||
@ -103,7 +101,7 @@ import org.jooq.tools.Convert;
|
||||
* @author Lukas Eder
|
||||
* @see Result
|
||||
*/
|
||||
public interface Record extends Attachable, Comparable<Record> {
|
||||
public interface Record extends Attachable, Comparable<Record>, Formattable {
|
||||
|
||||
/**
|
||||
* Get this record's fields as a {@link Row}.
|
||||
@ -1299,153 +1297,6 @@ public interface Record extends Attachable, Comparable<Record> {
|
||||
*/
|
||||
void fromArray(Object[] array, int... fieldIndexes);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Formatting methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get a simple formatted representation of this result as a text table.
|
||||
* <p>
|
||||
* The format is the following:<p>
|
||||
* <code><pre>
|
||||
* +------+------+------+
|
||||
* | COL1 | COL2 | COL3 |
|
||||
* +------+------+------+
|
||||
* | VAL1 | VAL2 | VAL3 |
|
||||
* +------+------+------+
|
||||
* </pre></code>
|
||||
*
|
||||
* @return The formatted result
|
||||
*/
|
||||
String format();
|
||||
|
||||
/**
|
||||
* Get a simple formatted representation of this result as a text data
|
||||
* structure, according to the format.
|
||||
*
|
||||
* @return The formatted result
|
||||
* @see TXTFormat
|
||||
*/
|
||||
String format(TXTFormat format);
|
||||
|
||||
/**
|
||||
* Like {@link #format()}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void format(OutputStream stream) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #format(TXTFormat)}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void format(OutputStream stream, TXTFormat format) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #format()}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void format(Writer writer) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #format(TXTFormat)}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void format(Writer writer, TXTFormat format) throws IOException;
|
||||
|
||||
/**
|
||||
* Get a simple formatted representation of this result as a JSON array.
|
||||
* <p>
|
||||
* The format is the following: <code><pre>
|
||||
* [value-2-1,value-2-2,...,value-2-n]
|
||||
* </pre></code>
|
||||
*
|
||||
* @return The formatted result
|
||||
*/
|
||||
String formatJSON();
|
||||
|
||||
/**
|
||||
* Get a simple formatted representation of this result as a JSON data
|
||||
* structure, according to the format.
|
||||
*
|
||||
* @return The formatted result
|
||||
* @see JSONFormat
|
||||
*/
|
||||
String formatJSON(JSONFormat format);
|
||||
|
||||
/**
|
||||
* Like {@link #formatJSON()}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatJSON(OutputStream stream) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatJSON(JSONFormat)}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatJSON(OutputStream stream, JSONFormat format) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatJSON()}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatJSON(Writer writer) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatJSON(JSONFormat)}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatJSON(Writer writer, JSONFormat format) throws IOException;
|
||||
|
||||
/**
|
||||
* Get this record formatted as XML.
|
||||
*
|
||||
* @see Result#formatXML()
|
||||
*/
|
||||
String formatXML();
|
||||
|
||||
/**
|
||||
* Get this record formatted as XML.
|
||||
*
|
||||
* @see Result#formatXML(XMLFormat)
|
||||
*/
|
||||
String formatXML(XMLFormat format);
|
||||
|
||||
/**
|
||||
* Like {@link #formatXML()}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatXML(OutputStream stream) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatXML(XMLFormat)}, but the data is output onto an {@link OutputStream}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatXML(OutputStream stream, XMLFormat format) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatXML()}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatXML(Writer writer) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #formatXML(XMLFormat)}, but the data is output onto a {@link Writer}.
|
||||
*
|
||||
* @throws IOException - an unchecked wrapper for {@link java.io.IOException}, if anything goes wrong.
|
||||
*/
|
||||
void formatXML(Writer writer, XMLFormat format) throws IOException;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Inherited methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -49,10 +49,7 @@ import static org.jooq.tools.StringUtils.abbreviate;
|
||||
import static org.jooq.tools.StringUtils.leftPad;
|
||||
import static org.jooq.tools.StringUtils.rightPad;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
@ -103,7 +100,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractCursor<R extends Record> implements Formattable, Iterable<R>, Serializable {
|
||||
abstract class AbstractCursor<R extends Record> extends AbstractFormattable implements Iterable<R>, Serializable {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
@ -118,48 +115,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format() {
|
||||
return format(TXTFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format(int maxRecords) {
|
||||
return format(TXTFormat.DEFAULT.maxRows(maxRecords));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format(TXTFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
format(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream) {
|
||||
format(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream, int maxRecords) {
|
||||
format(new OutputStreamWriter(stream), maxRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream, TXTFormat format) {
|
||||
format(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer) {
|
||||
format(writer, TXTFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer, int maxRecords) {
|
||||
format(writer, TXTFormat.DEFAULT.maxRows(maxRecords));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer, TXTFormat format) {
|
||||
try {
|
||||
@ -396,114 +351,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
return decimalPlaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV() {
|
||||
return formatCSV(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, header);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream) {
|
||||
formatCSV(stream, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header) {
|
||||
formatCSV(new OutputStreamWriter(stream), header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer) {
|
||||
formatCSV(writer, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header) {
|
||||
formatCSV(writer, header, ',', "\"\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(char delimiter) {
|
||||
return formatCSV(true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header, char delimiter) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, delimiter);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, char delimiter) {
|
||||
formatCSV(stream, true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header, char delimiter) {
|
||||
formatCSV(new OutputStreamWriter(stream), delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, char delimiter) {
|
||||
formatCSV(writer, true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header, char delimiter) {
|
||||
formatCSV(writer, header, delimiter, "\"\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(char delimiter, String nullString) {
|
||||
return formatCSV(true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header, char delimiter, String nullString) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, header, delimiter, nullString);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(CSVFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, char delimiter, String nullString) {
|
||||
formatCSV(stream, true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header, char delimiter, String nullString) {
|
||||
formatCSV(new OutputStreamWriter(stream), header, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, CSVFormat format) {
|
||||
formatCSV(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, char delimiter, String nullString) {
|
||||
formatCSV(writer, true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header, char delimiter, String nullString) {
|
||||
formatCSV(writer, new CSVFormat().header(header).delimiter(delimiter).nullString(nullString));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, CSVFormat format) {
|
||||
try {
|
||||
@ -571,35 +418,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON(JSONFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream) {
|
||||
formatJSON(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream, JSONFormat format) {
|
||||
formatJSON(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer) {
|
||||
formatJSON(writer, JSONFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer, JSONFormat format) {
|
||||
try {
|
||||
@ -768,11 +586,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
((Formattable) value).formatJSON(writer, format);
|
||||
}
|
||||
|
||||
// [#7355] Record should also implement Formattable
|
||||
else if (value instanceof Record) {
|
||||
((Record) value).formatJSON(writer, format);
|
||||
}
|
||||
|
||||
else {
|
||||
JSONValue.writeJSONString(value, writer);
|
||||
}
|
||||
@ -831,33 +644,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
writer.append(']');
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML() {
|
||||
return formatXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML(XMLFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatXML(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream) {
|
||||
formatXML(stream, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream, XMLFormat format) {
|
||||
formatXML(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer) {
|
||||
formatXML(writer, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer, XMLFormat format) {
|
||||
String newline = format.newline();
|
||||
@ -964,35 +750,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
writer.append(newline).append(format.indentString(recordLevel)).append("</record>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatChart() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatChart(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatChart(ChartFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatChart(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(OutputStream stream) {
|
||||
formatChart(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(OutputStream stream, ChartFormat format) {
|
||||
formatChart(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(Writer writer) {
|
||||
formatChart(writer, ChartFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final void formatChart(Writer writer, ChartFormat format) {
|
||||
@ -1176,35 +933,11 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatInsert() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatInsert(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(OutputStream stream) {
|
||||
formatInsert(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(Writer writer) {
|
||||
formatInsert(writer, null, fields.fields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatInsert(Table<?> table, Field<?>... f) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatInsert(writer, table, f);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(OutputStream stream, Table<?> table, Field<?>... f) {
|
||||
formatInsert(new OutputStreamWriter(stream), table, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(Writer writer, Table<?> table, Field<?>... f) {
|
||||
DSLContext ctx = configuration.dsl();
|
||||
@ -1228,18 +961,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatHTML() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatHTML(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatHTML(OutputStream stream) {
|
||||
formatHTML(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatHTML(Writer writer) {
|
||||
try {
|
||||
@ -1279,11 +1000,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Document intoXML() {
|
||||
return intoXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Document intoXML(XMLFormat format) {
|
||||
try {
|
||||
@ -1361,11 +1077,6 @@ abstract class AbstractCursor<R extends Record> implements Formattable, Iterable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <H extends ContentHandler> H intoXML(H handler) throws SAXException {
|
||||
return intoXML(handler, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <H extends ContentHandler> H intoXML(H handler, XMLFormat format) throws SAXException {
|
||||
Attributes empty = new AttributesImpl();
|
||||
|
||||
352
jOOQ/src/main/java/org/jooq/impl/AbstractFormattable.java
Normal file
352
jOOQ/src/main/java/org/jooq/impl/AbstractFormattable.java
Normal file
@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.jooq.CSVFormat;
|
||||
import org.jooq.ChartFormat;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Formattable;
|
||||
import org.jooq.JSONFormat;
|
||||
import org.jooq.TXTFormat;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.XMLFormat;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* A common base implementation for {@link Formattable}, implementing all the
|
||||
* various convenience overloads.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractFormattable implements Formattable, Serializable {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 8634798716074039885L;
|
||||
|
||||
@Override
|
||||
public final String format() {
|
||||
return format(TXTFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format(int maxRecords) {
|
||||
return format(TXTFormat.DEFAULT.maxRows(maxRecords));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format(TXTFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
format(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream) {
|
||||
format(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream, int maxRecords) {
|
||||
format(new OutputStreamWriter(stream), maxRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream, TXTFormat format) {
|
||||
format(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer) {
|
||||
format(writer, TXTFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer, int maxRecords) {
|
||||
format(writer, TXTFormat.DEFAULT.maxRows(maxRecords));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV() {
|
||||
return formatCSV(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, header);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream) {
|
||||
formatCSV(stream, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header) {
|
||||
formatCSV(new OutputStreamWriter(stream), header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer) {
|
||||
formatCSV(writer, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header) {
|
||||
formatCSV(writer, header, ',', "\"\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(char delimiter) {
|
||||
return formatCSV(true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header, char delimiter) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, delimiter);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, char delimiter) {
|
||||
formatCSV(stream, true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header, char delimiter) {
|
||||
formatCSV(new OutputStreamWriter(stream), delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, char delimiter) {
|
||||
formatCSV(writer, true, delimiter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header, char delimiter) {
|
||||
formatCSV(writer, header, delimiter, "\"\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(char delimiter, String nullString) {
|
||||
return formatCSV(true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(boolean header, char delimiter, String nullString) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, header, delimiter, nullString);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatCSV(CSVFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatCSV(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, char delimiter, String nullString) {
|
||||
formatCSV(stream, true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, boolean header, char delimiter, String nullString) {
|
||||
formatCSV(new OutputStreamWriter(stream), header, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(OutputStream stream, CSVFormat format) {
|
||||
formatCSV(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, char delimiter, String nullString) {
|
||||
formatCSV(writer, true, delimiter, nullString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatCSV(Writer writer, boolean header, char delimiter, String nullString) {
|
||||
formatCSV(writer, new CSVFormat().header(header).delimiter(delimiter).nullString(nullString));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON(JSONFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream) {
|
||||
formatJSON(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream, JSONFormat format) {
|
||||
formatJSON(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer) {
|
||||
formatJSON(writer, JSONFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML() {
|
||||
return formatXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML(XMLFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatXML(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream) {
|
||||
formatXML(stream, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream, XMLFormat format) {
|
||||
formatXML(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer) {
|
||||
formatXML(writer, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatChart() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatChart(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatChart(ChartFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatChart(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(OutputStream stream) {
|
||||
formatChart(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(OutputStream stream, ChartFormat format) {
|
||||
formatChart(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(Writer writer) {
|
||||
formatChart(writer, ChartFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatInsert() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatInsert(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(OutputStream stream) {
|
||||
formatInsert(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatInsert(Table<?> table, Field<?>... f) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatInsert(writer, table, f);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(OutputStream stream, Table<?> table, Field<?>... f) {
|
||||
formatInsert(new OutputStreamWriter(stream), table, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatHTML() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatHTML(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatHTML(OutputStream stream) {
|
||||
formatHTML(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Document intoXML() {
|
||||
return intoXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <H extends ContentHandler> H intoXML(H handler) throws SAXException {
|
||||
return intoXML(handler, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
}
|
||||
}
|
||||
@ -45,9 +45,6 @@ import static org.jooq.impl.Tools.resetChangedOnNotNull;
|
||||
import static org.jooq.impl.Tools.settings;
|
||||
import static org.jooq.impl.Tools.ThreadGuard.Guard.RECORD_TOSTRING;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
@ -61,6 +58,8 @@ import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jooq.Attachable;
|
||||
import org.jooq.CSVFormat;
|
||||
import org.jooq.ChartFormat;
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
@ -104,6 +103,10 @@ import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* A general base class for all {@link Record} types
|
||||
*
|
||||
@ -915,35 +918,6 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
// Formatting methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final String format() {
|
||||
StringWriter writer = new StringWriter();
|
||||
format(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String format(TXTFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
format(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream) {
|
||||
format(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(OutputStream stream, TXTFormat format) {
|
||||
format(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer) {
|
||||
format(writer, TXTFormat.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void format(Writer writer, TXTFormat format) {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
@ -952,33 +926,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON() {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatJSON(JSONFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatJSON(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream) {
|
||||
formatJSON(new OutputStreamWriter(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(OutputStream stream, JSONFormat format) {
|
||||
formatJSON(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer) {
|
||||
formatJSON(writer, JSONFormat.DEFAULT_FOR_RECORDS);
|
||||
}
|
||||
public final void formatCSV(Writer writer, CSVFormat format) {}
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer, JSONFormat format) {
|
||||
@ -1002,33 +950,6 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML() {
|
||||
return formatXML(XMLFormat.DEFAULT_FOR_RECORDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML(XMLFormat format) {
|
||||
StringWriter writer = new StringWriter();
|
||||
formatXML(writer, format);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream) {
|
||||
formatXML(stream, XMLFormat.DEFAULT_FOR_RECORDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream, XMLFormat format) {
|
||||
formatXML(new OutputStreamWriter(stream), format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer) {
|
||||
formatXML(writer, XMLFormat.DEFAULT_FOR_RECORDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer, XMLFormat format) {
|
||||
if (format.header())
|
||||
@ -1042,6 +963,46 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatHTML(Writer writer) {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
result.add(AbstractRecord.this);
|
||||
result.formatHTML(writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatChart(Writer writer, ChartFormat format) {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
result.add(AbstractRecord.this);
|
||||
result.formatChart(writer, format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(Writer writer) {
|
||||
formatInsert(writer, null, fields.fields.fields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void formatInsert(Writer writer, Table<?> table, Field<?>... f) {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
result.add(AbstractRecord.this);
|
||||
result.formatInsert(writer, table, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Document intoXML(XMLFormat format) {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
result.add(AbstractRecord.this);
|
||||
return result.intoXML(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <H extends ContentHandler> H intoXML(H handler, XMLFormat format) throws SAXException {
|
||||
Result<AbstractRecord> result = new ResultImpl<AbstractRecord>(configuration(), fields.fields.fields);
|
||||
result.add(AbstractRecord.this);
|
||||
return result.intoXML(handler, format);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Object and Comparable API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -54,7 +54,7 @@ import org.jooq.Record;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractStore implements Attachable {
|
||||
abstract class AbstractStore extends AbstractFormattable implements Attachable {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
|
||||
@ -37,6 +37,57 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user