From f7adf914efc8bcede1697e76a21321cd0778b918 Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Thu, 2 Oct 2014 19:06:19 +0200 Subject: [PATCH] [TAP] Log format reports and end of ADQLExecutor execution, add an OVERFLOW notification for the text/plain output and check by default that the given service connection is not null in constructor. --- src/tap/ADQLExecutor.java | 3 +++ src/tap/formatter/JSONFormat.java | 19 +++++++++++++------ src/tap/formatter/SVFormat.java | 25 +++++++++++++++++++------ src/tap/formatter/TextFormat.java | 20 ++++++++++++++++---- src/tap/formatter/VOTableFormat.java | 15 ++++++++------- 5 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/tap/ADQLExecutor.java b/src/tap/ADQLExecutor.java index 96f18fc..fc9c6c4 100644 --- a/src/tap/ADQLExecutor.java +++ b/src/tap/ADQLExecutor.java @@ -370,6 +370,9 @@ public class ADQLExecutor { // Set the total duration in the report: report.setTotalDuration(System.currentTimeMillis() - start); + + // Log and report the end of this execution: + logger.logTAP(LogLevel.INFO, report, "END_EXEC", "ADQL query execution finished.", null); } } diff --git a/src/tap/formatter/JSONFormat.java b/src/tap/formatter/JSONFormat.java index fbde557..06f3e23 100644 --- a/src/tap/formatter/JSONFormat.java +++ b/src/tap/formatter/JSONFormat.java @@ -42,7 +42,7 @@ import adql.db.DBColumn; * Format any given query (table) result into JSON. * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (09/2014) + * @version 2.0 (10/2014) */ public class JSONFormat implements OutputFormat { @@ -59,9 +59,11 @@ public class JSONFormat implements OutputFormat { * However if you want this behavior you must you {@link #JSONFormat(ServiceConnection, boolean)}.</i></p> * * @param service Description of the TAP service. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public JSONFormat(final ServiceConnection service){ - this(service, false); + public JSONFormat(final ServiceConnection service) throws NullPointerException{ + this(service, true); } /** @@ -69,8 +71,13 @@ public class JSONFormat implements OutputFormat { * * @param service Description of the TAP service. * @param logFormatReport <i>true</i> to write a log entry (with nb rows and columns + writing duration) each time a result is written, <i>false</i> otherwise. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public JSONFormat(final ServiceConnection service, final boolean logFormatReport){ + public JSONFormat(final ServiceConnection service, final boolean logFormatReport) throws NullPointerException{ + if (service == null) + throw new NullPointerException("The given service connection is NULL!"); + this.service = service; this.logFormatReport = logFormatReport; } @@ -130,9 +137,9 @@ public class JSONFormat implements OutputFormat { service.getLogger().logTAP(LogLevel.INFO, execReport, "FORMAT", "Result formatted (in JSON ; " + nbRows + " rows ; " + columns.length + " columns) in " + (System.currentTimeMillis() - start) + "ms!", null); }catch(JSONException je){ - throw new TAPException("Error while writing a query result in JSON !", je); + throw new TAPException("Error while writing a query result in JSON!", je); }catch(IOException ioe){ - throw new TAPException("Error while writing a query result in JSON !", ioe); + throw new TAPException("Error while writing a query result in JSON!", ioe); } } diff --git a/src/tap/formatter/SVFormat.java b/src/tap/formatter/SVFormat.java index 196410c..8b38953 100644 --- a/src/tap/formatter/SVFormat.java +++ b/src/tap/formatter/SVFormat.java @@ -63,8 +63,10 @@ public class SVFormat implements OutputFormat { * * @param service Description of the TAP service. * @param colSeparator Column separator to use. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public SVFormat(final ServiceConnection service, char colSeparator){ + public SVFormat(final ServiceConnection service, char colSeparator) throws NullPointerException{ this(service, colSeparator, true); } @@ -74,9 +76,11 @@ public class SVFormat implements OutputFormat { * @param service Description of the TAP service. * @param colSeparator Column separator to use. * @param delimitStrings <i>true</i> if String values must be delimited by double quotes, <i>false</i> otherwise. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public SVFormat(final ServiceConnection service, char colSeparator, boolean delimitStrings){ - this(service, colSeparator, delimitStrings, false); + public SVFormat(final ServiceConnection service, char colSeparator, boolean delimitStrings) throws NullPointerException{ + this(service, colSeparator, delimitStrings, true); } /** @@ -86,8 +90,10 @@ public class SVFormat implements OutputFormat { * @param colSeparator Column separator to use. * @param delimitStrings <i>true</i> if String values must be delimited by double quotes, <i>false</i> otherwise. * @param logFormatReport <i>true</i> to write a log entry (with nb rows and columns + writing duration) each time a result is written, <i>false</i> otherwise. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public SVFormat(final ServiceConnection service, char colSeparator, boolean delimitStrings, final boolean logFormatReport){ + public SVFormat(final ServiceConnection service, char colSeparator, boolean delimitStrings, final boolean logFormatReport) throws NullPointerException{ separator = "" + colSeparator; delimitStr = delimitStrings; this.service = service; @@ -99,8 +105,10 @@ public class SVFormat implements OutputFormat { * * @param service Description of the TAP service. * @param colSeparator Column separator to use. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public SVFormat(final ServiceConnection service, String colSeparator){ + public SVFormat(final ServiceConnection service, String colSeparator) throws NullPointerException{ this(service, colSeparator, true); } @@ -110,8 +118,13 @@ public class SVFormat implements OutputFormat { * @param service Description of the TAP service. * @param colSeparator Column separator to use. * @param delimitStrings <i>true</i> if String values must be delimited by double quotes, <i>false</i> otherwise. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public SVFormat(final ServiceConnection service, String colSeparator, boolean delimitStrings){ + public SVFormat(final ServiceConnection service, String colSeparator, boolean delimitStrings) throws NullPointerException{ + if (service == null) + throw new NullPointerException("The given service connection is NULL!"); + separator = (colSeparator == null) ? ("" + COMMA_SEPARATOR) : colSeparator; delimitStr = delimitStrings; this.service = service; diff --git a/src/tap/formatter/TextFormat.java b/src/tap/formatter/TextFormat.java index 65f8247..5ead35d 100644 --- a/src/tap/formatter/TextFormat.java +++ b/src/tap/formatter/TextFormat.java @@ -36,7 +36,7 @@ import cds.util.AsciiTable; * (columns' width are adjusted so that all columns are well aligned and of the same width). * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (09/2014) + * @version 2.0 (10/2014) */ public class TextFormat implements OutputFormat { @@ -50,9 +50,11 @@ public class TextFormat implements OutputFormat { * Build a {@link TextFormat}. * * @param service Description of the TAP service. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public TextFormat(final ServiceConnection service){ - this(service, false); + public TextFormat(final ServiceConnection service) throws NullPointerException{ + this(service, true); } /** @@ -60,8 +62,13 @@ public class TextFormat implements OutputFormat { * * @param service Description of the TAP service. * @param logFormatReport <i>true</i> to write a log entry (with nb rows and columns + writing duration) each time a result is written, <i>false</i> otherwise. + * + * @throws NullPointerException If the given service connection is <code>null</code>. */ - public TextFormat(final ServiceConnection service, final boolean logFormatReport){ + public TextFormat(final ServiceConnection service, final boolean logFormatReport) throws NullPointerException{ + if (service == null) + throw new NullPointerException("The given service connection is NULL!"); + this.service = service; this.logFormatReport = logFormatReport; } @@ -108,6 +115,11 @@ public class TextFormat implements OutputFormat { output.write(l.getBytes()); output.write('\n'); } + + // Add a line in case of an OVERFLOW: + if (execReport.parameters.getMaxRec() > 0 && nbRows >= execReport.parameters.getMaxRec()) + output.write("\nOVERFLOW (more rows were available but have been truncated by the TAP service)".getBytes()); + output.flush(); // Report stats about the result writing: diff --git a/src/tap/formatter/VOTableFormat.java b/src/tap/formatter/VOTableFormat.java index 6077ca0..0a34f6a 100644 --- a/src/tap/formatter/VOTableFormat.java +++ b/src/tap/formatter/VOTableFormat.java @@ -107,7 +107,7 @@ public class VOTableFormat implements OutputFormat { protected String shortMimeType; /** - * <p>Creates a VOTable formatter without format report.</p> + * <p>Creates a VOTable formatter.</p> * * <p><i>Note: * The MIME type is automatically set to "application/x-votable+xml" = "votable". @@ -119,7 +119,7 @@ public class VOTableFormat implements OutputFormat { * @throws NullPointerException If the given service connection is <code>null</code>. */ public VOTableFormat(final ServiceConnection service) throws NullPointerException{ - this(service, false); + this(service, true); } /** @@ -141,7 +141,7 @@ public class VOTableFormat implements OutputFormat { * @throws NullPointerException If the given service connection is <code>null</code>. */ public VOTableFormat(final ServiceConnection service, final DataFormat votFormat) throws NullPointerException{ - this(service, votFormat, null, false); + this(service, votFormat, null, true); } /** @@ -164,7 +164,7 @@ public class VOTableFormat implements OutputFormat { * @throws NullPointerException If the given service connection is <code>null</code>. */ public VOTableFormat(final ServiceConnection service, final DataFormat votFormat, final VOTableVersion votVersion) throws NullPointerException{ - this(service, votFormat, votVersion, false); + this(service, votFormat, votVersion, true); } /** @@ -206,7 +206,7 @@ public class VOTableFormat implements OutputFormat { */ public VOTableFormat(final ServiceConnection service, final DataFormat votFormat, final VOTableVersion votVersion, final boolean logFormatReport) throws NullPointerException{ if (service == null) - throw new NullPointerException("The given service connection is NULL !"); + throw new NullPointerException("The given service connection is NULL!"); this.service = service; this.logFormatReport = logFormatReport; @@ -384,7 +384,7 @@ public class VOTableFormat implements OutputFormat { if (logFormatReport) service.getLogger().logTAP(LogLevel.INFO, execReport, "FORMAT", "Result formatted (in VOTable ; " + table.getNbReadRows() + " rows ; " + table.getColumnCount() + " columns) in " + (System.currentTimeMillis() - start) + "ms!", null); }catch(IOException ioe){ - throw new TAPException("Error while writing a query result in VOTable !", ioe); + throw new TAPException("Error while writing a query result in VOTable!", ioe); } } @@ -610,7 +610,7 @@ public class VOTableFormat implements OutputFormat { * </p> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (07/2014) + * @version 2.0 (10/2014) * @since 2.0 */ private static class LimitedStarTable extends AbstractStarTable { @@ -702,6 +702,7 @@ public class VOTableFormat implements OutputFormat { if (hasNext){ for(int i = 0; i < nbCol && tableIt.hasNextCol(); i++) row[i] = tableIt.nextCol(); + nbRows++; }else row = null; return hasNext; -- GitLab