Commit ecb7500a authored by gmantele's avatar gmantele
Browse files

[TAP] Add an XML TableSet parser. The main modification done in JDBCConnection...

[TAP] Add an XML TableSet parser. The main modification done in JDBCConnection is about the schema prefix of table when the DBMS does not support schemas: now, only standard tables are expected with the prefix 'TAP_SCHEMA_' and the upload tables also with 'TAP_UPLOAD_'.
parent f0cfaf10
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ import adql.query.operand.function.geometry.RegionFunction;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 1.3 (11/2014)
 * @version 2.0 (02/2015)
 * @since 1.3
 * 
 * @see PostgreSQLTranslator
@@ -232,15 +232,40 @@ public abstract class JDBCTranslator implements ADQLTranslator {
	 * 
	 * @return	The qualified (with DB catalog and schema prefix if any, and with double quotes if needed) DB table name,
	 *        	or an empty string if the given table is NULL or if there is no DB name.
	 * 
	 * @see #getTableName(DBTable, boolean)
	 */
	public String getQualifiedTableName(final DBTable table){
		return getTableName(table, true);
	}

	/**
	 * <p>Get the DB name of the given table.
	 * The second parameter lets specify whether the table name must be prefixed by the qualified schema name or not.</p>
	 * 
	 * <p><i>Note:
	 * 	This function will, by default, add double quotes if the table name must be case sensitive in the SQL query.
	 * 	This information is provided by {@link #isCaseSensitive(IdentifierField)}.
	 * </i></p>
	 * 
	 * @param table			The table whose the DB name is asked.
	 * @param withSchema	<i>true</i> if the qualified schema name must prefix the table name, <i>false</i> otherwise. 
	 * 
	 * @return	The DB table name (prefixed by the qualified schema name if asked, and with double quotes if needed),
	 *        	or an empty string if the given table is NULL or if there is no DB name.
	 * 
	 * @since 2.0
	 */
	public String getTableName(final DBTable table, final boolean withSchema){
		if (table == null)
			return "";

		StringBuffer buf = new StringBuffer(getQualifiedSchemaName(table));
		StringBuffer buf = new StringBuffer();
		if (withSchema){
			buf.append(getQualifiedSchemaName(table));
			if (buf.length() > 0)
				buf.append('.');

		}
		appendIdentifier(buf, table.getDBName(), IdentifierField.TABLE);

		return buf.toString();
+30 −30
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import adql.db.DBType;
 * <p>{@link #getColType()} will return TAP type based on the type declared in the VOTable metadata part.</p>
 * 
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.0 (12/2014)
 * @version 2.0 (02/2015)
 * @since 2.0
 */
public class VOTableIterator implements TableIterator {
@@ -42,7 +42,7 @@ public class VOTableIterator implements TableIterator {
	 * </p> 
	 * 
	 * @author Gr&eacute;gory Mantelet (ARI)
	 * @version 2.0 (12/2014)
	 * @version 2.0 (01/2015)
	 * @since 2.0
	 */
	protected static class StreamVOTableSink implements TableSink {
@@ -288,34 +288,6 @@ public class VOTableIterator implements TableIterator {
			return (value != null) ? value.getValue().toString() : null;
		}

		/**
		 * Resolve a VOTable field type by using the datatype, arraysize and xtype strings as specified in a VOTable document.
		 * 
		 * @param datatype		Attribute value of VOTable corresponding to the datatype.
		 * @param arraysize		Attribute value of VOTable corresponding to the arraysize.
		 * @param xtype			Attribute value of VOTable corresponding to the xtype.
		 * 
		 * @return	The resolved VOTable field type, or a CHAR(*) type if the specified type can not be resolved.
		 * 
		 * @throws DataReadException	If a field datatype is unknown.
		 */
		protected VotType resolveVotType(final String datatype, final String arraysize, final String xtype) throws DataReadException{
			// If no datatype is specified, return immediately a CHAR(*) type:
			if (datatype == null || datatype.trim().length() == 0)
				return new VotType(VotDatatype.CHAR, "*");

			// Identify the specified datatype:
			VotDatatype votdatatype;
			try{
				votdatatype = VotDatatype.valueOf(datatype.toUpperCase());
			}catch(IllegalArgumentException iae){
				throw new DataReadException("unknown field datatype: \"" + datatype + "\"");
			}

			// Build the VOTable type:
			return new VotType(votdatatype, arraysize, xtype);
		}

	}

	/** Stream containing the VOTable on which this {@link TableIterator} is iterating. */
@@ -458,4 +430,32 @@ public class VOTableIterator implements TableIterator {
			throw new IllegalStateException("End of VOTable file already reached!");
	}

	/**
	 * Resolve a VOTable field type by using the datatype, arraysize and xtype strings as specified in a VOTable document.
	 * 
	 * @param datatype		Attribute value of VOTable corresponding to the datatype.
	 * @param arraysize		Attribute value of VOTable corresponding to the arraysize.
	 * @param xtype			Attribute value of VOTable corresponding to the xtype.
	 * 
	 * @return	The resolved VOTable field type, or a CHAR(*) type if the specified type can not be resolved.
	 * 
	 * @throws DataReadException	If a field datatype is unknown.
	 */
	public static VotType resolveVotType(final String datatype, final String arraysize, final String xtype) throws DataReadException{
		// If no datatype is specified, return immediately a CHAR(*) type:
		if (datatype == null || datatype.trim().length() == 0)
			return new VotType(VotDatatype.CHAR, "*");

		// Identify the specified datatype:
		VotDatatype votdatatype;
		try{
			votdatatype = VotDatatype.valueOf(datatype.toUpperCase());
		}catch(IllegalArgumentException iae){
			throw new DataReadException("unknown field datatype: \"" + datatype + "\"");
		}

		// Build the VOTable type:
		return new VotType(votdatatype, arraysize, xtype);
	}

}
+216 −76

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -569,11 +569,11 @@ public class VOTableFormat implements OutputFormat {
				return isScalar ? Boolean.class : boolean[].class;
			case DOUBLE:
				return isScalar ? Double.class : double[].class;
			case DOUBLE_COMPLEX:
			case DOUBLECOMPLEX:
				return double[].class;
			case FLOAT:
				return isScalar ? Float.class : float[].class;
			case FLOAT_COMPLEX:
			case FLOATCOMPLEX:
				return float[].class;
			case INT:
				return isScalar ? Integer.class : int[].class;
@@ -581,10 +581,10 @@ public class VOTableFormat implements OutputFormat {
				return isScalar ? Long.class : long[].class;
			case SHORT:
				return isScalar ? Short.class : short[].class;
			case UNSIGNED_BYTE:
			case UNSIGNEDBYTE:
				return isScalar ? Short.class : short[].class;
			case CHAR:
			case UNICODE_CHAR:
			case UNICODECHAR:
			default: /* If the type is not know (theoretically, never happens), return char[*] by default. */
				return isScalar ? Character.class : String.class;
		}
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public interface TAPLog extends UWSLog {
	 * 	<li>CLEAN_TAP_SCHEMA</li>
	 * 	<li>CREATE_TAP_SCHEMA</li>
	 * 	<li>TABLE_EXIST</li>
	 * 	<li>COLUMN_EXIST</li>
	 * 	<li>EXEC_UPDATE</li>
	 * 	<li>ADD_UPLOAD_TABLE</li>
	 * 	<li>DROP_UPLOAD_TABLE</li>
Loading