Ejemplo n.º 1
0
 /** @see salomon.engine.task.ITaskManager#addTask(salomon.platform.task.ITask) */
 public void addTask(ITask task) throws PlatformException {
   try {
     task.getInfo().save();
     _dbManager.commit();
   } catch (Exception e) {
     _dbManager.rollback();
     LOGGER.fatal("", e);
     throw new PlatformException(e.getLocalizedMessage());
   }
   _tasks.add(task);
 }
Ejemplo n.º 2
0
 public void saveTasks() throws PlatformException {
   try {
     for (ITask task : _tasks) {
       ((Task) task).getInfo().save();
     }
     _dbManager.commit();
   } catch (Exception e) {
     _dbManager.rollback();
     LOGGER.fatal("", e);
     throw new PlatformException(e.getLocalizedMessage());
   }
 }
 public void testDelete() {
   LOGGER.debug("DescriptionTest.testDelete()");
   boolean success = false;
   // PluginInfo desc = new PluginInfo();
   // desc.setPluginID(40);
   try {
     // desc.delete();
     success = true;
     _manager.commit();
   } catch (Exception e) {
     LOGGER.fatal("", e);
     _manager.rollback();
   }
   assertTrue(success);
 }
Ejemplo n.º 4
0
 /**
  * Saves itself in data base. If already exists in database performs update otherwise inserts new
  * record. Returns current id if update was executed or new id in case of insert.
  *
  * @return unique id
  */
 public int save() throws DBException {
   SQLUpdate update = new SQLUpdate(TABLE_NAME);
   if (_name != null) {
     update.addValue("solution_name", _name);
   }
   if (_info != null) {
     update.addValue("solution_info", _info);
   }
   if (_host != null) {
     update.addValue("hostname", _host);
   }
   if (_path != null) {
     update.addValue("db_path", _path);
   }
   if (_user != null) {
     update.addValue("username", _user);
   }
   if (_passwd != null) {
     update.addValue("passwd", _passwd);
   }
   update.addValue("lm_date", new Date(System.currentTimeMillis()));
   try {
     _solutionID = _dbManager.insertOrUpdate(update, "solution_id", _solutionID, GEN_NAME);
   } catch (SQLException e) {
     LOGGER.fatal("Exception was thrown!", e);
     throw new DBException("Cannot save solution info!", e);
   }
   return _solutionID;
 }
Ejemplo n.º 5
0
 public boolean delete() throws DBException {
   SQLDelete delete = new SQLDelete(TABLE_NAME);
   delete.addCondition("solution_id =", _solutionID);
   try {
     return (_dbManager.delete(delete) > 0);
   } catch (SQLException e) {
     LOGGER.fatal("Exception was thrown!", e);
     throw new DBException("Cannot delete solution info!", e);
   }
 }
Ejemplo n.º 6
0
 /**
  * Removes given tasks.
  *
  * @see salomon.engine.task.ITaskManager#removeTask(salomon.engine.task.ITask)
  */
 public boolean removeTask(ITask task) throws PlatformException {
   SQLDelete delete = new SQLDelete(TaskInfo.TABLE_NAME);
   IProject currProject = _managerEngine.getProjectManager().getCurrentProject();
   delete.addCondition("project_id =", currProject.getInfo().getId());
   delete.addCondition("task_id = ", task.getInfo().getId());
   boolean retVal = false;
   int deletedRows = 0;
   try {
     deletedRows = _dbManager.delete(delete);
     _dbManager.commit();
     // removing from list
     _tasks.remove(task);
     retVal = (deletedRows > 0);
   } catch (SQLException e) {
     _dbManager.rollback();
     LOGGER.fatal("", e);
     throw new PlatformException(e.getLocalizedMessage());
   }
   return retVal;
 }
 public void testSave() {
   LOGGER.debug("DescriptionTest.testSave()");
   boolean success = false;
   // PluginInfo desc = new PluginInfo();
   // desc.setName("test_plugin");
   // try {
   // desc.setLocation(new URL("http://www.test_description.pl"));
   //	success = true;
   // } catch (MalformedURLException e) {
   //	LOGGER.fatal("", e);
   // }
   assertTrue(success);
   success = false;
   try {
     // desc.save();
     _manager.commit();
     success = true;
   } catch (Exception e) {
     LOGGER.fatal("", e);
     _manager.rollback();
   }
   assertTrue(success);
 }
  public boolean delete() throws PlatformException, DBException {
    SQLDelete delete = new SQLDelete();
    // deleting data set
    delete.setTable(TABLE_NAME);
    delete.addCondition("attributeset_id =", _attributeSetID);
    int rows;
    try {
      rows = _dbManager.delete(delete);
    } catch (SQLException e) {
      LOGGER.fatal("", e);
      throw new DBException("Cannot delete!", e);
    }

    LOGGER.debug("rows deleted: " + rows);
    return (rows > 0);
  }
