Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class Column extends ChildEntity<Table> { public final static String UNIT_KEY = "unit"; public final static String UNIT_KEY = "unit"; public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String DBNAME = "dbname"; public final static String DBNAME = "dbname"; public final static String XTYPE_KEY = "xtype"; /** /** * Original datatype (computed from information_schema data), used for * Original datatype (computed from information_schema data), used for Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java +11 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,9 @@ public enum ADQL { BINARY, BINARY, VARBINARY, VARBINARY, REGION, REGION, POINT; POINT, CIRCLE, POLYGON; /** /** * Returns a string representing a datatype which can't be interpreted as an * Returns a string representing a datatype which can't be interpreted as an Loading @@ -64,4 +66,12 @@ public enum ADQL { public static boolean isVariable(ADQL adql) { public static boolean isVariable(ADQL adql) { return adql.equals(VARCHAR) || adql.equals(VARBINARY) || adql.equals(CLOB) || adql.equals(BLOB); return adql.equals(VARCHAR) || adql.equals(VARBINARY) || adql.equals(CLOB) || adql.equals(BLOB); } } public static ADQL parse(String adqlStr) { try { return ADQL.valueOf(adqlStr); } catch (IllegalArgumentException e) { return null; } } } } TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java +23 −6 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import it.inaf.ia2.tsm.datalayer.DBBrokerTemplate; import it.inaf.ia2.tsm.datalayer.DataTypeMode; import it.inaf.ia2.tsm.datalayer.DataTypeMode; import it.inaf.ia2.tsm.model.ColumnModel; import it.inaf.ia2.tsm.model.ColumnModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TypeMapping; import it.inaf.ia2.tsm.model.TypesMapping; import it.inaf.ia2.tsm.model.TypesMapping; import java.sql.Connection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.PreparedStatement; Loading Loading @@ -268,7 +269,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { int arraydimension = 0; int arraydimension = 0; String dbType = resultSet.getString("data_type").toUpperCase(); String dbType = resultSet.getString("data_type").toUpperCase(); boolean isArray = false; boolean isArray = false, userDefinedType = false; if ("ARRAY".equals(dbType)) { if ("ARRAY".equals(dbType)) { isArray = true; isArray = true; // example: integer array has data_type ARRAY and format_type integer[] // example: integer array has data_type ARRAY and format_type integer[] Loading @@ -277,10 +278,25 @@ public class PostgresDBBroker extends DBBrokerTemplate { // unfortunately it seems there is no easy way to get also the // unfortunately it seems there is no easy way to get also the // numbers inside brakets, so this case will be approximated to *x* // numbers inside brakets, so this case will be approximated to *x* arraydimension = resultSet.getInt("arraydim"); arraydimension = resultSet.getInt("arraydim"); } else if ("USER-DEFINED".equals(dbType)) { dbType = resultSet.getString("format_type"); userDefinedType = true; } } String arraySize = null; ADQL adqlType = TypesMapping.getADQLFromPostgresType(dbType); ADQL adqlType = TypesMapping.getADQLFromPostgresType(dbType); String datatype = TypesMapping.getDataTypeFromPostgresType(dbType, getDataTypeMode()); String datatype = TypesMapping.getDataTypeFromPostgresType(dbType, getDataTypeMode()); if (userDefinedType && adqlType != null) { // ADQL type must be used for the following search, because it is the most specific (a POINT is a double using VOTable syntax). TypeMapping mapping = TypesMapping.getTypeMapping(adqlType.toString(), DataTypeMode.ADQL); if (mapping.getArraysize() != null) { arraySize = mapping.getArraysize(); } if (mapping.getXtype() != null) { cm.put(Column.XTYPE_KEY, mapping.getXtype()); } } if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { size = resultSet.getInt("character_maximum_length"); size = resultSet.getInt("character_maximum_length"); Loading @@ -292,12 +308,13 @@ public class PostgresDBBroker extends DBBrokerTemplate { cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.SIZE_KEY, size); cm.put(Column.SIZE_KEY, size); String arraySize; if (arraySize == null) { if (isArray) { if (isArray) { arraySize = formatArraySize(arraydimension); arraySize = formatArraySize(arraydimension); } else { } else { arraySize = getArraysize(adqlType, size); arraySize = getArraysize(adqlType, size); } } } cm.put(Column.ARRAYSIZE_KEY, arraySize); cm.put(Column.ARRAYSIZE_KEY, arraySize); Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java +29 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,8 @@ public class TypeMapping { private String adqlType; private String adqlType; private String voTableType; private String voTableType; private String xtype; private String arraysize; private DBTypeMapping mysqlMapping; private DBTypeMapping mysqlMapping; private DBTypeMapping pgsqlMapping; private DBTypeMapping pgsqlMapping; private String javaTypeString; private String javaTypeString; Loading @@ -54,6 +56,33 @@ public class TypeMapping { return voTableType; return voTableType; } } /** * Returns the default xtype for this datatype. This value can be null. */ @XmlElement(name = "xtype") public String getXtype() { return xtype; } public void setXtype(String xtype) { this.xtype = xtype; } /** * Returns the arraysize defined for this datatype. This is necessary for * some special datatypes (e.g. {@code POINT}, {@code CIRCLE}) having an * arraysize defined by their semantic and not by the database metadata. * This value is null for all the other data types. */ @XmlElement(name = "arraysize") public String getArraysize() { return arraysize; } public void setArraysize(String arraysize) { this.arraysize = arraysize; } public void setVoTableType(String voTableType) { public void setVoTableType(String voTableType) { this.voTableType = voTableType; this.voTableType = voTableType; } } Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java +2 −10 Original line number Original line Diff line number Diff line Loading @@ -245,11 +245,7 @@ public class TypesMapping { * @param mysqlDBType the datatype, as read from MySQL information_schema. * @param mysqlDBType the datatype, as read from MySQL information_schema. */ */ public static ADQL getADQLFromMySQLType(String mysqlDBType) { public static ADQL getADQLFromMySQLType(String mysqlDBType) { try { return ADQL.parse(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); return ADQL.valueOf(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } } } /** /** Loading @@ -259,11 +255,7 @@ public class TypesMapping { * information_schema. * information_schema. */ */ public static ADQL getADQLFromPostgresType(String postgresDBType) { public static ADQL getADQLFromPostgresType(String postgresDBType) { try { return ADQL.parse(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); return ADQL.valueOf(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } } } /** /** Loading Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class Column extends ChildEntity<Table> { public final static String UNIT_KEY = "unit"; public final static String UNIT_KEY = "unit"; public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String DBNAME = "dbname"; public final static String DBNAME = "dbname"; public final static String XTYPE_KEY = "xtype"; /** /** * Original datatype (computed from information_schema data), used for * Original datatype (computed from information_schema data), used for Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java +11 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,9 @@ public enum ADQL { BINARY, BINARY, VARBINARY, VARBINARY, REGION, REGION, POINT; POINT, CIRCLE, POLYGON; /** /** * Returns a string representing a datatype which can't be interpreted as an * Returns a string representing a datatype which can't be interpreted as an Loading @@ -64,4 +66,12 @@ public enum ADQL { public static boolean isVariable(ADQL adql) { public static boolean isVariable(ADQL adql) { return adql.equals(VARCHAR) || adql.equals(VARBINARY) || adql.equals(CLOB) || adql.equals(BLOB); return adql.equals(VARCHAR) || adql.equals(VARBINARY) || adql.equals(CLOB) || adql.equals(BLOB); } } public static ADQL parse(String adqlStr) { try { return ADQL.valueOf(adqlStr); } catch (IllegalArgumentException e) { return null; } } } }
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java +23 −6 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import it.inaf.ia2.tsm.datalayer.DBBrokerTemplate; import it.inaf.ia2.tsm.datalayer.DataTypeMode; import it.inaf.ia2.tsm.datalayer.DataTypeMode; import it.inaf.ia2.tsm.model.ColumnModel; import it.inaf.ia2.tsm.model.ColumnModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TypeMapping; import it.inaf.ia2.tsm.model.TypesMapping; import it.inaf.ia2.tsm.model.TypesMapping; import java.sql.Connection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.PreparedStatement; Loading Loading @@ -268,7 +269,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { int arraydimension = 0; int arraydimension = 0; String dbType = resultSet.getString("data_type").toUpperCase(); String dbType = resultSet.getString("data_type").toUpperCase(); boolean isArray = false; boolean isArray = false, userDefinedType = false; if ("ARRAY".equals(dbType)) { if ("ARRAY".equals(dbType)) { isArray = true; isArray = true; // example: integer array has data_type ARRAY and format_type integer[] // example: integer array has data_type ARRAY and format_type integer[] Loading @@ -277,10 +278,25 @@ public class PostgresDBBroker extends DBBrokerTemplate { // unfortunately it seems there is no easy way to get also the // unfortunately it seems there is no easy way to get also the // numbers inside brakets, so this case will be approximated to *x* // numbers inside brakets, so this case will be approximated to *x* arraydimension = resultSet.getInt("arraydim"); arraydimension = resultSet.getInt("arraydim"); } else if ("USER-DEFINED".equals(dbType)) { dbType = resultSet.getString("format_type"); userDefinedType = true; } } String arraySize = null; ADQL adqlType = TypesMapping.getADQLFromPostgresType(dbType); ADQL adqlType = TypesMapping.getADQLFromPostgresType(dbType); String datatype = TypesMapping.getDataTypeFromPostgresType(dbType, getDataTypeMode()); String datatype = TypesMapping.getDataTypeFromPostgresType(dbType, getDataTypeMode()); if (userDefinedType && adqlType != null) { // ADQL type must be used for the following search, because it is the most specific (a POINT is a double using VOTable syntax). TypeMapping mapping = TypesMapping.getTypeMapping(adqlType.toString(), DataTypeMode.ADQL); if (mapping.getArraysize() != null) { arraySize = mapping.getArraysize(); } if (mapping.getXtype() != null) { cm.put(Column.XTYPE_KEY, mapping.getXtype()); } } if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { size = resultSet.getInt("character_maximum_length"); size = resultSet.getInt("character_maximum_length"); Loading @@ -292,12 +308,13 @@ public class PostgresDBBroker extends DBBrokerTemplate { cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.SIZE_KEY, size); cm.put(Column.SIZE_KEY, size); String arraySize; if (arraySize == null) { if (isArray) { if (isArray) { arraySize = formatArraySize(arraydimension); arraySize = formatArraySize(arraydimension); } else { } else { arraySize = getArraysize(adqlType, size); arraySize = getArraysize(adqlType, size); } } } cm.put(Column.ARRAYSIZE_KEY, arraySize); cm.put(Column.ARRAYSIZE_KEY, arraySize); Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java +29 −0 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,8 @@ public class TypeMapping { private String adqlType; private String adqlType; private String voTableType; private String voTableType; private String xtype; private String arraysize; private DBTypeMapping mysqlMapping; private DBTypeMapping mysqlMapping; private DBTypeMapping pgsqlMapping; private DBTypeMapping pgsqlMapping; private String javaTypeString; private String javaTypeString; Loading @@ -54,6 +56,33 @@ public class TypeMapping { return voTableType; return voTableType; } } /** * Returns the default xtype for this datatype. This value can be null. */ @XmlElement(name = "xtype") public String getXtype() { return xtype; } public void setXtype(String xtype) { this.xtype = xtype; } /** * Returns the arraysize defined for this datatype. This is necessary for * some special datatypes (e.g. {@code POINT}, {@code CIRCLE}) having an * arraysize defined by their semantic and not by the database metadata. * This value is null for all the other data types. */ @XmlElement(name = "arraysize") public String getArraysize() { return arraysize; } public void setArraysize(String arraysize) { this.arraysize = arraysize; } public void setVoTableType(String voTableType) { public void setVoTableType(String voTableType) { this.voTableType = voTableType; this.voTableType = voTableType; } } Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java +2 −10 Original line number Original line Diff line number Diff line Loading @@ -245,11 +245,7 @@ public class TypesMapping { * @param mysqlDBType the datatype, as read from MySQL information_schema. * @param mysqlDBType the datatype, as read from MySQL information_schema. */ */ public static ADQL getADQLFromMySQLType(String mysqlDBType) { public static ADQL getADQLFromMySQLType(String mysqlDBType) { try { return ADQL.parse(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); return ADQL.valueOf(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } } } /** /** Loading @@ -259,11 +255,7 @@ public class TypesMapping { * information_schema. * information_schema. */ */ public static ADQL getADQLFromPostgresType(String postgresDBType) { public static ADQL getADQLFromPostgresType(String postgresDBType) { try { return ADQL.parse(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); return ADQL.valueOf(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } } } /** /** Loading