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

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

?? librarytest.java

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

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

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

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 LibraryTest {

  private Session session;

  private Logger log = Logger.getLogger(this.getClass());

  public static void main(String[] args) {
    /*
     * hibernate needs log4j. Either specify a log4j.properties file
     *
     * PropertyConfigurator.configure("D:\\_projekte\\workspace\\LibraryPersistence\\src\\log4j.properties");
     * 
     * or alternatively make the following to create a standard configuration
     * BasicConfigurator.configure();
     */
    BasicConfigurator.configure();

    try {
      LibraryTest libraryTest = new LibraryTest();
      libraryTest.setSession(HibernateSessionFactory.currentSession());

      libraryTest.createBook();
      libraryTest.createCustomer();
      libraryTest.createRelation();
      libraryTest.deleteCustomer();
      libraryTest.listBooks();
      // [laliluna] 20.12.2004 always close the session at the end
      libraryTest.getSession().close();
    } catch (HibernateException e) {
      e.printStackTrace();
    }

  }

  /**
   * creates a book and saves it to the db.
   *
   */
  private void createBook() {
    System.out.println("############# create book");
    try {
      Transaction tx = session.beginTransaction();
      Book book = new Book();
      book.setAuthor("Karl");
      book.setTitle("Karls biography");
      session.save(book);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    }
  }

  /**
   * creates a user and saves it to the db
   *
   */
  private void createCustomer() {
    System.out.println("############# create user");
    try {
      Transaction tx = session.beginTransaction();
      Customer customer = new Customer();
      customer.setLastname("Fitz");
      customer.setName("John");
      customer.setAge(new Integer(25));
      session.save(customer);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    }

  }

  /**
   * creates a book and a user + a relation between the two
   *
   */
  private void createRelation() {
    System.out.println("############# create relation");
    try {
      Transaction tx = session.beginTransaction();

      Customer customer = new Customer();
      customer.setLastname("Schmidt");
      customer.setName("Jim");
      customer.setAge(new Integer(25));
      /* IMPORTANT You must save the customer first, before you can assign him to the book.
       * Hibernate creates and reads the ID only when you save the entry. 
       * The ID is needed as it is the foreign key
       */
      session.save(customer);

      Book book = new Book();
      book.setAuthor("Gerhard Petter");
      book.setTitle("Gerhards biography");

      session.save(book);
      Book book2 = new Book();
      book2.setAuthor("Karl May");
      book2.setTitle("Wildes Kurdistan");
      session.save(book2);
      session.flush();

      book.setCustomer(customer);
      book2.setCustomer(customer);
      tx.commit();

      // [laliluna] 20.12.2004 the customer is not updated automatically, so we have to refresh him
      session.refresh(customer);

      tx = session.beginTransaction();
      if (customer.getBooks() != null) {
        System.out.println("list books");

        for (Iterator iter = customer.getBooks().iterator(); iter.hasNext();) {
          Book element = (Book) iter.next();
          System.out.println("customer:" + element.getCustomer());
          System.out.println("customer is now:" + element.getCustomer());
        }
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    }

  }

  private void deleteCustomer() {
    System.out.println("############# delete customer");
    try {
      Transaction tx = session.beginTransaction();

      Customer customer = new Customer();
      customer.setLastname("Wumski");
      customer.setName("Gerhard");
      customer.setAge(new Integer(25));
      /* IMPORTANT You must save the customer first, before you can assign him to the book.
       * Hibernate creates and reads the ID only when you save the entry. 
       * The ID is needed as it is the foreign key
       */
      session.save(customer);

      Book book = new Book();
      book.setAuthor("Tim Tom");
      book.setTitle("My new biography");
      session.save(book);
      book.setCustomer(customer);
      tx.commit();

      // [laliluna] 20.12.2004 and now we are going to delete the customer which will set the foreign key in the book table to null
      tx = session.beginTransaction();
      //    [laliluna] 20.12.2004 the customer is not updated automatically, so we have to refresh him
      session.refresh(customer);
      session.delete(customer);
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    }

  }

  /**
   * lists all books in the db
   *
   */
  private void listBooks() {
    System.out.println("####### list customers");
    Query query;
    Transaction tx;
    try {
      tx = session.beginTransaction();
      query = session.createQuery("select c from Customer as c");
      for (Iterator iter = query.iterate(); iter.hasNext();) {
        Customer element = (Customer) iter.next();
        List list = element.getBooks();
        System.out.println(element.getName());
        if (list == null)
          System.out.println("list = null");
        else {
          for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            Book book = (Book) iterator.next();
            System.out.println(book.getAuthor());
          }
        }
        System.out.println(element);
      }
      tx.commit();
    } catch (HibernateException e1) {
      e1.printStackTrace();
    }
    System.out.println("####### list books");
    try {
      tx = session.beginTransaction();
      query = session.createQuery("select b from Book as b");
      for (Iterator iter = query.iterate(); iter.hasNext();) {
        System.out.println((Book) iter.next());
      }
      tx.commit();
    } catch (HibernateException e) {
      e.printStackTrace();
    }
  }

  /**
   * @return Returns the session.
   */
  public Session getSession() {
    return session;
  }

  /**
   * @param session The session to set.
   */
  public void setSession(Session session) {
    this.session = session;
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人综合在线| 亚洲一区二区三区中文字幕 | 亚洲色欲色欲www| 久久精品视频网| 久久久久久亚洲综合影院红桃| 欧美一区二区精品在线| 5566中文字幕一区二区电影| 欧美日韩国产中文| 91精品国产综合久久精品麻豆| 欧美精品vⅰdeose4hd| 欧美日韩国产综合一区二区| 欧美精品日韩精品| 欧美大片在线观看| 2017欧美狠狠色| 国产精品色婷婷| 一区二区三区四区视频精品免费 | 中文字幕视频一区| 中文字幕亚洲欧美在线不卡| 一区二区三区在线视频观看58| 亚洲一区二区在线观看视频| 午夜伦欧美伦电影理论片| 日本不卡在线视频| 国产一区二区在线看| 成人app软件下载大全免费| 国产精品一二三在| 94色蜜桃网一区二区三区| 欧美日韩精品一区二区三区四区| 91精品国产福利| 国产欧美精品一区aⅴ影院| 亚洲美腿欧美偷拍| 蜜臀av一区二区三区| 国产成人免费在线观看不卡| 成人久久久精品乱码一区二区三区 | 亚洲大型综合色站| 午夜精品福利一区二区三区av | 天天影视色香欲综合网老头| 日本欧美肥老太交大片| 国产不卡视频一区二区三区| 色婷婷亚洲综合| 精品欧美久久久| 亚洲美女淫视频| 美女尤物国产一区| 不卡区在线中文字幕| 欧亚洲嫩模精品一区三区| 精品三级av在线| 一色屋精品亚洲香蕉网站| 日韩高清在线观看| av高清久久久| 精品99一区二区| 亚洲r级在线视频| 成人91在线观看| 久久网站热最新地址| 亚洲国产视频直播| 97超碰欧美中文字幕| 26uuu亚洲| 日日嗨av一区二区三区四区| 99re免费视频精品全部| 久久久久久99精品| 蜜臀av在线播放一区二区三区| 欧美性一区二区| 亚洲乱码国产乱码精品精小说| 国产精品一区久久久久| 91精品国产综合久久久蜜臀粉嫩| 一区二区三区四区亚洲| 91影视在线播放| 国产精品每日更新在线播放网址| 紧缚奴在线一区二区三区| 欧美日韩精品高清| 午夜精品福利一区二区三区av| 91日韩精品一区| 欧美国产禁国产网站cc| 国产专区综合网| 久久―日本道色综合久久| 久久99热狠狠色一区二区| 日韩欧美国产wwwww| 免费在线观看不卡| 日韩午夜激情电影| 麻豆传媒一区二区三区| 日韩欧美一区电影| 精品一区二区三区在线播放| 精品国产伦一区二区三区观看方式 | 欧美性猛交xxxx乱大交退制版| 亚洲欧美日韩久久| 91极品视觉盛宴| 亚洲一区二区三区四区在线免费观看| 99久久精品99国产精品| 亚洲精品国产无天堂网2021| 欧洲一区在线观看| 亚洲成av人影院| 日韩亚洲欧美在线观看| 国产在线精品一区二区不卡了 | 日韩欧美综合一区| 久久不见久久见免费视频7| 日韩女优av电影在线观看| 国产一区不卡精品| 国产精品嫩草影院av蜜臀| 91麻豆福利精品推荐| 亚洲大尺度视频在线观看| 日韩三级中文字幕| 国产成人a级片| 最新热久久免费视频| 欧美天堂亚洲电影院在线播放| 奇米影视一区二区三区小说| 久久免费精品国产久精品久久久久| 丁香六月久久综合狠狠色| 一区二区三区视频在线看| 欧美激情一区在线观看| 99riav久久精品riav| 三级一区在线视频先锋 | 亚洲天堂a在线| 欧美日韩一级视频| 国产综合色视频| 亚洲免费视频成人| 精品免费国产二区三区| 色婷婷综合久久| 精品午夜一区二区三区在线观看 | 欧美日韩一区小说| 国产精品亚洲一区二区三区妖精| 亚洲女与黑人做爰| 精品日产卡一卡二卡麻豆| 色哟哟一区二区在线观看| 婷婷综合在线观看| 欧美激情在线一区二区| 日韩午夜在线观看视频| 在线观看av不卡| 国产黄色精品网站| 日韩电影在线免费看| 亚洲日本va在线观看| 国产亚洲精品免费| 91精品国产色综合久久| 色激情天天射综合网| 丁香婷婷综合五月| 美女国产一区二区三区| 亚洲一区二区三区四区五区中文 | 日韩欧美精品三级| 色综合久久99| 国产成人精品www牛牛影视| 日日噜噜夜夜狠狠视频欧美人| 亚洲美女在线一区| 亚洲国产高清在线| 精品国产一区二区三区不卡| 555夜色666亚洲国产免| 欧美三区在线观看| 色综合 综合色| 91在线porny国产在线看| 丰满少妇在线播放bd日韩电影| 紧缚奴在线一区二区三区| 蜜桃免费网站一区二区三区| 婷婷中文字幕综合| 亚洲成av人片在线| 亚洲国产一区二区三区青草影视| 亚洲精品高清在线| 亚洲精品五月天| 亚洲日本va午夜在线影院| 最新不卡av在线| 亚洲男人天堂av网| 亚洲美女视频一区| 亚洲精品一二三| 亚洲午夜在线电影| 亚洲18女电影在线观看| 日韩电影在线一区| 久久精品av麻豆的观看方式| 久久电影国产免费久久电影| 激情都市一区二区| 国产精品综合一区二区三区| 国产白丝精品91爽爽久久| 99亚偷拍自图区亚洲| 色综合一个色综合| 欧美日韩一区在线观看| 日韩片之四级片| 国产女主播视频一区二区| 国产精品成人免费精品自在线观看| 一区在线观看视频| 亚洲最色的网站| 日本欧美一区二区在线观看| 国产在线视频不卡二| www.久久久久久久久| 欧美在线观看你懂的| 日韩欧美亚洲另类制服综合在线| 久久久久97国产精华液好用吗 | 欧美日韩国产中文| 欧美va在线播放| 国产精品久久久久久久久久久免费看| 亚洲欧美成aⅴ人在线观看| 亚洲午夜在线视频| 国产一区二区三区| 在线亚洲免费视频| 精品久久久久久久久久久院品网| 国产精品女同一区二区三区| 天天色综合天天| 成人免费视频国产在线观看| 欧美性极品少妇| 久久精品视频一区二区| 亚洲成av人影院| www.日韩在线| 精品卡一卡二卡三卡四在线| 亚洲视频在线一区二区| 国产在线播精品第三| 欧美日韩一区二区电影| 中文av一区二区|