Skip to content

Commit

Permalink
minor fixes for tap_schema internal flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Sep 12, 2024
1 parent 715293b commit db3b2df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class TapSchemaDAOTest {
private static final Logger log = Logger.getLogger(TapSchemaDAOTest.class);

static {
Log4jInit.setLevel("ca.nrc.cadc.tap.schema", Level.INFO);
Log4jInit.setLevel("ca.nrc.cadc.tap.schema", Level.DEBUG);
Log4jInit.setLevel("ca.nrc.cadc.db.version", Level.INFO);
}

Expand All @@ -116,8 +116,10 @@ public TapSchemaDAOTest() {
log.info("configured data source: " + cc.getServer() + "," + cc.getDatabase() + "," + cc.getDriver() + "," + cc.getURL());

// init creates the tap_schema tables and populates with self-describing content
log.info("InitDatabaseTS: START");
InitDatabaseTS init = new InitDatabaseTS(dataSource, "cadctest", "tap_schema");
init.doInit();
log.info("InitDatabaseTS: OK");

// add test schema so other test content will satisfy FK constraints
TapSchemaDAO dao = new TapSchemaDAO();
Expand All @@ -130,6 +132,11 @@ public TapSchemaDAOTest() {
}
}

@Test
public void noop() {

}

@Test
public void testReadTapSchemaSelf() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public class InitDatabaseTS extends InitDatabase {
private static final Logger log = Logger.getLogger(InitDatabaseTS.class);

public static final String MODEL_NAME = "TAP_SCHEMA";
public static final String MODEL_VERSION = "1.2.0";
public static final String PREV_MODEL_VERSION = "1.1.6";
public static final String MODEL_VERSION = "1.2.1";
public static final String PREV_MODEL_VERSION = "1.2.0";

static String[] CREATE_SQL = new String[] {
"tap_schema.ModelVersion.sql",
Expand All @@ -92,7 +92,7 @@ public class InitDatabaseTS extends InitDatabase {
};

static String[] UPGRADE_SQL = new String[]{
"tap_schema.upgrade-1.2.0.sql"
"tap_schema.upgrade-1.2.1.sql"
};

public InitDatabaseTS(DataSource dataSource, String database, String schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public class TapSchemaDAO {
protected String keysTableName = "tap_schema.keys" + TAP_VERSION;
protected String keyColumnsTableName = "tap_schema.key_columns" + TAP_VERSION;

private String[] tsSchemaCols = new String[] { "description", "utype", "schema_index", "schema_name" };
private String[] tsSchemaCols = new String[] {
"description", "utype", "schema_index", "api_created", "schema_name" };
protected String orderSchemaClause = " ORDER BY schema_name";

private String[] tsTablesCols = new String[] { "table_type", "description", "utype", "table_index", "schema_name",
"table_name" };
private String[] tsTablesCols = new String[] {
"schema_name", "table_type", "description", "utype", "table_index", "api_created", "table_name" };
protected String orderTablesClause = " ORDER BY schema_name,table_index,table_name";

private String[] tsColumnsCols = new String[] { "description", "utype", "ucd", "unit", "datatype", "arraysize",
Expand All @@ -144,9 +145,6 @@ public class TapSchemaDAO {
protected static String readWriteCol = "read_write_group";
private static String[] accessControlCols = new String[] { ownerCol, readAnonCol, readOnlyCol, readWriteCol };

// api_created is in the tables and schemas schema, but not exposed as a tap_schema column
private static String apiCreated = "api_created";

protected Job job;
protected DataSource dataSource;
private boolean ordered;
Expand Down Expand Up @@ -778,7 +776,6 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
StringBuilder sb = new StringBuilder();
sb.append("SELECT ").append(toCommaList(tsSchemaCols, 0));
sb.append(",").append(toCommaList(accessControlCols, 0));
sb.append(",").append(apiCreated);
sb.append(" FROM ").append(tap_schema_tab);

if (schemaName != null) {
Expand Down Expand Up @@ -823,7 +820,6 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
StringBuilder sb = new StringBuilder();
sb.append("SELECT ").append(toCommaList(tsTablesCols, 0));
sb.append(",").append(toCommaList(accessControlCols, 0));
sb.append(",").append(apiCreated);
sb.append(" FROM ").append(tap_schema_tab);

if (tableName != null) {
Expand Down Expand Up @@ -1103,20 +1099,16 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
sb.append("UPDATE ").append(schemasTableName);
sb.append(" SET (");
sb.append(toCommaList(tsSchemaCols, 1));
sb.append(",").append(apiCreated);
sb.append(") = (");
sb.append(toParamList(tsSchemaCols, 1));
sb.append(",?");
sb.append(")");
sb.append(" WHERE schema_name=?");
} else {
sb.append("INSERT INTO ").append(schemasTableName);
sb.append(" (");
sb.append(toCommaList(tsSchemaCols, 0));
sb.append(",").append(apiCreated);
sb.append(") VALUES (");
sb.append(toParamList(tsSchemaCols, 0));
sb.append(",?");
sb.append(")");
}
String sql = sb.toString();
Expand All @@ -1129,8 +1121,8 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
safeSetString(sb, ps, col++, schema.description);
safeSetString(sb, ps, col++, schema.utype);
safeSetInteger(sb, ps, col++, schema.schema_index);
safeSetString(sb, ps, col++, schema.getSchemaName());
safeSetBoolean(sb, ps, col++, schema.apiCreated);
safeSetString(sb, ps, col++, schema.getSchemaName());

return ps;
}
Expand All @@ -1154,21 +1146,17 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
if (update) {
sb.append("UPDATE ").append(tablesTableName);
sb.append(" SET (");
sb.append(toCommaList(tsTablesCols, 2));
sb.append(",").append(apiCreated);
sb.append(toCommaList(tsTablesCols, 1));
sb.append(") = (");
sb.append(toParamList(tsTablesCols, 2));
sb.append(",?");
sb.append(toParamList(tsTablesCols, 1));
sb.append(")");
sb.append(" WHERE schema_name=? AND table_name=?");
sb.append(" WHERE table_name=?");
} else {
sb.append("INSERT INTO ").append(tablesTableName);
sb.append(" (");
sb.append(toCommaList(tsTablesCols, 0));
sb.append(",").append(apiCreated);
sb.append(") VALUES (");
sb.append(toParamList(tsTablesCols, 0));
sb.append(",?");
sb.append(")");
}
String sql = sb.toString();
Expand All @@ -1178,13 +1166,13 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
// load values: description, utype, schema_name, table_name, api_created
sb = new StringBuilder();
int col = 1;
safeSetString(sb, ps, col++, table.getSchemaName());
safeSetString(sb, ps, col++, table.tableType.getValue());
safeSetString(sb, ps, col++, table.description);
safeSetString(sb, ps, col++, table.utype);
safeSetInteger(sb, ps, col++, table.tableIndex);
safeSetString(sb, ps, col++, table.getSchemaName());
safeSetString(sb, ps, col++, table.getTableName());
safeSetBoolean(sb, ps, col++, table.apiCreated);
safeSetString(sb, ps, col++, table.getTableName());

return ps;
}
Expand Down Expand Up @@ -1522,11 +1510,12 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {

schemaDesc.description = rs.getString("description");
schemaDesc.utype = rs.getString("utype");

schemaDesc.schema_index = rs.getInt("schema_index");
schemaDesc.apiCreated = rs.getInt("api_created") == 1;

if (tapPermissionsMapper != null) {
schemaDesc.tapPermissions = tapPermissionsMapper.mapRow(rs, rowNum);
}
schemaDesc.apiCreated = rs.getInt("api_created") == 1;

return schemaDesc;
}
Expand All @@ -1550,12 +1539,13 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
tableDesc.tableType = TableDesc.TableType.toValue(rs.getString("table_type"));
tableDesc.description = rs.getString("description");
tableDesc.utype = rs.getString("utype");

tableDesc.tableIndex = rs.getInt("table_index");
tableDesc.apiCreated = rs.getInt("api_created") == 1;

if (tapPermissionsMapper != null) {
tableDesc.tapPermissions = tapPermissionsMapper.mapRow(rs, rowNum);
}
tableDesc.apiCreated = rs.getInt("api_created") == 1;


return tableDesc;
}
}
Expand Down Expand Up @@ -1585,7 +1575,8 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
col.indexed = intToBoolean(rs.getInt("indexed"));
col.std = intToBoolean(rs.getInt("std"));
col.id = rs.getString("id");

col.column_index = rs.getInt("column_index");

return col;
}

Expand Down
4 changes: 2 additions & 2 deletions cadc-tap-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.1.24'
version = '1.1.25'

description = 'OpenCADC TAP-1.1 tap server library'
def git_url = 'https://github.com/opencadc/tap'
Expand All @@ -23,7 +23,7 @@ dependencies {

implementation 'org.opencadc:cadc-util:[1.6,)'
implementation 'org.opencadc:cadc-tap:[1.1.0,1.2)'
implementation 'org.opencadc:cadc-tap-schema:[1.1.28,1.2)'
implementation 'org.opencadc:cadc-tap-schema:[1.1.28,)'
implementation 'org.opencadc:cadc-vosi:[1.4.2,)'
implementation 'org.opencadc:cadc-dali:[1.2.5,)'
implementation 'org.opencadc:cadc-registry:[1.4,)'
Expand Down

0 comments on commit db3b2df

Please sign in to comment.