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

📄 baseauthor.java

📁 Torque示例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else        {            // the following code is to determine if a new query is            // called for.  If the criteria is the same as the last            // one, just return the collection.            boolean newCriteria = true;                        criteria.add(BookPeer.AUTHOR_ID, getAuthorId());                        if (!lastBooksCriteria.equals(criteria))            {                collBooks = BookPeer.doSelectJoinPublisher(criteria);            }        }        lastBooksCriteria = criteria;        return collBooks;    }                                                                                                                                                                                                                                                                /**     * If this collection has already been initialized with     * an identical criteria, it returns the collection.     * Otherwise if this Author is new, it will return     * an empty collection; or if this Author has previously     * been saved, it will retrieve related Books from storage.     *     * This method is protected by default in order to keep the public     * api reasonable.  You can provide public methods for those you     * actually need in Author.     */    protected List getBooksJoinAuthor(Criteria criteria)        throws TorqueException    {        if (collBooks == null)        {            if (isNew())            {               collBooks = new ArrayList();            }            else            {                            criteria.add(BookPeer.AUTHOR_ID, getAuthorId());                            collBooks = BookPeer.doSelectJoinAuthor(criteria);            }        }        else        {            // the following code is to determine if a new query is            // called for.  If the criteria is the same as the last            // one, just return the collection.            boolean newCriteria = true;                        criteria.add(BookPeer.AUTHOR_ID, getAuthorId());                        if (!lastBooksCriteria.equals(criteria))            {                collBooks = BookPeer.doSelectJoinAuthor(criteria);            }        }        lastBooksCriteria = criteria;        return collBooks;    }                                          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("AuthorId");              fieldNames.add("FirstName");              fieldNames.add("LastName");              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("AuthorId"))        {                return new Integer(getAuthorId());            }          if (name.equals("FirstName"))        {                return getFirstName();            }          if (name.equals("LastName"))        {                return getLastName();            }          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(AuthorPeer.AUTHOR_ID))        {                return new Integer(getAuthorId());            }          if (name.equals(AuthorPeer.FIRST_NAME))        {                return getFirstName();            }          if (name.equals(AuthorPeer.LAST_NAME))        {                return getLastName();            }          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(getAuthorId());            }              if (pos == 1)        {                return getFirstName();            }              if (pos == 2)        {                return getLastName();            }              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(AuthorPeer.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())                {                    AuthorPeer.doInsert((Author) this, con);                    setNew(false);                }                else                {                    AuthorPeer.doUpdate((Author) this, con);                }            }                                                                  if (collBooks != null)            {                for (int i = 0; i < collBooks.size(); i++)                {                    ((Book) collBooks.get(i)).save(con);                }            }                          alreadyInSave = false;        }      }                                /**     * Set the PrimaryKey using ObjectKey.     *     * @param  authorId ObjectKey     */    public void setPrimaryKey(ObjectKey key)        throws TorqueException    {            setAuthorId(((NumberKey) key).intValue());        }    /**     * Set the PrimaryKey using a String.     *     * @param key     */    public void setPrimaryKey(String key) throws TorqueException    {            setAuthorId(Integer.parseInt(key));        }      /**     * returns an id that differentiates this object from others     * of its class.     */    public ObjectKey getPrimaryKey()    {          return SimpleKey.keyFor(getAuthorId());      }     /**     * 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 Author copy() throws TorqueException    {        return copyInto(new Author());    }      protected Author copyInto(Author copyObj) throws TorqueException    {          copyObj.setAuthorId(authorId);          copyObj.setFirstName(firstName);          copyObj.setLastName(lastName);                      copyObj.setAuthorId(0);                                                                                      List v = getBooks();        for (int i = 0; i < v.size(); i++)        {            Book obj = (Book) v.get(i);            copyObj.addBook(obj.copy());        }                            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 AuthorPeer getPeer()    {        return peer;    }    public String toString()    {        StringBuffer str = new StringBuffer();        str.append("Author:\n");        str.append("AuthorId = ")           .append(getAuthorId())           .append("\n");        str.append("FirstName = ")           .append(getFirstName())           .append("\n");        str.append("LastName = ")           .append(getLastName())           .append("\n");        return(str.toString());    }}

⌨️ 快捷键说明

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