Ejemplo n.º 9
0
  /*
   * Test method for 'salomon.engine.platform.data.dataset.Data.getData()'
   */
  public void testGetData() throws Exception {
    LOGGER.info("DataTest.testGetData()");
    SQLSelect select = new SQLSelect();
    select.addTable(SolutionInfo.TABLE_NAME);

    ResultSet resultSet = _manager.select(select);

    IData data = new Data(resultSet);

    while (data.next()) {
      Object[] dataArray = data.getData();
      StringBuilder dataString = new StringBuilder();
      for (Object d : dataArray) {
        dataString.append("|");
        dataString.append(d);
      }
      LOGGER.debug(dataString);
    }
    data.close();
  }
 public void testLoad() {
   LOGGER.debug("DescriptionTest.testLoad()");
   boolean success = false;
   SQLSelect select = new SQLSelect();
   select.addTable(PluginInfo.TABLE_NAME);
   select.addCondition("plugin_id =", 20);
   ResultSet resultSet = null;
   try {
     resultSet = _manager.select(select);
     assertNotNull(resultSet);
     success = true;
   } catch (SQLException e) {
     LOGGER.fatal("", e);
   }
   assertTrue(success);
   success = false;
   // PluginInfo desc = new PluginInfo();
   try {
     if (resultSet.next()) {
       // desc.load(resultSet);
       success = true;
     } else {
       LOGGER.debug("No data found");
       success = true;
     }
   } catch (Exception e) {
     LOGGER.fatal("", e);
   } finally {
     try {
       resultSet.close();
     } catch (SQLException ex) {
       LOGGER.fatal("", ex);
     }
   }
   assertTrue(success);
   // LOGGER.debug(desc);
 }
