⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookstore.java

📁 Torque示例
💻 JAVA
字号:
package com.becom;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.util.*;import com.becom.om.*;import org.apache.torque.Torque;import org.apache.torque.util.Criteria;public class Bookstore{  public static void main(String[] args)  {    try    {      /*       * Initializing Torque       */      Torque.init("Torque.properties");      /*       * Creating new objects.  These will be inserted       * into your database automatically when the       * save method is called.       */      Publisher addison = new Publisher();      addison.setName("Addison Wesley Professional");      addison.save();      Author bloch = new Author();      bloch.setFirstName("Joshua");      bloch.setLastName("Bloch");      bloch.save();      /*       * An alternative method to inserting rows       * in your database.       */      Author stevens = new Author();      stevens.setFirstName("W.");      stevens.setLastName("Stevens");      AuthorPeer.doInsert(stevens);      /*       * Using the convenience methods to handle       * the foreign keys.       */      Book effective = new Book();      effective.setTitle("Effective Java");      effective.setISBN("0-618-12902-2");      effective.setPublisher(addison);      effective.setAuthor(bloch);      effective.save();      /*       * Inserting the foreign-keys manually.       */      Book tcpip = new Book();      tcpip.setTitle("TCP/IP Illustrated, Volume 1");      tcpip.setISBN("0-201-63346-9");      tcpip.setPublisherId(addison.getPublisherId());      tcpip.setAuthorId(stevens.getAuthorId());      tcpip.save();      /*       * Selecting all books from the database and       * printing the results to stdout using our       * helper method defined in BookPeer       * (doSelectAll).       */      System.out.println("Full booklist:\n");      List booklist = BookPeer.doSelectAll();      printBooklist(booklist);      /*       * Selecting specific objects.  Just search for       * objects that match this criteria (and print       * to stdout).       */      System.out.println("Booklist (specific ISBN):\n");      Criteria crit = new Criteria();      crit.add(BookPeer.ISBN, "0-201-63346-9");      booklist = BookPeer.doSelect(crit);      printBooklist(booklist);      /*       * Updating data.  These lines will swap the       * authors of the two books.  The booklist is       * printed to stdout to verify the results.       */      effective.setAuthor(stevens);      effective.save();      tcpip.setAuthor(bloch);      BookPeer.doUpdate(tcpip);      System.out.println("Booklist (authors swapped):\n");      booklist = BookPeer.doSelectAll();      printBooklist(booklist);      /*       * Deleting data.  These lines will delete the       * data that matches the specified criteria.       */      crit = new Criteria();      crit.add(BookPeer.ISBN, "0-618-12902-2");      BookPeer.doDelete(crit);      crit = new Criteria();      crit.add(BookPeer.ISBN, "0-201-63346-9");      crit.add(BookPeer.TITLE, "TCP/IP Illustrated, Volume 1");      BookPeer.doDelete(crit);      /*       * Deleting data by passing Data Objects instead of       * specifying criteria.       */      AuthorPeer.doDelete(bloch);      AuthorPeer.doDelete(stevens);      PublisherPeer.doDelete(addison);      System.out.println("Booklist (should be empty):\n");      booklist = BookPeer.doSelectAll();      printBooklist(booklist);    }    catch (Exception e)    {      e.printStackTrace();    }  }  /*   * Helper method to print a booklist to standard out.   */  private static void printBooklist(List booklist)    throws Exception  {    Iterator i = booklist.iterator();    while (i.hasNext())    {      Book book = (Book) i.next();      System.out.println(book);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -