Newer
Older
ps.setString(1, table);
LOG.debug("Executing query {} [{}]", query, table);
ps.executeUpdate();
}
}
for (String schema : consistencyChecks.getUnexisingSchemas()) {
query = String.format("DELETE FROM %s.%s WHERE table_name LIKE ?", tapSchemaNameEscaped, escape(TapSchema.COLUMNS_TABLE));
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(1, schema + "%");
LOG.debug("Executing query {} [{}%]", query, schema);
ps.executeUpdate();
}
}
// Removing all tables
for (String table : consistencyChecks.getUnexistingTables()) {
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
query = String.format("DELETE FROM %s.%s WHERE table_name = ?", tapSchemaNameEscaped, escape(TapSchema.TABLES_TABLE));
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(1, table);
LOG.debug("Executing query {} [{}]", query, table);
ps.executeUpdate();
}
}
for (String schema : consistencyChecks.getUnexisingSchemas()) {
query = String.format("DELETE FROM %s.%s WHERE schema_name = ?", tapSchemaNameEscaped, escape(TapSchema.TABLES_TABLE));
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(1, schema);
LOG.debug("Executing query {} [{}]", query, schema);
ps.executeUpdate();
}
}
// Removing all schemas
for (String schema : consistencyChecks.getUnexisingSchemas()) {
query = String.format("DELETE FROM %s.%s WHERE schema_name = ?", tapSchemaNameEscaped, escape(TapSchema.SCHEMAS_TABLE));
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(1, schema);
LOG.debug("Executing query {} [{}]", query, schema);
ps.executeUpdate();
}
}
conn.commit();
} catch (SQLException e) {
LOG.error("Exception detected. Executing rollback!", e);
try {
conn.rollback();
conn.setAutoCommit(true);
} catch (SQLException er) {
LOG.error("Exception during rollback", er);
throw er;
}
}
}
}
/**
* {@inheritDoc}
*/
@Override
public void updateTapSchemaColumnValue(String tapSchemaName, String completeTableName, String columnName, String key, Object value) throws SQLException {
String query = String.format("UPDATE %s.%s SET %s = ? WHERE table_name = ? and column_name = ?",
escape(tapSchemaName), escape(TapSchema.COLUMNS_TABLE), escape(key));
try (Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(query)) {
LOG.debug("Executing query {} [{}, {}, {}]", query, value, completeTableName, columnName);
ps.setObject(1, value);
ps.setString(2, completeTableName);
ps.setString(3, columnName);
ps.executeUpdate();
}
}
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
protected String getEnumDefinition(List<String> enumValues) {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String enumValue : enumValues) {
if (!first) {
sb.append(',');
}
sb.append(String.format("'%s'", enumValue));
first = false;
}
return sb.toString();
}
private String getCheckConstraint(ColumnModel columnModel) {
if (columnModel.getMinValue() != null && columnModel.getMaxValue() != null) {
return String.format("CHECK (%s >= %s AND %s <= %s)", columnModel.getName(),
columnModel.getMinValue(), columnModel.getName(), columnModel.getMaxValue());
} else if (columnModel.getMinValue() != null && columnModel.getMaxValue() == null) {
return String.format("CHECK (%s >= %s)", columnModel.getName(), columnModel.getMinValue());
} else if (columnModel.getMinValue() == null && columnModel.getMaxValue() != null) {
return String.format("CHECK (%s <= %s)", columnModel.getName(), columnModel.getMaxValue());
}
return null;
}
protected void appendCheckConstraints(StringBuilder querySb, TableModel tableModel) {
for (ColumnModel cm : tableModel.getColumns()) {
String checkConstraint = getCheckConstraint(cm);
if (checkConstraint != null) {
querySb.append(",\n");
querySb.append(checkConstraint);
}
}
}
protected String getExposedSchemaName(String schemaName, String realSchemaName, String keySchemaName) {
if (keySchemaName.equals(realSchemaName)) {
return schemaName;
}
return keySchemaName;
}
protected String getArraysize(ADQL adqlType, Integer size) {
String arraySize = null;
if (size != null) {
arraySize = String.valueOf(size);
}
if (adqlType != null && ADQL.isVariable(adqlType)) {
// variable length columns must have a "*" symbol on arraysize
if (arraySize == null) {
arraySize = "*";
} else {
arraySize += "*";
}
}
return arraySize;
}