Exemple #1
0
 /**
  * Change all oldDataObjectIDs to newDataObjectIDs in table "dataobjectinstance".
  *
  * @param oldDataObjectID dataobject_id that gets updated by newDataObjectID
  * @param newDataObjectID new dataobject_id that overwrites oldDataObjectID
  */
 public void migrateDataObjectInstance(int oldDataObjectID, int newDataObjectID) {
   DbDataObject dbDataObject = new DbDataObject();
   String update =
       "UPDATE dataobjectinstance "
           + "SET dataobject_id = "
           + newDataObjectID
           + " WHERE dataobject_id = "
           + oldDataObjectID;
   dbDataObject.executeUpdateStatement(update);
   String sql =
       "SELECT state_id FROM dataobjectinstance " + "WHERE dataobject_id = " + newDataObjectID;
   List<Integer> stateIds = dbDataObject.executeStatementReturnsListInt(sql, "state_id");
   for (int stateId : stateIds) {
     update =
         "UPDATE dataobjectinstance SET state_id = "
             + "(SELECT state.id FROM state WHERE olc_id = "
             + "(SELECT `dataclass_id` FROM `dataobject` "
             + "WHERE `id` = "
             + newDataObjectID
             + ") "
             + "AND name = (SELECT state.name FROM state "
             + "WHERE state.id = "
             + stateId
             + ")) "
             + "WHERE dataobject_id = "
             + newDataObjectID
             + " AND state_id = "
             + stateId;
     dbDataObject.executeUpdateStatement(update);
   }
 }
Exemple #2
0
 /**
  * Get the newest scenarioID for its modelId.
  *
  * @param scenarioID modelID of the scenario
  * @return the databaseID of the scenario for the LATEST version (we assume that the scenario with
  *     the largest id is the one of the newest version)
  */
 public int getScenarioID(long scenarioID) {
   DbDataObject dbDataObject = new DbDataObject();
   String select = "SELECT id FROM scenario " + "WHERE modelid = " + scenarioID;
   LinkedList<Integer> ids = dbDataObject.executeStatementReturnsListInt(select, "id");
   if (!ids.isEmpty()) {
     return Collections.max(ids);
   } else {
     return -1;
   }
 }
Exemple #3
0
 /**
  * Get the version of a scenario which is in the database.
  *
  * @param scenarioID databaseID of the scenario
  * @return the version of the scenario with the scenarioID (Error: -1).
  */
 public int getScenarioVersion(int scenarioID) {
   DbDataObject dbDataObject = new DbDataObject();
   String select = "SELECT modelversion FROM scenario " + "WHERE id = " + scenarioID;
   LinkedList<Integer> versions =
       dbDataObject.executeStatementReturnsListInt(select, "modelversion");
   if (versions.isEmpty()) {
     return -1;
   }
   return versions.get(0);
 }
Exemple #4
0
 /**
  * Get the databaseIDs of all dataClasses that belong to one scenario.
  *
  * @param scenarioID databaseID of the scenario
  * @return List of all databaseIDs that belong to the scenario specified by scenarioID
  */
 public List<Integer> getDataClassIDs(int scenarioID) {
   DbDataObject dbDataObject = new DbDataObject();
   String select =
       "SELECT dataclass_id " + "FROM dataobject " + "WHERE scenario_id = " + scenarioID;
   // temporaryDataClassIDs might contain duplicate entries
   List<Integer> temporaryDataClassIDs =
       dbDataObject.executeStatementReturnsListInt(select, "dataclass_id");
   List<Integer> resultDataClassIDs = new LinkedList<>();
   for (int entry : temporaryDataClassIDs) {
     if (!resultDataClassIDs.contains(entry)) {
       resultDataClassIDs.add(entry);
     }
   }
   return resultDataClassIDs;
 }
Exemple #5
0
 /**
  * Get the version of a fragment which is in the database.
  *
  * @param scenarioID databaseID of the scenario the fragment belongs to
  * @param modelID modelID of the fragment
  * @return version of the specified fragment (return -1 if there is no fragment of this id)
  */
 public int getFragmentVersion(int scenarioID, long modelID) {
   DbDataObject dbDataObject = new DbDataObject();
   String select =
       "SELECT modelversion FROM fragment "
           + "WHERE scenario_id = "
           + scenarioID
           + " AND modelid = "
           + modelID;
   LinkedList<Integer> versions =
       dbDataObject.executeStatementReturnsListInt(select, "modelversion");
   if (versions.isEmpty()) {
     return -1;
   }
   return versions.get(0);
 }
Exemple #6
0
 /**
  * Change all oldScenarioIDs to newScenarioIDs of all running instances with oldScenarioID in
  * table "scenarioinstance".
  *
  * @param oldScenarioID scenarioID that gets updated by newScenarioId
  * @param newScenarioID new scenarioID that overwrites oldScenarioId
  * @return List of all IDs that running scenarioinstances of oldScenarioID hold
  */
 public List<Integer> migrateScenarioInstance(int oldScenarioID, int newScenarioID) {
   DbDataObject dbDataObject = new DbDataObject();
   String select =
       "SELECT id "
           + "FROM scenarioinstance "
           + "WHERE scenarioinstance.terminated = 0 "
           + "AND scenario_id = "
           + oldScenarioID;
   List<Integer> runningInstances = dbDataObject.executeStatementReturnsListInt(select, "id");
   String update =
       "UPDATE scenarioinstance "
           + "SET scenario_id = "
           + newScenarioID
           + " WHERE scenarioinstance.terminated = 0 "
           + "AND scenario_id = "
           + oldScenarioID;
   dbDataObject.executeUpdateStatement(update);
   return runningInstances;
 }