Beispiel #1
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 #2
0
 @Test
 public void shouldUpdateAuthorIfNecessary() throws Exception {
   SqlSession session = sqlMapper.openSession();
   Author original;
   Author updated;
   try {
     original =
         session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
     original.setEmail("*****@*****.**");
     original.setBio(null);
     int updates =
         session.update(
             "org.apache.ibatis.domain.blog.mappers.AuthorMapper.updateAuthorIfNecessary",
             original);
     assertEquals(1, updates);
     updated =
         session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
     assertEquals(original.getEmail(), updated.getEmail());
     session.commit();
   } finally {
     session.close();
   }
   try {
     session = sqlMapper.openSession();
     updated =
         session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAuthor", 101);
     assertEquals(original.getEmail(), updated.getEmail());
   } finally {
     session.close();
   }
 }
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();
    }
  }
  protected Object executeWith(DataSource dataSource, SqlSessionCallback action) {
    SqlSession sqlSession =
        getSqlSession(
            super.getSqlSessionFactory(),
            dataSource,
            super.getExecutorType(),
            super.getPersistenceExceptionTranslator());
    try {

      Object result = action.doInSession(sqlSession);
      if (!SqlSessionUtils.isSqlSessionTransactional(sqlSession, super.getSqlSessionFactory())) {
        sqlSession.commit();
      }
      return result;
    } finally {
      SqlSessionUtils.closeSqlSession(sqlSession, super.getSqlSessionFactory());
    }
  }
Beispiel #5
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 #7
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 #8
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 #9
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 #10
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;
  }
Beispiel #11
0
 @Test
 public void shouldCacheAllAuthors() throws Exception {
   int first = -1;
   int second = -1;
   SqlSession session = sqlMapper.openSession();
   try {
     List<Author> authors = session.selectList("com.domain.CachedAuthorMapper.selectAllAuthors");
     first = System.identityHashCode(authors);
     session.commit(); // commit should not be required for read/only
     // activity.
   } finally {
     session.close();
   }
   session = sqlMapper.openSession();
   try {
     List<Author> authors = session.selectList("com.domain.CachedAuthorMapper.selectAllAuthors");
     second = System.identityHashCode(authors);
   } finally {
     session.close();
   }
   assertEquals(first, second);
 }
  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 #13
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 #14
0
 @Test
 public void shouldCommitAnUnUsedSqlSession() throws Exception {
   SqlSession session = sqlMapper.openSession(TransactionIsolationLevel.SERIALIZABLE);
   session.commit(true);
   session.close();
 }