Newer
Older
package it.inaf.oats.ia2.tapschemamanager.datalayer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Utility class that contains some static methods to manage various operations
* with the TAP_SCHEMA entities.
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class DLUtil {
/**
* Retrieve a <code>TapSchemaEntity</code> from a list searching it by name.
*/
public static <T extends TapSchemaEntity> T getEntityByName(List<T> entities, String name) {
for (T entity : entities) {
if (entity.getName().equals(name)) {
return entity;
}
}
return null;
}
/**
* Given a list of <code>TapSchemaEntity</code> objects returns a list
* containing their names.
*
* @return list of entities names alphabetically and case insensitively
* ordered.
*/
public static <T extends TapSchemaEntity> List<String> getEntitiesNames(List<T> entities) {
List<String> entitiesNames = new ArrayList<>();
for (T entity : entities) {
entitiesNames.add(entity.getName());
}
Collections.sort(entitiesNames, String.CASE_INSENSITIVE_ORDER);
return entitiesNames;
}
* Remove an entity from a list of <code>TapSchemaEntity</code> instances
* searching it by name.
*
* This method is protected because this operation should be performed by
* the entity that contains the list.
protected static <T extends TapSchemaEntity> void removeEntity(List<T> entities, String entityName) {
Iterator<T> iterator = entities.iterator();
while (iterator.hasNext()) {
T entity = iterator.next();
if (entity.getName().equals(entityName)) {
iterator.remove();
return;
}
}
}
private static void setColumnDescription(TableEntity tableEntity, String columnName, String description) {
ColumnEntity columnEntity = getEntityByName(tableEntity.getColumns(), columnName);
columnEntity.setDescription(description);
columnEntity.setStd(1);
}
/**
* Fill descriptions of the TAP_SCHEMA schema entities.
*
* @param schema the TAP_SCHEMA schema <code>SchemaEntity</code>.
*/
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
protected static void putInfoIntoTapSchemaSchema(SchemaEntity schema) {
schema.setDescription("a special schema to describe a TAP tableset");
// SCHEMAS
TableEntity schemasTable = schema.getTableByShortName("schemas");
schemasTable.setDescription("description of schemas in this tableset");
setColumnDescription(schemasTable, "schema_name", "schema name for reference to TAP_SCHEMA.schemas");
setColumnDescription(schemasTable, "utype", "lists the utypes of schemas in the tableset");
setColumnDescription(schemasTable, "description", "describes schemas in the tableset");
// TABLES
TableEntity tablesTable = schema.getTableByShortName("tables");
tablesTable.setDescription("description of tables in this tableset");
setColumnDescription(tablesTable, "schema_name", "the schema this table belongs to");
setColumnDescription(tablesTable, "table_name", "the fully qualified table name");
setColumnDescription(tablesTable, "table_type", "one of: table view");
setColumnDescription(tablesTable, "utype", "lists the utype of tables in the tableset");
setColumnDescription(tablesTable, "description", "describes tables in the tableset");
// COLUMNS
TableEntity columnsTable = schema.getTableByShortName("columns");
columnsTable.setDescription("description of columns in this tableset");
setColumnDescription(columnsTable, "table_name", "the table this column belongs to");
setColumnDescription(columnsTable, "column_name", "the column name");
setColumnDescription(columnsTable, "utype", "lists the utypes of columns in the tableset");
setColumnDescription(columnsTable, "ucd", "lists the UCDs of columns in the tableset");
setColumnDescription(columnsTable, "unit", "lists the unit used for column values in the tableset");
setColumnDescription(columnsTable, "description", "describes the columns in the tableset");
setColumnDescription(columnsTable, "datatype", "lists the ADQL datatype of columns in the tableset");
setColumnDescription(columnsTable, "size", "lists the size of variable-length columns in the tableset");
setColumnDescription(columnsTable, "principal", "a principal column; 1 means 1, 0 means 0");
setColumnDescription(columnsTable, "indexed", "an indexed column; 1 means 1, 0 means 0");
setColumnDescription(columnsTable, "std", "a standard column; 1 means 1, 0 means 0");
// KEYS
TableEntity keysTable = schema.getTableByShortName("keys");
keysTable.setDescription("description of foreign keys in this tableset");
setColumnDescription(keysTable, "key_id", "unique key to join to TAP_SCHEMA.key_columns");
setColumnDescription(keysTable, "from_table", "the table with the foreign key");
setColumnDescription(keysTable, "target_table", "the table with the primary key");
setColumnDescription(keysTable, "utype", "lists the utype of keys in the tableset");
setColumnDescription(keysTable, "description", "describes keys in the tableset");
// KEY COLUMNS
TableEntity keyColumnsTable = schema.getTableByShortName("key_columns");
keyColumnsTable.setDescription("description of foreign key columns in this tableset");
setColumnDescription(keyColumnsTable, "key_id", "key to join to TAP_SCHEMA.keys");
setColumnDescription(keyColumnsTable, "from_column", "column in the from_table");
setColumnDescription(keyColumnsTable, "target_column", "column in the target_table");
}