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

📄 objectwithmanager.vm

📁 一个数据访问层Torque3.1的生成器的源代码
💻 VM
📖 第 1 页 / 共 4 页
字号:
              #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )              #set ( $colFK = $tblFK.getColumn($colFKName) )                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );            #end            if (!last${relCol}Criteria.equals(criteria))            {                $collName = ${className}Peer.doSelectJoin${relCol2}(criteria);            }        }        last${relCol}Criteria = criteria;        return $collName;    }          #end         #end       #end     #end## ===========================================================#*  #if ($countFK > 2)    /**     * If this collection has already been initialized with     * an identical criteria, it returns the collection.     * Otherwise if this $table.JavaName is new, it will return     * an empty collection; or if this $table.JavaName has previously     * been saved, it will retrieve related ${relCol} 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 ${table.JavaName}.     */    protected List get${relCol}JoinAllExcept${table.JavaName}(Criteria criteria)        throws TorqueException    {        if ($collName == null)        {            if ( isNew() )            {               $collName = new ArrayList();            }            else            {   #foreach ($columnName in $fk.ForeignColumns)       #set ( $column = $table.getColumn($columnName) )       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )       #set ( $colFK = $tblFK.getColumn($colFKName) )                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );   #end                $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(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;   #foreach ($columnName in $fk.ForeignColumns)       #set ( $column = $table.getColumn($columnName) )       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )       #set ( $colFK = $tblFK.getColumn($colFKName) )                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );   #end            if ( !last${relCol}Criteria.equals(criteria)  )            {                $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);            }        }        last${relCol}Criteria = criteria;        return $collName;    }  #end*### ------------------------------------------------------------  #end    ## ends foreach over table.Referrers#end    ##ends the if(complexObjectModel)#### getByName code###if (!$table.isAlias() && $addGetByNameMethod)    private static List fieldNames = null;    /**     * Generate a list of field names.     */    public static synchronized List getFieldNames()    {        if (fieldNames == null)        {            fieldNames = new ArrayList();  #foreach ($col in $table.Columns)            fieldNames.add("${col.JavaName}");  #end            fieldNames = Collections.unmodifiableList(fieldNames);        }        return fieldNames;    }    /**     * Retrieves a field from the object by name passed in     * as a String.     */    public Object getByName(String name)    {  #foreach ($col in $table.Columns)    #set ( $cfc = $col.JavaName )    #set ( $cjtype = $col.JavaNative )        if (name.equals("${col.JavaName}"))        {    #if ($cjtype == "int")            return new Integer(get${cfc}());    #elseif ($cjtype == "long")            return new Long(get${cfc}());    #elseif ($cjtype == "float")            return new Float(get${cfc}());    #elseif ($cjtype == "double")            return new Double(get${cfc}());    #elseif ($cjtype == "boolean")            return new Boolean(get${cfc}());    #elseif ($cjtype == "short")            return new Short(get${cfc}());    #elseif ($cjtype == "byte")            return new Byte(get${cfc}());    #elseif ($cjtype == "char")            return new Character(get${cfc}());    #else            return get${cfc}();    #end        }  #end        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.     */    public Object getByPeerName(String name)    {  #foreach ($col in $table.Columns)    #set ( $cfc = $col.JavaName )    #set ( $cup=$col.Name.toUpperCase() )    #set ( $cjtype = $col.JavaNative )        if (name.equals(${table.JavaName}Peer.$cup ))        {    #if ($cjtype == "int")            return new Integer(get${cfc}());    #elseif ($cjtype == "long")            return new Long(get${cfc}());    #elseif ($cjtype == "float")            return new Float(get${cfc}());    #elseif ($cjtype == "double")            return new Double(get${cfc}());    #elseif ($cjtype == "boolean")            return new Boolean(get${cfc}());    #elseif ($cjtype == "short")            return new Short(get${cfc}());    #elseif ($cjtype == "byte")            return new Byte(get${cfc}());    #elseif ($cjtype == "char")            return new Character(get${cfc}());    #else            return get${cfc}();    #end        }  #end        return null;    }    /**     * Retrieves a field from the object by Position as specified     * in the xml schema.  Zero-based.     */    public Object getByPosition(int pos)    {  #set ($i = 0)  #foreach ($col in $table.Columns)    #set ( $cfc = $col.JavaName )    #set ( $cjtype = $col.JavaNative )        if ( pos == $i )        {    #if ($cjtype == "int")            return new Integer(get${cfc}());    #elseif ($cjtype == "long")            return new Long(get${cfc}());    #elseif ($cjtype == "float")            return new Float(get${cfc}());    #elseif ($cjtype == "double")            return new Double(get${cfc}());    #elseif ($cjtype == "boolean")            return new Boolean(get${cfc}());    #elseif ($cjtype == "short")            return new Short(get${cfc}());    #elseif ($cjtype == "byte")            return new Byte(get${cfc}());    #elseif ($cjtype == "char")            return new Character(get${cfc}());    #else            return get${cfc}();    #end        }    #set ($i = $i + 1)  #end        return null;    }#end     ## ends the if(addGetByNameMethod)#if (!$table.isAlias() && $addSaveMethod)    /**     * Stores the object in the database.  If the object is new,     * it inserts it; otherwise an update is performed.     */    public void save() throws $saveException    {  #if ($complexObjectModel)        save(${table.JavaName}Peer.getMapBuilder()                .getDatabaseMap().getName());  #else        if (isModified())        {            if (isNew())            {                ${table.JavaName}Peer.doInsert(($table.JavaName)this);                setNew(false);            }            else            {                ${table.JavaName}Peer.doUpdate(($table.JavaName)this);            }        }  #end    }    /**     * Stores the object in the database.  If the object is new,     * it inserts it; otherwise an update is performed.  #if ($complexObjectModel)     * 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.  #end     */    public void save(String dbName) throws TorqueException    {        Connection con = null;  #if ($complexObjectModel)        try        {            con = Transaction.begin(dbName);            save(con);            Transaction.commit(con);        }        catch(TorqueException e)        {            Transaction.safeRollback(con);            throw e;        }  #else        if (isModified())        {            try            {                con = Torque.getConnection( dbName );                if (isNew())                {                    ${table.JavaName}Peer                        .doInsert(($table.JavaName)this, con);                    setNew(false);                }                else                {                    ${table.JavaName}Peer                        .doUpdate(($table.JavaName)this, con);                }            }            finally            {                Torque.closeConnection(con);            }        }  #end    }  #if ($complexObjectModel)    /** flag to prevent endless save loop, if this object is referenced        by another object which falls in this transaction. */    private boolean alreadyInSave = false;  #end    /**     * 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     */    public void save(Connection con) throws TorqueException    {  #if ($complexObjectModel)        if (!alreadyInSave)        {            alreadyInSave = true;#* FIXME! the following code can cause an infinite loop, needs more thoughtshows the infinite loop: System.out.println("Entering save for " + this);    #if ($pVars.size() != 0)        // We call the save method on the following object(s) if they        // were passed to this object by their coresponding set        // method.  This object relates to these object(s) by a        // foreign key reference.  If the object(s) being saved were        // new to the database, an insert was performed, then they may        // have a new PrimaryKey.  We call the coresponding set method        // for the given object(s) to set this object's Id reference        // to this new Primary key so that it will be saved.      #foreach ($aVarName in $aVars)        #set($i = $velocityCount - 1)        if ($aVarName != null)        {            ${aVarName}.save(con);            set$pVars.get($i)($aVarName);        }      #end    #end*#  #end            // If this object has been modified, then save it to the database.            if (isModified())            {                if (isNew())                {                    ${table.JavaName}Peer.doInsert(($table.JavaName)this, con);                    setNew(false);                }                else                {                    ${table.JavaName}Peer.doUpdate(($table.JavaName)this, con);                }  #if ($table.PrimaryKey.size() > 0)    #set ($interfaceName = $table.JavaName)    #if ($table.Interface)      #set ($interfaceName = $table.Interface)    #end                if (isCacheOnSave())                {                    ${interfaceName}Manager.putInstance(this);                }  #end            }  #if ($complexObjectModel)

⌨️ 快捷键说明

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