Skip to content
Snippets Groups Projects
Commit c04326b7 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added support for PGSPhere data types

parent 7da179b1
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -48,6 +48,7 @@ public class Column extends ChildEntity<Table> { ...@@ -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
......
...@@ -43,7 +43,9 @@ public enum ADQL { ...@@ -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
...@@ -64,4 +66,12 @@ public enum ADQL { ...@@ -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;
}
}
} }
...@@ -30,6 +30,7 @@ import it.inaf.ia2.tsm.datalayer.DBBrokerTemplate; ...@@ -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;
...@@ -268,7 +269,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { ...@@ -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[]
...@@ -277,10 +278,25 @@ public class PostgresDBBroker extends DBBrokerTemplate { ...@@ -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");
...@@ -292,12 +308,13 @@ public class PostgresDBBroker extends DBBrokerTemplate { ...@@ -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);
......
...@@ -36,6 +36,8 @@ public class TypeMapping { ...@@ -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;
...@@ -54,6 +56,33 @@ public class TypeMapping { ...@@ -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;
} }
......
...@@ -245,11 +245,7 @@ public class TypesMapping { ...@@ -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;
}
} }
/** /**
...@@ -259,11 +255,7 @@ public class TypesMapping { ...@@ -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;
}
} }
/** /**
......
...@@ -39,6 +39,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -39,6 +39,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<column name="xtype"> <column name="xtype">
<type>VARCHAR</type> <type>VARCHAR</type>
<updatable>true</updatable> <updatable>true</updatable>
<key>xtype</key>
<standard>true</standard> <standard>true</standard>
</column> </column>
<column name="column_index"> <column name="column_index">
......
...@@ -133,6 +133,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -133,6 +133,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type> <type>
<adql>CLOB</adql> <adql>CLOB</adql>
<votable>char</votable> <votable>char</votable>
<xtype>adql:clob</xtype>
<mysql inverse="true"> <mysql inverse="true">
<type>LONGTEXT</type> <type>LONGTEXT</type>
<type>MEDIUMTEXT</type> <type>MEDIUMTEXT</type>
...@@ -147,6 +148,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -147,6 +148,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type> <type>
<adql>BLOB</adql> <adql>BLOB</adql>
<votable>unsignedByte</votable> <votable>unsignedByte</votable>
<xtype>adql:blob</xtype>
<mysql inverse="true"> <mysql inverse="true">
<type>BLOB</type> <type>BLOB</type>
</mysql> </mysql>
...@@ -159,6 +161,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -159,6 +161,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type> <type>
<adql>TIMESTAMP</adql> <adql>TIMESTAMP</adql>
<votable>char</votable> <votable>char</votable>
<xtype>timestamp</xtype>
<mysql inverse="true"> <mysql inverse="true">
<type>DATETIME</type> <type>DATETIME</type>
<type>DATE</type> <type>DATE</type>
...@@ -203,8 +206,9 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -203,8 +206,9 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type> <type>
<adql>REGION</adql> <adql>REGION</adql>
<votable>char</votable> <votable>char</votable>
<xtype>adql:region</xtype>
<mysql> <mysql>
<type>VARCHAR</type> <type>TEXT</type>
</mysql> </mysql>
<pgsql> <pgsql>
<type>character varying</type> <type>character varying</type>
...@@ -214,12 +218,45 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -214,12 +218,45 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type> <type>
<adql>POINT</adql> <adql>POINT</adql>
<votable>char</votable> <votable>double</votable>
<!--<votable>float</votable>-->
<xtype>point</xtype>
<arraysize>2</arraysize>
<mysql> <mysql>
<type>VARCHAR</type> <type>VARCHAR</type>
</mysql> </mysql>
<pgsql> <pgsql inverse="true">
<type>character varying</type> <type>spoint</type>
</pgsql>
<java>java.lang.String</java>
</type>
<type>
<adql>CIRCLE</adql>
<votable>double</votable>
<!--<votable>float</votable>-->
<xtype>circle</xtype>
<arraysize>3</arraysize>
<mysql>
<type>VARCHAR</type>
</mysql>
<pgsql inverse="true">
<type>scircle</type>
</pgsql>
<java>java.lang.String</java>
</type>
<type>
<adql>POLYGON</adql>
<votable>double</votable>
<!--<votable>float</votable>-->
<xtype>polygon</xtype>
<arraysize>*</arraysize>
<mysql>
<type>VARCHAR</type>
</mysql>
<pgsql inverse="true">
<type>spoly</type>
</pgsql> </pgsql>
<java>java.lang.String</java> <java>java.lang.String</java>
</type> </type>
......
...@@ -145,11 +145,14 @@ public class TapSchemaEditingBean implements Serializable { ...@@ -145,11 +145,14 @@ public class TapSchemaEditingBean implements Serializable {
return sb.toString(); return sb.toString();
} }
public boolean isShowWarningOnDataType() { public boolean isShowWarning(String key) {
if (selectedColumn == null) { if (selectedColumn == null) {
return false; return false;
} }
EntityProperty dataTypeProp = selectedColumn.getProperty("datatype"); EntityProperty dataTypeProp = selectedColumn.getProperty(key);
if (dataTypeProp.getDefaultValue() == null) {
return false;
}
return !Objects.equals(dataTypeProp.getDefaultValue(), dataTypeProp.getValue()); return !Objects.equals(dataTypeProp.getDefaultValue(), dataTypeProp.getValue());
} }
......
...@@ -329,7 +329,7 @@ ...@@ -329,7 +329,7 @@
<f:ajax event="keyup" execute="@form" render=":main:datatype-warning" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'datatype')}" onevent="TSM.textInputChanged" /> <f:ajax event="keyup" execute="@form" render=":main:datatype-warning" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'datatype')}" onevent="TSM.textInputChanged" />
</h:inputText> </h:inputText>
<h:panelGroup id="datatype-warning"> <h:panelGroup id="datatype-warning">
<h:panelGroup class="text-warning" rendered="#{tapSchemaEditing.showWarningOnDataType}"> <h:panelGroup class="text-warning" rendered="#{tapSchemaEditing.isShowWarning('datatype')}">
<small> <small>
<span class="glyphicon glyphicon-warning-sign"></span> <span class="glyphicon glyphicon-warning-sign"></span>
Suggested value: #{tapSchemaEditing.selectedColumn.getProperty('datatype').defaultValue} Suggested value: #{tapSchemaEditing.selectedColumn.getProperty('datatype').defaultValue}
...@@ -425,8 +425,16 @@ ...@@ -425,8 +425,16 @@
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('xtype') ? 'changed' : ''}" class="form-control #{tapSchemaEditing.selectedColumn.isChanged('xtype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.getProperty('xtype').value}"> value="#{tapSchemaEditing.selectedColumn.getProperty('xtype').value}">
<f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" /> <f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" />
<f:ajax event="keyup" execute="@form" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'xtype')}" onevent="TSM.textInputChanged" /> <f:ajax event="keyup" execute="@form" render=":main:xtype-warning" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'xtype')}" onevent="TSM.textInputChanged" />
</h:inputText> </h:inputText>
<h:panelGroup id="xtype-warning">
<h:panelGroup class="text-warning" rendered="#{tapSchemaEditing.isShowWarning('xtype')}">
<small>
<span class="glyphicon glyphicon-warning-sign"></span>
Suggested value: #{tapSchemaEditing.selectedColumn.getProperty('xtype').defaultValue}
</small>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup> </h:panelGroup>
</h:panelGroup> </h:panelGroup>
</h:panelGroup> </h:panelGroup>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment