亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? librarymanager.java

?? struts + hibernate + spring ssh 的源碼練習
?? JAVA
字號:
/*
 * Created on 25.11.2004 by HS
 * 
 */
package persistence.bl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import persistence.Book;
import persistence.Customer;
import persistence.HibernateSessionFactory;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;

/**
 * @author HS
 *
 * 
 */
public class LibraryManager {

  /**
   * get all books from the database
   * @return Array of BookValue 
   */
  public Book[] getAllBooks() {
    /* will hold the books we are going to return later */
    List books = new ArrayList();
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;
    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Query query = session
          .createQuery("select b from Book as b order by b.author, b.title");
      for (Iterator iter = query.iterate(); iter.hasNext();) {
        books.add((Book) iter.next());
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    }
    return (Book[]) books.toArray(new Book[0]);
  }

  /**
   * get book by primary key
   * @param primaryKey
   * @return a Book or null
   */
  public Book getBookByPrimaryKey(Long primaryKey) {
    /* holds our return value */
    Book book = null;
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      book = (Book) session.get(Book.class, primaryKey);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();

      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
    return book;
  }

  /**
   * sets the book as borrowed to the user specified in the database
   * @param primaryKey
   * @param userPrimaryKey
   */
  public void borrowBook(Long primaryKey, Long customerPrimaryKey) {
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Book book = (Book) session.get(Book.class, primaryKey);
      Customer customer = (Customer) session.get(Customer.class,
          customerPrimaryKey);
      if (book != null && customer != null) 
        book.setCustomer(customer);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

  /**
   * customer returns a book, relation in the db between customer and book is deleted
   * @param primaryKey
   */
  public void returnBook(Long primaryKey) {
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;
    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Book book = (Book) session.get(Book.class, primaryKey);

      if (book != null) // session.get returns null when no entry is found
          book.setCustomer(null);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

  /**
   * updates/creates a book
   * @param bookValue
   */
  public void saveBook(Book bookValue) {

    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;
    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Book book;
      if (bookValue.getId() != null && bookValue.getId().intValue() != 0) { // [laliluna] 04.12.2004 load book from DB
        book = (Book) session.get(Book.class, bookValue.getId());
        if (book != null) {
          book.setAuthor(bookValue.getAuthor());
          book.setTitle(bookValue.getTitle());
          book.setAvailable(bookValue.getAvailable());
          session.update(book);
        }
      }
      else // [laliluna] 04.12.2004 create new book
      {
        book = new Book();
        book.setAuthor(bookValue.getAuthor());
        book.setTitle(bookValue.getTitle());
        book.setAvailable(bookValue.getAvailable());
        session.save(book);
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

  /**
   * deletes a book
   * @param primaryKey
   */
  public void removeBookByPrimaryKey(Long primaryKey) {
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Book book = (Book) session.get(Book.class, primaryKey);
      if (book != null) session.delete(book);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

  /**
   * returns all customers from the db
   * @return
   */

  public Customer[] getAllCustomers() {
    /* will hold the books we are going to return later */
    List customers = new ArrayList();
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Query query = session
          .createQuery("select c from Customer as c order by c.name");
      for (Iterator iter = query.iterate(); iter.hasNext();) {
        customers.add((Customer) iter.next());
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
    return (Customer[]) customers.toArray(new Customer[0]);
  }

  /**
   * gets a customer from the db
   * @param primaryKey
   * @return the customer class or  null, when no customer is found
   */
  public Customer getCustomerByPrimaryKey(Long primaryKey) {
    /* holds our return value */
    Customer customer = null;
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      customer = (Customer) session.get(Customer.class, primaryKey);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
    return customer;
  }

  /**
   * saves the customers to the db
   * @param customer
   */
  public void saveCustomer(Customer customer) {
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;
    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      if (customer.getId() == null || customer.getId().intValue() == 0) // [laliluna] 06.12.2004 create customer 
        session.save(customer);
      else {
        Customer toBeUpdated = (Customer) session.get(Customer.class, customer
            .getId());
        toBeUpdated.setAge(customer.getAge());
        toBeUpdated.setLastname(customer.getLastname());
        toBeUpdated.setName(customer.getName());
        session.update(toBeUpdated);
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }

    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

  /**
   * deletes a customer from the database
   * @param primaryKey
   */
  public void removeCustomerByPrimaryKey(Long primaryKey) {
    /* a Hibernate session */
    Session session = null;
    /* we always need a transaction */
    Transaction tx = null;

    try {
      /* get session of the current thread */
      session = HibernateSessionFactory.currentSession();

      tx = session.beginTransaction();
      Customer customer = (Customer) session.get(Customer.class, primaryKey);
      if (customer != null) session.delete(customer);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
      // [laliluna] 17.12.2004 it is recommended to roll back the transaction after an error occured
      if (tx != null) try {
        tx.rollback();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        if (session != null) session.close();
      } catch (HibernateException e1) {
        e1.printStackTrace();
      }
    }
  }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
97精品久久久久中文字幕| 欧美精品一区二区三区久久久| 久久久久久一级片| 老色鬼精品视频在线观看播放| 欧美va亚洲va香蕉在线 | 最新日韩在线视频| 91在线视频播放| 亚洲国产欧美日韩另类综合| 欧美电影一区二区三区| 欧美a级理论片| 久久精品欧美日韩精品 | 中文字幕一区二区三| 99国产麻豆精品| 午夜欧美2019年伦理| 日韩欧美国产一区二区在线播放| 狠狠色丁香九九婷婷综合五月| 国产亚洲精品aa午夜观看| 91蜜桃传媒精品久久久一区二区| 亚洲最色的网站| 欧美岛国在线观看| 成人精品国产一区二区4080| 亚洲综合一二区| 欧美mv日韩mv国产| caoporn国产一区二区| 亚洲va欧美va人人爽| 亚洲精品一区二区精华| 99精品欧美一区二区三区小说| 午夜伊人狠狠久久| 国产女人水真多18毛片18精品视频| 91久久香蕉国产日韩欧美9色| 日韩精品色哟哟| 国产欧美日韩精品a在线观看| 欧美在线你懂的| 国产一区二区美女诱惑| 亚洲一区二区三区精品在线| 久久精品一区二区三区四区| 欧美在线视频全部完| 国产呦萝稀缺另类资源| 亚洲大片免费看| 综合激情成人伊人| 欧美大片免费久久精品三p| 91网站最新网址| 国产一区美女在线| 水蜜桃久久夜色精品一区的特点| 久久精品视频一区二区三区| 精品视频999| 成人开心网精品视频| 老司机精品视频一区二区三区| 亚洲精品久久久久久国产精华液| 久久亚洲精华国产精华液 | 欧美三区免费完整视频在线观看| 国产精品资源站在线| 日韩成人dvd| 亚洲一区二区精品视频| 国产精品嫩草久久久久| 久久先锋影音av| 日韩三级av在线播放| 精品视频在线免费| 色综合久久综合网欧美综合网| 六月丁香婷婷色狠狠久久| 午夜精品福利在线| 亚洲激情自拍视频| 中文字幕一区二区三区蜜月| 国产欧美视频一区二区| 欧美va亚洲va国产综合| 欧美一级片在线| 欧美精选午夜久久久乱码6080| 色94色欧美sute亚洲线路一ni | 亚洲三级久久久| 中文幕一区二区三区久久蜜桃| 日韩精品一区二区三区三区免费| 91精品久久久久久久久99蜜臂| 91成人在线免费观看| 91免费在线看| 色综合天天狠狠| 色一区在线观看| 色国产综合视频| 在线视频一区二区三| 日本久久一区二区三区| 色婷婷精品大视频在线蜜桃视频 | 91小视频免费看| 欧美日韩精品福利| 91成人免费电影| 色丁香久综合在线久综合在线观看| 成人app网站| 99国产精品久久久久| 99免费精品在线| 一本到不卡精品视频在线观看| 成人午夜免费视频| av影院午夜一区| 在线视频综合导航| 欧美日韩精品一区二区三区| 欧美一区二区不卡视频| 欧美sm美女调教| 国产欧美日韩精品在线| 亚洲三级电影网站| 亚洲成人黄色小说| 毛片基地黄久久久久久天堂| 国产精品影视在线| av在线播放成人| 欧美在线观看禁18| 日韩欧美在线不卡| 一级精品视频在线观看宜春院| 国产欧美日产一区| 蜜臀va亚洲va欧美va天堂| 国产综合久久久久久鬼色 | 美女mm1313爽爽久久久蜜臀| 麻豆精品蜜桃视频网站| 国产成人精品www牛牛影视| 99视频有精品| 69久久99精品久久久久婷婷| 久久久久久电影| 亚洲综合成人在线视频| 麻豆91精品91久久久的内涵| 福利视频网站一区二区三区| 欧洲色大大久久| wwwwww.欧美系列| 洋洋av久久久久久久一区| 美日韩黄色大片| 色噜噜狠狠色综合欧洲selulu | 精品美女一区二区| 中文字幕在线观看一区二区| 视频一区视频二区中文| 成人黄动漫网站免费app| 欧美精品一二三区| 中文字幕一区二区三区精华液| 日日噜噜夜夜狠狠视频欧美人| 成人免费视频播放| 91麻豆精品国产91久久久久久 | 99久久婷婷国产综合精品| 在线电影欧美成精品| 国产精品久久看| 青椒成人免费视频| 日本韩国一区二区| 久久久久久久国产精品影院| 丝袜美腿亚洲一区| 色综合久久久久综合| 久久综合五月天婷婷伊人| 亚洲成人激情av| 一本色道**综合亚洲精品蜜桃冫| 久久综合色鬼综合色| 日韩国产在线一| 色综合天天综合色综合av | 欧美日韩亚洲综合| 国产精品久久久久精k8| 国产毛片精品视频| 日韩一区国产二区欧美三区| 亚洲人成人一区二区在线观看 | 日本不卡一区二区三区高清视频| 91亚洲国产成人精品一区二区三 | 日韩一区二区精品| 午夜精品影院在线观看| 91一区一区三区| 国产精品理伦片| 成人综合在线网站| 国产欧美精品一区二区色综合朱莉| 欧美aa在线视频| 欧美一区二区三区白人| 亚洲成a人v欧美综合天堂下载| 91蝌蚪porny九色| 亚洲日本青草视频在线怡红院| 粉嫩蜜臀av国产精品网站| 精品国产精品网麻豆系列 | 亚洲激情六月丁香| 91在线一区二区三区| 亚洲三级免费电影| 日本精品一区二区三区高清 | 久久久久久免费| 激情综合色丁香一区二区| 日韩情涩欧美日韩视频| 麻豆专区一区二区三区四区五区| 91精品中文字幕一区二区三区| 午夜视频久久久久久| 欧美精品电影在线播放| 日本在线播放一区二区三区| 欧美一级在线免费| 久久草av在线| 国产亚洲婷婷免费| 成人精品鲁一区一区二区| 国产精品久久久久久福利一牛影视| av日韩在线网站| 亚洲毛片av在线| 欧洲av一区二区嗯嗯嗯啊| 亚洲国产婷婷综合在线精品| 欧美日韩不卡一区| 麻豆免费看一区二区三区| 久久久久久99久久久精品网站| 成人一区二区三区| 亚洲欧美日韩久久精品| 在线电影一区二区三区| 国产在线精品视频| 成人欧美一区二区三区视频网页| 色婷婷狠狠综合| 麻豆精品视频在线观看视频| 亚洲国产精品高清| 欧美伊人久久大香线蕉综合69 | 一区二区国产盗摄色噜噜| 欧美日韩精品免费观看视频| 久久99精品国产麻豆不卡| 国产精品国产三级国产|