diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java index ef7113bb25e61fc973405dc8cf05714af926430c..96cf36cda44a777db5ec33f4fa520628cdeed57f 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java @@ -22,8 +22,6 @@ */ package it.inaf.ia2.tsm; -import it.inaf.ia2.tsm.model.TableModel; -import it.inaf.ia2.tsm.model.TypesMapping; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,22 +63,6 @@ public class Column extends ChildEntity<Table> { setStatus(Status.LOADED); } - private void overrideDataTypeFromModels() { - - Schema parentSchema = parentTable.getParent(); - String type = null; - - if (tapSchema.getName().equals(parentSchema.getName())) { - TableModel tableModel = tapSchema.getTapSchemaModel().getTable(parentTable.getName()); - type = tableModel.get(getName()).getType(); - } - - if (type != null) { - String compatibleType = TypesMapping.getCompatibleADQLType(type, tapSchema.getVersion()); - getProperty(DATATYPE_KEY).init(compatibleType); - } - } - public Key getForeignKey() { if (!foreignKeySearched) { // lazy loading (but the foreignKey value can be null, so we use this boolean) diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java index 0a5ff261eda1c781ca971ec3577b315dc182a370..eba9ae5dd6edbb4e126b7af1a535ab48c4d9f6db 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java @@ -37,6 +37,7 @@ public class EntityProperty<T> implements Serializable { private ColumnModel propertyModel; private Class<T> type; + private T defaultValue; private T originalValue; private T value; private boolean changed; @@ -47,6 +48,7 @@ public class EntityProperty<T> implements Serializable { public EntityProperty(ColumnModel propertyModel, T defaultValue) { this.propertyModel = propertyModel; this.type = propertyModel.getJavaType(); + this.defaultValue = defaultValue; this.init(defaultValue); } @@ -68,6 +70,10 @@ public class EntityProperty<T> implements Serializable { return originalValue; } + public T getDefaultValue() { + return defaultValue; + } + public <X> X getOriginalValue(Class<X> type) { return (X) originalValue; } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java index 234b5a82c023d4f725d6fa61af445740f78f618e..e16e9de962bf9b2254ee68e3b2533f156e1a7a0c 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java @@ -25,6 +25,7 @@ package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.datalayer.DBBroker; import it.inaf.ia2.tsm.datalayer.DBBrokerFactory; import it.inaf.ia2.tsm.datalayer.DBWrapper; +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.SchemaModel; @@ -68,24 +69,22 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { private boolean loading; private DBWrapper dbWrapper; private boolean exists; - private String tapSchemaVersion; - private String tapSchemaName; - private boolean obscore; - private String obscoreVersion; + private TapSchemaSettings settings; + private DataTypeMode dataTypeMode; private transient DBBroker sourceDBBroker; private transient DBBroker tapSchemaDBBroker; public final DBBroker getSourceDBBroker() { if (sourceDBBroker == null) { - sourceDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getSourceDataSourceWrapper(), tapSchemaVersion); + sourceDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getSourceDataSourceWrapper(), dataTypeMode); } return sourceDBBroker; } public final DBBroker getTapSchemaDBBroker() { if (tapSchemaDBBroker == null) { - tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), tapSchemaVersion); + tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), dataTypeMode); } return tapSchemaDBBroker; } @@ -103,16 +102,15 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { loading = true; this.dbWrapper = dbWrapper; this.exists = exists; - this.tapSchemaVersion = settings.getTapSchemaVersion(); - this.tapSchemaName = settings.getTapSchemaName(); - this.obscore = settings.isHasObscore(); - this.obscoreVersion = settings.getObscoreVersion(); + this.settings = settings; + + dataTypeMode = getTapSchemaModel().getDataTypeMode(); // Initializing schemas map for (String schemaName : getSourceDBBroker().getAllSchemaNames()) { schemas.put(schemaName, null); } - schemas.put(tapSchemaName, null); // the TAP_SCHEMA contains itself + schemas.put(settings.getTapSchemaName(), null); // the TAP_SCHEMA contains itself if (exists) { loadSavedTapSchema(); @@ -282,7 +280,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { } public DBBroker getDBBroker(String schemaName) { - if (schemaName.equals(tapSchemaName)) { + if (schemaName.equals(getName())) { return getTapSchemaDBBroker(); } else { return getSourceDBBroker(); @@ -293,14 +291,18 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { * The name of the TAP_SCHEMA schema. */ public final String getName() { - return tapSchemaName; + return settings.getTapSchemaName(); } /** * The version selected for this TAP_SCHEMA. */ public String getVersion() { - return tapSchemaVersion; + return settings.getTapSchemaVersion(); + } + + public DataTypeMode getDataTypeMode() { + return dataTypeMode; } private void loadSchemaKeysMetadata(String schemaName) throws SQLException { @@ -428,8 +430,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { } public SchemaModel getIvoaSchemaModel() { - if (obscore) { - return SchemaModels.getIvoaSchemaModel(obscoreVersion); + if (settings.isHasObscore()) { + return SchemaModels.getIvoaSchemaModel(settings.getObscoreVersion()); } return null; } @@ -453,13 +455,13 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { if (!exists) { SchemaModel tapSchemaModel = getTapSchemaModel(); - broker.createTapSchemaStructure(tapSchemaName, tapSchemaModel); + broker.createTapSchemaStructure(getName(), tapSchemaModel); // Adding TAP_SCHEMA into TAP_SCHEMA - addEntireSchema(tapSchemaName); - fillColumnProperties(tapSchemaModel, tapSchemaName); + addEntireSchema(getName()); + fillColumnProperties(tapSchemaModel, getName()); - if (obscore) { + if (settings.isHasObscore()) { SchemaModel ivoaSchemaModel = getIvoaSchemaModel(); // ivoa schema has to be created into source database @@ -561,7 +563,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { StringBuilder sb = new StringBuilder("\n"); - sb.append(String.format(">> TAP_SCHEMA %s <<\n", tapSchemaName)); + sb.append(String.format(">> TAP_SCHEMA %s <<\n", getName())); for (Schema schema : getChildren()) { sb.append("--"); @@ -655,8 +657,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { return consistencyChecks; } - public SchemaModel getTapSchemaModel() { - return SchemaModels.getTapSchemaModel(tapSchemaVersion); + public final SchemaModel getTapSchemaModel() { + return SchemaModels.getTapSchemaModel(getVersion()); } public final TableModel getTableModel(String tableName) { @@ -687,9 +689,9 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { } public boolean isHasObscore() { - return obscore; + return settings.isHasObscore(); } - + /** * Fill descriptions of the TAP_SCHEMA schema entities for a given * SchemaModel (TAP_SCHEMA or ivoa). @@ -704,15 +706,19 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { for (TableModel tableModel : schemaModel.getTables()) { Table table = schema.getChild(tableModel.getName()); table.setValue(DESCRIPTION_KEY, tableModel.getDescription()); - for (ColumnModel propertyModel : tableModel.getColumns()) { - Column column = table.getChild(propertyModel.getName()); - column.setValue(DESCRIPTION_KEY, propertyModel.getDescription()); - column.setValue(Column.UCD_KEY, propertyModel.getUcd()); - column.setValue(Column.UNIT_KEY, propertyModel.getUnit()); - column.setValue(Column.UTYPE_KEY, propertyModel.getUtype()); - - Object compatibleStd = useIntegerAsBool ? getIntAsBool(propertyModel.isStandard()) : propertyModel.isStandard(); - Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(propertyModel.isPrincipal()) : propertyModel.isPrincipal(); + for (ColumnModel columnModel : tableModel.getColumns()) { + Column column = table.getChild(columnModel.getName()); + if (!columnModel.isMandatory() && column == null) { + // column could be null if it is not mandatory + continue; + } + column.setValue(DESCRIPTION_KEY, columnModel.getDescription()); + column.setValue(Column.UCD_KEY, columnModel.getUcd()); + column.setValue(Column.UNIT_KEY, columnModel.getUnit()); + column.setValue(Column.UTYPE_KEY, columnModel.getUtype()); + + Object compatibleStd = useIntegerAsBool ? getIntAsBool(columnModel.isStandard()) : columnModel.isStandard(); + Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(columnModel.isPrincipal()) : columnModel.isPrincipal(); column.setValue(Column.STD_KEY, compatibleStd); column.setValue(Column.PRINCIPAL_KEY, compatiblePrincipal); } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaSettings.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaSettings.java index 9a339e1c7f33384f0da18d2980662e59a0cf7544..fd85ec534697c4df2105c276eb4d868b454d2da5 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaSettings.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaSettings.java @@ -22,6 +22,7 @@ */ package it.inaf.ia2.tsm; +import it.inaf.ia2.tsm.datalayer.DataTypeMode; import java.io.Serializable; /** diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java index 3c15c03c7425ef3be2ca991bcc4762bb86f9de16..49001db4e2534ad1b968933f4755f4ba85b699ca 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/ADQL.java @@ -29,18 +29,31 @@ package it.inaf.ia2.tsm.datalayer; */ public enum ADQL { - INTEGER, + VARCHAR, + CHAR, + BOOLEAN, SMALLINT, + INTEGER, BIGINT, REAL, DOUBLE, - BOOLEAN, - CHAR, + TIMESTAMP, CLOB, - VARCHAR, - TIMESTAMP; + BLOB, + BINARY, + VARBINARY, + REGION, + POINT; + /** + * For not standard types + */ public static String getDataType(String dataType) { - return dataType.toUpperCase(); + // removing size from datatype. + return dataType.toUpperCase().replaceAll("\\(.+\\)", ""); + } + + public static boolean isVariable(ADQL adql) { + return adql.equals(VARCHAR) || adql.equals(VARBINARY); } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerFactory.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerFactory.java index ec59db5326c49fb23c303ef089da933961ad5ab0..73e2915dd4985e4b9e4656662c4c2c6b593cfe4c 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerFactory.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerFactory.java @@ -31,13 +31,13 @@ import it.inaf.ia2.tsm.datalayer.pgsql.PostgresDBBroker; */ public class DBBrokerFactory { - public static DBBroker getDBBroker(DataSourceWrapper dataSourceWrapper, String tapSchemaVersion) { + public static DBBroker getDBBroker(DataSourceWrapper dataSourceWrapper, DataTypeMode dataTypeMode) { switch (dataSourceWrapper.getDatabaseType()) { case MYSQL: - return new MySQLDBBroker(dataSourceWrapper.getDataSource(), tapSchemaVersion); + return new MySQLDBBroker(dataSourceWrapper.getDataSource(), dataTypeMode); default: String pgDatabase = dataSourceWrapper.getCredentials().getDatabase(); - return new PostgresDBBroker(dataSourceWrapper.getDataSource(), pgDatabase, tapSchemaVersion); + return new PostgresDBBroker(dataSourceWrapper.getDataSource(), pgDatabase, dataTypeMode); } } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerTemplate.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerTemplate.java index 6bee192078eab627ea9b17db501226787e54a431..7230bef246bfd3a052eaac41b7e05dc1d9e6e981 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerTemplate.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerTemplate.java @@ -62,12 +62,12 @@ public abstract class DBBrokerTemplate implements DBBroker { protected final DataSource dataSource; private final char escapeCharacter; - private final String tapSchemaVersion; + private final DataTypeMode dataTypeMode; - public DBBrokerTemplate(DataSource dataSource, char escapeCharacter, String tapSchemaVersion) { + public DBBrokerTemplate(DataSource dataSource, char escapeCharacter, DataTypeMode dataTypeMode) { this.dataSource = dataSource; this.escapeCharacter = escapeCharacter; - this.tapSchemaVersion = tapSchemaVersion; + this.dataTypeMode = dataTypeMode; } protected List<String> getAllItemsNames(String query) throws SQLException { @@ -778,20 +778,16 @@ public abstract class DBBrokerTemplate implements DBBroker { if (tableModel != null) { for (Map.Entry<String, Map<String, Object>> entry : metadata.entrySet()) { String columnName = entry.getKey(); - String declaredDataType = tableModel.get(columnName).getType(); - String compatibleType = TypesMapping.getCompatibleADQLType(declaredDataType, tapSchemaVersion); - Integer size = (Integer) entry.getValue().get(Column.SIZE_KEY); - if (size != null) { - compatibleType += String.format("(%s)", size); - } - entry.getValue().put(Column.DATATYPE_KEY, compatibleType); + String adqlType = tableModel.get(columnName).getType(); + String tapDataType = TypesMapping.getDataType(adqlType, dataTypeMode); + entry.getValue().put(Column.DATATYPE_KEY, tapDataType); } } return metadata; } - protected String getTapSchemaVersion() { - return tapSchemaVersion; + protected DataTypeMode getDataTypeMode() { + return dataTypeMode; } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DataTypeMode.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DataTypeMode.java new file mode 100644 index 0000000000000000000000000000000000000000..20b9da06a4229c267d62534118aef24d1a26aee6 --- /dev/null +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DataTypeMode.java @@ -0,0 +1,43 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2017 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.datalayer; + +/** + * + * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} + */ +public enum DataTypeMode { + + ADQL("ADQL"), + VOTABLE("VOTable"); + + private final String name; + + private DataTypeMode(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/mysql/MySQLDBBroker.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/mysql/MySQLDBBroker.java index a7728c25a07c4575420f122b32ff1e180fc2ef8a..455cc6b8001b57ed2ef637b96a852b4b5c948a4f 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/mysql/MySQLDBBroker.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/mysql/MySQLDBBroker.java @@ -27,6 +27,7 @@ import it.inaf.ia2.tsm.Key; import it.inaf.ia2.tsm.TapSchema; import it.inaf.ia2.tsm.datalayer.ADQL; 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.TypesMapping; @@ -50,8 +51,8 @@ public class MySQLDBBroker extends DBBrokerTemplate { private static final Logger LOG = LoggerFactory.getLogger(MySQLDBBroker.class); - public MySQLDBBroker(DataSource dataSource, String tapSchemaVersion) { - super(dataSource, '`', tapSchemaVersion); + public MySQLDBBroker(DataSource dataSource, DataTypeMode mode) { + super(dataSource, '`', mode); } @Override @@ -115,13 +116,12 @@ public class MySQLDBBroker extends DBBrokerTemplate { cm.put(Column.INDEXED_KEY, indexed); // Datatype and Size - String type = resultSet.getString("Type").toUpperCase(); - String datatype = TypesMapping.getADQLTypeFromMySQLType(type, getTapSchemaVersion()); - Integer size = getSize(type); - if (size != null && size > 0 && !datatype.contains("(")) { - // Adding size at the end of datatype - datatype += String.format("(%s)", size); - } + String dbType = resultSet.getString("Type").toUpperCase(); + + ADQL adqlType = TypesMapping.getADQLFromDBType(dbType); + String datatype = TypesMapping.getDataTypeFromMySQLType(dbType, getDataTypeMode()); + + Integer size = getSize(dbType); cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.SIZE_KEY, size); @@ -130,7 +130,7 @@ public class MySQLDBBroker extends DBBrokerTemplate { if (size != null) { arraySize = String.valueOf(size); // variable length columns must have a "*" symbol on arraysize - if (datatype.startsWith(ADQL.VARCHAR.name())) { + if (adqlType != null && ADQL.isVariable(adqlType)) { arraySize += "*"; } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java index 96b24042bad209b689284d6a5edd7afbafc8f2f0..35882b928b2eacc1ef0e2b185d6b864a92bacecf 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java @@ -27,6 +27,7 @@ import it.inaf.ia2.tsm.Key; import it.inaf.ia2.tsm.TapSchema; import it.inaf.ia2.tsm.datalayer.ADQL; 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.TypesMapping; @@ -53,8 +54,8 @@ public class PostgresDBBroker extends DBBrokerTemplate { private final String pgDatabaseName; - public PostgresDBBroker(DataSource dataSource, String pgDatabaseName, String tapSchemaVersion) { - super(dataSource, '"', tapSchemaVersion); + public PostgresDBBroker(DataSource dataSource, String pgDatabaseName, DataTypeMode mode) { + super(dataSource, '"', mode); this.pgDatabaseName = pgDatabaseName; } @@ -197,28 +198,25 @@ public class PostgresDBBroker extends DBBrokerTemplate { Integer size = null; int arraydimension = 0; - String datatype; - String type = resultSet.getString("data_type").toUpperCase(); + String dbType = resultSet.getString("data_type").toUpperCase(); boolean isArray = false; - if ("ARRAY".equals(type)) { + if ("ARRAY".equals(dbType)) { isArray = true; // example: integer array has data_type ARRAY and format_type integer[] - type = resultSet.getString("format_type").toUpperCase(); + dbType = resultSet.getString("format_type").toUpperCase(); // example: an array defined as integer[5][5] has arraydim = 2 // 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"); } - datatype = TypesMapping.getADQLTypeFromPostgresType(type, getTapSchemaVersion()); - if (!isArray && (datatype.equals(ADQL.VARCHAR.name()) || datatype.equals(ADQL.CHAR.name()))) { + ADQL adqlType = TypesMapping.getADQLFromDBType(dbType); + String datatype = TypesMapping.getDataTypeFromPostgresType(dbType, getDataTypeMode()); + + if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { size = resultSet.getInt("character_maximum_length"); } - if (size != null && size > 0 && !datatype.contains("(")) { - // Adding size at the end of datatype - datatype += String.format("(%s)", size); - } cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.SIZE_KEY, size); @@ -229,7 +227,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { } else if (size != null) { arraySize = String.valueOf(size); // variable length columns must have a "*" symbol on arraysize - if (datatype.startsWith(ADQL.VARCHAR.name())) { + if (adqlType != null && ADQL.isVariable(adqlType)) { arraySize += "*"; } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DBTypeMapping.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DBTypeMapping.java new file mode 100644 index 0000000000000000000000000000000000000000..7d827f647aa332acab8b3b81de009e61ddd28c49 --- /dev/null +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DBTypeMapping.java @@ -0,0 +1,59 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2017 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.model; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +/** + * + * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} + */ +public class DBTypeMapping { + + private boolean inverse; + private final List<String> types; + + public DBTypeMapping() { + types = new ArrayList<>(); + } + + @XmlAttribute(name = "inverse") + public boolean isInverse() { + return inverse; + } + + public void setInverse(boolean inverse) { + this.inverse = inverse; + } + + @XmlElements({ + @XmlElement(name = "type") + }) + public List<String> getTypes() { + return types; + } +} diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DataTypeModeAdapter.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DataTypeModeAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..02fcd4e73d446b8f9317803725f7b8c5eb516915 --- /dev/null +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/DataTypeModeAdapter.java @@ -0,0 +1,56 @@ +/* + * _____________________________________________________________________________ + * + * INAF - OATS National Institute for Astrophysics - Astronomical Observatory of + * Trieste INAF - IA2 Italian Center for Astronomical Archives + * _____________________________________________________________________________ + * + * Copyright (C) 2017 Istituto Nazionale di Astrofisica + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License Version 3 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.inaf.ia2.tsm.model; + +import it.inaf.ia2.tsm.datalayer.DataTypeMode; +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * + * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} + */ +public class DataTypeModeAdapter extends XmlAdapter<String, DataTypeMode> { + + @Override + public DataTypeMode unmarshal(String value) throws Exception { + if (value == null) { + return null; + } + + for (DataTypeMode mode : DataTypeMode.values()) { + if (mode.getName().equals(value)) { + return mode; + } + } + + return null; + } + + @Override + public String marshal(DataTypeMode mode) throws Exception { + if (mode == null) { + return null; + } + return mode.getName(); + } +} diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/SchemaModel.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/SchemaModel.java index 7926339bff5c3d935cabdff58e80f5263663014f..f82241eab5d096035e40c2a2964eb22ecba36c90 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/SchemaModel.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/SchemaModel.java @@ -22,6 +22,7 @@ */ package it.inaf.ia2.tsm.model; +import it.inaf.ia2.tsm.datalayer.DataTypeMode; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -29,6 +30,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; /** * @@ -45,7 +47,9 @@ public class SchemaModel implements Serializable { private String version; private String extendsFrom; private String description; - private String datatypeType; + + // Used only in TAP_SCHEMA + private DataTypeMode dataTypeMode; public SchemaModel() { tables = new ArrayList<>(); @@ -104,11 +108,12 @@ public class SchemaModel implements Serializable { } @XmlAttribute(name = "datatype") - public String getDatatypeType() { - return datatypeType; + @XmlJavaTypeAdapter(DataTypeModeAdapter.class) + public DataTypeMode getDataTypeMode() { + return dataTypeMode; } - public void setDatatypeType(String datatypeType) { - this.datatypeType = datatypeType; + public void setDataTypeMode(DataTypeMode dataTypeMode) { + this.dataTypeMode = dataTypeMode; } } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java index e1d5fbaf1b97b25e2a77d5ad165663fdc8582352..eba8e4bd7b6a5a30a0a2f55812e44a7360c45e10 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypeMapping.java @@ -32,8 +32,9 @@ import javax.xml.bind.annotation.XmlTransient; public class TypeMapping { private String adqlType; - private String mysqlType; - private String pgsqlType; + private String voTableType; + private DBTypeMapping mysqlMapping; + private DBTypeMapping pgsqlMapping; private String javaTypeString; @XmlElement(name = "adql") @@ -45,22 +46,31 @@ public class TypeMapping { this.adqlType = adqlType; } + @XmlElement(name = "votable") + public String getVoTableType() { + return voTableType; + } + + public void setVoTableType(String voTableType) { + this.voTableType = voTableType; + } + @XmlElement(name = "mysql") - public String getMySQLType() { - return mysqlType; + public DBTypeMapping getMySQLMapping() { + return mysqlMapping; } - public void setMySQLType(String mysqlType) { - this.mysqlType = mysqlType; + public void setMySQLMapping(DBTypeMapping mysqlMapping) { + this.mysqlMapping = mysqlMapping; } @XmlElement(name = "pgsql") - public String getPgsqlType() { - return pgsqlType; + public DBTypeMapping getPgsqlMapping() { + return pgsqlMapping; } - public void setPgsqlType(String pgsqlType) { - this.pgsqlType = pgsqlType; + public void setPgsqlMapping(DBTypeMapping pgsqlMapping) { + this.pgsqlMapping = pgsqlMapping; } @XmlElement(name = "java") diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java index cf341f51405e67674a8df2aa300038f6becc156b..ec8988e09ac83ebdf56989f8d7b79fb099101f55 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/model/TypesMapping.java @@ -23,6 +23,7 @@ package it.inaf.ia2.tsm.model; import it.inaf.ia2.tsm.datalayer.ADQL; +import it.inaf.ia2.tsm.datalayer.DataTypeMode; import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -37,9 +38,6 @@ import javax.xml.bind.annotation.XmlRootElement; */ public class TypesMapping { - // For older TAP_SCHEMA versions - private static final String ADQL_PREFIX = "adql:"; - @XmlRootElement(name = "sql_type_mapping") static class TypesWrapper { @@ -78,17 +76,6 @@ public class TypesMapping { return null; } - /** - * returns an ADQL type String compatible with older TAP_SCHEMA versions - * (for older versions "adql:" prefix is needed). - */ - public static String getCompatibleADQLType(String adqlType, String tapSchemaVersion) { - if (tapSchemaVersion.startsWith("1.0")) { - return ADQL_PREFIX + adqlType; - } - return adqlType; - } - public static Class getClassFromAdqlType(String adqlType) { TypeMapping typeMapping = getTypeMappingFromADQLType(adqlType); if (typeMapping == null) { @@ -102,7 +89,7 @@ public class TypesMapping { if (typeMapping == null) { return "VARCHAR"; } - return typeMapping.getMySQLType(); + return typeMapping.getMySQLMapping().getTypes().get(0); } public static String getPostgresSQLTypeFromADQLType(String adqlType) { @@ -110,33 +97,94 @@ public class TypesMapping { if (typeMapping == null) { return "character varying"; } - return typeMapping.getPgsqlType(); + return typeMapping.getPgsqlMapping().getTypes().get(0); } - private static String getADQLTypeFromPostgresType(String pgsqlType) { - for (TypeMapping typeMapping : TYPES) { - if (pgsqlType.toUpperCase().startsWith(typeMapping.getPgsqlType().toUpperCase())) { - return typeMapping.getAdqlType(); - } + public static String getDataType(String adqlType, DataTypeMode mode) { + switch (mode) { + case ADQL: + return adqlType; + case VOTABLE: + return getTypeMappingFromADQLType(adqlType).getVoTableType(); + default: + throw new UnsupportedOperationException("DataTypeMode " + mode + " not supported yet"); } - return ADQL.getDataType(pgsqlType); } - public static String getADQLTypeFromPostgresType(String pgsqlType, String tapSchemaVersion) { - return getCompatibleADQLType(getADQLTypeFromPostgresType(pgsqlType), tapSchemaVersion); + private static abstract class DataTypeFromDBTypeMapper { + + private final DataTypeMode mode; + + DataTypeFromDBTypeMapper(DataTypeMode mode) { + this.mode = mode; + } + + abstract DBTypeMapping getDBTypeMapping(TypeMapping typeMapping); + + private String getDataType(TypeMapping mapping) { + switch (mode) { + case ADQL: + return mapping.getAdqlType(); + case VOTABLE: + return mapping.getVoTableType(); + default: + throw new UnsupportedOperationException("DataTypeMode " + mode + " not supported yet"); + } + } + + private String getDefaultDataType(String dbType) { + switch (mode) { + case ADQL: + return ADQL.getDataType(dbType); + case VOTABLE: + return "char"; + default: + throw new UnsupportedOperationException("DataTypeMode " + mode + " not supported yet"); + } + } + + String getDataTypeFromDBType(String dbType) { + String dbTypeWithoutSize = dbType.toUpperCase().replaceAll("\\(.+\\)", ""); + for (TypeMapping typeMapping : TYPES) { + DBTypeMapping dbMapping = getDBTypeMapping(typeMapping); + if (dbMapping.isInverse()) { + for (String type : dbMapping.getTypes()) { + if (dbTypeWithoutSize.toLowerCase().startsWith(type.toLowerCase())) { + return getDataType(typeMapping); + } + } + } + } + return getDefaultDataType(dbTypeWithoutSize); + } } - private static String getADQLTypeFromMySQLType(String mysqlType) { - for (TypeMapping typeMapping : TYPES) { - if (mysqlType.toUpperCase().startsWith(typeMapping.getMySQLType().toUpperCase())) { - return typeMapping.getAdqlType(); + public static String getDataTypeFromPostgresType(String pgsqlType, DataTypeMode mode) { + + return (new DataTypeFromDBTypeMapper(mode) { + @Override + DBTypeMapping getDBTypeMapping(TypeMapping typeMapping) { + return typeMapping.getPgsqlMapping(); } + }).getDataTypeFromDBType(pgsqlType); + } + + public static ADQL getADQLFromDBType(String dbType) { + try { + return ADQL.valueOf(TypesMapping.getDataTypeFromPostgresType(dbType, DataTypeMode.ADQL)); + } catch (IllegalArgumentException e) { + return null; } - return ADQL.getDataType(mysqlType); } - public static String getADQLTypeFromMySQLType(String mysqlType, String tapSchemaVersion) { - return getCompatibleADQLType(getADQLTypeFromMySQLType(mysqlType), tapSchemaVersion); + public static String getDataTypeFromMySQLType(String mysqlType, DataTypeMode mode) { + + return (new DataTypeFromDBTypeMapper(mode) { + @Override + DBTypeMapping getDBTypeMapping(TypeMapping typeMapping) { + return typeMapping.getMySQLMapping(); + } + }).getDataTypeFromDBType(mysqlType); } public static Object parseDefaultValue(String defaultValue, String type) { @@ -146,11 +194,11 @@ public class TypesMapping { public static Object parseDefaultValue(String defaultValue, ADQL type) { switch (type) { - case VARCHAR: - case CHAR: - return defaultValue; - case INTEGER: + case BOOLEAN: + return Boolean.parseBoolean(defaultValue); case SMALLINT: + return Short.parseShort(defaultValue); + case INTEGER: return Integer.parseInt(defaultValue); case BIGINT: return Long.parseLong(defaultValue); @@ -158,10 +206,8 @@ public class TypesMapping { return Float.parseFloat(defaultValue); case DOUBLE: return Double.parseDouble(defaultValue); - case BOOLEAN: - return Boolean.parseBoolean(defaultValue); default: - throw new UnsupportedOperationException("Default value for type " + type + " not supported yet."); + return defaultValue; } } } diff --git a/TASMAN-core/src/main/resources/sql_type_mapping.xml b/TASMAN-core/src/main/resources/sql_type_mapping.xml index 51cf20d42bb836c696d18db1f769b9c84c951d14..83e05ab3f4368f984943ce158e871540e4216061 100644 --- a/TASMAN-core/src/main/resources/sql_type_mapping.xml +++ b/TASMAN-core/src/main/resources/sql_type_mapping.xml @@ -25,56 +25,202 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <type> <adql>VARCHAR</adql> - <mysql>VARCHAR</mysql> - <pgsql>character varying</pgsql> + <votable>char</votable> + <mysql inverse="true"> + <type>VARCHAR</type> + </mysql> + <pgsql inverse="true"> + <type>character varying</type> + <type>varchar</type> + </pgsql> <java>java.lang.String</java> </type> + <type> <adql>CHAR</adql> - <mysql>CHAR</mysql> - <pgsql>character</pgsql> + <votable>char</votable> + <mysql inverse="true"> + <type>CHAR</type> + </mysql> + <pgsql inverse="true"> + <type>character</type> + <type>char</type> + </pgsql> <java>java.lang.String</java> </type> + + <type> + <adql>SMALLINT</adql> + <votable>short</votable> + <mysql inverse="true"> + <type>SMALLINT</type> + <type>TINYINT</type> + </mysql> + <pgsql inverse="true"> + <type>smallint</type> + </pgsql> + <java>java.lang.Short</java> + </type> + <type> <adql>INTEGER</adql> - <mysql>INT</mysql> - <pgsql>integer</pgsql> + <votable>int</votable> + <mysql inverse="true"> + <type>INT</type> + <type>MEDIUMINT</type> + </mysql> + <pgsql inverse="true"> + <type>integer</type> + <type>serial</type> + </pgsql> <java>java.lang.Integer</java> </type> + <type> <adql>BIGINT</adql> - <mysql>BIGINT</mysql> - <pgsql>bigint</pgsql> + <votable>long</votable> + <mysql inverse="true"> + <type>BIGINT</type> + </mysql> + <pgsql inverse="true"> + <type>bigint</type> + <type>bigserial</type> + </pgsql> <java>java.lang.Long</java> </type> + <type> <adql>REAL</adql> - <mysql>FLOAT</mysql> - <pgsql>integer</pgsql> + <votable>float</votable> + <mysql inverse="true"> + <type>FLOAT</type> + </mysql> + <pgsql inverse="true"> + <type>real</type> + </pgsql> <java>java.lang.Float</java> </type> + <type> <adql>DOUBLE</adql> - <mysql>DOUBLE</mysql> - <pgsql>double precision</pgsql> + <votable>double</votable> + <mysql inverse="true"> + <type>DOUBLE</type> + <type>DECIMAL</type> + </mysql> + <pgsql inverse="true"> + <type>double precision</type> + <type>decimal</type> + <type>numeric</type> + </pgsql> <java>java.lang.Double</java> </type> + <type> <adql>BOOLEAN</adql> - <mysql>BIT</mysql> - <pgsql>boolean</pgsql> + <votable>boolean</votable> + <mysql inverse="true"> + <type>BIT</type> + <type>BOOL</type> + <type>BOOLEAN</type> + </mysql> + <pgsql inverse="true"> + <type>boolean</type> + </pgsql> <java>java.lang.Boolean</java> </type> + <type> <adql>CLOB</adql> - <mysql>LONGTEXT</mysql> - <pgsql>text</pgsql> + <votable>char</votable> + <mysql inverse="true"> + <type>LONGTEXT</type> + <type>MEDIUMTEXT</type> + <type>TEXT</type> + </mysql> + <pgsql inverse="true"> + <type>text</type> + </pgsql> + <java>java.lang.String</java> + </type> + + <type> + <adql>BLOB</adql> + <votable>unsignedByte</votable> + <mysql inverse="true"> + <type>BLOB</type> + </mysql> + <pgsql> + <type>bytea</type> + </pgsql> <java>java.lang.String</java> </type> + <type> <adql>TIMESTAMP</adql> - <mysql>TIMESTAMP</mysql> - <pgsql>timestamp</pgsql> + <votable>char</votable> + <mysql inverse="true"> + <type>DATETIME</type> + <type>DATE</type> + <type>YEAR</type> + <!-- + <type>TIMESTAMP</type> + <type>TIME</type> + --> + </mysql> + <pgsql inverse="true"> + <type>timestamp</type> + <type>time</type> + <type>date</type> + </pgsql> + <java>java.lang.String</java> + </type> + + <type> + <adql>BINARY</adql> + <votable>unsignedByte</votable> + <mysql inverse="true"> + <type>BINARY</type> + </mysql> + <pgsql> + <type>bytea</type> + </pgsql> + <java>java.lang.String</java> + </type> + + <type> + <adql>VARBINARY</adql> + <votable>unsignedByte</votable> + <mysql inverse="true"> + <type>VARBINARY</type> + </mysql> + <pgsql inverse="true"> + <type>bytea</type> + </pgsql> + <java>java.lang.String</java> + </type> + + <type> + <adql>REGION</adql> + <votable>char</votable> + <mysql> + <type>VARCHAR</type> + </mysql> + <pgsql> + <type>character varying</type> + </pgsql> + <java>java.lang.String</java> + </type> + + <type> + <adql>POINT</adql> + <votable>char</votable> + <mysql> + <type>VARCHAR</type> + </mysql> + <pgsql> + <type>character varying</type> + </pgsql> <java>java.lang.String</java> </type> diff --git a/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java b/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java index 6e2f5f1fadcb3bd49ecc506bcfc96d299ffc1f56..62920a0997fe1dcd578df875ad9d1589409a511a 100644 --- a/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java +++ b/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java @@ -461,7 +461,7 @@ public class TestAll { // Checking size and arraysize detection Column descriptionColumn = tapSchema.getChild(tapSchema.getName()).getChild("columns").getChild("description"); - assertEquals("VARCHAR(255)", descriptionColumn.getProperty("datatype").getValue(String.class)); + assertEquals("char", descriptionColumn.getProperty("datatype").getValue(String.class)); assertEquals(255, descriptionColumn.getProperty("size").getValue(Integer.class)); assertEquals("255*", descriptionColumn.getProperty("arraysize").getValue(String.class)); diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java index f3db6d4ed6239c85eb1f1db22880301fb123bfd2..e4cbfeeb4706a2f08e3d215f7390bafe5967a5a2 100644 --- a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaEditingBean.java @@ -26,6 +26,7 @@ import it.inaf.ia2.tsm.ChildEntity; import it.inaf.ia2.tsm.Column; import it.inaf.ia2.tsm.webapp.env.CustomPartialResponseWriter; import it.inaf.ia2.tsm.EntitiesContainer; +import it.inaf.ia2.tsm.EntityProperty; import it.inaf.ia2.tsm.Key; import it.inaf.ia2.tsm.KeyColumn; import it.inaf.ia2.tsm.Schema; @@ -39,6 +40,7 @@ import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; @@ -142,6 +144,14 @@ public class TapSchemaEditingBean implements Serializable { return sb.toString(); } + public boolean isShowWarningOnDataType() { + if (selectedColumn == null) { + return false; + } + EntityProperty dataTypeProp = selectedColumn.getProperty("datatype"); + return !Objects.equals(dataTypeProp.getDefaultValue(), dataTypeProp.getValue()); + } + public static class AddableItem implements Serializable { private static final long serialVersionUID = 2732253307571391962L; diff --git a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoader.java b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoader.java index d31a9bda2b02f033aca8b84a428463430b8cc5e1..46a1b26b684012fd78c84505a1cf004a4558cbe7 100644 --- a/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoader.java +++ b/TASMAN-webapp/src/main/java/it/inaf/ia2/tsm/webapp/TapSchemaLoader.java @@ -27,6 +27,8 @@ import it.inaf.ia2.tsm.TapSchemaSettings; import it.inaf.ia2.tsm.datalayer.DBBroker; import it.inaf.ia2.tsm.datalayer.DBBrokerFactory; import it.inaf.ia2.tsm.datalayer.DBWrapper; +import it.inaf.ia2.tsm.datalayer.DataTypeMode; +import it.inaf.ia2.tsm.model.SchemaModels; import it.inaf.ia2.tsm.webapp.env.CustomPartialResponseWriter; import it.inaf.ia2.tsm.webapp.xmlconfig.JoinedCredentials; import it.inaf.ia2.tsm.webapp.xmlconfig.SeparatedCredentials; @@ -79,7 +81,8 @@ public class TapSchemaLoader implements Serializable { dbWrapper.testConnections(); // Searching for TAP_SCHEMA name - DBBroker broker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), tapCredentials.getTapSchemaVersion()); + DataTypeMode dataTypeMode = SchemaModels.getTapSchemaModel(tapCredentials.getTapSchemaVersion()).getDataTypeMode(); + DBBroker broker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), dataTypeMode); boolean tapSchemaExists = false; for (String schemaName : broker.getAllSchemaNames()) { if (schemaName.equals(tapCredentials.getTapSchemaName())) { diff --git a/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml b/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml index b7a428bfd230bbe90e99e1df0fbff689fdb6433b..387d45db5e2dfad5dcada87f3ca049362146c7e9 100644 --- a/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml +++ b/TASMAN-webapp/src/main/webapp/tapSchemaEditing.xhtml @@ -272,25 +272,7 @@ <h:panelGroup rendered="#{!tapSchemaEditing.toRemove(tapSchemaEditing.selectedColumn)}"> <div class="row"> - <div class="col-xs-6"> - <div class="form-group"> - <label for="datatype" class="control-label">Datatype:</label> - <span>#{tapSchemaEditing.selectedColumn.getProperty('datatype').value}</span> - </div> - </div> - <div class="col-xs-6"> - <h:panelGroup class="form-group" layout="block" rendered="#{tapSchemaEditing.selectedColumn.getProperty('arraysize') eq null}"> - <label for="size" class="control-label">Size:</label> - <span>#{tapSchemaEditing.selectedColumn.getProperty('size').value}</span> - </h:panelGroup> - <h:panelGroup class="form-group" layout="block" rendered="#{tapSchemaEditing.selectedColumn.getProperty('arraysize') ne null}"> - <label for="arraysize" class="control-label">Arraysize:</label> - <span>#{tapSchemaEditing.selectedColumn.getProperty('arraysize').value}</span> - </h:panelGroup> - </div> - </div> - <div class="row"> - <div class="col-xs-6"> + <div class="col-xs-4"> <div class="checkbox"> <label> <h:selectBooleanCheckbox @@ -302,7 +284,7 @@ </label> </div> </div> - <div class="col-xs-6"> + <div class="col-xs-4"> <div class="checkbox"> <label> <h:selectBooleanCheckbox @@ -314,6 +296,36 @@ </label> </div> </div> + <div class="col-xs-4"> + <div class="checkbox"> + <h:panelGroup class="form-group" layout="block" rendered="#{tapSchemaEditing.selectedColumn.getProperty('arraysize') eq null}"> + <strong>Size:</strong> + <span>#{tapSchemaEditing.selectedColumn.getProperty('size').value}</span> + </h:panelGroup> + <h:panelGroup class="form-group" layout="block" rendered="#{tapSchemaEditing.selectedColumn.getProperty('arraysize') ne null}"> + <strong>Arraysize:</strong> + <span>#{tapSchemaEditing.selectedColumn.getProperty('arraysize').value}</span> + </h:panelGroup> + </div> + </div> + </div> + <div class="form-group"> + <h:outputLabel for="datatype" class="control-label">Datatype:</h:outputLabel> + <h:inputText + id="datatype" + class="form-control #{tapSchemaEditing.selectedColumn.isChanged('datatype') ? 'changed' : ''}" + value="#{tapSchemaEditing.selectedColumn.getProperty('datatype').value}"> + <f:converter converterId="it.inaf.ia2.NullOrEmptyConverter" /> + <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}"> + <small> + <span class="glyphicon glyphicon-warning-sign"></span> + Suggested value: #{tapSchemaEditing.selectedColumn.getProperty('datatype').defaultValue} + </small> + </h:panelGroup> + </h:panelGroup> </div> <div class="form-group"> <h:outputLabel for="column_utype" class="control-label">UType:</h:outputLabel> @@ -328,7 +340,7 @@ <div class="form-group"> <label for=":main:column_ucd" class="control-label">UCD:</label> <h:commandLink action="#{tapSchemaEditing.openUCDDialog()}" class="form-control #{tapSchemaEditing.selectedColumn.isChanged('ucd') ? 'changed' : ''}" id="column_ucd"> - #{tapSchemaEditing.selectedColumn.getProperty('UCD').value} + #{tapSchemaEditing.selectedColumn.getProperty('ucd').value} <f:ajax execute="@form" render=":ucd_search_form:search_UCD_modal_content" onevent="TSM.openSearchUCDModal"/> </h:commandLink> </div>