Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Molinaro
tap_schema_manager
Commits
e258024b
Commit
e258024b
authored
Jan 12, 2018
by
Sonia Zorba
Browse files
Supported dbname column, for compatibility with taplib.
parent
06003c06
Changes
16
Hide whitespace changes
Inline
Side-by-side
TASMAN-core/pom.xml
View file @
e258024b
...
...
@@ -3,7 +3,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
it.inaf.ia2.tap
</groupId>
<artifactId>
tasman-core
</artifactId>
<version>
1.3.
1
</version>
<version>
1.3.
2
</version>
<packaging>
jar
</packaging>
<name>
tasman-core
</name>
<properties>
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/Column.java
View file @
e258024b
...
...
@@ -44,6 +44,7 @@ public class Column extends ChildEntity<Table> {
public
final
static
String
UCD_KEY
=
"ucd"
;
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"
;
// Original datatype (computed from information_schema data), used for consistency checking
public
final
static
String
ORIGINAL_DATATYPE_KEY
=
"original_datatype"
;
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/Schema.java
View file @
e258024b
...
...
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
public
class
Schema
extends
ChildEntity
<
TapSchema
>
implements
EntitiesContainer
<
Table
>
{
public
final
static
String
SCHEMA_NAME_KEY
=
"schema_name"
;
public
final
static
String
DBNAME
=
"dbname"
;
private
static
final
long
serialVersionUID
=
8828583158332877855L
;
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
Schema
.
class
);
...
...
@@ -61,7 +62,7 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
tables
=
new
TreeMap
<>(
String
.
CASE_INSENSITIVE_ORDER
);
tablesTypes
=
broker
.
getAllTableTypes
(
name
);
for
(
String
tableName
:
broker
.
getAllTablesNames
(
n
ame
))
{
for
(
String
tableName
:
broker
.
getAllTablesNames
(
getRealSchemaN
ame
()
))
{
tables
.
put
(
tableName
,
null
);
}
LOG
.
debug
(
"Schema {} contains {} tables"
,
name
,
tables
.
size
());
...
...
@@ -69,6 +70,13 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
setStatus
(
Status
.
LOADED
);
}
public
String
getRealSchemaName
()
{
if
(
tapSchema
.
getDBName
()
!=
null
&&
this
.
getName
().
equals
(
tapSchema
.
getName
()))
{
return
tapSchema
.
getDBName
();
}
return
getName
();
}
/**
* {@inheritDoc} The value in the {@code schema_name} column.
*/
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/Table.java
View file @
e258024b
...
...
@@ -42,6 +42,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
public
final
static
String
SCHEMA_NAME_KEY
=
"schema_name"
;
public
final
static
String
TABLE_NAME_KEY
=
"table_name"
;
public
final
static
String
TABLE_TYPE_KEY
=
"table_type"
;
public
final
static
String
DBNAME
=
"dbname"
;
private
static
final
long
serialVersionUID
=
8265331530960896871L
;
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
Table
.
class
);
...
...
@@ -98,7 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
DBBroker
broker
=
tapSchema
.
getDBBroker
(
schema
.
getName
());
tableTableModel
=
getTableTableModel
();
columnsMetadata
=
broker
.
getAllColumnsMetadata
(
schema
.
getName
(),
tableSimpleName
,
tableTableModel
,
tapSchema
.
getDataTypeMode
());
columnsMetadata
=
broker
.
getAllColumnsMetadata
(
schema
.
get
RealSchema
Name
(),
tableSimpleName
,
tableTableModel
,
tapSchema
.
getDataTypeMode
());
fixIndexedMetadataValues
();
for
(
Map
.
Entry
<
String
,
Map
<
String
,
Object
>>
entry
:
columnsMetadata
.
entrySet
())
{
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchema.java
View file @
e258024b
...
...
@@ -47,6 +47,8 @@ import org.slf4j.LoggerFactory;
*/
public
class
TapSchema
implements
EntitiesContainer
<
Schema
>,
Serializable
{
public
static
final
String
STANDARD_NAME
=
"TAP_SCHEMA"
;
// Mandatory tables constants
public
static
final
String
TABLES_TABLE
=
"tables"
;
public
static
final
String
SCHEMAS_TABLE
=
"schemas"
;
...
...
@@ -65,6 +67,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
private
boolean
loading
;
private
DBWrapper
dbWrapper
;
private
String
dbName
;
private
String
name
;
private
boolean
exists
;
private
TapSchemaSettings
settings
;
private
DataTypeMode
dataTypeMode
;
...
...
@@ -101,12 +105,32 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
this
.
dbWrapper
=
dbWrapper
;
this
.
exists
=
exists
;
this
.
settings
=
settings
;
// Don't change the instructions order!
loadDBName
();
loadName
();
dataTypeMode
=
getTapSchemaModel
().
getDataTypeMode
();
load
();
}
private
void
loadDBName
()
{
// Detect if the TAP_SCHEMA version supports dbmodel
SchemaModel
tapSchemaModel
=
SchemaModels
.
getTapSchemaModel
(
settings
.
getTapSchemaVersion
());
boolean
hasDBName
=
tapSchemaModel
.
getTable
(
SCHEMAS_TABLE
).
get
(
"dbname"
)
!=
null
;
if
(
hasDBName
&&
!
STANDARD_NAME
.
equals
(
settings
.
getTapSchemaName
()))
{
dbName
=
settings
.
getTapSchemaName
();
}
}
private
void
loadName
()
{
if
(
dbName
!=
null
)
{
name
=
STANDARD_NAME
;
}
else
{
name
=
settings
.
getTapSchemaName
();
}
}
public
final
void
load
()
throws
SQLException
{
loading
=
true
;
...
...
@@ -115,7 +139,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
for
(
String
schemaName
:
getSourceDBBroker
().
getAllSchemaNames
())
{
schemas
.
put
(
schemaName
,
null
);
}
schemas
.
put
(
settings
.
getTapSchema
Name
(),
null
);
// the TAP_SCHEMA contains itself
schemas
.
put
(
get
Name
(),
null
);
// the TAP_SCHEMA contains itself
if
(
exists
)
{
consistencyChecks
=
TapSchemaLoader
.
loadExistingTapSchema
((
this
));
...
...
@@ -138,7 +162,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
* The name of the TAP_SCHEMA schema.
*/
public
final
String
getName
()
{
return
settings
.
getTapSchemaN
ame
()
;
return
n
ame
;
}
/**
...
...
@@ -153,7 +177,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
}
private
void
loadSchemaKeysMetadata
(
String
schemaName
)
throws
SQLException
{
allKeys
.
addAll
(
getDBBroker
(
schemaName
).
getKeys
(
this
,
schemaName
));
allKeys
.
addAll
(
getDBBroker
(
schemaName
)
.
getKeys
(
this
,
schemaName
,
getRealSchemaName
(
schemaName
)));
}
public
Set
<
Key
>
getAllKeys
()
{
...
...
@@ -307,7 +332,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
if
(!
exists
)
{
SchemaModel
tapSchemaModel
=
getTapSchemaModel
();
broker
.
createTapSchemaStructure
(
getName
(),
tapSchemaModel
);
broker
.
createTapSchemaStructure
(
get
Real
Name
(),
tapSchemaModel
);
// Adding TAP_SCHEMA into TAP_SCHEMA
addEntireSchema
(
getName
());
...
...
@@ -525,6 +550,11 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public
Map
<
String
,
Object
>
getSchemaMetadata
(
String
schemaName
)
{
Map
<
String
,
Object
>
metadata
=
new
HashMap
<>();
metadata
.
put
(
Schema
.
SCHEMA_NAME_KEY
,
schemaName
);
String
dbNameMetadata
=
null
;
if
(
dbName
!=
null
&&
schemaName
.
equals
(
STANDARD_NAME
))
{
dbNameMetadata
=
dbName
;
}
metadata
.
put
(
Schema
.
DBNAME
,
dbNameMetadata
);
return
metadata
;
}
...
...
@@ -585,4 +615,25 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public
void
fillColumnsProperties
(
SchemaModel
schemaModel
)
{
fillColumnProperties
(
schemaModel
,
schemaModel
.
getName
());
}
/**
* Allows to name the TAP_SCHEMA using the standard name, but referring to a
* differently named schema. This value is null if the TAP_SCHEMA version
* doesn't support the dbname column or if the schema name is already the
* standard value.
*/
public
String
getDBName
()
{
return
dbName
;
}
public
String
getRealName
()
{
return
getRealSchemaName
(
getName
());
}
public
String
getRealSchemaName
(
String
schemaName
)
{
if
(
dbName
!=
null
&&
STANDARD_NAME
.
equals
(
schemaName
))
{
return
dbName
;
}
return
schemaName
;
}
}
TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaLoader.java
View file @
e258024b
...
...
@@ -241,7 +241,7 @@ public class TapSchemaLoader {
}
private
void
loadAndCheckSchemata
()
throws
SQLException
{
for
(
Map
<
String
,
Object
>
schemaProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
getName
(),
tapSchema
.
getTableModel
(
SCHEMAS_TABLE
)))
{
for
(
Map
<
String
,
Object
>
schemaProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
get
Real
Name
(),
tapSchema
.
getTableModel
(
SCHEMAS_TABLE
)))
{
String
schemaName
=
(
String
)
schemaProps
.
get
(
Schema
.
SCHEMA_NAME_KEY
);
Schema
schema
=
tapSchema
.
addChild
(
schemaName
);
if
(
schema
==
null
)
{
...
...
@@ -254,7 +254,7 @@ public class TapSchemaLoader {
}
private
void
loadAndCheckTables
()
throws
SQLException
{
for
(
Map
<
String
,
Object
>
tableProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
getName
(),
tapSchema
.
getTableModel
(
TABLES_TABLE
)))
{
for
(
Map
<
String
,
Object
>
tableProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
get
Real
Name
(),
tapSchema
.
getTableModel
(
TABLES_TABLE
)))
{
String
tableCompleteName
=
(
String
)
tableProps
.
get
(
Table
.
TABLE_NAME_KEY
);
String
[]
tableNameSplit
=
tableCompleteName
.
split
(
Pattern
.
quote
(
"."
));
String
schemaName
=
tableNameSplit
[
0
];
...
...
@@ -275,7 +275,7 @@ public class TapSchemaLoader {
}
private
void
loadAndCheckColumns
()
throws
SQLException
{
for
(
Map
<
String
,
Object
>
columnProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
getName
(),
tapSchema
.
getTableModel
(
COLUMNS_TABLE
)))
{
for
(
Map
<
String
,
Object
>
columnProps
:
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
get
Real
Name
(),
tapSchema
.
getTableModel
(
COLUMNS_TABLE
)))
{
String
tableCompleteName
=
(
String
)
columnProps
.
get
(
Column
.
TABLE_NAME_KEY
);
String
[]
tableNameSplit
=
tableCompleteName
.
split
(
Pattern
.
quote
(
"."
));
String
schemaName
=
tableNameSplit
[
0
];
...
...
@@ -302,8 +302,8 @@ public class TapSchemaLoader {
}
private
void
loadAndCheckKeys
()
throws
SQLException
{
List
<
Map
<
String
,
Object
>>
keysProps
=
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
getName
(),
tapSchema
.
getTableModel
(
KEYS_TABLE
));
List
<
Map
<
String
,
Object
>>
keysColumnsProps
=
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
getName
(),
tapSchema
.
getTableModel
(
KEY_COLUMNS_TABLE
));
List
<
Map
<
String
,
Object
>>
keysProps
=
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
get
Real
Name
(),
tapSchema
.
getTableModel
(
KEYS_TABLE
));
List
<
Map
<
String
,
Object
>>
keysColumnsProps
=
tapSchemaDBBroker
.
getSavedItems
(
tapSchema
.
get
Real
Name
(),
tapSchema
.
getTableModel
(
KEY_COLUMNS_TABLE
));
for
(
Map
<
String
,
Object
>
keyProp
:
keysProps
)
{
String
fromTable
=
(
String
)
keyProp
.
get
(
Key
.
FROM_TABLE_KEY
);
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaMender.java
View file @
e258024b
...
...
@@ -152,7 +152,7 @@ public class TapSchemaMender {
private
void
fixInconsistentValues
()
throws
SQLException
{
for
(
InconsistentColumnProperty
inconsistency
:
consistencyChecks
.
getInconsistencies
())
{
tapSchema
.
getTapSchemaDBBroker
().
updateTapSchemaColumnValue
(
tapSchema
.
getName
(),
tapSchema
.
getTapSchemaDBBroker
().
updateTapSchemaColumnValue
(
tapSchema
.
get
Real
Name
(),
inconsistency
.
getTableCompleteName
(),
inconsistency
.
getColumnName
(),
inconsistency
.
getKey
(),
inconsistency
.
getCorrectValue
());
}
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBroker.java
View file @
e258024b
...
...
@@ -58,7 +58,7 @@ public interface DBBroker {
Map
<
String
,
Map
<
String
,
Object
>>
getAllColumnsMetadata
(
String
schemaName
,
String
tableSimpleName
,
TableModel
tableModel
,
DataTypeMode
dataTypeMode
)
throws
SQLException
;
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
)
throws
SQLException
;
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
,
String
realSchemaName
)
throws
SQLException
;
List
<
Map
<
String
,
Object
>>
getSavedItems
(
String
tapSchemaName
,
TableModel
tableModel
,
String
whereCondition
,
Object
[]
whereParams
)
throws
SQLException
;
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/DBBrokerTemplate.java
View file @
e258024b
...
...
@@ -210,7 +210,7 @@ public abstract class DBBrokerTemplate implements DBBroker {
connection
.
setAutoCommit
(
false
);
// start transaction
transactionStarted
=
true
;
String
tapSchemaNameEscaped
=
escape
(
tapSchema
.
getName
());
String
tapSchemaNameEscaped
=
escape
(
tapSchema
.
get
Real
Name
());
// REMOVE ELEMENTS
if
(
tapSchema
.
exists
())
{
...
...
@@ -265,21 +265,21 @@ public abstract class DBBrokerTemplate implements DBBroker {
LOG
.
debug
(
"Inserting {} new schemas"
,
operations
.
getSchemasToAdd
().
size
());
}
for
(
Schema
schema
:
operations
.
getSchemasToAdd
())
{
insertItem
(
tapSchema
.
getName
(),
schema
,
connection
);
insertItem
(
tapSchema
.
get
Real
Name
(),
schema
,
connection
);
}
if
(!
operations
.
getTablesToAdd
().
isEmpty
())
{
LOG
.
debug
(
"Inserting {} new tables"
,
operations
.
getTablesToAdd
().
size
());
}
for
(
Table
table
:
operations
.
getTablesToAdd
())
{
insertItem
(
tapSchema
.
getName
(),
table
,
connection
);
insertItem
(
tapSchema
.
get
Real
Name
(),
table
,
connection
);
}
if
(!
operations
.
getColumnsToAdd
().
isEmpty
())
{
LOG
.
debug
(
"Inserting {} new columns"
,
operations
.
getColumnsToAdd
().
size
());
}
for
(
Column
column
:
operations
.
getColumnsToAdd
())
{
insertItem
(
tapSchema
.
getName
(),
column
,
connection
);
insertItem
(
tapSchema
.
get
Real
Name
(),
column
,
connection
);
}
if
(!
operations
.
getKeysToAdd
().
isEmpty
())
{
...
...
@@ -287,9 +287,9 @@ public abstract class DBBrokerTemplate implements DBBroker {
}
for
(
Key
key
:
operations
.
getKeysToAdd
())
{
// insert new keys and their key columns
insertItem
(
tapSchema
.
getName
(),
key
,
connection
);
insertItem
(
tapSchema
.
get
Real
Name
(),
key
,
connection
);
for
(
KeyColumn
keyColumn
:
key
.
getKeyColumns
())
{
insertItem
(
tapSchema
.
getName
(),
keyColumn
,
connection
);
insertItem
(
tapSchema
.
get
Real
Name
(),
keyColumn
,
connection
);
}
}
...
...
@@ -298,26 +298,26 @@ public abstract class DBBrokerTemplate implements DBBroker {
for
(
Key
key
:
operations
.
getKeysToUpdate
())
{
// update keys and their key columns
String
whereCond
=
String
.
format
(
"%s = ?"
,
escape
(
Key
.
ID_KEY
));
updateItem
(
tapSchema
.
getName
(),
key
,
connection
,
whereCond
,
key
.
getId
());
updateItem
(
tapSchema
.
get
Real
Name
(),
key
,
connection
,
whereCond
,
key
.
getId
());
for
(
KeyColumn
keyColumn
:
key
.
getKeyColumns
())
{
whereCond
=
String
.
format
(
"%s = ?"
,
escape
(
KeyColumn
.
KEY_ID_KEY
));
updateItem
(
tapSchema
.
getName
(),
keyColumn
,
connection
,
whereCond
,
keyColumn
.
getKeyId
());
updateItem
(
tapSchema
.
get
Real
Name
(),
keyColumn
,
connection
,
whereCond
,
keyColumn
.
getKeyId
());
}
}
for
(
Schema
schema
:
operations
.
getSchemasToUpdate
())
{
String
whereCond
=
String
.
format
(
"%s = ?"
,
escape
(
Schema
.
SCHEMA_NAME_KEY
));
updateItem
(
tapSchema
.
getName
(),
schema
,
connection
,
whereCond
,
schema
.
getName
());
updateItem
(
tapSchema
.
get
Real
Name
(),
schema
,
connection
,
whereCond
,
schema
.
getName
());
}
for
(
Table
table
:
operations
.
getTablesToUpdate
())
{
String
whereCond
=
String
.
format
(
"%s = ?"
,
escape
(
Table
.
TABLE_NAME_KEY
));
updateItem
(
tapSchema
.
getName
(),
table
,
connection
,
whereCond
,
table
.
getCompleteName
());
updateItem
(
tapSchema
.
get
Real
Name
(),
table
,
connection
,
whereCond
,
table
.
getCompleteName
());
}
for
(
Column
column
:
operations
.
getColumnsToUpdate
())
{
String
whereCond
=
String
.
format
(
"%s = ? AND %s = ?"
,
escape
(
Column
.
TABLE_NAME_KEY
),
escape
(
Column
.
COLUMN_NAME_KEY
));
updateItem
(
tapSchema
.
getName
(),
column
,
connection
,
whereCond
,
column
.
getTableCompleteName
(),
column
.
getName
());
updateItem
(
tapSchema
.
get
Real
Name
(),
column
,
connection
,
whereCond
,
column
.
getTableCompleteName
(),
column
.
getName
());
}
}
...
...
@@ -1050,4 +1050,11 @@ public abstract class DBBrokerTemplate implements DBBroker {
}
}
}
protected
String
getExposedSchemaName
(
String
schemaName
,
String
realSchemaName
,
String
keySchemaName
)
{
if
(
keySchemaName
.
equals
(
realSchemaName
))
{
return
schemaName
;
}
return
keySchemaName
;
}
}
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/mysql/MySQLDBBroker.java
View file @
e258024b
...
...
@@ -132,7 +132,7 @@ public class MySQLDBBroker extends DBBrokerTemplate {
cm
.
put
(
Column
.
DATATYPE_KEY
,
datatype
);
cm
.
put
(
Column
.
SIZE_KEY
,
size
);
String
arraySize
=
null
;
String
arraySize
=
"*"
;
if
(
size
!=
null
)
{
arraySize
=
String
.
valueOf
(
size
);
// variable length columns must have a "*" symbol on arraysize
...
...
@@ -219,7 +219,7 @@ public class MySQLDBBroker extends DBBrokerTemplate {
}
@Override
public
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
)
throws
SQLException
{
public
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
,
String
realSchemaName
)
throws
SQLException
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"SELECT\n"
);
...
...
@@ -235,9 +235,9 @@ public class MySQLDBBroker extends DBBrokerTemplate {
sb
.
append
(
"ON c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND c.TABLE_SCHEMA = k.TABLE_SCHEMA\n"
);
sb
.
append
(
"WHERE c.CONSTRAINT_TYPE = 'FOREIGN KEY' \n"
);
sb
.
append
(
"AND k.TABLE_SCHEMA = '"
);
sb
.
append
(
s
chemaName
);
sb
.
append
(
realS
chemaName
);
sb
.
append
(
"' OR k.REFERENCED_TABLE_SCHEMA = '"
);
sb
.
append
(
s
chemaName
);
sb
.
append
(
realS
chemaName
);
sb
.
append
(
"'"
);
String
query
=
sb
.
toString
();
...
...
@@ -258,8 +258,10 @@ public class MySQLDBBroker extends DBBrokerTemplate {
String
targetTableName
=
resultSet
.
getString
(
"target_table"
);
Map
<
String
,
Object
>
keyMetadata
=
new
HashMap
<>();
keyMetadata
.
put
(
Key
.
FROM_TABLE_KEY
,
fromSchemaName
+
"."
+
fromTableName
);
keyMetadata
.
put
(
Key
.
TARGET_TABLE_KEY
,
targetSchemaName
+
"."
+
targetTableName
);
String
exposedFromSchemaName
=
getExposedSchemaName
(
schemaName
,
realSchemaName
,
fromSchemaName
);
keyMetadata
.
put
(
Key
.
FROM_TABLE_KEY
,
String
.
format
(
"%s.%s"
,
exposedFromSchemaName
,
fromTableName
));
String
exposedTargetSchemaName
=
getExposedSchemaName
(
schemaName
,
realSchemaName
,
targetSchemaName
);
keyMetadata
.
put
(
Key
.
TARGET_TABLE_KEY
,
String
.
format
(
"%s.%s"
,
exposedTargetSchemaName
,
targetTableName
));
Key
key
=
null
;
// Searching for a partial built key
...
...
TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java
View file @
e258024b
...
...
@@ -131,7 +131,7 @@ public class PostgresDBBroker extends DBBrokerTemplate {
}
first
=
false
;
querySb
.
append
(
cm
.
getName
());
querySb
.
append
(
escape
(
cm
.
getName
())
)
;
querySb
.
append
(
" "
);
if
(
cm
.
getEnumValues
()
==
null
)
{
...
...
@@ -283,19 +283,13 @@ public class PostgresDBBroker extends DBBrokerTemplate {
cm
.
put
(
Column
.
DATATYPE_KEY
,
datatype
);
cm
.
put
(
Column
.
SIZE_KEY
,
size
);
String
arraySize
=
null
;
String
arraySize
=
"*"
;
if
(
isArray
)
{
arraySize
=
formatArraySize
(
arraydimension
);
}
else
{
if
(
size
!=
null
)
{
arraySize
=
String
.
valueOf
(
size
);
}
}
else
if
(
size
!=
null
)
{
arraySize
=
String
.
valueOf
(
size
);
// variable length columns must have a "*" symbol on arraysize
if
(
adqlType
!=
null
&&
ADQL
.
isVariable
(
adqlType
))
{
if
(
arraySize
==
null
)
{
arraySize
=
""
;
}
arraySize
+=
"*"
;
}
}
...
...
@@ -310,7 +304,7 @@ public class PostgresDBBroker extends DBBrokerTemplate {
}
@Override
public
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
)
throws
SQLException
{
public
List
<
Key
>
getKeys
(
TapSchema
tapSchema
,
String
schemaName
,
String
realSchemaName
)
throws
SQLException
{
StringBuilder
queryKeysSb
=
new
StringBuilder
();
...
...
@@ -321,10 +315,10 @@ public class PostgresDBBroker extends DBBrokerTemplate {
queryKeysSb
.
append
(
"FROM pg_catalog.pg_constraint\n"
);
queryKeysSb
.
append
(
"WHERE contype = 'f'\n"
);
queryKeysSb
.
append
(
"AND ((conrelid::regclass || '' LIKE '"
);
queryKeysSb
.
append
(
s
chemaName
);
queryKeysSb
.
append
(
realS
chemaName
);
queryKeysSb
.
append
(
".%')\n"
);
queryKeysSb
.
append
(
"OR (confrelid::regclass || '' LIKE '"
);
queryKeysSb
.
append
(
s
chemaName
);
queryKeysSb
.
append
(
realS
chemaName
);
queryKeysSb
.
append
(
".%'))"
);
String
queryKeys
=
queryKeysSb
.
toString
();
...
...
@@ -341,14 +335,21 @@ public class PostgresDBBroker extends DBBrokerTemplate {
String
constraintName
=
resultSet
.
getString
(
"constraint_name"
);
String
fromTableCompleteName
=
resultSet
.
getString
(
"from_table"
);
String
[]
splitFrom
=
fromTableCompleteName
.
split
(
Pattern
.
quote
(
"."
));
String
targetTableCompleteName
=
resultSet
.
getString
(
"target_table"
);
String
[]
splitTarget
=
targetTableCompleteName
.
split
(
Pattern
.
quote
(
"."
));
String
fromSchema
=
splitFrom
[
0
];
String
fromTable
=
splitFrom
[
1
];
String
targetSchema
=
splitTarget
[
0
];
String
targetTable
=
splitTarget
[
1
];
String
f
romSchema
=
fromTableCompleteName
.
split
(
Pattern
.
quote
(
"."
))[
0
]
;
String
t
argetSchema
=
targetTableCompleteName
.
split
(
Pattern
.
quote
(
"."
))[
0
]
;
String
exposedF
romSchema
Name
=
getExposedSchemaName
(
schemaName
,
realSchemaName
,
fromSchema
)
;
String
exposedT
argetSchema
Name
=
getExposedSchemaName
(
schemaName
,
realSchemaName
,
targetSchema
)
;
Map
<
String
,
Object
>
keyMetadata
=
new
HashMap
<>();
keyMetadata
.
put
(
Key
.
FROM_TABLE_KEY
,
fromTableCompleteName
);
keyMetadata
.
put
(
Key
.
TARGET_TABLE_KEY
,
targetTableCompleteName
);
keyMetadata
.
put
(
Key
.
FROM_TABLE_KEY
,
String
.
format
(
"%s.%s"
,
exposedFromSchemaName
,
fromTable
)
);
keyMetadata
.
put
(
Key
.
TARGET_TABLE_KEY
,
String
.
format
(
"%s.%s"
,
exposedTargetSchemaName
,
targetTable
)
);
Key
key
=
new
Key
(
tapSchema
,
keyMetadata
);
keys
.
add
(
key
);
...
...
TASMAN-core/src/main/resources/core.properties
View file @
e258024b
...
...
@@ -3,5 +3,5 @@
# Comma separated list of files inside schema_definition folder.
# (It is necessary to put this list here because, unfortunately, there is no
# easy way to read an entire resource folder using the ClassLoader API).
tap_schema_models
=
tap_schema-1-IA2.xml,tap_schema-1.xml,tap_schema-1_1.xml
tap_schema_models
=
tap_schema-1-IA2.xml,tap_schema-1.xml,tap_schema-1_1.xml
,tap_schema-1_1-IA2.xml
ivoa_schema_models
=
ivoa-1_1.xml
TASMAN-core/src/main/resources/schema_definition/tap_schema-1_1-IA2.xml
0 → 100644
View file @
e258024b
<?xml version="1.0" encoding="UTF-8"?>
<!--
_____________________________________________________________________________
INAF - OATS National Institute for Astrophysics - Astronomical Observatory of
Trieste INAF - IA2 Italian Center for Astronomical Archives
_____________________________________________________________________________
Copyright (C) 2016 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.
-->
<schema
name=
"tap_schema"
version=
"1.1-IA2"
extends=
"1.1"
datatype=
"VOTable"
>
<table
name=
"schemas"
>
<column
name=
"schemaID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
<column
name=
"schemaID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
<column
name=
"dbname"
>
<type>
VARCHAR
</type>
<updatable>
false
</updatable>
<key>
dbname
</key>
<standard>
false
</standard>
</column>
</table>
<table
name=
"tables"
>
<column
name=
"tableID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
<column
name=
"dbname"
>
<type>
VARCHAR
</type>
<updatable>
false
</updatable>
<key>
dbname
</key>
<standard>
false
</standard>
</column>
</table>
<table
name=
"columns"
>
<column
name=
"columnID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
<column
name=
"id"
>
<type>
INTEGER
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
<column
name=
"dbname"
>
<type>
VARCHAR
</type>
<updatable>
false
</updatable>
<key>
dbname
</key>
<standard>
false
</standard>
</column>
</table>
<table
name=
"keys"
>
<column
name=
"keyID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
</table>
<table
name=
"key_columns"
>
<column
name=
"key_columnID"
>
<type>
BIGINT
</type>
<updatable>
true
</updatable>
<standard>
false
</standard>
</column>
</table>
</schema>
TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java
View file @
e258024b
...
...
@@ -92,7 +92,7 @@ public class TestAll {
settings
=
new
TapSchemaSettings
();
settings
.
setTapSchemaName
(
"test_tap_schema"
);
settings
.
setTapSchemaVersion
(
"1.1"
);
settings
.
setTapSchemaVersion
(
"1.1
-IA2
"
);
settings
.
setHasObscore
(
true
);
settings
.
setObscoreVersion
(
"1.1"
);
...
...
@@ -460,17 +460,23 @@ public class TestAll {
assertFalse
(
operations
.
getHasOperations
());
// Checking size and arraysize detection
Column
descriptionColumn
=
tapSchema
.
getChild
(
tapSchema
.
getName