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

📄 basebook.java

📁 Torque示例
💻 JAVA
字号:
package com.becom.om;import java.math.BigDecimal;import java.sql.Connection;import java.util.ArrayList;import java.util.Date;import java.util.Collections;import java.util.List;import org.apache.commons.lang.ObjectUtils;import org.apache.torque.TorqueException;import org.apache.torque.om.BaseObject;import org.apache.torque.om.ComboKey;import org.apache.torque.om.DateKey;import org.apache.torque.om.NumberKey;import org.apache.torque.om.ObjectKey;import org.apache.torque.om.SimpleKey;import org.apache.torque.om.StringKey;import org.apache.torque.om.Persistent;import org.apache.torque.util.Criteria;import org.apache.torque.util.Transaction;        /** * This class was autogenerated by Torque on: * * [Tue Apr 20 13:21:09 CST 2004] * * You should not use this class directly.  It should not even be * extended all references should be to Book */public abstract class BaseBook extends BaseObject{    /** The Peer class */    private static final BookPeer peer =        new BookPeer();            /** The value for the bookId field */    private int bookId;          /** The value for the title field */    private String title;          /** The value for the iSBN field */    private String iSBN;          /** The value for the publisherId field */    private int publisherId;          /** The value for the authorId field */    private int authorId;          /**     * Get the BookId     *     * @return int     */    public int getBookId()    {        return bookId;    }                            /**     * Set the value of BookId     *     * @param v new value     */    public void setBookId(int v)     {                      if (this.bookId != v)              {            this.bookId = v;            setModified(true);        }                            }      /**     * Get the Title     *     * @return String     */    public String getTitle()    {        return title;    }                            /**     * Set the value of Title     *     * @param v new value     */    public void setTitle(String v)     {                      if (!ObjectUtils.equals(this.title, v))              {            this.title = v;            setModified(true);        }                            }      /**     * Get the ISBN     *     * @return String     */    public String getISBN()    {        return iSBN;    }                            /**     * Set the value of ISBN     *     * @param v new value     */    public void setISBN(String v)     {                      if (!ObjectUtils.equals(this.iSBN, v))              {            this.iSBN = v;            setModified(true);        }                            }      /**     * Get the PublisherId     *     * @return int     */    public int getPublisherId()    {        return publisherId;    }                                  /**     * Set the value of PublisherId     *     * @param v new value     */    public void setPublisherId(int v) throws TorqueException    {                      if (this.publisherId != v)              {            this.publisherId = v;            setModified(true);        }                                              if (aPublisher != null && !(aPublisher.getPublisherId() == v))                {            aPublisher = null;        }                    }      /**     * Get the AuthorId     *     * @return int     */    public int getAuthorId()    {        return authorId;    }                                  /**     * Set the value of AuthorId     *     * @param v new value     */    public void setAuthorId(int v) throws TorqueException    {                      if (this.authorId != v)              {            this.authorId = v;            setModified(true);        }                                              if (aAuthor != null && !(aAuthor.getAuthorId() == v))                {            aAuthor = null;        }                    }                                          private Publisher aPublisher;    /**     * Declares an association between this object and a Publisher object     *     * @param v Publisher     * @throws TorqueException     */    public void setPublisher(Publisher v) throws TorqueException    {            if (v == null)        {                    setPublisherId(0);                  }        else        {            setPublisherId(v.getPublisherId());        }                aPublisher = v;    }                                                /**     * Get the associated Publisher object     *     * @return the associated Publisher object     * @throws TorqueException     */    public Publisher getPublisher() throws TorqueException    {        if (aPublisher == null && (this.publisherId > 0))        {                          aPublisher = PublisherPeer.retrieveByPK(SimpleKey.keyFor(this.publisherId));                          /* The following can be used instead of the line above to               guarantee the related object contains a reference               to this object, but this level of coupling               may be undesirable in many circumstances.               As it can lead to a db query with many results that may               never be used.               Publisher obj = PublisherPeer.retrieveByPK(this.publisherId);               obj.addBooks(this);            */        }        return aPublisher;    }    /**     * Provides convenient way to set a relationship based on a     * ObjectKey.  e.g.     * <code>bar.setFooKey(foo.getPrimaryKey())</code>     *           */    public void setPublisherKey(ObjectKey key) throws TorqueException    {                              setPublisherId(((NumberKey) key).intValue());                  }                                      private Author aAuthor;    /**     * Declares an association between this object and a Author object     *     * @param v Author     * @throws TorqueException     */    public void setAuthor(Author v) throws TorqueException    {            if (v == null)        {                    setAuthorId(0);                  }        else        {            setAuthorId(v.getAuthorId());        }                aAuthor = v;    }                                                /**     * Get the associated Author object     *     * @return the associated Author object     * @throws TorqueException     */    public Author getAuthor() throws TorqueException    {        if (aAuthor == null && (this.authorId > 0))        {                          aAuthor = AuthorPeer.retrieveByPK(SimpleKey.keyFor(this.authorId));                          /* The following can be used instead of the line above to               guarantee the related object contains a reference               to this object, but this level of coupling               may be undesirable in many circumstances.               As it can lead to a db query with many results that may               never be used.               Author obj = AuthorPeer.retrieveByPK(this.authorId);               obj.addBooks(this);            */        }        return aAuthor;    }    /**     * Provides convenient way to set a relationship based on a     * ObjectKey.  e.g.     * <code>bar.setFooKey(foo.getPrimaryKey())</code>     *           */    public void setAuthorKey(ObjectKey key) throws TorqueException    {                              setAuthorId(((NumberKey) key).intValue());                  }                           private static List fieldNames = null;    /**     * Generate a list of field names.     *     * @return a list of field names     */    public static synchronized List getFieldNames()    {        if (fieldNames == null)        {            fieldNames = new ArrayList();              fieldNames.add("BookId");              fieldNames.add("Title");              fieldNames.add("ISBN");              fieldNames.add("PublisherId");              fieldNames.add("AuthorId");              fieldNames = Collections.unmodifiableList(fieldNames);        }        return fieldNames;    }    /**     * Retrieves a field from the object by name passed in as a String.     *     * @param name field name     * @return value     */    public Object getByName(String name)    {          if (name.equals("BookId"))        {                return new Integer(getBookId());            }          if (name.equals("Title"))        {                return getTitle();            }          if (name.equals("ISBN"))        {                return getISBN();            }          if (name.equals("PublisherId"))        {                return new Integer(getPublisherId());            }          if (name.equals("AuthorId"))        {                return new Integer(getAuthorId());            }          return null;    }        /**     * Retrieves a field from the object by name passed in     * as a String.  The String must be one of the static     * Strings defined in this Class' Peer.     *     * @param name peer name     * @return value     */    public Object getByPeerName(String name)    {          if (name.equals(BookPeer.BOOK_ID))        {                return new Integer(getBookId());            }          if (name.equals(BookPeer.TITLE))        {                return getTitle();            }          if (name.equals(BookPeer.ISBN))        {                return getISBN();            }          if (name.equals(BookPeer.PUBLISHER_ID))        {                return new Integer(getPublisherId());            }          if (name.equals(BookPeer.AUTHOR_ID))        {                return new Integer(getAuthorId());            }          return null;    }    /**     * Retrieves a field from the object by Position as specified     * in the xml schema.  Zero-based.     *     * @param pos position in xml schema     * @return value     */    public Object getByPosition(int pos)    {            if (pos == 0)        {                return new Integer(getBookId());            }              if (pos == 1)        {                return getTitle();            }              if (pos == 2)        {                return getISBN();            }              if (pos == 3)        {                return new Integer(getPublisherId());            }              if (pos == 4)        {                return new Integer(getAuthorId());            }              return null;    }         /**     * Stores the object in the database.  If the object is new,     * it inserts it; otherwise an update is performed.     *     * @throws Exception     */    public void save() throws Exception    {          save(BookPeer.getMapBuilder()                .getDatabaseMap().getName());      }    /**     * Stores the object in the database.  If the object is new,     * it inserts it; otherwise an update is performed.       * Note: this code is here because the method body is     * auto-generated conditionally and therefore needs to be     * in this file instead of in the super class, BaseObject.       *     * @param dbName     * @throws TorqueException     */    public void save(String dbName) throws TorqueException    {        Connection con = null;          try        {            con = Transaction.begin(dbName);            save(con);            Transaction.commit(con);        }        catch(TorqueException e)        {            Transaction.safeRollback(con);            throw e;        }      }      /** flag to prevent endless save loop, if this object is referenced        by another object which falls in this transaction. */    private boolean alreadyInSave = false;      /**     * Stores the object in the database.  If the object is new,     * it inserts it; otherwise an update is performed.  This method     * is meant to be used as part of a transaction, otherwise use     * the save() method and the connection details will be handled     * internally     *     * @param con     * @throws TorqueException     */    public void save(Connection con) throws TorqueException    {          if (!alreadyInSave)        {            alreadyInSave = true;              // If this object has been modified, then save it to the database.            if (isModified())            {                if (isNew())                {                    BookPeer.doInsert((Book) this, con);                    setNew(false);                }                else                {                    BookPeer.doUpdate((Book) this, con);                }            }                      alreadyInSave = false;        }      }                          /**     * Set the PrimaryKey using ObjectKey.     *     * @param  bookId ObjectKey     */    public void setPrimaryKey(ObjectKey key)            {            setBookId(((NumberKey) key).intValue());        }    /**     * Set the PrimaryKey using a String.     *     * @param key     */    public void setPrimaryKey(String key)     {            setBookId(Integer.parseInt(key));        }      /**     * returns an id that differentiates this object from others     * of its class.     */    public ObjectKey getPrimaryKey()    {          return SimpleKey.keyFor(getBookId());      }     /**     * Makes a copy of this object.     * It creates a new object filling in the simple attributes.       * It then fills all the association collections and sets the     * related objects to isNew=true.       */      public Book copy() throws TorqueException    {        return copyInto(new Book());    }      protected Book copyInto(Book copyObj) throws TorqueException    {          copyObj.setBookId(bookId);          copyObj.setTitle(title);          copyObj.setISBN(iSBN);          copyObj.setPublisherId(publisherId);          copyObj.setAuthorId(authorId);                      copyObj.setBookId(0);                                                    return copyObj;    }    /**     * returns a peer instance associated with this om.  Since Peer classes     * are not to have any instance attributes, this method returns the     * same instance for all member of this class. The method could therefore     * be static, but this would prevent one from overriding the behavior.     */    public BookPeer getPeer()    {        return peer;    }    public String toString()    {        StringBuffer str = new StringBuffer();        str.append("Book:\n");        str.append("BookId = ")           .append(getBookId())           .append("\n");        str.append("Title = ")           .append(getTitle())           .append("\n");        str.append("ISBN = ")           .append(getISBN())           .append("\n");        str.append("PublisherId = ")           .append(getPublisherId())           .append("\n");        str.append("AuthorId = ")           .append(getAuthorId())           .append("\n");        return(str.toString());    }}

⌨️ 快捷键说明

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