Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +1 −0 Original line number 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 COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String DBNAME = "dbname"; public final static String XTYPE_KEY = "xtype"; /** * 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 Diff line number Diff line Loading @@ -43,7 +43,9 @@ public enum ADQL { BINARY, VARBINARY, REGION, POINT; POINT, CIRCLE, POLYGON; /** * 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) { 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 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.model.ColumnModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TypeMapping; import it.inaf.ia2.tsm.model.TypesMapping; import java.sql.Connection; import java.sql.PreparedStatement; Loading Loading @@ -268,7 +269,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { int arraydimension = 0; String dbType = resultSet.getString("data_type").toUpperCase(); boolean isArray = false; boolean isArray = false, userDefinedType = false; if ("ARRAY".equals(dbType)) { isArray = true; // 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 // numbers inside brakets, so this case will be approximated to *x* 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); 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))) { 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.SIZE_KEY, size); String arraySize; if (arraySize == null) { if (isArray) { arraySize = formatArraySize(arraydimension); } else { arraySize = getArraysize(adqlType, size); } } cm.put(Column.ARRAYSIZE_KEY, arraySize); Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java +29 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ public class TypeMapping { private String adqlType; private String voTableType; private String xtype; private String arraysize; private DBTypeMapping mysqlMapping; private DBTypeMapping pgsqlMapping; private String javaTypeString; Loading @@ -54,6 +56,33 @@ public class TypeMapping { 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) { this.voTableType = voTableType; } Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java +2 −10 Original line number Diff line number Diff line Loading @@ -245,11 +245,7 @@ public class TypesMapping { * @param mysqlDBType the datatype, as read from MySQL information_schema. */ public static ADQL getADQLFromMySQLType(String mysqlDBType) { try { return ADQL.valueOf(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } return ADQL.parse(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } /** Loading @@ -259,11 +255,7 @@ public class TypesMapping { * information_schema. */ public static ADQL getADQLFromPostgresType(String postgresDBType) { try { return ADQL.valueOf(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } return ADQL.parse(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } /** Loading Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +1 −0 Original line number 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 COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String DBNAME = "dbname"; public final static String XTYPE_KEY = "xtype"; /** * 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 Diff line number Diff line Loading @@ -43,7 +43,9 @@ public enum ADQL { BINARY, VARBINARY, REGION, POINT; POINT, CIRCLE, POLYGON; /** * 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) { 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 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.model.ColumnModel; import it.inaf.ia2.tsm.model.TableModel; import it.inaf.ia2.tsm.model.TypeMapping; import it.inaf.ia2.tsm.model.TypesMapping; import java.sql.Connection; import java.sql.PreparedStatement; Loading Loading @@ -268,7 +269,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { int arraydimension = 0; String dbType = resultSet.getString("data_type").toUpperCase(); boolean isArray = false; boolean isArray = false, userDefinedType = false; if ("ARRAY".equals(dbType)) { isArray = true; // 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 // numbers inside brakets, so this case will be approximated to *x* 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); 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))) { 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.SIZE_KEY, size); String arraySize; if (arraySize == null) { if (isArray) { arraySize = formatArraySize(arraydimension); } else { arraySize = getArraysize(adqlType, size); } } cm.put(Column.ARRAYSIZE_KEY, arraySize); Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java +29 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ public class TypeMapping { private String adqlType; private String voTableType; private String xtype; private String arraysize; private DBTypeMapping mysqlMapping; private DBTypeMapping pgsqlMapping; private String javaTypeString; Loading @@ -54,6 +56,33 @@ public class TypeMapping { 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) { this.voTableType = voTableType; } Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java +2 −10 Original line number Diff line number Diff line Loading @@ -245,11 +245,7 @@ public class TypesMapping { * @param mysqlDBType the datatype, as read from MySQL information_schema. */ public static ADQL getADQLFromMySQLType(String mysqlDBType) { try { return ADQL.valueOf(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } return ADQL.parse(getDataTypeFromMySQLType(mysqlDBType, DataTypeMode.ADQL)); } /** Loading @@ -259,11 +255,7 @@ public class TypesMapping { * information_schema. */ public static ADQL getADQLFromPostgresType(String postgresDBType) { try { return ADQL.valueOf(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } catch (IllegalArgumentException e) { return null; } return ADQL.parse(getDataTypeFromPostgresType(postgresDBType, DataTypeMode.ADQL)); } /** Loading