Commit c04326b7 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added support for PGSPhere data types

parent 7da179b1
Pipeline #108 passed with stage
in 17 seconds
......@@ -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
......
......@@ -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
......@@ -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;
}
}
}
......@@ -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;
......@@ -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[]
......@@ -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");
......@@ -292,11 +308,12 @@ public class PostgresDBBroker extends DBBrokerTemplate {
cm.put(Column.DATATYPE_KEY, datatype);
cm.put(Column.SIZE_KEY, size);
String arraySize;
if (isArray) {
arraySize = formatArraySize(arraydimension);
} else {
arraySize = getArraysize(adqlType, size);
if (arraySize == null) {
if (isArray) {
arraySize = formatArraySize(arraydimension);
} else {
arraySize = getArraysize(adqlType, size);
}
}
cm.put(Column.ARRAYSIZE_KEY, arraySize);
......
......@@ -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;
......@@ -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;
}
......
......@@ -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));
}
/**
......@@ -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));
}
/**
......
......@@ -39,6 +39,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<column name="xtype">
<type>VARCHAR</type>
<updatable>true</updatable>
<key>xtype</key>
<standard>true</standard>
</column>
<column name="column_index">
......
......@@ -133,6 +133,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>
<adql>CLOB</adql>
<votable>char</votable>
<xtype>adql:clob</xtype>
<mysql inverse="true">
<type>LONGTEXT</type>
<type>MEDIUMTEXT</type>
......@@ -147,6 +148,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>
<adql>BLOB</adql>
<votable>unsignedByte</votable>
<xtype>adql:blob</xtype>
<mysql inverse="true">
<type>BLOB</type>
</mysql>
......@@ -159,6 +161,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>
<adql>TIMESTAMP</adql>
<votable>char</votable>
<xtype>timestamp</xtype>
<mysql inverse="true">
<type>DATETIME</type>
<type>DATE</type>
......@@ -203,8 +206,9 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>
<adql>REGION</adql>
<votable>char</votable>
<xtype>adql:region</xtype>
<mysql>
<type>VARCHAR</type>
<type>TEXT</type>
</mysql>
<pgsql>
<type>character varying</type>
......@@ -214,12 +218,45 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>
<adql>POINT</adql>
<votable>char</votable>
<votable>double</votable>
<!--<votable>float</votable>-->
<xtype>point</xtype>
<arraysize>2</arraysize>
<mysql>
<type>VARCHAR</type>
</mysql>
<pgsql>
<type>character varying</type>
<pgsql inverse="true">
<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>
<java>java.lang.String</java>
</type>
......
......@@ -145,11 +145,14 @@ public class TapSchemaEditingBean implements Serializable {
return sb.toString();
}
public boolean isShowWarningOnDataType() {
public boolean isShowWarning(String key) {
if (selectedColumn == null) {
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());
}
......
......@@ -329,7 +329,7 @@
<f:ajax event="keyup" execute="@form" render=":main:datatype-warning" listener="#{tapSchemaEditing.textInputChanged(tapSchemaEditing.selectedColumn, 'datatype')}" onevent="TSM.textInputChanged" />
</h:inputText>
<h:panelGroup id="datatype-warning">
<h:panelGroup class="text-warning" rendered="#{tapSchemaEditing.showWarningOnDataType}">
<h:panelGroup class="text-warning" rendered="#{tapSchemaEditing.isShowWarning('datatype')}">
<small>
<span class="glyphicon glyphicon-warning-sign"></span>
Suggested value: #{tapSchemaEditing.selectedColumn.getProperty('datatype').defaultValue}
......@@ -425,8 +425,16 @@
class="form-control #{tapSchemaEditing.selectedColumn.isChanged('xtype') ? 'changed' : ''}"
value="#{tapSchemaEditing.selectedColumn.getProperty('xtype').value}">
<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: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>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment