Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CADC-13694 added created boolean column to tap_schema.tables #173

Merged
merged 8 commits into from
Sep 10, 2024
4 changes: 2 additions & 2 deletions cadc-tap-schema/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.1.33'
version = '1.2.0'
pdowler marked this conversation as resolved.
Show resolved Hide resolved

description = 'OpenCADC TAP-1.1 tap schema server library'
def git_url = 'https://github.com/opencadc/tap'
Expand All @@ -34,7 +34,7 @@ dependencies {
compile 'org.opencadc:cadc-cdp:[1.2.3,2.0)'
compile 'org.opencadc:cadc-gms:[1.0,2.0)'
compile 'org.opencadc:cadc-rest:[1.3.1,2.0)'
compile 'org.opencadc:cadc-tap:[1.1,2.0)'
compile 'org.opencadc:cadc-tap:[1.1.17,2.0)'
compile 'uk.ac.starlink:jcdf:[1.2.3,2.0)'
compile 'uk.ac.starlink:stil:[4.0,5.0)'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,12 @@

import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.auth.IdentityManager;
import ca.nrc.cadc.cred.client.CredUtil;
import ca.nrc.cadc.db.DatabaseTransactionManager;
import ca.nrc.cadc.net.ResourceNotFoundException;
import ca.nrc.cadc.profiler.Profiler;
import ca.nrc.cadc.reg.Standards;
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.uws.Job;

import java.net.URI;
import java.security.AccessControlException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -96,9 +90,7 @@
import javax.security.auth.Subject;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.opencadc.gms.GroupClient;
import org.opencadc.gms.GroupURI;
import org.opencadc.gms.GroupUtil;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.RowMapper;
Expand Down Expand Up @@ -152,6 +144,9 @@ 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 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 @@ -480,7 +475,7 @@ public void put(TableDesc td) {
jdbc.update(pts);
prof.checkpoint("put-table");

// add/remove columns not supported so udpate flag is same for the table and
// add/remove columns not supported so update flag is same for the table and
// column(s)
PutColumnStatement pcs = new PutColumnStatement(update);
for (ColumnDesc cd : td.getColumnDescs()) {
Expand Down Expand Up @@ -827,6 +822,7 @@ 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 @@ -1161,8 +1157,10 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
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,6 +1176,10 @@ public PreparedStatement createPreparedStatement(Connection conn) throws SQLExce
safeSetInteger(sb, ps, col++, table.tableIndex);
safeSetString(sb, ps, col++, table.getSchemaName());
safeSetString(sb, ps, col++, table.getTableName());
// created set only in a PUT
pdowler marked this conversation as resolved.
Show resolved Hide resolved
if (!update) {
safeSetBoolean(sb, ps, col++, table.created);
}

return ps;
}
Expand Down Expand Up @@ -1546,6 +1548,7 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
if (tapPermissionsMapper != null) {
tableDesc.tapPermissions = tapPermissionsMapper.mapRow(rs, rowNum);
}
tableDesc.created = rs.getInt("api_created") == 1;

return tableDesc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import ca.nrc.cadc.profiler.Profiler;
import ca.nrc.cadc.rest.RestAction;
import ca.nrc.cadc.tap.db.TableCreator;
import ca.nrc.cadc.tap.schema.TableDesc;
import ca.nrc.cadc.tap.schema.TapSchemaDAO;
import java.security.AccessControlException;
import javax.sql.DataSource;
Expand Down Expand Up @@ -118,8 +119,13 @@ public void doAction() throws Exception {

// drop table
TableCreator tc = new TableCreator(ds);
tc.dropTable(tableName);
prof.checkpoint("delete-table");
// if the table was created with the API, drop the table,
// otherwise only delete the table from the tap_schema
TableDesc tableDesc = ts.getTable(tableName);
if (tableDesc.created) {
tc.dropTable(tableName);
prof.checkpoint("delete-table");
}

// remove from tap_schema last to minimise locking
ts.delete(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ private void createTable(TapSchemaDAO ts, String schemaName, String tableName) t
if (td != null) {
throw new ResourceAlreadyExistsException("table " + tableName + " already exists");
}
// flag table as created using the API to allow table deletion in the DeleteAction
td.created = true;

Profiler prof = new Profiler(PutAction.class);
DatabaseTransactionManager tm = new DatabaseTransactionManager(ds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--
-- upgrade from 1.2.0 to 1.2.1
-- add api_created to flag a table created using the TAP API

alter table tap_schema.tables11 add column api_created integer;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ create table tap_schema.tables11
read_only_group varchar(128),
read_write_group varchar(128),

-- extension: flag to indicate if a table was created using a Tap service API
api_created integer,
pdowler marked this conversation as resolved.
Show resolved Hide resolved

primary key (table_name),
foreign key (schema_name) references tap_schema.schemas11 (schema_name)
)
Expand Down
2 changes: 1 addition & 1 deletion cadc-tap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply from: '../opencadc.gradle'
sourceCompatibility = 1.8

group = 'org.opencadc'
version = '1.1.16'
version = '1.1.17'

description = 'OpenCADC TAP-1.1 tap client library'
def git_url = 'https://github.com/opencadc/tap'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class TableDesc
public Integer tableIndex;
public TableType tableType = TableType.TABLE;
public TapPermissions tapPermissions;
public Boolean created;
pdowler marked this conversation as resolved.
Show resolved Hide resolved

public enum TableType {
TABLE("table"),
Expand Down
Loading