Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/contract/ChildEntity.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/ChildEntity.java +35 −11 Original line number Diff line number Diff line Loading @@ -20,7 +20,10 @@ * 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.api.contract; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.xmlmodel.TableModel; import java.util.Map; /** * A {@link TapSchemaEntity} that can be a child of an Loading @@ -28,23 +31,44 @@ package it.inaf.ia2.tsm.api.contract; * * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} */ public interface ChildEntity<T extends EntitiesContainer> extends TapSchemaEntity { public abstract class ChildEntity<T extends EntitiesContainer> extends TapSchemaEntity { private static final long serialVersionUID = -8941059435527998685L; private Status status; protected ChildEntity() { } public ChildEntity(TapSchema tapSchema, TableModel tableModel, Map<String, Object> metadata) { super(tapSchema, tableModel, metadata); } /** * Each child has a name that is univocal for a given parent, in this way * the parent can search a child by name. * The persistence status of the {@link ChildEntity}. */ String getName(); public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } @Override public void save() { setStatus(Status.ADDED_PERSISTED); super.save(); } /** * The {@link EntitiesContainer} that owns the {@link ChildEntity}. * Each child has a name that is univocal for a given parent, in this way * the parent can search a child by name. */ T getParent(); public abstract String getName(); /** * The persistence status of the {@link ChildEntity}. * The {@link EntitiesContainer} that owns the {@link ChildEntity}. */ Status getStatus(); void setStatus(Status status); public abstract T getParent(); } TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/ColumnImpl.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +120 −0 Original line number Diff line number Diff line Loading @@ -20,254 +20,71 @@ * 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.api; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.api.contract.Column; import it.inaf.ia2.tsm.api.contract.Key; import it.inaf.ia2.tsm.api.contract.KeyColumn; import it.inaf.ia2.tsm.api.contract.Status; import it.inaf.ia2.tsm.api.contract.Table; import it.inaf.ia2.tsm.api.contract.TapSchema; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The main implementation of {@link Column}. * * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} */ public class ColumnImpl extends ChildEntityImpl<Table> implements Column { public class Column extends ChildEntity<Table> { private static final long serialVersionUID = 9175956487892235521L; private static final Logger log = LoggerFactory.getLogger(ColumnImpl.class); public final static String TABLE_NAME_KEY = "table_name"; public final static String COLUMN_NAME_KEY = "column_name"; public final static String DATATYPE_KEY = "datatype"; public final static String SIZE_KEY = "size"; public final static String ARRAYSIZE_KEY = "arraysize"; public final static String INDEXED_KEY = "indexed"; public final static String PRIMARY_KEY = "primary_key"; private boolean isPrimaryKey; private static final long serialVersionUID = 9175956487892235521L; private static final Logger LOG = LoggerFactory.getLogger(Column.class); private boolean foreignKeySearched; private Key foreignKey; private KeyMetadata foreignKey; private Table parentTable; private ColumnImpl() { private Column() { // for serialization super(); } protected ColumnImpl(DBWrapper dbWrapper, TapSchema tapSchema, Table table, String columnName, boolean indexed, boolean isPrimaryKey, String datatype, Integer size, Integer arraySize) { super(dbWrapper, tapSchema); this.isPrimaryKey = isPrimaryKey; protected Column(TapSchema tapSchema, Table table, String columnName) { super(tapSchema, tapSchema.getTableModel(TapSchema.COLUMNS_TABLE), table.getColumnMetadata(columnName)); parentTable = table; addProperty(TABLE_NAME_KEY, new FixedEntityProperty<>(table.getCompleteName())); addProperty(COLUMN_NAME_KEY, new FixedEntityProperty<>(columnName)); addProperty(DATATYPE_KEY, new FixedEntityProperty<>(datatype)); addProperty(SIZE_KEY, new FixedEntityProperty<>(size)); addProperty(ARRAYSIZE_KEY, new FixedEntityProperty<>(arraySize)); addProperty(INDEXED_KEY, new FixedEntityProperty<>(indexed)); // Updatables addProperty(DESCRIPTION_KEY, new EditableProperty<String>()); addProperty(UTYPE_KEY, new EditableProperty<String>()); addProperty(UNIT_KEY, new EditableProperty<String>()); addProperty(UCD_KEY, new EditableProperty<String>()); addProperty(PRINCIPAL_KEY, new EditableProperty<>(isPrimaryKey, false)); addProperty(STD_KEY, new EditableProperty<>(false, false)); addProperty(COLUMN_INDEX_KEY, new EditableProperty<Integer>()); addProperty(ID_KEY, new EditableProperty<Integer>()); addProperty(COLUMN_ID_KEY, new EditableProperty<Long>()); setStatus(Status.LOADED); } /** * {@inheritDoc} */ @Override public Key getForeignKey() { public KeyMetadata getForeignKey() { if (!foreignKeySearched) { // lazy loading (but the foreignKey value can be null, so we use this boolean) String tableCompleteName = getParent().getCompleteName(); String columnName = getValue(COLUMN_NAME_KEY, String.class); keysloop: // we want to loop on all schema keys, also hidden ones. for (Key key : ((TapSchemaImpl) tapSchema).getAllKeys()) { if (key.getFromTableCompleteName().equals(tableCompleteName)) { for (KeyColumn keyColumn : key.getKeyColumns()) { if (keyColumn.getFromColumn().equals(columnName)) { foreignKey = key; break keysloop; } } } } foreignKeySearched = true; foreignKey = tapSchema.searchKeyMetadata(parentTable.getParent().getName(), parentTable.getName(), getName()); } return foreignKey; } /** * {@inheritDoc} */ @Override public String getTableCompleteName() { return getValue(TABLE_NAME_KEY, String.class); } /** * {@inheritDoc} */ @Override public String getName() { return getValue(COLUMN_NAME_KEY, String.class); } @Override public boolean getIndexed() { return getValue(INDEXED_KEY, Boolean.class); } /** * {@inheritDoc} * * This information is not stored into the TAP_SCHEMA, so it will be * reloaded from the source schema each time. */ @Override public boolean isPrimaryKey() { return isPrimaryKey; } /** * {@inheritDoc} */ @Override public String getDatatype() { return getValue(DATATYPE_KEY, String.class); } /** * {@inheritDoc} */ @Override public Integer getArraySize() { return getValue(ARRAYSIZE_KEY, Integer.class); } /** * {@inheritDoc} */ @Override public Integer getSize() { return getValue(SIZE_KEY, Integer.class); } /** * {@inheritDoc} */ @Override public String getDescription() { return getValue(DESCRIPTION_KEY, String.class); } @Override public void setDescription(String description) { setValue(DESCRIPTION_KEY, description); } /** * {@inheritDoc} */ @Override public String getUtype() { return getValue(UTYPE_KEY, String.class); } @Override public void setUtype(String utype) { setValue(UTYPE_KEY, utype); } /** * {@inheritDoc} */ @Override public String getUnit() { return getValue(UNIT_KEY, String.class); } @Override public void setUnit(String unit) { setValue(UNIT_KEY, unit); } /** * {@inheritDoc} */ @Override public String getUCD() { return getValue(UCD_KEY, String.class); } @Override public void setUCD(String ucd) { setValue(UCD_KEY, ucd); } /** * {@inheritDoc} */ @Override public boolean getPrincipal() { return getValue(PRINCIPAL_KEY, Boolean.class); } @Override public void setPrincipal(boolean principal) { setValue(PRINCIPAL_KEY, principal); } /** * {@inheritDoc} */ @Override public boolean getStd() { return getValue(STD_KEY, Boolean.class); } @Override public void setStd(boolean std) { setValue(STD_KEY, std); } /** * {@inheritDoc} */ @Override public Integer getColumnIndex() { return getValue(COLUMN_INDEX_KEY, Integer.class); } @Override public void setColumnIndex(Integer columnIndex) { setValue(COLUMN_INDEX_KEY, columnIndex); } /** * {@inheritDoc} */ @Override public Long getColumnID() { return getValue(COLUMN_ID_KEY, Long.class); } @Override public void setColumnID(Long columnID) { setValue(COLUMN_ID_KEY, columnID); return (boolean) getMetadata(PRIMARY_KEY); } @Override Loading @@ -286,14 +103,11 @@ public class ColumnImpl extends ChildEntityImpl<Table> implements Column { if (getClass() != obj.getClass()) { return false; } final ColumnImpl other = (ColumnImpl) obj; final Column other = (Column) obj; if (!Objects.equals(this.getTableCompleteName(), other.getTableCompleteName())) { return false; } if (!Objects.equals(this.getName(), other.getName())) { return false; } return true; return Objects.equals(this.getName(), other.getName()); } /** Loading TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/ConsistencyChecks.java +3 −3 Original line number Diff line number Diff line Loading @@ -20,10 +20,10 @@ * 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.api; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.api.contract.DatabaseType; import it.inaf.ia2.tsm.api.contract.TapSchema; import it.inaf.ia2.tsm.datalayer.DatabaseType; import it.inaf.ia2.tsm.datalayer.DBWrapper; import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; Loading Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/contract/ChildEntity.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/ChildEntity.java +35 −11 Original line number Diff line number Diff line Loading @@ -20,7 +20,10 @@ * 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.api.contract; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.xmlmodel.TableModel; import java.util.Map; /** * A {@link TapSchemaEntity} that can be a child of an Loading @@ -28,23 +31,44 @@ package it.inaf.ia2.tsm.api.contract; * * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} */ public interface ChildEntity<T extends EntitiesContainer> extends TapSchemaEntity { public abstract class ChildEntity<T extends EntitiesContainer> extends TapSchemaEntity { private static final long serialVersionUID = -8941059435527998685L; private Status status; protected ChildEntity() { } public ChildEntity(TapSchema tapSchema, TableModel tableModel, Map<String, Object> metadata) { super(tapSchema, tableModel, metadata); } /** * Each child has a name that is univocal for a given parent, in this way * the parent can search a child by name. * The persistence status of the {@link ChildEntity}. */ String getName(); public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } @Override public void save() { setStatus(Status.ADDED_PERSISTED); super.save(); } /** * The {@link EntitiesContainer} that owns the {@link ChildEntity}. * Each child has a name that is univocal for a given parent, in this way * the parent can search a child by name. */ T getParent(); public abstract String getName(); /** * The persistence status of the {@link ChildEntity}. * The {@link EntitiesContainer} that owns the {@link ChildEntity}. */ Status getStatus(); void setStatus(Status status); public abstract T getParent(); }
TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/ColumnImpl.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java +120 −0 Original line number Diff line number Diff line Loading @@ -20,254 +20,71 @@ * 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.api; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.api.contract.Column; import it.inaf.ia2.tsm.api.contract.Key; import it.inaf.ia2.tsm.api.contract.KeyColumn; import it.inaf.ia2.tsm.api.contract.Status; import it.inaf.ia2.tsm.api.contract.Table; import it.inaf.ia2.tsm.api.contract.TapSchema; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The main implementation of {@link Column}. * * @author Sonia Zorba {@literal <zorba at oats.inaf.it>} */ public class ColumnImpl extends ChildEntityImpl<Table> implements Column { public class Column extends ChildEntity<Table> { private static final long serialVersionUID = 9175956487892235521L; private static final Logger log = LoggerFactory.getLogger(ColumnImpl.class); public final static String TABLE_NAME_KEY = "table_name"; public final static String COLUMN_NAME_KEY = "column_name"; public final static String DATATYPE_KEY = "datatype"; public final static String SIZE_KEY = "size"; public final static String ARRAYSIZE_KEY = "arraysize"; public final static String INDEXED_KEY = "indexed"; public final static String PRIMARY_KEY = "primary_key"; private boolean isPrimaryKey; private static final long serialVersionUID = 9175956487892235521L; private static final Logger LOG = LoggerFactory.getLogger(Column.class); private boolean foreignKeySearched; private Key foreignKey; private KeyMetadata foreignKey; private Table parentTable; private ColumnImpl() { private Column() { // for serialization super(); } protected ColumnImpl(DBWrapper dbWrapper, TapSchema tapSchema, Table table, String columnName, boolean indexed, boolean isPrimaryKey, String datatype, Integer size, Integer arraySize) { super(dbWrapper, tapSchema); this.isPrimaryKey = isPrimaryKey; protected Column(TapSchema tapSchema, Table table, String columnName) { super(tapSchema, tapSchema.getTableModel(TapSchema.COLUMNS_TABLE), table.getColumnMetadata(columnName)); parentTable = table; addProperty(TABLE_NAME_KEY, new FixedEntityProperty<>(table.getCompleteName())); addProperty(COLUMN_NAME_KEY, new FixedEntityProperty<>(columnName)); addProperty(DATATYPE_KEY, new FixedEntityProperty<>(datatype)); addProperty(SIZE_KEY, new FixedEntityProperty<>(size)); addProperty(ARRAYSIZE_KEY, new FixedEntityProperty<>(arraySize)); addProperty(INDEXED_KEY, new FixedEntityProperty<>(indexed)); // Updatables addProperty(DESCRIPTION_KEY, new EditableProperty<String>()); addProperty(UTYPE_KEY, new EditableProperty<String>()); addProperty(UNIT_KEY, new EditableProperty<String>()); addProperty(UCD_KEY, new EditableProperty<String>()); addProperty(PRINCIPAL_KEY, new EditableProperty<>(isPrimaryKey, false)); addProperty(STD_KEY, new EditableProperty<>(false, false)); addProperty(COLUMN_INDEX_KEY, new EditableProperty<Integer>()); addProperty(ID_KEY, new EditableProperty<Integer>()); addProperty(COLUMN_ID_KEY, new EditableProperty<Long>()); setStatus(Status.LOADED); } /** * {@inheritDoc} */ @Override public Key getForeignKey() { public KeyMetadata getForeignKey() { if (!foreignKeySearched) { // lazy loading (but the foreignKey value can be null, so we use this boolean) String tableCompleteName = getParent().getCompleteName(); String columnName = getValue(COLUMN_NAME_KEY, String.class); keysloop: // we want to loop on all schema keys, also hidden ones. for (Key key : ((TapSchemaImpl) tapSchema).getAllKeys()) { if (key.getFromTableCompleteName().equals(tableCompleteName)) { for (KeyColumn keyColumn : key.getKeyColumns()) { if (keyColumn.getFromColumn().equals(columnName)) { foreignKey = key; break keysloop; } } } } foreignKeySearched = true; foreignKey = tapSchema.searchKeyMetadata(parentTable.getParent().getName(), parentTable.getName(), getName()); } return foreignKey; } /** * {@inheritDoc} */ @Override public String getTableCompleteName() { return getValue(TABLE_NAME_KEY, String.class); } /** * {@inheritDoc} */ @Override public String getName() { return getValue(COLUMN_NAME_KEY, String.class); } @Override public boolean getIndexed() { return getValue(INDEXED_KEY, Boolean.class); } /** * {@inheritDoc} * * This information is not stored into the TAP_SCHEMA, so it will be * reloaded from the source schema each time. */ @Override public boolean isPrimaryKey() { return isPrimaryKey; } /** * {@inheritDoc} */ @Override public String getDatatype() { return getValue(DATATYPE_KEY, String.class); } /** * {@inheritDoc} */ @Override public Integer getArraySize() { return getValue(ARRAYSIZE_KEY, Integer.class); } /** * {@inheritDoc} */ @Override public Integer getSize() { return getValue(SIZE_KEY, Integer.class); } /** * {@inheritDoc} */ @Override public String getDescription() { return getValue(DESCRIPTION_KEY, String.class); } @Override public void setDescription(String description) { setValue(DESCRIPTION_KEY, description); } /** * {@inheritDoc} */ @Override public String getUtype() { return getValue(UTYPE_KEY, String.class); } @Override public void setUtype(String utype) { setValue(UTYPE_KEY, utype); } /** * {@inheritDoc} */ @Override public String getUnit() { return getValue(UNIT_KEY, String.class); } @Override public void setUnit(String unit) { setValue(UNIT_KEY, unit); } /** * {@inheritDoc} */ @Override public String getUCD() { return getValue(UCD_KEY, String.class); } @Override public void setUCD(String ucd) { setValue(UCD_KEY, ucd); } /** * {@inheritDoc} */ @Override public boolean getPrincipal() { return getValue(PRINCIPAL_KEY, Boolean.class); } @Override public void setPrincipal(boolean principal) { setValue(PRINCIPAL_KEY, principal); } /** * {@inheritDoc} */ @Override public boolean getStd() { return getValue(STD_KEY, Boolean.class); } @Override public void setStd(boolean std) { setValue(STD_KEY, std); } /** * {@inheritDoc} */ @Override public Integer getColumnIndex() { return getValue(COLUMN_INDEX_KEY, Integer.class); } @Override public void setColumnIndex(Integer columnIndex) { setValue(COLUMN_INDEX_KEY, columnIndex); } /** * {@inheritDoc} */ @Override public Long getColumnID() { return getValue(COLUMN_ID_KEY, Long.class); } @Override public void setColumnID(Long columnID) { setValue(COLUMN_ID_KEY, columnID); return (boolean) getMetadata(PRIMARY_KEY); } @Override Loading @@ -286,14 +103,11 @@ public class ColumnImpl extends ChildEntityImpl<Table> implements Column { if (getClass() != obj.getClass()) { return false; } final ColumnImpl other = (ColumnImpl) obj; final Column other = (Column) obj; if (!Objects.equals(this.getTableCompleteName(), other.getTableCompleteName())) { return false; } if (!Objects.equals(this.getName(), other.getName())) { return false; } return true; return Objects.equals(this.getName(), other.getName()); } /** Loading
TASMAN-core/src/main/java/it/inaf/ia2/tsm/api/ConsistencyChecks.java→TASMAN-core/src/main/java/it/inaf/ia2/tsm/ConsistencyChecks.java +3 −3 Original line number Diff line number Diff line Loading @@ -20,10 +20,10 @@ * 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.api; package it.inaf.ia2.tsm; import it.inaf.ia2.tsm.api.contract.DatabaseType; import it.inaf.ia2.tsm.api.contract.TapSchema; import it.inaf.ia2.tsm.datalayer.DatabaseType; import it.inaf.ia2.tsm.datalayer.DBWrapper; import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; Loading