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

📄 peer.vm

📁 torque服务器源代码
💻 VM
📖 第 1 页 / 共 4 页
字号:
    /**     * Method to do inserts     *     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doInsert($table.JavaName obj) throws TorqueException    {  #if ($table.IdMethod.equals("none") || $table.PrimaryKey.size() == 0)        doInsert(buildCriteria(obj));  #else        obj.setPrimaryKey(doInsert(buildCriteria(obj)));  #end        obj.setNew(false);        obj.setModified(false);    }    /**     * @param obj the data object to update in the database.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doUpdate($table.JavaName obj) throws TorqueException    {        doUpdate(buildCriteria(obj));        obj.setModified(false);    }    /**     * @param obj the data object to delete in the database.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doDelete($table.JavaName obj) throws TorqueException    {        doDelete(buildCriteria(obj));    }    /**     * Method to do inserts.  This method is to be used during a transaction,     * otherwise use the doInsert($table.JavaName) method.  It will take     * care of the connection details internally.     *     * @param obj the data object to insert into the database.     * @param con the connection to use     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doInsert($table.JavaName obj, Connection con)        throws TorqueException    {  #if ($table.IdMethod.equals("none") || $table.PrimaryKey.size() == 0)        doInsert(buildCriteria(obj), con);  #else        obj.setPrimaryKey(doInsert(buildCriteria(obj), con));  #end        obj.setNew(false);        obj.setModified(false);    }    /**     * Method to do update.  This method is to be used during a transaction,     * otherwise use the doUpdate($table.JavaName) method.  It will take     * care of the connection details internally.     *     * @param obj the data object to update in the database.     * @param con the connection to use     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doUpdate($table.JavaName obj, Connection con)        throws TorqueException    {        doUpdate(buildCriteria(obj), con);        obj.setModified(false);    }    /**     * Method to delete.  This method is to be used during a transaction,     * otherwise use the doDelete($table.JavaName) method.  It will take     * care of the connection details internally.     *     * @param obj the data object to delete in the database.     * @param con the connection to use     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doDelete($table.JavaName obj, Connection con)        throws TorqueException    {        doDelete(buildCriteria(obj), con);    }    /**     * Method to do deletes.     *     * @param pk ObjectKey that is used DELETE from database.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static void doDelete(ObjectKey pk) throws TorqueException    {        $basePrefix${table.JavaName}Peer           .doDelete(pk, (Connection) null);    }    /**     * Method to delete.  This method is to be used during a transaction,     * otherwise use the doDelete(ObjectKey) method.  It will take     * care of the connection details internally.     *     * @param pk the primary key for the object to delete in the database.     * @param con the connection to use     * @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();  #if ($table.PrimaryKey.size() == 1)            criteria.add($table.PrimaryKey.get(0).Name.toUpperCase(), pk);  #else        SimpleKey[] keys = (SimpleKey[])pk.getValue();    #set ( $i = 0 )    #foreach ($col in $table.PrimaryKey)      #set ( $cup=$col.Name.toUpperCase() )            criteria.add($cup, keys[$i]);      #set ( $i = $i + 1 )    #end  #end        return criteria;     }    /** Build a Criteria object from the data object for this peer */    public static Criteria buildCriteria( $table.JavaName obj )    {        Criteria criteria = new Criteria(DATABASE_NAME);  #foreach ($col in $table.Columns)    #set ( $cfc=$col.JavaName )    #set ( $cup=$col.Name.toUpperCase() )    #if ($col.isPrimaryKey() && !$table.IdMethod.equals("none"))        if (!obj.isNew())    #end            criteria.add($cup, obj.get${cfc}());  #end        return criteria;    }#end ## ends if (!$table.isAlias())#if ($table.PrimaryKey.size() > 0)  #if ($table.isAlias())    #set ($retrieveMethod = "retrieve${table.JavaName}ByPK")  #else    #set ($retrieveMethod = "retrieveByPK")  #end  #set ($pks = $table.PrimaryKey)  #if ($pks.size() == 1)    #set ($pk = $pks.get(0))    /**     * 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 $table.JavaName ${retrieveMethod}($pk.JavaNative pk)        throws TorqueException, NoRowsException, TooManyRowsException    {        return ${retrieveMethod}(SimpleKey.keyFor(pk));    }  #end    /**     * 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 $table.JavaName ${retrieveMethod}(ObjectKey pk)        throws TorqueException, NoRowsException, TooManyRowsException    {        Connection db = null;        $table.JavaName retVal = null;        try        {            db = Torque.getConnection(DATABASE_NAME);            retVal = ${retrieveMethod}(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 $table.JavaName ${retrieveMethod}(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 ($table.JavaName)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 ${retrieveMethod}s(List pks)        throws TorqueException    {        Connection db = null;        List retVal = null;        try        {           db = Torque.getConnection(DATABASE_NAME);           retVal = ${retrieveMethod}s(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 ${retrieveMethod}s( List pks, Connection dbcon )        throws TorqueException    {        List objs = null;        if (pks == null || pks.size() == 0)        {            objs = new LinkedList();        }        else        {            Criteria criteria = new Criteria();  #if ($table.PrimaryKey.size() == 1)            criteria.addIn( $table.PrimaryKey.get(0).Name.toUpperCase(), pks );  #else            Iterator iter = pks.iterator();            while (iter.hasNext())            {                ObjectKey pk = (ObjectKey)iter.next();                SimpleKey[] keys = (SimpleKey[])pk.getValue();    #set ( $i = 0 )    #foreach ($col in $table.PrimaryKey)      #set ( $cup=$col.Name.toUpperCase() )                    Criteria.Criterion c$i = criteria.getNewCriterion(                        $cup, keys[$i], Criteria.EQUAL);      #set ( $j = $i - 1 )      #if ($i > 0)                        c${j}.and(c${i});      #end      #set ( $i = $i + 1 )    #end                criteria.or(c0);            }  #end        objs = doSelect(criteria, dbcon);        }        return objs;    }#end ## ends if($table.PrimaryKey.size() > 0)#if ($table.PrimaryKey.size() > 1)  #set ( $comma = false )    /**     * retrieve object using using pk values.     *  #foreach ($col in $table.PrimaryKey)    #set ( $clo=$col.Name.toLowerCase() )    #set ( $cjtype= $col.JavaNative )     * @param $clo $cjtype  #end     */    public static $table.JavaName ${retrieveMethod}(  #foreach ($col in $table.PrimaryKey)    #set ( $clo=$col.Name.toLowerCase() )    #set ( $cjtype = $col.JavaNative )    #if ($comma),#end $cjtype $clo    #set ( $comma = true )  #end        ) throws TorqueException    {        Connection db = null;        $table.JavaName retVal = null;        try        {           db = Torque.getConnection(DATABASE_NAME);           retVal = retrieveByPK(  #set ( $comma = false )  #foreach ($col in $table.PrimaryKey)    #set ( $clo=$col.Name.toLowerCase() )    #if ($comma),#end $clo    #set ( $comma = true )  #end               , db);        }        finally        {            Torque.closeConnection(db);        }        return(retVal);    }  #set ( $comma = false )    /**     * retrieve object using using pk values.     *  #foreach ($col in $table.PrimaryKey)    #set ( $clo=$col.Name.toLowerCase() )    #set ( $cjtype= $col.JavaNative )     * @param $clo $cjtype  #end     * @param Connection con     */    public static $table.JavaName ${retrieveMethod}(  #foreach ($col in $table.PrimaryKey)    #set ( $clo=$col.Name.toLowerCase() )    #set ( $cjtype = $col.JavaNative )    #if ($comma),#end $cjtype $clo    #set ( $comma = true )  #end       ,Connection con) throws TorqueException    {        Criteria criteria = new Criteria(5);  #foreach ($col in $table.PrimaryKey)    #set ( $cup=$col.Name.toUpperCase() )    #set ( $clo=$col.Name.toLowerCase() )        criteria.add($cup, $clo);  #end        List v = doSelect(criteria, con);        if (v.size() != 1)        {            throw new TorqueException("Failed to select one and only one row.");        }        else        {            return ($table.JavaName) v.get(0);        }    }#end#if ($complexObjectModel)

⌨️ 快捷键说明

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