Ejemplo n.º 11
0
  /**
   * Returns tasks associated with current project. They are returned sorted by task_nr.
   *
   * @see salomon.engine.task.ITaskManager#getTasks()
   */
  public ITask[] getTasks() throws PlatformException {
    LinkedList<ITask> tasks = null;
    // TODO: use _project in stead of it
    IProject currProject = _managerEngine.getProjectManager().getCurrentProject();
    if (_tasks.isEmpty() && currProject != null) {
      tasks = new LinkedList<ITask>();
      SQLSelect select = new SQLSelect();
      select.addTable(TaskInfo.TABLE_NAME + " t");
      select.addTable(PluginInfo.TABLE_NAME + " p");
      select.addColumn("t.task_id");
      select.addColumn("t.task_nr");
      select.addColumn("t.project_id");
      select.addColumn("t.task_name");
      select.addColumn("t.task_info");
      select.addColumn("t.status");
      select.addColumn("t.plugin_settings");
      select.addColumn("t.plugin_result");
      select.addColumn("p.plugin_id");
      select.addColumn("p.plugin_name");
      select.addColumn("p.plugin_info");
      select.addColumn("p.location");
      int projectID = currProject.getInfo().getId();
      select.addCondition("t.project_id =", projectID);
      select.addCondition("t.plugin_id = p.plugin_id");
      // tasks are sorted by task_nr
      select.addOrderBy("t.task_nr");

      // executing query
      ResultSet resultSet = null;
      try {
        resultSet = _dbManager.select(select);
        while (resultSet.next()) {
          // TODO: Plugin info shoul not be instantied from outside of pluginManger :-/
          PluginInfo pluginInfo = new PluginInfo(_dbManager);
          pluginInfo.load(resultSet);
          LocalPlugin localPlugin =
              (LocalPlugin) _managerEngine.getPluginManager().getPlugin(pluginInfo);
          localPlugin.load();
          // FIXME: real settings should be loaded
          ISettings pluginSettings = localPlugin.getSettingComponent().getDefaultSettings();

          Task task = (Task) this.createTask();
          task.setSettings(pluginSettings);
          task.setPlugin(localPlugin);
          // loading task
          task.getInfo().load(resultSet);
          tasks.add(task);
        }
        resultSet.close();
        // if everything is OK, then loaded tasks list is assigned
        // to manager's tasks list
        _tasks = tasks;
      } catch (Exception e) {
        LOGGER.fatal("", e);
        try {
          resultSet.close();
        } catch (SQLException ex) {
          LOGGER.fatal("", ex);
        }
        throw new PlatformException(e.getLocalizedMessage());
      }
    }
    ITask[] tasksArr = new ITask[_tasks.size()];
    return _tasks.toArray(tasksArr);
  }
  public int save() throws PlatformException, DBException {
    // removing old attribute set with the same name
    SQLDelete delete = new SQLDelete();
    delete.setTable(TABLE_NAME);
    delete.addCondition("attributeset_name = ", _name);
    int rows;
    try {
      rows = _dbManager.delete(delete);
    } catch (SQLException e) {
      LOGGER.fatal("!", e);
      throw new DBException("Cannot delete!", e);
    }
    LOGGER.debug("rows deleted: " + rows);

    // saving header
    SQLUpdate update = new SQLUpdate(TABLE_NAME);
    if (_name != null) {
      update.addValue("attributeset_name", _name);
    }
    if (_info != null) {
      update.addValue("attributeset_info", _info);
    }

    if (_attributeSetID == 0) {
      update.addValue("c_date", new Date(System.currentTimeMillis()));
    }

    update.addValue("solution_id", _solutionID);
    update.addValue("lm_date", new Date(System.currentTimeMillis()));

    try {
      _attributeSetID =
          _dbManager.insertOrUpdate(update, "attributeset_id", _attributeSetID, GEN_NAME);
    } catch (SQLException e) {
      LOGGER.fatal("Exception was thrown!", e);
      throw new DBException("Cannot save!", e);
    }

    try {
      // saving items
      for (IAttributeDescription description : _descriptions) {
        // FIXME: why it can be null???
        if (description != null) {
          SQLInsert insert = new SQLInsert(ITEMS_TABLE_NAME);
          insert.addValue("attributeset_id", _attributeSetID);
          insert.addValue("attribute_name", description.getName());
          insert.addValue("attribute_type", description.getType().getDBString());
          insert.addValue("table_name", description.getColumn().getTable().getName());
          insert.addValue("column_name", description.getColumn().getName());
          insert.addValue("is_output", description.isOutput() ? "Y" : "N");
          // FIXME: workaround!
          if (description instanceof EnumAttributeDescription) {
            insert.addValue(
                "attribute_value", ((EnumAttributeDescription) description).valuesToString());
          }

          LOGGER.debug("insert: " + insert.getQuery());
          _dbManager.insert(insert, "attributeset_item_id");
        }
      }
    } catch (SQLException e) {
      LOGGER.fatal("Exception was thrown!", e);
      throw new DBException("Cannot save!", e);
    }

    return _attributeSetID;
  }
 protected void setUp() throws Exception {
   PropertyConfigurator.configure("log.conf"); // $NON-NLS-1$
   _manager = new DBManager();
   _manager.connect();
 }