Beispiel #1
0
  @Test
  public void shouldDeleteAuthor() throws Exception {
    SqlSession session = sqlMapper.openSession();
    try {
      final int id = 102;

      List<Author> authors =
          session.selectList("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", id);
      assertEquals(1, authors.size());

      int updates =
          session.delete("org.apache.ibatis.domain.blog.mappers.AuthorMapper.deleteAuthor", id);
      assertEquals(1, updates);

      authors =
          session.selectList("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", id);
      assertEquals(0, authors.size());

      session.rollback();
      authors =
          session.selectList("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", id);
      assertEquals(1, authors.size());

    } finally {
      session.close();
    }
  }
Beispiel #2
0
  /** USE THIS INSTEAD OF THE BATGEN DELETE It also deletes associated events of the object.s */
  public int delete(Long key) throws BoException {
    SqlSession session = null;
    int result = 0;
    String where = "KEY='" + key + "' ";
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("where", where);

    // first delete all events associated with this object
    EventBo.getInstance().deleteEventsOf(ItemType.SOFTWARE, key);

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      result = mapper.delete(map);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return result;
  }
Beispiel #3
0
  /**
   * Deletes all data (rows) from SOFTWARE
   *
   * @throws BoException
   */
  public void deleteAll() throws BoException {
    SqlSession session = null;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      mapper.deleteAll();
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }
  }
Beispiel #4
0
  /**
   * Get a list of software objects between (inclusive) the dates start and end.
   *
   * @param start
   * @param end
   * @return
   * @throws BoException
   */
  public List<Software> getListByPurchaseRange(Date start, Date end) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.getListByPurchaseRange(start, end);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);
    } finally {
      if (session != null) session.close();
    }

    return list;
  }
  public int update(Fda2 value) throws BoException {
    SqlSession session = null;
    int result = 0;

    try {
      session = SessionFactory.getSession();
      Fda2Dao mapper = session.getMapper(Fda2Dao.class);
      result = mapper.update(value);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return result;
  }
Beispiel #6
0
  /**
   * Get a list of software objects within a cost range
   *
   * @param minCost
   * @param maxCost
   * @return
   * @throws BoException
   */
  public List<Software> getListByCostRange(String minCost, String maxCost) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.getListByCostRange(minCost, maxCost);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return list;
  }
Beispiel #7
0
  /**
   * Retrieves max size software objects from database (Software table).
   *
   * @param size
   * @return List of software objects to populate results page for empty search bar.
   * @throws BoException
   */
  public List<Software> getDefaultResults(int size) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.getDefaultResults(size);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return list;
  }
Beispiel #8
0
  /**
   * Retrieves all software objects from database (Software table) matching search term.
   *
   * @param searchText
   * @return List of all software objects matching search term.
   * @throws BoException
   */
  public List<Software> search(String searchText) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.search(searchText);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return list;
  }
Beispiel #9
0
  public List<Software> getListByIsActive(Boolean key) throws BoException {
    SqlSession session = null;
    List<Software> list;

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.getListByIsActive(key);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return list;
  }
  public Fda2 read(Long key) throws BoException {
    SqlSession session = null;
    Fda2 result;
    String where = "KEY='" + key + "' ";
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("where", where);

    try {
      session = SessionFactory.getSession();
      Fda2Dao mapper = session.getMapper(Fda2Dao.class);
      result = mapper.read(map);
      session.commit();

    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return result;
  }
Beispiel #11
0
  /**
   * Retrieves all software objects from the database (Software table) matching search terms.
   *
   * @param columns
   * @param searches
   * @return List of all software objects matching search terms.
   * @throws BoException
   */
  public List<Software> searchAdvanced(
      ArrayList<String> columns, ArrayList<ArrayList<String>> searches) throws BoException {
    SqlSession session = null;
    List<Software> list = new ArrayList<Software>();

    if (columns.size() == 0 && searches.size() == 0) {
      return SoftwareBo.getInstance().getAll();
    }

    try {
      session = SessionFactory.getSession();
      SoftwareDao mapper = session.getMapper(SoftwareDao.class);
      list = mapper.searchAdvanced(columns, searches);
      session.commit();
    } catch (Exception e) {
      session.rollback();
      throw new BoException(e);

    } finally {
      if (session != null) session.close();
    }

    return list;
  }
Beispiel #12
0
 @Test
 public void shouldRollbackAnUnUsedSqlSession() throws Exception {
   SqlSession session = sqlMapper.openSession(TransactionIsolationLevel.SERIALIZABLE);
   session.rollback(true);
   session.close();
 }