Skip to content
Snippets Groups Projects
Commit 6f607bc6 authored by gmantele's avatar gmantele
Browse files

[ADQL,TAP] Add geometry format in output and correct upload of STC-S regions....

[ADQL,TAP] Add geometry format in output and correct upload of STC-S regions. Geometrical type conversion from and into a DB type is now required in all JDBCTranslator. This allows formatting of geometrical column value coming from the database, but also the translation of STC-S expressions provided in uploaded table into geometrical column values.
parent 9d511687
No related branches found
No related tags found
No related merge requests found
......@@ -1236,7 +1236,7 @@ public final class STCS {
* Let parse any STC-S expression.
*
* @author Grégory Mantelet (ARI)
* @version 1.3 (10/2014)
* @version 1.3 (11/2014)
* @since 1.3
*/
private static class STCSParser {
......@@ -1318,7 +1318,7 @@ public final class STCS {
* @param newStcs New STC-S expression to parse from now.
*/
private void init(final String newStcs){
stcs = (newStcs == null) ? "" : newStcs.replaceAll("\\s", " ");
stcs = (newStcs == null) ? "" : newStcs;
token = null;
buffer = new StringBuffer();
pos = 0;
......@@ -1351,7 +1351,7 @@ public final class STCS {
* Tool function which skip all next space characters until the next meaningful characters.
*/
private void skipSpaces(){
while(pos < stcs.length() && stcs.charAt(pos) == ' ')
while(pos < stcs.length() && Character.isWhitespace(stcs.charAt(pos)))
pos++;
}
......@@ -1371,7 +1371,7 @@ public final class STCS {
skipSpaces();
// Fetch all characters until word separator (a space or a open/close parenthesis):
while(pos < stcs.length() && stcs.charAt(pos) != ' ' && stcs.charAt(pos) != '(' && stcs.charAt(pos) != ')')
while(pos < stcs.length() && !Character.isWhitespace(stcs.charAt(pos)) && stcs.charAt(pos) != '(' && stcs.charAt(pos) != ')')
buffer.append(stcs.charAt(pos++));
// If no character has been fetched while at least one was expected, throw an exception:
......
......@@ -23,9 +23,13 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import tap.data.DataReadException;
import adql.db.DBColumn;
import adql.db.DBTable;
import adql.db.DBType;
import adql.db.STCS.Region;
import adql.db.exception.UnresolvedJoin;
import adql.parser.ParseException;
import adql.query.ADQLList;
import adql.query.ADQLObject;
import adql.query.ADQLOrder;
......@@ -93,8 +97,9 @@ import adql.query.operand.function.geometry.RegionFunction;
* <h3>PostgreSQLTranslator and PgSphereTranslator</h3>
*
* <p>
* {@link PgSphereTranslator} extends {@link PostgreSQLTranslator} and is just translating geometrical
* functions according to the syntax given by PgSphere.
* {@link PgSphereTranslator} extends {@link PostgreSQLTranslator} and is able to translate geometrical
* functions according to the syntax given by PgSphere. But it can also convert geometrical types
* (from and toward the database), translate PgSphere regions into STC expression and vice-versa.
* </p>
*
* <p>
......@@ -150,8 +155,8 @@ import adql.query.operand.function.geometry.RegionFunction;
* </p>
*
* <p><i>Note:
* Geometrical function have not been translated here. They stay abstract because it is obviously impossible to have a generic
* translation ; it totally depends from the database system.
* Geometrical regions and types have not been managed here. They stay abstract because it is obviously impossible to have a generic
* translation and conversion ; it totally depends from the database system.
* </i></p>
*
* <h3>Translation of "FROM" with JOINs</h3>
......@@ -162,8 +167,8 @@ import adql.query.operand.function.geometry.RegionFunction;
* </p>
*
* @author Gr&eacute;gory Mantelet (ARI)
* @version 1.3 (09/2014)
* @since 2.0
* @version 1.3 (11/2014)
* @since 1.3
*
* @see PostgreSQLTranslator
* @see PgSphereTranslator
......@@ -802,4 +807,77 @@ public abstract class JDBCTranslator implements ADQLTranslator {
return translate(geomValue.getValue());
}
/**
* Convert any type provided by a JDBC driver into a type understandable by the ADQL/TAP library.
*
* @param dbmsType Type returned by a JDBC driver. <i>Note: this value is returned by ResultSetMetadata.getColumnType(int) and correspond to a type of java.sql.Types</i>
* @param rawDbmsTypeName Full name of the type returned by a JDBC driver. <i>Note: this name is returned by ResultSetMetadata.getColumnTypeName(int) ; this name may contain parameters</i>
* @param dbmsTypeName Name of type, without the eventual parameters. <i>Note: this name is extracted from rawDbmsTypeName.</i>
* @param typeParams The eventual type parameters (e.g. char string length). <i>Note: these parameters are extracted from rawDbmsTypeName.</i>
*
* @return The corresponding ADQL/TAP type or NULL if the specified type is unknown.
*/
public abstract DBType convertTypeFromDB(final int dbmsType, final String rawDbmsTypeName, final String dbmsTypeName, final String[] typeParams);
/**
* <p>Convert any type provided by the ADQL/TAP library into a type understandable by a JDBC driver.</p>
*
* <p><i>Note:
* The returned DBMS type may contain some parameters between brackets.
* </i></p>
*
* @param type The ADQL/TAP library's type to convert.
*
* @return The corresponding DBMS type or NULL if the specified type is unknown.
*/
public abstract String convertTypeToDB(final DBType type);
/**
* <p>Parse the given JDBC column value as a geometry object and convert it into a {@link Region}.</p>
*
* <p><i>Note:
* Generally the returned object will be used to get its STC-S expression.
* </i></p>
*
* <p><i>Note:
* If the given column value is NULL, NULL will be returned.
* </i></p>
*
* <p><i><b>Important note:</b>
* This function is called ONLY for value of columns flagged as geometries by
* {@link #convertTypeFromDB(int, String, String, String[])}. So the value should always
* be of the expected type and format. However, if it turns out that the type is wrong
* and that the conversion is finally impossible, this function SHOULD throw a
* {@link DataReadException}.
* </i></p>
*
* @param jdbcColValue A JDBC column value (returned by ResultSet.getObject(int)).
*
* @return The corresponding {@link Region} if the given value is a geometry.
*
* @throws ParseException If the given object is not a geometrical object
* or can not be transformed into a {@link Region} object.
*/
public abstract Region translateGeometryFromDB(final Object jdbcColValue) throws ParseException;
/**
* <p>Convert the given STC region into a DB column value.</p>
*
* <p><i>Note:
* This function is used only by the UPLOAD feature, to import geometries provided as STC-S expression in
* a VOTable document inside a DB column.
* </i></p>
*
* <p><i>Note:
* If the given region is NULL, NULL will be returned.
* </i></p>
*
* @param stcs The region to store in the DB.
*
* @return The corresponding DB column object.
*
* @throws ParseException If the given STC Region can not be converted into a DB object.
*/
public abstract Object translateGeometryToDB(final Region region) throws ParseException;
}
This diff is collapsed.
......@@ -20,6 +20,10 @@ package adql.translator;
* Astronomisches Rechen Institut (ARI)
*/
import adql.db.DBType;
import adql.db.DBType.DBDatatype;
import adql.db.STCS.Region;
import adql.parser.ParseException;
import adql.query.IdentifierField;
import adql.query.operand.StringConstant;
import adql.query.operand.function.MathFunction;
......@@ -46,7 +50,7 @@ import adql.query.operand.function.geometry.RegionFunction;
* </i></p>
*
* @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.3 (10/2014)
* @version 1.3 (11/2014)
*
* @see PgSphereTranslator
*/
......@@ -188,4 +192,108 @@ public class PostgreSQLTranslator extends JDBCTranslator {
return getDefaultADQLFunction(region);
}
@Override
public DBType convertTypeFromDB(final int dbmsType, final String rawDbmsTypeName, String dbmsTypeName, final String[] params){
// If no type is provided return VARCHAR:
if (dbmsTypeName == null || dbmsTypeName.trim().length() == 0)
return new DBType(DBDatatype.VARCHAR, DBType.NO_LENGTH);
// Put the dbmsTypeName in lower case for the following comparisons:
dbmsTypeName = dbmsTypeName.toLowerCase();
// Extract the length parameter (always the first one):
int lengthParam = DBType.NO_LENGTH;
if (params != null && params.length > 0){
try{
lengthParam = Integer.parseInt(params[0]);
}catch(NumberFormatException nfe){}
}
// SMALLINT
if (dbmsTypeName.equals("smallint") || dbmsTypeName.equals("int2") || dbmsTypeName.equals("smallserial") || dbmsTypeName.equals("serial2") || dbmsTypeName.equals("boolean") || dbmsTypeName.equals("bool"))
return new DBType(DBDatatype.SMALLINT);
// INTEGER
else if (dbmsTypeName.equals("integer") || dbmsTypeName.equals("int") || dbmsTypeName.equals("int4") || dbmsTypeName.equals("serial") || dbmsTypeName.equals("serial4"))
return new DBType(DBDatatype.INTEGER);
// BIGINT
else if (dbmsTypeName.equals("bigint") || dbmsTypeName.equals("int8") || dbmsTypeName.equals("bigserial") || dbmsTypeName.equals("bigserial8"))
return new DBType(DBDatatype.BIGINT);
// REAL
else if (dbmsTypeName.equals("real") || dbmsTypeName.equals("float4"))
return new DBType(DBDatatype.REAL);
// DOUBLE
else if (dbmsTypeName.equals("double precision") || dbmsTypeName.equals("float8"))
return new DBType(DBDatatype.DOUBLE);
// BINARY
else if (dbmsTypeName.equals("bit"))
return new DBType(DBDatatype.BINARY, lengthParam);
// VARBINARY
else if (dbmsTypeName.equals("bit varying") || dbmsTypeName.equals("varbit"))
return new DBType(DBDatatype.VARBINARY, lengthParam);
// CHAR
else if (dbmsTypeName.equals("char") || dbmsTypeName.equals("character"))
return new DBType(DBDatatype.CHAR, lengthParam);
// VARCHAR
else if (dbmsTypeName.equals("varchar") || dbmsTypeName.equals("character varying"))
return new DBType(DBDatatype.VARCHAR, lengthParam);
// BLOB
else if (dbmsTypeName.equals("bytea"))
return new DBType(DBDatatype.BLOB);
// CLOB
else if (dbmsTypeName.equals("text"))
return new DBType(DBDatatype.CLOB);
// TIMESTAMP
else if (dbmsTypeName.equals("timestamp") || dbmsTypeName.equals("timestamptz") || dbmsTypeName.equals("time") || dbmsTypeName.equals("timetz") || dbmsTypeName.equals("date"))
return new DBType(DBDatatype.TIMESTAMP);
// Default:
else
return new DBType(DBDatatype.VARCHAR, DBType.NO_LENGTH);
}
@Override
public String convertTypeToDB(final DBType type){
if (type == null)
return "VARCHAR";
switch(type.type){
case SMALLINT:
case INTEGER:
case REAL:
case BIGINT:
case CHAR:
case VARCHAR:
case TIMESTAMP:
return type.type.toString();
case DOUBLE:
return "DOUBLE PRECISION";
case BINARY:
case VARBINARY:
return "bytea";
case BLOB:
return "bytea";
case CLOB:
return "TEXT";
case POINT:
case REGION:
default:
return "VARCHAR";
}
}
@Override
public Region translateGeometryFromDB(final Object jdbcColValue) throws ParseException{
throw new ParseException("Unsupported geometrical value! The value \"" + jdbcColValue + "\" can not be parsed as a region.");
}
@Override
public Object translateGeometryToDB(final Region region) throws ParseException{
throw new ParseException("Geometries can not be uploaded in the database in this implementation!");
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -384,6 +384,9 @@ 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){
if (ioe.getCause() != null && ioe.getCause() instanceof DataReadException)
throw (DataReadException)ioe.getCause();
else
throw new TAPException("Error while writing a query result in VOTable!", ioe);
}
}
......@@ -432,7 +435,7 @@ public class VOTableFormat implements OutputFormat {
* 2/ a GROUP item with the STC expression of the coordinate system.
*/
out.flush();
//out.flush(); // TODO DEBUG flush() => commit
}
/**
......
package adql.translator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.sql.Types;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.postgresql.util.PGobject;
import adql.db.DBType;
import adql.db.DBType.DBDatatype;
import adql.db.STCS.Region;
import adql.parser.ParseException;
public class TestPgSphereTranslator {
@BeforeClass
public static void setUpBeforeClass() throws Exception{}
@AfterClass
public static void tearDownAfterClass() throws Exception{}
@Before
public void setUp() throws Exception{}
@After
public void tearDown() throws Exception{}
@Test
public void testConvertTypeFromDB(){
PgSphereTranslator translator = new PgSphereTranslator();
// POINT
DBType type = translator.convertTypeFromDB(Types.OTHER, "spoint", "spoint", null);
assertNotNull(type);
assertEquals(DBDatatype.POINT, type.type);
assertEquals(DBType.NO_LENGTH, type.length);
// CIRCLE
type = translator.convertTypeFromDB(Types.OTHER, "scircle", "scircle", null);
assertNotNull(type);
assertEquals(DBDatatype.REGION, type.type);
assertEquals(DBType.NO_LENGTH, type.length);
// BOX
type = translator.convertTypeFromDB(Types.OTHER, "sbox", "sbox", null);
assertNotNull(type);
assertEquals(DBDatatype.REGION, type.type);
assertEquals(DBType.NO_LENGTH, type.length);
// POLYGON
type = translator.convertTypeFromDB(Types.OTHER, "spoly", "spoly", null);
assertNotNull(type);
assertEquals(DBDatatype.REGION, type.type);
assertEquals(DBType.NO_LENGTH, type.length);
}
@Test
public void testConvertTypeToDB(){
PgSphereTranslator translator = new PgSphereTranslator();
// NULL
assertEquals("VARCHAR", translator.convertTypeToDB(null));
// POINT
assertEquals("spoint", translator.convertTypeToDB(new DBType(DBDatatype.POINT)));
// REGION (any other region is transformed into a polygon)
assertEquals("spoly", translator.convertTypeToDB(new DBType(DBDatatype.REGION)));
}
@Test
public void testTranslateGeometryFromDB(){
PgSphereTranslator translator = new PgSphereTranslator();
PGobject pgo = new PGobject();
// NULL
try{
assertNull(translator.translateGeometryFromDB(null));
}catch(Throwable t){
t.printStackTrace();
fail(t.getMessage());
}
// SPOINT
try{
pgo.setType("spoint");
pgo.setValue("(0.1 , 0.2)");
Region r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(11.45915, r.coordinates[0][1], 1e-5);
pgo.setValue("(5.72957d , 11.45915d)");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(11.45915, r.coordinates[0][1], 1e-5);
pgo.setValue("( 5d 43m 46.480625s , +11d 27m 32.961249s)");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(11.45915, r.coordinates[0][1], 1e-5);
pgo.setValue("( 0h 22m 55.098708s , +11d 27m 32.961249s)");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(11.45915, r.coordinates[0][1], 1e-5);
}catch(Throwable t){
t.printStackTrace();
fail(t.getMessage());
}
// SCIRCLE
try{
pgo.setType("scircle");
pgo.setValue("<(0.1,-0.2),1>");
Region r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(-11.45915, r.coordinates[0][1], 1e-5);
assertEquals(57.29577, r.radius, 1e-5);
pgo.setValue("<(5.72957d , -11.45915d) , 57.29577d>");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(-11.45915, r.coordinates[0][1], 1e-5);
assertEquals(57.29577, r.radius, 1e-5);
pgo.setValue("<( 5d 43m 46.452s , -11d 27m 32.94s) , 57d 17m 44.772s>");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(-11.45915, r.coordinates[0][1], 1e-5);
assertEquals(57.29577, r.radius, 1e-5);
pgo.setValue("<( 0h 22m 55.0968s , -11d 27m 32.94s) , 57d 17m 44.772s>");
r = translator.translateGeometryFromDB(pgo);
assertEquals(5.72957, r.coordinates[0][0], 1e-5);
assertEquals(-11.45915, r.coordinates[0][1], 1e-5);
assertEquals(57.29577, r.radius, 1e-5);
}catch(Throwable t){
t.printStackTrace();
fail(t.getMessage());
}
// SBOX
try{
pgo.setType("sbox");
pgo.setValue("((0.1,0.2),(0.5,0.5))");
Region r = translator.translateGeometryFromDB(pgo);
assertEquals(17.18873, r.coordinates[0][0], 1e-5);
assertEquals(20.05352, r.coordinates[0][1], 1e-5);
assertEquals(22.91831, r.width, 1e-5);
assertEquals(17.18873, r.height, 1e-5);
pgo.setValue("((5.72957795130823d , 11.4591559026165d), (28.6478897565412d , 28.6478897565412d))");
r = translator.translateGeometryFromDB(pgo);
assertEquals(17.18873, r.coordinates[0][0], 1e-5);
assertEquals(20.05352, r.coordinates[0][1], 1e-5);
assertEquals(22.91831, r.width, 1e-5);
assertEquals(17.18873, r.height, 1e-5);
pgo.setValue("(( 5d 43m 46.480625s , +11d 27m 32.961249s), ( 28d 38m 52.403124s , +28d 38m 52.403124s))");
r = translator.translateGeometryFromDB(pgo);
assertEquals(17.18873, r.coordinates[0][0], 1e-5);
assertEquals(20.05352, r.coordinates[0][1], 1e-5);
assertEquals(22.91831, r.width, 1e-5);
assertEquals(17.18873, r.height, 1e-5);
pgo.setValue("(( 0h 22m 55.098708s , +11d 27m 32.961249s), ( 1h 54m 35.493542s , +28d 38m 52.403124s))");
r = translator.translateGeometryFromDB(pgo);
assertEquals(17.18873, r.coordinates[0][0], 1e-5);
assertEquals(20.05352, r.coordinates[0][1], 1e-5);
assertEquals(22.91831, r.width, 1e-5);
assertEquals(17.18873, r.height, 1e-5);
}catch(Throwable t){
t.printStackTrace();
fail(t.getMessage());
}
// SPOLY
try{
pgo.setType("spoly");
pgo.setValue("{(0.789761486527434 , 0.00436332312998582),(0.789761486527434 , 0.00872664625997165),(0.785398163397448 , 0.00872664625997165),(0.785398163397448 , 0.00436332312998582),(0.781034840267463 , 0.00436332312998582),(0.781034840267463 , 0),(0.785398163397448 , 0)}");
Region r = translator.translateGeometryFromDB(pgo);
assertEquals(45.25, r.coordinates[0][0], 1e-2);
assertEquals(0.25, r.coordinates[0][1], 1e-2);
assertEquals(45.25, r.coordinates[1][0], 1e-2);
assertEquals(0.5, r.coordinates[1][1], 1e-2);
assertEquals(45, r.coordinates[2][0], 1e-2);
assertEquals(0.5, r.coordinates[2][1], 1e-2);
assertEquals(45, r.coordinates[3][0], 1e-2);
assertEquals(0.25, r.coordinates[3][1], 1e-2);
assertEquals(44.75, r.coordinates[4][0], 1e-2);
assertEquals(0.25, r.coordinates[4][1], 1e-2);
assertEquals(44.75, r.coordinates[5][0], 1e-2);
assertEquals(0, r.coordinates[5][1], 1e-2);
assertEquals(45, r.coordinates[6][0], 1e-2);
assertEquals(0, r.coordinates[6][1], 1e-2);
pgo.setValue("{(45.25d , 0.25d), (45.25d , 0.5d), (45d , 0.5d), (45d , 0.25d), (44.75d , 0.25d), (44.75d , 0d), (45d , 0d)}");
r = translator.translateGeometryFromDB(pgo);
assertEquals(45.25, r.coordinates[0][0], 1e-2);
assertEquals(0.25, r.coordinates[0][1], 1e-2);
assertEquals(45.25, r.coordinates[1][0], 1e-2);
assertEquals(0.5, r.coordinates[1][1], 1e-2);
assertEquals(45, r.coordinates[2][0], 1e-2);
assertEquals(0.5, r.coordinates[2][1], 1e-2);
assertEquals(45, r.coordinates[3][0], 1e-2);
assertEquals(0.25, r.coordinates[3][1], 1e-2);
assertEquals(44.75, r.coordinates[4][0], 1e-2);
assertEquals(0.25, r.coordinates[4][1], 1e-2);
assertEquals(44.75, r.coordinates[5][0], 1e-2);
assertEquals(0, r.coordinates[5][1], 1e-2);
assertEquals(45, r.coordinates[6][0], 1e-2);
assertEquals(0, r.coordinates[6][1], 1e-2);
pgo.setValue("{( 45d 15m 0s , + 0d 15m 0s),( 45d 15m 0s , + 0d 30m 0s),( 45d 0m 0s , + 0d 30m 0s),( 45d 0m 0s , + 0d 15m 0s),( 44d 45m 0s , + 0d 15m 0s),( 44d 45m 0s , + 0d 0m 0s),( 45d 0m 0s , + 0d 0m 0s)}");
r = translator.translateGeometryFromDB(pgo);
assertEquals(45.25, r.coordinates[0][0], 1e-2);
assertEquals(0.25, r.coordinates[0][1], 1e-2);
assertEquals(45.25, r.coordinates[1][0], 1e-2);
assertEquals(0.5, r.coordinates[1][1], 1e-2);
assertEquals(45, r.coordinates[2][0], 1e-2);
assertEquals(0.5, r.coordinates[2][1], 1e-2);
assertEquals(45, r.coordinates[3][0], 1e-2);
assertEquals(0.25, r.coordinates[3][1], 1e-2);
assertEquals(44.75, r.coordinates[4][0], 1e-2);
assertEquals(0.25, r.coordinates[4][1], 1e-2);
assertEquals(44.75, r.coordinates[5][0], 1e-2);
assertEquals(0, r.coordinates[5][1], 1e-2);
assertEquals(45, r.coordinates[6][0], 1e-2);
assertEquals(0, r.coordinates[6][1], 1e-2);
pgo.setValue("{( 3h 1m 0s , + 0d 15m 0s),( 3h 1m 0s , + 0d 30m 0s),( 3h 0m 0s , + 0d 30m 0s),( 3h 0m 0s , + 0d 15m 0s),( 2h 59m 0s , + 0d 15m 0s),( 2h 59m 0s , + 0d 0m 0s),( 3h 0m 0s , + 0d 0m 0s)}");
r = translator.translateGeometryFromDB(pgo);
assertEquals(45.25, r.coordinates[0][0], 1e-2);
assertEquals(0.25, r.coordinates[0][1], 1e-2);
assertEquals(45.25, r.coordinates[1][0], 1e-2);
assertEquals(0.5, r.coordinates[1][1], 1e-2);
assertEquals(45, r.coordinates[2][0], 1e-2);
assertEquals(0.5, r.coordinates[2][1], 1e-2);
assertEquals(45, r.coordinates[3][0], 1e-2);
assertEquals(0.25, r.coordinates[3][1], 1e-2);
assertEquals(44.75, r.coordinates[4][0], 1e-2);
assertEquals(0.25, r.coordinates[4][1], 1e-2);
assertEquals(44.75, r.coordinates[5][0], 1e-2);
assertEquals(0, r.coordinates[5][1], 1e-2);
assertEquals(45, r.coordinates[6][0], 1e-2);
assertEquals(0, r.coordinates[6][1], 1e-2);
}catch(Throwable t){
t.printStackTrace();
fail(t.getMessage());
}
// OTHER
try{
translator.translateGeometryFromDB(new Double(12.3));
fail("The translation of a Double as a geometry is not supported!");
}catch(Throwable t){
assertTrue(t instanceof ParseException);
assertEquals("Incompatible type! The column value \"12.3\" was supposed to be a geometrical object.", t.getMessage());
}
try{
pgo.setType("sline");
pgo.setValue("( -90d, -20d, 200d, XYZ ), 30d ");
translator.translateGeometryFromDB(pgo);
fail("The translation of a sline is not supported!");
}catch(Throwable t){
assertTrue(t instanceof ParseException);
assertEquals("Unsupported PgSphere type: \"sline\"! Impossible to convert the column value \"( -90d, -20d, 200d, XYZ ), 30d \" into a Region.", t.getMessage());
}
}
@Test
public void testTranslateGeometryToDB(){
PgSphereTranslator translator = new PgSphereTranslator();
try{
// NULL
assertNull(translator.translateGeometryToDB(null));
// POSITION
Region r = new Region(null, new double[]{45,0});
PGobject pgo = (PGobject)translator.translateGeometryToDB(r);
assertNotNull(pgo);
assertEquals("spoint", pgo.getType());
assertEquals("(45.0d,0.0d)", pgo.getValue());
// CIRCLE
r = new Region(null, new double[]{45,0}, 1.2);
pgo = (PGobject)translator.translateGeometryToDB(r);
assertNotNull(pgo);
assertEquals("spoly", pgo.getType());
assertEquals("{(46.2d,0.0d),(46.176942336483876d,0.2341083864193539d),(46.108655439013546d,0.4592201188381077d),(45.99776353476305d,0.6666842796235226d),(45.848528137423855d,0.8485281374238569d),(45.666684279623524d,0.9977635347630542d),(45.45922011883811d,1.1086554390135441d),(45.23410838641935d,1.1769423364838765d),(45.0d,1.2d),(44.76589161358065d,1.1769423364838765d),(44.54077988116189d,1.1086554390135441d),(44.333315720376476d,0.9977635347630543d),(44.151471862576145d,0.848528137423857d),(44.00223646523695d,0.6666842796235226d),(43.891344560986454d,0.4592201188381073d),(43.823057663516124d,0.23410838641935325d),(43.8d,-9.188564877424678E-16d),(43.823057663516124d,-0.23410838641935505d),(43.891344560986454d,-0.45922011883810904d),(44.00223646523695d,-0.6666842796235241d),(44.151471862576145d,-0.8485281374238584d),(44.333315720376476d,-0.9977635347630555d),(44.540779881161896d,-1.108655439013545d),(44.76589161358065d,-1.176942336483877d),(45.0d,-1.2d),(45.23410838641936d,-1.1769423364838758d),(45.45922011883811d,-1.1086554390135428d),(45.666684279623524d,-0.9977635347630521d),(45.84852813742386d,-0.8485281374238541d),(45.99776353476306d,-0.6666842796235192d),(46.108655439013546d,-0.45922011883810354d),(46.176942336483876d,-0.23410838641934922d)}", pgo.getValue());
// BOX
r = new Region(null, new double[]{45,0}, 1.2, 5);
pgo = (PGobject)translator.translateGeometryToDB(r);
assertNotNull(pgo);
assertEquals("spoly", pgo.getType());
assertEquals("{(44.4d,-2.5d),(44.4d,2.5d),(45.6d,2.5d),(45.6d,-2.5d)}", pgo.getValue());
// POLYGON
r = new Region(null, new double[][]{new double[]{45.25,0.25},new double[]{45.25,0.5},new double[]{45,0.5},new double[]{45,0.25},new double[]{44.75,0.25},new double[]{44.75,0},new double[]{45,0}});
pgo = (PGobject)translator.translateGeometryToDB(r);
assertNotNull(pgo);
assertEquals("spoly", pgo.getType());
assertEquals("{(45.25d,0.25d),(45.25d,0.5d),(45.0d,0.5d),(45.0d,0.25d),(44.75d,0.25d),(44.75d,0.0d),(45.0d,0.0d)}", pgo.getValue());
// OTHER
try{
r = new Region(new Region(null, new double[]{45,0}));
translator.translateGeometryToDB(r);
fail("The translation of a STC Not region is not supported!");
}catch(Throwable ex){
assertTrue(ex instanceof ParseException);
assertEquals("Unsupported geometrical region: \"" + r.type + "\"!", ex.getMessage());
}
}catch(ParseException t){
t.printStackTrace();
fail(t.getMessage());
}
}
}
......@@ -176,11 +176,11 @@ public class JDBCConnectionTest {
@Test
public void testGetDBMSDatatype(){
assertEquals("VARCHAR", pgJDBCConnection.getDBMSDatatype(null));
assertEquals("TEXT", sqliteJDBCConnection.getDBMSDatatype(null));
assertEquals("VARCHAR", pgJDBCConnection.defaultTypeConversion(null));
assertEquals("TEXT", sqliteJDBCConnection.defaultTypeConversion(null));
assertEquals("bytea", pgJDBCConnection.getDBMSDatatype(new DBType(DBDatatype.VARBINARY)));
assertEquals("BLOB", sqliteJDBCConnection.getDBMSDatatype(new DBType(DBDatatype.VARBINARY)));
assertEquals("bytea", pgJDBCConnection.defaultTypeConversion(new DBType(DBDatatype.VARBINARY)));
assertEquals("BLOB", sqliteJDBCConnection.defaultTypeConversion(new DBType(DBDatatype.VARBINARY)));
}
@Test
......@@ -379,6 +379,19 @@ public class JDBCConnectionTest {
for(TAPColumn c : cols)
tableDef.addColumn(c);
// Test with no schema set:
try{
conn.addUploadedTable(tableDef, it);
fail("The table is not inside a TAPSchema, so this test should have failed!");
}catch(Exception ex){
assertTrue(ex instanceof DBException);
assertEquals("Missing upload schema! An uploaded table must be inside a schema whose the ADQL name is strictly equals to \"" + STDSchema.UPLOADSCHEMA.label + "\" (but the DB name may be different).", ex.getMessage());
}
// Specify the UPLOAD schema for the table to upload:
TAPSchema schema = new TAPSchema(STDSchema.UPLOADSCHEMA.label);
schema.addTable(tableDef);
// Prepare the test: no TAP_UPLOAD schema and no table TAP_UPLOAD.UploadExample:
dropSchema(STDSchema.UPLOADSCHEMA.label, conn);
// Test:
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment