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

📄 basebookpeer.java

📁 Torque示例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doDelete(ObjectKey pk, Connection con)        throws TorqueException    {        doDelete(buildCriteria(pk), con);    }    /** Build a Criteria object from an ObjectKey */    public static Criteria buildCriteria( ObjectKey pk )    {        Criteria criteria = new Criteria();              criteria.add(BOOK_ID, pk);          return criteria;     }    /** Build a Criteria object from the data object for this peer */    public static Criteria buildCriteria( Book obj )    {        Criteria criteria = new Criteria(DATABASE_NAME);              if (!obj.isNew())                criteria.add(BOOK_ID, obj.getBookId());                  criteria.add(TITLE, obj.getTitle());                  criteria.add(ISBN, obj.getISBN());                  criteria.add(PUBLISHER_ID, obj.getPublisherId());                  criteria.add(AUTHOR_ID, obj.getAuthorId());          return criteria;    }             /**     * Retrieve a single object by pk     *     * @param pk the primary key     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     * @throws NoRowsException Primary key was not found in database.     * @throws TooManyRowsException Primary key was not found in database.     */    public static Book retrieveByPK(int pk)        throws TorqueException, NoRowsException, TooManyRowsException    {        return retrieveByPK(SimpleKey.keyFor(pk));    }      /**     * Retrieve a single object by pk     *     * @param pk the primary key     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     * @throws NoRowsException Primary key was not found in database.     * @throws TooManyRowsException Primary key was not found in database.     */    public static Book retrieveByPK(ObjectKey pk)        throws TorqueException, NoRowsException, TooManyRowsException    {        Connection db = null;        Book retVal = null;        try        {            db = Torque.getConnection(DATABASE_NAME);            retVal = retrieveByPK(pk, db);        }        finally        {            Torque.closeConnection(db);        }        return(retVal);    }    /**     * Retrieve a single object by pk     *     * @param pk the primary key     * @param con the connection to use     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     * @throws NoRowsException Primary key was not found in database.     * @throws TooManyRowsException Primary key was not found in database.     */    public static Book retrieveByPK(ObjectKey pk, Connection con)        throws TorqueException, NoRowsException, TooManyRowsException    {        Criteria criteria = buildCriteria(pk);        List v = doSelect(criteria, con);        if (v.size() == 0)        {            throw new NoRowsException("Failed to select a row.");        }        else if (v.size() > 1)        {            throw new TooManyRowsException("Failed to select only one row.");        }        else        {            return (Book)v.get(0);        }    }    /**     * Retrieve a multiple objects by pk     *     * @param pks List of primary keys     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List retrieveByPKs(List pks)        throws TorqueException    {        Connection db = null;        List retVal = null;        try        {           db = Torque.getConnection(DATABASE_NAME);           retVal = retrieveByPKs(pks, db);        }        finally        {            Torque.closeConnection(db);        }        return(retVal);    }    /**     * Retrieve a multiple objects by pk     *     * @param pks List of primary keys     * @param dbcon the connection to use     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List retrieveByPKs( List pks, Connection dbcon )        throws TorqueException    {        List objs = null;        if (pks == null || pks.size() == 0)        {            objs = new LinkedList();        }        else        {            Criteria criteria = new Criteria();              criteria.addIn( BOOK_ID, pks );          objs = doSelect(criteria, dbcon);        }        return objs;    }                                                                                               /**     * selects a collection of Book objects pre-filled with their     * Publisher objects.     *     * 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 BookPeer.     *     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    protected static List doSelectJoinPublisher(Criteria c)        throws TorqueException    {        // Set the correct dbName if it has not been overridden        // c.getDbName will return the same object if not set to        // another value so == check is okay and faster        if (c.getDbName() == Torque.getDefaultDB())        {            c.setDbName(DATABASE_NAME);        }        BookPeer.addSelectColumns(c);        int offset = numColumns + 1;        PublisherPeer.addSelectColumns(c);                        c.addJoin(BookPeer.PUBLISHER_ID,            PublisherPeer.PUBLISHER_ID);                                                                                                                  List rows = BasePeer.doSelect(c);        List results = new ArrayList();        for (int i = 0; i < rows.size(); i++)        {            Record row = (Record) rows.get(i);                            Class omClass = BookPeer.getOMClass();                    Book obj1 = (Book) BookPeer                .row2Object(row, 1, omClass);                     omClass = PublisherPeer.getOMClass();                    Publisher obj2 = (Publisher)PublisherPeer                .row2Object(row, offset, omClass);            boolean newObject = true;            for (int j = 0; j < results.size(); j++)            {                Book temp_obj1 = (Book)results.get(j);                Publisher temp_obj2 = (Publisher)temp_obj1.getPublisher();                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))                {                    newObject = false;                    temp_obj2.addBook(obj1);                    break;                }            }            if (newObject)            {                obj2.initBooks();                obj2.addBook(obj1);            }            results.add(obj1);        }        return results;    }                                                                                                /**     * selects a collection of Book objects pre-filled with their     * Author objects.     *     * 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 BookPeer.     *     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    protected static List doSelectJoinAuthor(Criteria c)        throws TorqueException    {        // Set the correct dbName if it has not been overridden        // c.getDbName will return the same object if not set to        // another value so == check is okay and faster        if (c.getDbName() == Torque.getDefaultDB())        {            c.setDbName(DATABASE_NAME);        }        BookPeer.addSelectColumns(c);        int offset = numColumns + 1;        AuthorPeer.addSelectColumns(c);                        c.addJoin(BookPeer.AUTHOR_ID,            AuthorPeer.AUTHOR_ID);                                                                                                                  List rows = BasePeer.doSelect(c);        List results = new ArrayList();        for (int i = 0; i < rows.size(); i++)        {            Record row = (Record) rows.get(i);                            Class omClass = BookPeer.getOMClass();                    Book obj1 = (Book) BookPeer                .row2Object(row, 1, omClass);                     omClass = AuthorPeer.getOMClass();                    Author obj2 = (Author)AuthorPeer                .row2Object(row, offset, omClass);            boolean newObject = true;            for (int j = 0; j < results.size(); j++)            {                Book temp_obj1 = (Book)results.get(j);                Author temp_obj2 = (Author)temp_obj1.getAuthor();                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))                {                    newObject = false;                    temp_obj2.addBook(obj1);                    break;                }            }            if (newObject)            {                obj2.initBooks();                obj2.addBook(obj1);            }            results.add(obj1);        }        return results;    }                                  /**     * Returns the TableMap related to this peer.  This method is not     * needed for general use but a specific application could have a need.     *     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    protected static TableMap getTableMap()        throws TorqueException    {        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);    }   }

⌨️ 快捷键说明

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