Exemplo n.º 1
0
 private void indexBookByYear(Book book) {
   Integer year = book.getYear();
   if (!booksByYear.containsKey(year)) {
     booksByYear.put(year, new HashSet<Book>());
   }
   booksByYear.get(year).add(book);
 }
Exemplo n.º 2
0
 public boolean insertBook(Book book) throws SQLException {
   PreparedStatement stmt =
       getConnection().prepareStatement("INSERT INTO Books(title, year) VALUES (?,?);");
   stmt.setString(1, book.getTitle());
   stmt.setInt(2, book.getYear());
   int rs = stmt.executeUpdate();
   return rs != 0;
 }
Exemplo n.º 3
0
 @Override
 public synchronized boolean removeBook(Book book) {
   boolean removed = books.remove(book);
   if (removed) {
     booksByISBN.remove(book.getIsbn());
     booksByAuthor.get(book.getAuthor()).remove(book);
     booksByYear.get(book.getYear()).remove(book);
   }
   return removed;
 }
Exemplo n.º 4
0
  private void majListBook() {
    ListView bookList = (ListView) findViewById(R.id.bookList);
    List<Map<String, String>> l_books = new ArrayList<Map<String, String>>();

    for (Book book : BookCollection.getBooks()) {
      Map<String, String> bookMap = new HashMap<String, String>();
      bookMap.put("img", String.valueOf(book.getId_img())); // use available img
      bookMap.put("author", book.getAuthor());
      bookMap.put("title", book.getTitle());
      bookMap.put("gender", book.getGender());
      bookMap.put("isbn", book.getIsbn());
      bookMap.put("year", book.getYear());
      bookMap.put("description", book.getDescription());
      l_books.add(bookMap);
    }

    SimpleAdapter listAdapter =
        new SimpleAdapter(
            this.getBaseContext(),
            l_books,
            R.layout.book_detail,
            /*ajout gender*/
            new String[] {"img", "author", "title", "gender", "isbn", "year", "description"},
            new int[] {
              R.id.img_cover,
              R.id.author,
              R.id.title,
              R.id.gender,
              R.id.isbn,
              R.id.year,
              R.id.description
            });

    bookList.setAdapter(listAdapter);
    bookList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ActionBar actionBar = getSupportActionBar();
            HashMap<String, String> map =
                (HashMap<String, String>) parent.getItemAtPosition(position);
            actionBar.setTitle(map.get("title"));
            lastItemClicked = position;
            System.out.println(position + "   " + id);
          }
        });
  }
Exemplo n.º 5
0
  public void listThem() {
    Session session = factory.openSession();
    Transaction tx = null;

    try {
      tx = session.beginTransaction();
      List books = session.createQuery("From Book").list();
      for (Iterator iterator = books.iterator(); iterator.hasNext(); ) {
        Book book = (Book) iterator.next();
        System.out.print("Title : " + book.getTitle());
        System.out.print(" Author : " + book.getAuthor());
        System.out.print(" Pages: " + book.getPages());
        System.out.print(" Year: " + book.getYear());
        System.out.println();
      }
      tx.commit();
    } catch (HibernateException e) {
      if (tx != null) tx.rollback();
      e.printStackTrace();
    } finally {
      session.close();
    }
  }
 public void addBook(String username, Book book) {
   Connection connection = null;
   try {
     connection = getConnection();
     PreparedStatement statement =
         connection.prepareStatement(
             "insert into "
                 + username
                 + " (title, author, category, year, color, level, availability)"
                 + " values (?, ?, ?, ?, ?, ?, ?)");
     statement.setString(1, book.getTitle());
     statement.setString(2, book.getAuthor());
     statement.setString(3, book.getCategory());
     statement.setInt(4, book.getYear());
     statement.setString(5, book.getColor());
     statement.setInt(6, book.getLevel());
     statement.setString(7, book.getAvailability());
     statement.executeUpdate();
   } catch (SQLException ex) {
     ex.printStackTrace();
   } finally {
     closeConnection(connection);
   }
 }