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 shouldExecuteSelectOneAuthorUsingMapperClassThatReturnsALinedHashMap() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     LinkedHashMap<String, Object> author = mapper.selectAuthorLinkedHashMap(101);
     assertEquals(101, author.get("ID"));
   } finally {
     session.close();
   }
 }
Beispiel #3
0
 @Test
 public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsAnArray() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author[] authors = mapper.selectAllAuthorsArray();
     assertEquals(2, authors.length);
   } finally {
     session.close();
   }
 }
Beispiel #4
0
 @Test
 public void shouldSelectAllPostsUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     BlogMapper mapper = session.getMapper(BlogMapper.class);
     List<Map> posts = mapper.selectAllPosts();
     assertEquals(5, posts.size());
   } finally {
     session.close();
   }
 }
Beispiel #5
0
 @Test
 public void shouldSelectAuthorsUsingMapperClass() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     List<Author> authors = mapper.selectAllAuthors();
     assertEquals(2, authors.size());
   } finally {
     session.close();
   }
 }
Beispiel #6
0
 @Test
 public void shouldExecuteSelectOneAuthorUsingMapperClass() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author author = mapper.selectAuthor(101);
     assertEquals(101, author.getId());
   } finally {
     session.close();
   }
 }
Beispiel #7
0
 @Test
 public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsLinkedList() {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Collection<Author> authors = mapper.selectAllAuthorsLinkedList();
     assertEquals(2, authors.size());
   } finally {
     session.close();
   }
 }
Beispiel #8
0
 @Test
 public void shouldSelectAuthorsUsingMapperClassWithResultHandler() {
   SqlSession session = sqlMapper.openSession();
   try {
     DefaultResultHandler handler = new DefaultResultHandler();
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     mapper.selectAllAuthors(handler);
     assertEquals(2, handler.getResultList().size());
   } finally {
     session.close();
   }
 }
Beispiel #9
0
 @Test
 public void shouldDeleteAuthorUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     int count = mapper.deleteAuthor(101);
     assertEquals(1, count);
     assertNull(mapper.selectAuthor(101));
   } finally {
     session.close();
   }
 }
Beispiel #10
0
 @Test(expected = BindingException.class)
 public void shouldFailExecutingAnAnnotatedMapperClassWithResultHandler() {
   SqlSession session = sqlMapper.openSession();
   try {
     DefaultResultHandler handler = new DefaultResultHandler();
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     mapper.selectAuthor2(101, handler);
     Author author = (Author) handler.getResultList().get(0);
     assertEquals(101, author.getId());
   } finally {
     session.close();
   }
 }
Beispiel #11
0
 @Test
 public void shouldLimitResultsUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     BlogMapper mapper = session.getMapper(BlogMapper.class);
     List<Map> posts = mapper.selectAllPosts(new RowBounds(0, 2), null);
     assertEquals(2, posts.size());
     assertEquals(1, posts.get(0).get("ID"));
     assertEquals(2, posts.get(1).get("ID"));
   } finally {
     session.close();
   }
 }
Beispiel #12
0
 @Test
 public void shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler() {
   SqlSession session = sqlMapper.openSession();
   try {
     DefaultResultHandler handler = new DefaultResultHandler();
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     mapper.selectAuthor(101, handler);
     Author author = (Author) handler.getResultList().get(0);
     assertEquals(101, author.getId());
   } finally {
     session.close();
   }
 }
Beispiel #13
0
 @Test
 public void shouldUpdateAuthorUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author expected = mapper.selectAuthor(101);
     expected.setUsername("NewUsername");
     int count = mapper.updateAuthor(expected);
     assertEquals(1, count);
     Author actual = mapper.selectAuthor(101);
     assertEquals(expected.getUsername(), actual.getUsername());
   } finally {
     session.close();
   }
 }
Beispiel #14
0
 @Test(expected = BindingException.class)
 public void shouldFailSelectOneAuthorUsingMapperClassWithTwoRowBounds() {
   Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
   configuration.addMapper(AuthorMapperWithRowBounds.class);
   SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
   SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession();
   try {
     RowBounds bounds1 = new RowBounds(0, 1);
     RowBounds bounds2 = new RowBounds(0, 1);
     AuthorMapperWithRowBounds mapper = sqlSession.getMapper(AuthorMapperWithRowBounds.class);
     mapper.selectAuthor(101, bounds1, bounds2);
   } finally {
     sqlSession.close();
   }
 }
Beispiel #15
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 #16
0
 @Test
 public void shouldInsertAuthorUsingMapperClass() throws Exception {
   SqlSession session = sqlMapper.openSession();
   try {
     AuthorMapper mapper = session.getMapper(AuthorMapper.class);
     Author expected =
         new Author(500, "cbegin", "******", "*****@*****.**", "Something...", null);
     mapper.insertAuthor(expected);
     Author actual = mapper.selectAuthor(500);
     assertNotNull(actual);
     assertEquals(expected.getId(), actual.getId());
     assertEquals(expected.getUsername(), actual.getUsername());
     assertEquals(expected.getPassword(), actual.getPassword());
     assertEquals(expected.getEmail(), actual.getEmail());
     assertEquals(expected.getBio(), actual.getBio());
   } finally {
     session.close();
   }
 }
Beispiel #17
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;
  }
Beispiel #18
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 #19
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 #20
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 #21
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 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;
  }
  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 #24
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;
  }