From 8a41592743d47f88188f742a2e4cb009248efc6d Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Tue, 30 Apr 2024 09:03:25 -0400 Subject: [PATCH] Set schema before backup is attempted --- .../org/gusdb/wdk/model/fix/table/TableRowUpdater.java | 4 ++++ .../fix/table/edaanalysis/AbstractAnalysisUpdater.java | 2 +- .../fix/table/edaanalysis/AnalysisRecordFactory.java | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Model/src/main/java/org/gusdb/wdk/model/fix/table/TableRowUpdater.java b/Model/src/main/java/org/gusdb/wdk/model/fix/table/TableRowUpdater.java index aee4046a3..eeda0e470 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/fix/table/TableRowUpdater.java +++ b/Model/src/main/java/org/gusdb/wdk/model/fix/table/TableRowUpdater.java @@ -230,6 +230,10 @@ private ExitStatus run() { Set tables = _writers.stream() .map(writer -> writer.getTableNamesForBackup(userSchema)) .flatMap(Collection::stream) + .peek(name -> { + if (name == null) + throw new RuntimeException(getClass().getName() + " returned a null table name for backup."); + }) .collect(Collectors.toSet()); // create backup tables backUpTables(userDb.getDataSource(), tables); diff --git a/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AbstractAnalysisUpdater.java b/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AbstractAnalysisUpdater.java index 328c7a7a0..0301da198 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AbstractAnalysisUpdater.java +++ b/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AbstractAnalysisUpdater.java @@ -23,7 +23,7 @@ public void configure(WdkModel wdkModel, List additionalArgs) throws Exc @Override public TableRowUpdater getTableRowUpdater(WdkModel wdkModel) { - AnalysisRecordFactory factory = new AnalysisRecordFactory(); + AnalysisRecordFactory factory = new AnalysisRecordFactory(wdkModel.getProjectId()); return new TableRowUpdater(factory, factory, this, wdkModel); } diff --git a/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AnalysisRecordFactory.java b/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AnalysisRecordFactory.java index 61b1dbc13..12cf39c8a 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AnalysisRecordFactory.java +++ b/Model/src/main/java/org/gusdb/wdk/model/fix/table/edaanalysis/AnalysisRecordFactory.java @@ -20,14 +20,17 @@ public class AnalysisRecordFactory implements TableRowFactory, Tabl private String _schema; - @Override - public String getRecordsSql(String schema, String projectId) { - // reset schema based on project (userdb schema is not where eda data lives + public AnalysisRecordFactory(String projectId) { + // set schema based on project (userdb schema is not where eda data lives switch(projectId) { case "ClinEpiDB": _schema = "edauserce"; break; case "MicrobiomeDB": _schema = "edausermb"; break; default: _schema = "edauservb"; break; } + } + + @Override + public String getRecordsSql(String schema, String projectId) { return "select analysis_id, study_id, analysis_descriptor, num_filters, num_computations, num_visualizations" + " from " + _schema + ".analysis";