public List<BookType> getAllType() { StringBuffer hql = new StringBuffer("FROM BookType bookType"); List<BookType> result = (List<BookType>) baseDao.findWithHql(hql.toString()); if (result.isEmpty()) { return null; } return result; }
public List<Book> getBooksByTypeName(String typeName) { StringBuffer hql = new StringBuffer("FROM Book book WHERE book.bookType.typeName='" + typeName + "'"); List<Book> result = (List<Book>) baseDao.findWithHql(hql.toString()); if (result.isEmpty()) { return null; } return result; }
public List<Book> getBooksByType(int typeID, Pager pager) { StringBuffer hql = new StringBuffer("FROM Book book WHERE book.bookType.typeId like '%" + typeID + "'"); String countHql = "SELECT count(book.isbn) FROM Book book WHERE book.bookType.typeId like '%" + typeID + "'"; Long count = ((List<Long>) baseDao.findWithHql(countHql)).get(0); List<Book> result; if (pager == null) { result = (List<Book>) baseDao.findWithHql(hql.toString()); } else { pager.setTotalSize(count); // 设置总页数 result = (List<Book>) baseDao.findWithHql(pager, hql.toString()); } if (result.isEmpty()) { return null; } return result; }
public BookType findByTypeId(Integer typeId) { StringBuffer hql = new StringBuffer("FROM BookType bookType WHERE bookType.typeId='" + typeId + "'"); List<BookType> result = (List<BookType>) baseDao.findWithHql(hql.toString()); if (result.isEmpty()) { return null; } BookType bookType = result.get(0); return bookType; }
public int deleteByTypeName(BookType bookType) { baseDao.delete(bookType); return 1; }
public void updateType(BookType bookType) { baseDao.update(bookType); }
public void saveType(String typeName) { BookType type = new BookType(); type.setTypeName(typeName); baseDao.save(type); }