Example #1
0
  @Override
  public void open(int run_id) throws SiriusException {
    success = false;
    if (1 != scenario.numEnsemble) logger.warn("scenario.numEnsembles != 1");
    if (null == db_scenario) throw new SiriusException("Scenario was not loaded from the database");

    logger.info("Initializing simulation run");
    Connection conn = null;
    try {
      conn = Transaction.begin();

      DataSources db_ds = new DataSources();
      db_ds.setId(DataSourcesPeer.nextId(DataSourcesPeer.ID, conn));
      db_ds.save(conn);

      Criteria crit = new Criteria();
      crit.add(ScenariosPeer.ID, db_scenario.getId());
      com.workingdogs.village.Value max_runnum =
          SimulationRunsPeer.maxColumnValue(SimulationRunsPeer.RUN_NUMBER, crit, conn);
      final long run_number = null == max_runnum ? 1 : max_runnum.asLong() + 1;
      logger.info("Run number: " + run_number);

      db_simulation_run = new com.relteq.sirius.om.SimulationRuns();
      db_simulation_run.setDataSources(db_ds);
      db_simulation_run.setScenarios(db_scenario);
      db_simulation_run.setRunNumber(run_number);
      db_simulation_run.setVersion(com.relteq.sirius.Version.get().getEngineVersion());
      db_simulation_run.setBuild("");
      db_simulation_run.setSimulationStartTime(BigDecimal.valueOf(scenario.getTimeStart()));
      db_simulation_run.setSimulationDuration(
          BigDecimal.valueOf(scenario.getTimeEnd() - scenario.getTimeStart()));
      db_simulation_run.setSimulationDt(BigDecimal.valueOf(scenario.getSimDtInSeconds()));
      db_simulation_run.setOutputDt(BigDecimal.valueOf(scenario.getOutputDt()));
      db_simulation_run.setExecutionStartTime(Calendar.getInstance().getTime());
      db_simulation_run.setStatus(-1);
      db_simulation_run.save(conn);

      Transaction.commit(conn);
      conn = null;
      success = true;
    } catch (TorqueException exc) {
      throw new SiriusException(exc);
    } catch (DataSetException exc) {
      throw new SiriusException(exc);
    } finally {
      if (null != conn) {
        Transaction.safeRollback(conn);
        db_simulation_run = null;
      }
    }
    ts = Calendar.getInstance();
    ts.set(Calendar.MILLISECOND, 0);
  }
Example #2
0
 @Override
 public void close() {
   ts = null;
   if (null != db_simulation_run) {
     db_simulation_run.setExecutionEndTime(Calendar.getInstance().getTime());
     db_simulation_run.setStatus(success ? 0 : 1);
     try {
       db_simulation_run.save();
     } catch (Exception exc) {
       logger.error("Failed to update simulation run status", exc);
     } finally {
       db_simulation_run = null;
     }
   }
 }