`
tylzhuang
  • 浏览: 55233 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

关于适配器模式的介绍以及torque中的实现

    博客分类:
  • java
阅读更多
关于适配器模式的介绍:
1、Java接口和Java抽象类最大的一个区别,就在于Java抽象类可以提供某些方法的部分实现,而Java接口不可以,这是Java抽象类唯一的优点吧,但这个优点非常有用。如果向一个抽象类里加入一个公共的具体方法时,那么它所有的子类都会自动拥有了这个新方法,而Java接口做不到这一点,如果向一个Java接口里加入一个新方法,所有实现这个接口的类就无法成功进行编译了,因为你必须让每一个类都要再实现这个方法。
2、由于Java语言的单继承性,所以抽象类作为类型定义工具的效能大打折扣,一个抽象类的实现只能由这个抽象类的子类给出。在这一点上,Java接口的优势就出来了,任何一个实现了一个Java接口所规定的方法的类都可以具有这个接口的类型,而一个类可以实现任意多个Java接口,从而这个类就有了多种类型。
3、从第2点不难看出,Java接口是定义混合类型的理想工具,混合类表明一个类不仅仅具有某个主类型的行为,而且具有其他的次要行为。这里也可以理解为,混合类可以有共同的业务逻辑,也可以有很多特定的业务逻辑。
4、结合1、2点中抽象类和Java接口的各自优势,最精典的设计模式就出来了:声明类型的工作仍然由Java接口承担,但是同时给出一个Java 抽象类,且实现了这个接口,而其他同属于这个抽象类型的具体类可以选择实现这个Java接口,也可以选择继承这个抽象类,也就是说在层次结构中,Java 接口在最上面,然后紧跟着抽象类。这个模式就是“缺省适配模式”。
在Java语言API中用了这种模式,而且全都遵循一定的命名规范:Abstract +接口名。
Java接口和Java抽象类的存在就是为了用于具体类的实现和继承的,如果你准备写一个具体类去继承另一个具体类的话,那你的设计就有很大问题了。Java抽象类就是为了继承而存在的,它的抽象方法就是为了强制子类必须去实现的。
具体例子:torque3.3
一、 Torque多数据库支持的实现方式:
接口类:DB.java
抽象类:AbstractDBAdapter.java
部分遵循了java语言的命名规范:Abstract +接口名
具体实现类:DBOracle.java  连接oracle
            DBMSSQL.java   连接SQL Server
            DBSybase.java  连接Sysbase
上述类均继承:AbstractDBAdapter.java
配置文件torque.properties
torque.database.default=yf
torque.database.yf.adapter=sqlserver
torque.dsfactory.yf.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
torque.dsfactory.yf.pool.maxWait = 10000
torque.dsfactory.yf.pool.maxIdle=8
torque.dsfactory.yf.pool.maxActive=20
torque.dsfactory.yf.pool.minEvictableIdleTimeMillis = 3600000
torque.dsfactory.yf.connection.driver = com.microsoft.jdbc.sqlserver.SQLServerDriver
torque.dsfactory.yf.connection.url = jdbc:sqlserver://10.7.14.14:1433;databaseName=AuthCenter
torque.dsfactory.yf.connection.user = sa
torque.dsfactory.yf.connection.password = shdxgwzf
当我们更换为数据库时,修改配置文件(红色字体部分),即可。
package org.apache.torque.adapter;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

import org.apache.torque.TorqueException;
import org.apache.torque.util.Query;

/**
 * <code>DB</code> defines the interface for a Torque database
 * adapter.  Support for new databases is added by implementing this
 * interface. A couple of default settings is provided by
 * subclassing <code>AbstractDBAdapter</code>. The new database adapter
 * and its corresponding JDBC driver need to be registered in the service
 * configuration file.
 *
 * <p>The Torque database adapters exist to present a uniform
 * interface to database access across all available databases.  Once
 * the necessary adapters have been written and configured,
 * transparent swapping of databases is theoretically supported with
 * <i>zero code changes</i> and minimal configuration file
 * modifications.
 *
 * All database adapters need to be thread safe, as they are instantiated
 * only once fore a given configured database and may be accessed
 * simultaneously from several threads.
 *
 * <p>Torque uses the driver class name to find the right adapter.
 * A JDBC driver corresponding to your adapter must be added to the properties
 * file, using the fully-qualified class name of the driver. If no driver is
 * specified for your database, <code>driver.default</code> is used.
 *
 * <pre>
 * #### MySQL MM Driver
 * database.default.driver=org.gjt.mm.mysql.Driver
 * database.default.url=jdbc:mysql://localhost/DATABASENAME
 * </pre>
 *
 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
 * @version $Id: DB.java 476550 2006-11-18 16:08:37Z tfischer $
 */
public interface DB extends Serializable, IDMethod
{
    /** Database does not support limiting result sets.
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_NONE = 0;

    /** <code>SELECT ... LIMIT <limit>, [&lt;offset&gt;]</code>
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_POSTGRES = 1;

    /** <code>SELECT ... LIMIT [<offset>, ] &lt;offset&gt;</code>
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_MYSQL = 2;

    /** <code>SET ROWCOUNT &lt;offset&gt; SELECT ... SET ROWCOUNT 0</code>
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_SYBASE = 3;

    /** <code><pre>SELECT ... WHERE ... AND ROWNUM < <limit></pre></code>
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_ORACLE = 4;

    /** <code><pre>SELECT ... WHERE ... AND ROW_NUMBER() OVER() < <limit></pre></code>
     *  @deprecated This should not be exposed to the outside
     */
    int LIMIT_STYLE_DB2 = 5;

    /**
     * Key for the configuration which contains database adapters.
     */
    String ADAPTER_KEY = "adapter";

    /**
     * Key for the configuration which contains database drivers.
     */
    String DRIVER_KEY = "driver";

    /**
     * This method is used to ignore case.
     *
     * @param in The string to transform to upper case.
     * @return The upper case string.
     */
    String toUpperCase(String in);

    /**
     * Returns the character used to indicate the beginning and end of
     * a piece of text used in a SQL statement (generally a single
     * quote).
     *
     * @return The text delimeter.
     */
    char getStringDelimiter();

    /**
     * Returns the constant from the {@link
     * org.apache.torque.adapter.IDMethod} interface denoting which
     * type of primary key generation method this type of RDBMS uses.
     *
     * @return IDMethod constant
     */
    String getIDMethodType();

    /**
     * Returns SQL used to get the most recently inserted primary key.
     * Databases which have no support for this return
     * <code>null</code>.
     *
     * @param obj Information used for key generation.
     * @return The most recently inserted database key.
     */
    String getIDMethodSQL(Object obj);

    /**
     * Locks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to lock.
     * @throws SQLException No Statement could be created or executed.
     */
    void lockTable(Connection con, String table)
            throws SQLException;

    /**
     * Unlocks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to unlock.
     * @throws SQLException No Statement could be created or executed.
     */
    void unlockTable(Connection con, String table)
            throws SQLException;

    /**
     * Modifies a SQL snippet such that its case is ignored by the database.
     * The SQL snippet can be a column name (like AURHOR.NAME), an
     * quoted explicit sql string (like 'abc') or any other sql value (like a
     * number etc.).
     *
     * @param in The SQL snippet whose case to ignore.
     * @return The string in a case that can be ignored.
     */
    String ignoreCase(String in);

    /**
     * This method is used to ignore case in an ORDER BY clause.
     * Usually it is the same as ignoreCase, but some databases
     * (Interbase for example) does not use the same SQL in ORDER BY
     * and other clauses.
     *
     * @param in The string whose case to ignore.
     * @return The string in a case that can be ignored.
     */
    String ignoreCaseInOrderBy(String in);

    /**
     * This method is used to check whether the database natively
     * supports limiting the size of the resultset.
     *
     * @return True if the database natively supports limiting the
     * size of the resultset.
     */
    boolean supportsNativeLimit();

    /**
     * This method is used to check whether the database natively
     * supports returning results starting at an offset position other
     * than 0.
     *
     * @return True if the database natively supports returning
     * results starting at an offset position other than 0.
     */
    boolean supportsNativeOffset();

    /**
     * This method is used to generate the database specific query
     * extension to limit the number of record returned.
     *
     * @param query The query to modify
     * @param offset the offset Value
     * @param limit the limit Value
     *
     * @throws TorqueException if any error occurs when building the query
     */
    void generateLimits(Query query, int offset, int limit)
        throws TorqueException;

    /**
    * Whether backslashes (\) should be escaped in explicit SQL strings.
    * If true is returned, a BACKSLASH will be changed to "\\". If false
    * is returned, a BACKSLASH will be left as "\".
    *
    * @return true if the database needs to escape backslashes
    *         in SqlExpressions.
    */

    boolean escapeText();

    /**
     * This method is used to check whether the database supports
     * limiting the size of the resultset.
     *
     * @return The limit style for the database.
     * @deprecated This should not be exposed to the outside
     */
    int getLimitStyle();

    /**
     * This method is used to format any date string.
     * Database can use different default date formats.
     *
     * @param date the Date to format
     * @return The proper date formatted String.
     */
    String getDateString(Date date);

    /**
     * This method is used to format a boolean string.
     *
     * @param b the Boolean to format
     * @return The proper date formatted String.
     */
    String getBooleanString(Boolean b);

    /**
     * Whether ILIKE should be used for case insensitive like clauses.
     *
     * @return true if ilike should be used for case insensitive likes,
     *         false if ignoreCase should be applied to the compared strings.
     */
    boolean useIlike();

    /**
     * Whether an escape clause in like should be used.
     * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
     *
     * @return whether the escape clause should be appended or not.
     */
    boolean useEscapeClauseForLike();
}

package org.apache.torque.adapter;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import org.apache.torque.TorqueException;
import org.apache.torque.util.Query;

/**
 * This class is the abstract base for any database adapter
 * Support for new databases is added by subclassing this
 * class and implementing its abstract methods, and by
 * registering the new database adapter and its corresponding
 * JDBC driver in the service configuration file.
 *
 * <p>The Torque database adapters exist to present a uniform
 * interface to database access across all available databases.  Once
 * the necessary adapters have been written and configured,
 * transparent swapping of databases is theoretically supported with
 * <i>zero code changes</i> and minimal configuration file
 * modifications.
 *
 * <p>Torque uses the driver class name to find the right adapter.
 * A JDBC driver corresponding to your adapter must be added to the properties
 * file, using the fully-qualified class name of the driver. If no driver is
 * specified for your database, <code>driver.default</code> is used.
 *
 * <pre>
 * #### MySQL MM Driver
 * database.default.driver=org.gjt.mm.mysql.Driver
 * database.default.url=jdbc:mysql://localhost/DATABASENAME
 * </pre>
 *
 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
 * @version $Id: DB.java 393063 2006-04-10 20:59:16Z tfischer $
 */
public abstract class AbstractDBAdapter implements DB
{
    /**
     * Empty constructor.
     */
    protected AbstractDBAdapter()
    {
    }

    /**
     * This method is used to ignore case.
     *
     * @param in The string to transform to upper case.
     * @return The upper case string.
     */
    public abstract String toUpperCase(String in);

    /**
     * Returns the character used to indicate the beginning and end of
     * a piece of text used in a SQL statement (generally a single
     * quote).
     *
     * @return The text delimeter.
     */
    public char getStringDelimiter()
    {
        return '\'';
    }

    /**
     * Returns the constant from the {@link
     * org.apache.torque.adapter.IDMethod} interface denoting which
     * type of primary key generation method this type of RDBMS uses.
     *
     * @return IDMethod constant
     */
    public abstract String getIDMethodType();

    /**
     * Returns SQL used to get the most recently inserted primary key.
     * Databases which have no support for this return
     * <code>null</code>.
     *
     * @param obj Information used for key generation.
     * @return The most recently inserted database key.
     */
    public abstract String getIDMethodSQL(Object obj);

    /**
     * Locks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to lock.
     * @throws SQLException No Statement could be created or executed.
     */
    public abstract void lockTable(Connection con, String table)
            throws SQLException;

    /**
     * Unlocks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to unlock.
     * @throws SQLException No Statement could be created or executed.
     */
    public abstract void unlockTable(Connection con, String table)
            throws SQLException;

    /**
     * This method is used to ignore case.
     *
     * @param in The string whose case to ignore.
     * @return The string in a case that can be ignored.
     */
    public abstract String ignoreCase(String in);

    /**
     * This method is used to ignore case in an ORDER BY clause.
     * Usually it is the same as ignoreCase, but some databases
     * (Interbase for example) does not use the same SQL in ORDER BY
     * and other clauses.
     *
     * @param in The string whose case to ignore.
     * @return The string in a case that can be ignored.
     */
    public String ignoreCaseInOrderBy(String in)
    {
        return ignoreCase(in);
    }

    /**
     * This method is used to check whether the database natively
     * supports limiting the size of the resultset.
     *
     * @return True if the database natively supports limiting the
     * size of the resultset.
     */
    public boolean supportsNativeLimit()
    {
        return false;
    }

    /**
     * This method is used to check whether the database natively
     * supports returning results starting at an offset position other
     * than 0.
     *
     * @return True if the database natively supports returning
     * results starting at an offset position other than 0.
     */
    public boolean supportsNativeOffset()
    {
        return false;
    }

    /**
     * This method is used to generate the database specific query
     * extension to limit the number of record returned.
     *
     * @param query The query to modify
     * @param offset the offset Value
     * @param limit the limit Value
     *
     * @throws TorqueException if any error occurs when building the query
     */
    public void generateLimits(Query query, int offset, int limit)
        throws TorqueException
    {
        if (supportsNativeLimit())
        {
            query.setLimit(String.valueOf(limit));
        }
    }

    /**
    * This method is for the SqlExpression.quoteAndEscape rules.  The rule is,
    * any string in a SqlExpression with a BACKSLASH will either be changed to
    * "\\" or left as "\".  SapDB does not need the escape character.
    *
    * @return true if the database needs to escape text in SqlExpressions.
    */

    public boolean escapeText()
    {
        return true;
    }

    /**
     * This method is used to check whether the database supports
     * limiting the size of the resultset.
     *
     * @return The limit style for the database.
     * @deprecated This should not be exposed to the outside
     */
    public int getLimitStyle()
    {
        return LIMIT_STYLE_NONE;
    }

    /**
     * This method is used to format any date string.
     * Database can use different default date formats.
     *
     * @param date the Date to format
     * @return The proper date formatted String.
     */
    public String getDateString(Date date)
    {
        Timestamp ts = null;
        if (date instanceof Timestamp)
        {
            ts = (Timestamp) date;
        }
        else
        {
            ts = new Timestamp(date.getTime());
        }

        return ("{ts '" + ts + "'}");
    }

    /**
     * This method is used to format a boolean string.
     *
     * @param b the Boolean to format
     * @return The proper date formatted String.
     */
    public String getBooleanString(Boolean b)
    {
        return (Boolean.TRUE.equals(b) ? "1" : "0");
    }

    /**
     * Whether ILIKE should be used for case insensitive like clauses.
     *
     * As most databases do not use ILIKE, this implementation returns false.
     * This behaviour may be overwritten in subclasses.
     *
     * @return true if ilike should be used for case insensitive likes,
     *         false if ignoreCase should be applied to the compared strings.
     */
    public boolean useIlike()
    {
        return false;
    }

    /**
     * Whether an escape clause in like should be used.
     * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
     *
     * As most databases do not need the escape clause, this implementation
     * always returns <code>false</code>. This behaviour can be overwritten
     * in subclasses.
     *
     * @return whether the escape clause should be appended or not.
     */
    public boolean useEscapeClauseForLike()
    {
        return false;
    }
}

package org.apache.torque.adapter;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.ListIterator;
import java.util.Set;

import org.apache.torque.util.Query;
import org.apache.torque.util.UniqueList;

/**
 * This code should be used for an Oracle database pool.
 *
 * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
 * @author <a href="mailto:bschneider@vecna.com">Bill Schneider</a>
 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 * @version $Id: DBOracle.java 476550 2006-11-18 16:08:37Z tfischer $
 */
public class DBOracle extends AbstractDBAdapter
{
    /**
     * Serial version
     */
    private static final long serialVersionUID = 8966976210230241194L;

    /** date format used in getDateString() */
    private static final String DATE_FORMAT = "dd-MM-yyyy HH:mm:ss";

    /**
     * Empty constructor.
     */
    protected DBOracle()
    {
    }

    /**
     * This method is used to ignore case.
     *
     * @param in The string to transform to upper case.
     * @return The upper case string.
     */
    public String toUpperCase(String in)
    {
        return new StringBuffer("UPPER(").append(in).append(")").toString();
    }

    /**
     * This method is used to ignore case.
     *
     * @param in The string whose case to ignore.
     * @return The string in a case that can be ignored.
     */
    public String ignoreCase(String in)
    {
        return new StringBuffer("UPPER(").append(in).append(")").toString();
    }

    /**
     * This method is used to format any date string.
     *
     * @param date the Date to format
     * @return The date formatted String for Oracle.
     */
    public String getDateString(Date date)
    {
        return "TO_DATE('" + new SimpleDateFormat(DATE_FORMAT).format(date)
                + "', 'DD-MM-YYYY HH24:MI:SS')";
    }

    /**
     * @see org.apache.torque.adapter.DB#getIDMethodType()
     */
    public String getIDMethodType()
    {
        return SEQUENCE;
    }

    /**
     * Returns the next key from a sequence.  Uses the following
     * implementation:
     *
     * <blockquote><code><pre>
     * select sequenceName.nextval from dual
     * </pre></code></blockquote>
     *
     * @param sequenceName The name of the sequence (should be of type
     * <code>String</code>).
     * @return SQL to retreive the next database key.
     * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object)
     */
    public String getIDMethodSQL(Object sequenceName)
    {
        return ("select " + sequenceName + ".nextval from dual");
    }

    /**
     * Locks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to lock.
     * @exception SQLException No Statement could be created or executed.
     */
    public void lockTable(Connection con, String table) throws SQLException
    {
        Statement statement = con.createStatement();

        StringBuffer stmt = new StringBuffer();
        stmt.append("SELECT next_id FROM ")
                .append(table)
                .append(" FOR UPDATE");

        statement.executeQuery(stmt.toString());
    }

    /**
     * Unlocks the specified table.
     *
     * @param con The JDBC connection to use.
     * @param table The name of the table to unlock.
     * @exception SQLException No Statement could be created or executed.
     */
    public void unlockTable(Connection con, String table) throws SQLException
    {
        // Tables in Oracle are unlocked when a commit is issued.  The
        // user may have issued a commit but do it here to be sure.
        con.commit();
    }

    /**
     * This method is used to check whether the database supports
     * limiting the size of the resultset.
     *
     * @return LIMIT_STYLE_ORACLE.
     * @deprecated This should not be exposed to the outside
     */
    public int getLimitStyle()
    {
        return DB.LIMIT_STYLE_ORACLE;
    }

    /**
     * Return true for Oracle
     * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
     */
    public boolean supportsNativeLimit()
    {
        return true;
    }

    /**
     * Return true for Oracle
     * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset()
     */
    public boolean supportsNativeOffset()
    {
        return true;
    }

    /**
     * Build Oracle-style query with limit or offset.
     * If the original SQL is in variable: query then the requlting
     * SQL looks like this:
     * <pre>
     * SELECT B.* FROM (
     *          SELECT A.*, rownum as TORQUE$ROWNUM FROM (
     *                  query
     *          ) A
     *     ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
     *     <= offset + limit
     * </pre>
     *
     * @param query The query to modify
     * @param offset the offset Value
     * @param limit the limit Value
     */
    public void generateLimits(Query query, int offset, int limit)
    {
        StringBuffer preLimit = new StringBuffer()
        .append("SELECT B.* FROM ( ")
        .append("SELECT A.*, rownum AS TORQUE$ROWNUM FROM ( ");

        StringBuffer postLimit = new StringBuffer()
                .append(" ) A ")
                .append(" ) B WHERE ");

        if (offset > 0)
        {
            postLimit.append(" B.TORQUE$ROWNUM > ")
                    .append(offset);

            if (limit >= 0)
            {
                postLimit.append(" AND B.TORQUE$ROWNUM <= ")
                        .append(offset + limit);
            }
        }
        else
        {
            postLimit.append(" B.TORQUE$ROWNUM <= ")
                    .append(limit);
        }

        query.setPreLimit(preLimit.toString());
        query.setPostLimit(postLimit.toString());
        query.setLimit(null);

        // the query must not contain same column names or aliases.
        // Find double column names and aliases and create unique aliases
        // TODO: does not work for functions yet
        UniqueList selectColumns = query.getSelectClause();
        int replacementSuffix = 0;
        Set columnNames = new HashSet();
        // first pass: only remember aliased columns
        // No replacements need to take place because double aliases
        // are not allowed anyway
        // So alias names will be retained
        for (ListIterator columnIt = selectColumns.listIterator();
                columnIt.hasNext();)
        {
            String selectColumn = (String) columnIt.next();

            // check for sql function
            if ((selectColumn.indexOf('(') != -1)
                || (selectColumn.indexOf(')') != -1))
            {
                // Sql function. Disregard.
                continue;
            }

            // check if alias name exists
            int spacePos = selectColumn.lastIndexOf(' ');
            if (spacePos == -1)
            {
                // no alias, disregard for now
                continue;
            }

            String aliasName = selectColumn.substring(spacePos + 1);
            columnNames.add(aliasName);
        }

        // second pass. Regard ordinary columns only
        for (ListIterator columnIt = selectColumns.listIterator();
                columnIt.hasNext();)
        {
            String selectColumn = (String) columnIt.next();

            // check for sql function
            if ((selectColumn.indexOf('(') != -1)
                || (selectColumn.indexOf(')') != -1))
            {
                // Sql function. Disregard.
                continue;
            }

            {
                int spacePos = selectColumn.lastIndexOf(' ');
                if (spacePos != -1)
                {
                    // alias, already processed in first pass
                    continue;
                }
            }
            // split into column name and tableName
            String column;
            {
                int dotPos = selectColumn.lastIndexOf('.');
                if (dotPos != -1)
                {
                    column = selectColumn.substring(dotPos + 1);
                }
                else
                {
                    column = selectColumn;
                }
            }
            if (columnNames.contains(column))
            {
                // column needs to be aliased
                // get replacement name
                String aliasName;
                do
                {
                    aliasName = "a" + replacementSuffix;
                    ++replacementSuffix;
                }
                while (columnNames.contains(aliasName));

                selectColumn = selectColumn + " " + aliasName;
                columnIt.set(selectColumn);
                columnNames.add(aliasName);
            }
            else
            {
                columnNames.add(column);
            }
        }
    }

    /**
     * This method is for the SqlExpression.quoteAndEscape rules.  The rule is,
     * any string in a SqlExpression with a BACKSLASH will either be changed to
     * "\\" or left as "\".  SapDB does not need the escape character.
     *
     * @return false.
     */
    public boolean escapeText()
    {
        return false;
    }

    /**
     * Whether an escape clause in like should be used.
     * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
     *
     * Oracle needs this, so this implementation always returns
     * <code>true</code>.
     *
     * @return whether the escape clause should be appended or not.
     */
    public boolean useEscapeClauseForLike()
    {
        return true;
    }
}



二、关于torque数据源工厂类的实现方式:
接口类:DataSourceFactory.java
抽象类:AbstractDataSourceFactory.java
遵循了java语言的命名规范:Abstract +接口名
具体实现类:C3P0DataSourceFactory.java
SharedPoolDataSourceFactory.java
JndiDataSourceFactory.java
上述类均继承:AbstractDataSourceFactory.java

配置文件torque.properties
torque.dsfactory.yf.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
torque.dsfactory.yf.pool.maxWait = 10000
torque.dsfactory.yf.pool.maxIdle=8
torque.dsfactory.yf.pool.maxActive=20
torque.dsfactory.yf.pool.minEvictableIdleTimeMillis = 3600000
torque.dsfactory.yf.connection.driver = com.microsoft.jdbc.sqlserver.SQLServerDriver
torque.dsfactory.yf.connection.url = jdbc:sqlserver://10.7.14.14:1433;databaseName=AuthCenter
torque.dsfactory.yf.connection.user = sa
torque.dsfactory.yf.connection.password = shdxgwzf
其中C3P0DataSourceFactory.java 是我为将hibernate使用的C3P0数据库连接池作为一种可以使用的数据库连接池而实现的。当我们更换为C3P0数据库连接池,修改配置文件(红色字体部分),即可。
package org.apache.torque.dsfactory;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import javax.sql.DataSource;
import org.apache.commons.configuration.Configuration;
import org.apache.torque.TorqueException;

/**
 * A factory that returns a DataSource.
 *
 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
 * @version $Id: DataSourceFactory.java 473821 2006-11-11 22:37:25Z tv $
 */
public interface DataSourceFactory
{
    /**
     * Key for the configuration which contains DataSourceFactories
     */
    String DSFACTORY_KEY = "dsfactory";

    /**
     *  Key for the configuration which contains the fully qualified name
     *  of the factory implementation class
     */
    String FACTORY_KEY = "factory";

    /**
     * @return the <code>DataSource</code> configured by the factory.
     * @throws TorqueException if the source can't be returned
     */
    DataSource getDataSource() throws TorqueException;

    /**
     * Initialize the factory.
     *
     * @param configuration where to load the factory settings from
     * @throws TorqueException Any exceptions caught during processing will be
     *         rethrown wrapped into a TorqueException.
     */
    void initialize(Configuration configuration)
        throws TorqueException;

    /**
     * Sets the current schema for the database connection
     *
     * @param schema The current schema name
     * @deprecated use DatabaseInfo.setSchema() instead. Will be removed
     *             in a future version of Torque.
     */
    void setSchema(String schema);

    /**
     * This method returns the current schema for the database connection
     *
     * @return The current schema name. Null means, no schema has been set.
     * @throws TorqueException Any exceptions caught during processing will be
     *         rethrown wrapped into a TorqueException.
     * @deprecated use DatabaseInfo.getSchema() instead. Will be removed
     *             in a future version of Torque.
     */
    String getSchema();

    /**
     * A hook which is called when the resources of the associated DataSource
     * can be released.
     * After close() is called, the other methods may not work any more
     * (e.g. getDataSource() might return null).
     * It is not guaranteed that this method does anything. For example,
     * we do not want to close connections retrieved via JNDI, so the
     * JndiDataSouurceFactory does not close these connections
     *
     * @throws TorqueException Any exceptions caught during processing will be
     *         rethrown wrapped into a TorqueException.
     */
    void close()
        throws TorqueException;
}

package org.apache.torque.dsfactory;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.Iterator;

import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.MappedPropertyDescriptor;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.TorqueRuntimeException;

/**
 * A class that contains common functionality of the factories in this
 * package.
 *
 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 * @version $Id: AbstractDataSourceFactory.java 473821 2006-11-11 22:37:25Z tv $
 */
public abstract class AbstractDataSourceFactory
        implements DataSourceFactory
{
    /** "pool" Key for the configuration */
    public static final String POOL_KEY = "pool";

    /** "connection" Key for the configuration */
    public static final String CONNECTION_KEY = "connection";

    /** "schema" Key for the configuration */
    public static final String SCHEMA_KEY = "schema";

    /** "defaults" Key for the configuration */
    public static final String DEFAULTS_KEY = "defaults";

    /** "defaults.pool" Key for the configuration */
    public static final String DEFAULT_POOL_KEY
            = DEFAULTS_KEY + "." + POOL_KEY;

    /** "defaults.connection" Key for the configuration */
    public static final String DEFAULT_CONNECTION_KEY
            = DEFAULTS_KEY + "." + CONNECTION_KEY;

    /** default schema name for the configuration */
    public static final String DEFAULT_SCHEMA_KEY
            = DEFAULTS_KEY + "." + SCHEMA_KEY;


    /** The log */
    private static Log log = LogFactory.getLog(AbstractDataSourceFactory.class);

    /** Internal Marker for the Schema name of this database connection */
    private String schema = null;

    /**
     * Encapsulates setting configuration properties on
     * <code>DataSource</code> objects.
     *
     * @param property the property to read from the configuration
     * @param c the configuration to read the property from
     * @param ds the <code>DataSource</code> instance to write the property to
     * @throws Exception if anything goes wrong
     */
    protected void setProperty(String property, Configuration c, Object ds)
        throws Exception
    {
        if (c == null || c.isEmpty())
        {
            return;
        }

        String key = property;
        Class dsClass = ds.getClass();
        int dot = property.indexOf('.');
        try
        {
            if (dot > 0)
            {
                property = property.substring(0, dot);

                MappedPropertyDescriptor mappedPD =
                    new MappedPropertyDescriptor(property, dsClass);
                Class propertyType = mappedPD.getMappedPropertyType();
                Configuration subProps = c.subset(property);
                // use reflection to set properties
                Iterator j = subProps.getKeys();
                while (j.hasNext())
                {
                    String subProp = (String) j.next();
                    String propVal = subProps.getString(subProp);
                    Object value = ConvertUtils.convert(propVal, propertyType);
                    PropertyUtils
                        .setMappedProperty(ds, property, subProp, value);

                    if (log.isDebugEnabled())
                    {
                        log.debug("setMappedProperty("
                                       + ds + ", "
                                       + property + ", "
                                       + subProp + ", "
                                       + value
                                       + ")");
                    }
                }
            }
            else
            {
                if ("password".equals(key))
                {
                    // do not log value of password
                    // for this, ConvertUtils.convert cannot be used
                    // as it also logs the value of the converted property
                    // so it is assumed here that the password is a String
                    String value = c.getString(property);
                    PropertyUtils.setSimpleProperty(ds, property, value);
                    if (log.isDebugEnabled())
                    {
                        log.debug("setSimpleProperty("
                                       + ds + ", "
                                       + property + ", "
                                       + " (value not logged)"
                                       + ")");
                    }
                    log.error(property + " == "
                            + value
                    		);
                }
                else
                {
                	
                    Class propertyType =
                        PropertyUtils.getPropertyType(ds, property);
                    Object value =
                        ConvertUtils.convert(c.getString(property), propertyType);
                    PropertyUtils.setSimpleProperty(ds, property, value);

                    if (log.isDebugEnabled())
                    {
                        log.debug("setSimpleProperty("
                                       + ds + ", "
                                       + property + ", "
                                       + value
                                       + ")");
                    }
                    else
                    {
                    	if("user".equals(key) || "url".equals(key) || "driver".equals(key))
                        log.error(property + " == "
                                + value
                                );
                    }
                    
                }
            }
        }
        catch (RuntimeException e)
        {
            throw new TorqueRuntimeException(
                "Runtime error setting property " + property, e);
        }
        catch (Exception e)
        {
            log.error(
                "Property: "
                + property
                + " value: "
                + c.getString(key)
                + " is not supported by DataSource: "
                + ds.getClass().getName());
        }
    }

    /**
     * Iterate over a Configuration subset and apply all
     * properties to a passed object which must contain Bean
     * setter and getter
     *
     * @param c The configuration subset
     * @param o The object to apply the properties to
     * @throws TorqueException if a property set fails
     */
    protected void applyConfiguration(Configuration c, Object o)
        throws TorqueException
    {
        log.debug("applyConfiguration(" + c + ", " + o + ")");

        if (c != null)
        {
            try
            {
                for (Iterator i = c.getKeys(); i.hasNext();)
                {
                    String key = (String) i.next();
                    setProperty(key, c, o);
                }
            }
            catch (Exception e)
            {
                log.error(e);
                throw new TorqueException(e);
            }
        }
    }

    /**
     * Initializes the ConnectionPoolDataSource.
     *
     * @param configuration where to read the settings from
     * @throws TorqueException if a property set fails
     * @return a configured <code>ConnectionPoolDataSource</code>
     */
    protected ConnectionPoolDataSource initCPDS(Configuration configuration)
        throws TorqueException
    {
        log.debug("Starting initCPDS");
        ConnectionPoolDataSource cpds = new DriverAdapterCPDS();
        Configuration c = Torque.getConfiguration();

        if (c == null || c.isEmpty())
        {
            log.warn("Global Configuration not set,"
                    + " no Default connection pool data source configured!");
        }
        else
        {
            Configuration conf = c.subset(DEFAULT_CONNECTION_KEY);
            applyConfiguration(conf, cpds);
        }

        Configuration conf = configuration.subset(CONNECTION_KEY);
        applyConfiguration(conf, cpds);

        return cpds;
    }

    /**
     * Sets the current schema for the database connection
     *
     * @param schema The current schema name
     */
    public void setSchema(String schema)
    {
        this.schema = schema;
    }

    /**
     * This method returns the current schema for the database connection
     *
     * @return The current schema name. Null means, no schema has been set.
     * @throws TorqueException Any exceptions caught during processing will be
     *         rethrown wrapped into a TorqueException.
     * @deprecated use DatabaseInfo.setSchema() instead. Will be removed
     *             in a future version of Torque.
     */
    public String getSchema()
    {
        return schema;
    }

    /**
     * @return the <code>DataSource</code> configured by the factory.
     * @throws TorqueException if the source can't be returned
     */
    public abstract DataSource getDataSource()
            throws TorqueException;

    /**
     * Initialize the factory.
     *
     * @param configuration where to load the factory settings from
     * @throws TorqueException Any exceptions caught during processing will be
     *         rethrown wrapped into a TorqueException.
     */
    public void initialize(Configuration configuration)
        throws TorqueException
    {
        if (configuration == null)
        {
            throw new TorqueException(
                "Torque cannot be initialized without "
                    + "a valid configuration. Please check the log files "
                    + "for further details.");
        }

        schema = configuration.getString(SCHEMA_KEY, null);

        if (StringUtils.isEmpty(schema))
        {
            Configuration conf = Torque.getConfiguration();
            schema = conf.getString(DEFAULT_SCHEMA_KEY, null);
        }
    }
}

package org.apache.torque.dsfactory;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;

import org.apache.commons.configuration.Configuration;

import org.apache.commons.dbcp.datasources.SharedPoolDataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.torque.Torque;
import org.apache.torque.TorqueException;

/**
 * A factory that looks up the DataSource using the JDBC2 pool methods.
 *
 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 * @version $Id: SharedPoolDataSourceFactory.java 476550 2006-11-18 16:08:37Z tfischer $
 */
public class SharedPoolDataSourceFactory
    extends AbstractDataSourceFactory
{

    /** The log. */
    private static Log log
            = LogFactory.getLog(SharedPoolDataSourceFactory.class);

    /** The wrapped <code>DataSource</code>. */
    private SharedPoolDataSource ds = null;

    /**
     * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
     */
    public DataSource getDataSource()
    {
        return ds;
    }

    /**
     * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
     */
    public void initialize(Configuration configuration) throws TorqueException
    {
        super.initialize(configuration);

        ConnectionPoolDataSource cpds = initCPDS(configuration);
        SharedPoolDataSource dataSource = initJdbc2Pool(configuration);
        dataSource.setConnectionPoolDataSource(cpds);
        this.ds = dataSource;
    }

    /**
     * Initializes the Jdbc2PoolDataSource.
     *
     * @param configuration where to read the settings from
     * @throws TorqueException if a property set fails
     * @return a configured <code>Jdbc2PoolDataSource</code>
     */
    private SharedPoolDataSource initJdbc2Pool(Configuration configuration)
        throws TorqueException
    {
        log.debug("Starting initJdbc2Pool");
        SharedPoolDataSource dataSource = new SharedPoolDataSource();
        Configuration c = Torque.getConfiguration();

        if (c == null || c.isEmpty())
        {
            log.warn("Global Configuration not set,"
                    + " no Default pool data source configured!");
        }
        else
        {
            Configuration conf = c.subset(DEFAULT_POOL_KEY);
            applyConfiguration(conf, dataSource);
        }

        Configuration conf = configuration.subset(POOL_KEY);
        applyConfiguration(conf, dataSource);
        return dataSource;
    }


    /**
     * Closes the pool associated with this factory and releases it.
     * @throws TorqueException if the pool cannot be closed properly
     */
    public void close() throws TorqueException
    {
        try
        {
            ds.close();
        }
        catch (Exception e)
        {
            log.error("Exception caught during close()", e);
            throw new TorqueException(e);
        }
        ds = null;
    }
}

package org.apache.torque.dsfactory;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;

import org.apache.commons.configuration.Configuration;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.torque.Torque;
import org.apache.torque.TorqueException;

/**
 * A factory that looks up the DataSource using the JDBC2 pool methods.
 *
 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 * @version $Id: C3P0DataSourceFactory.java 476550 2006-11-18 16:08:37Z tfischer $
 */
public class C3P0DataSourceFactory
    extends AbstractDataSourceFactory
{

    /** The log. */
    private static Log log
            = LogFactory.getLog(C3P0DataSourceFactory.class);

    /** The wrapped <code>DataSource</code>. */
    private ComboPooledDataSource ds = null;

    /**
     * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
     */
    public DataSource getDataSource()
    {
        return ds;
    }

    /**
     * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
     */
    public void initialize(Configuration configuration) throws TorqueException
    {
    	log.debug("Starting initialize ----------- ");
        super.initialize(configuration);
       
        ComboPooledDataSource dataSource = initJdbc2Pool(configuration);
        
        this.ds = dataSource;
    }

    /**
     * Initializes the Jdbc2PoolDataSource.
     *
     * @param configuration where to read the settings from
     * @throws TorqueException if a property set fails
     * @return a configured <code>Jdbc2PoolDataSource</code>
     */
    private ComboPooledDataSource initJdbc2Pool(Configuration configuration)
        throws TorqueException
    {
        log.debug("Starting initJdbc2Pool");
		Configuration c = Torque.getConfiguration();
        ComboPooledDataSource dataSource = new ComboPooledDataSource();        

        if (c == null || c.isEmpty())
        {
            log.warn("Global Configuration not set,"
                    + " no Default pool data source configured!");
        }
        else
        {
            Configuration conf = c.subset(DEFAULT_POOL_KEY);
           	
            applyConfiguration(conf, dataSource);
        }
        //init 数据库连接
        Configuration connConf = configuration.subset(CONNECTION_KEY);
        applyConfiguration(connConf, dataSource);
        //init 数据库连接池
        Configuration conf = configuration.subset(POOL_KEY);
        applyConfiguration(conf, dataSource);

        return dataSource;
    }


    /**
     * Closes the pool associated with this factory and releases it.
     * @throws TorqueException if the pool cannot be closed properly
     */
    public void close() throws TorqueException
    {
        try
        {
            ds.close();
        }
        catch (Exception e)
        {
            log.error("Exception caught during close()", e);
            throw new TorqueException(e);
        }
        ds = null;
    }
}


分享到:
评论

相关推荐

    Torque中文教程

    在Torque中,资源可以是模型、纹理、音频文件等。理解如何导入、导出和管理这些资源是提高开发效率的关键。此外,我们还会学习如何使用内置的编辑器创建和编辑场景,以及调整光照、摄像机视角和地形等元素。 在物理...

    Torque2D 中文翻译版基础教程(收集)

    《Torque2D 中文翻译版基础教程》是一个针对游戏开发者的资源,它提供了关于Torque2D引擎的详细中文指南。Torque2D是一款2D游戏开发引擎,专为创建2D游戏而设计,具有丰富的功能和易用性。这个教程集合旨在帮助中国...

    Methods _matlab_torque_

    标题中的“Methods _matlab_torque_”暗示了我们将在MATLAB环境中探讨关于扭矩最大化(torque maximization)的磁场削弱(field weakening)控制策略。磁场削弱是交流电机(AC motors)控制的一种技术,用于在高转速...

    hpc作业调度 torque 6.1.2 (for Linux)

    在HPC环境中,作业调度涉及到决定哪些作业应该被运行,何时运行以及在哪个计算节点上运行。Torque通过分配作业到合适的资源来实现这一目标,考虑了作业的优先级、资源需求、依赖关系和当前系统的状态。此外,它还...

    torque 6.1.2

    【标题】"Torque 6.1.2" 是一个重要的集群作业调度系统,它主要用于大规模计算环境,如科学计算和大数据分析。该版本是Torque作业提交系统的更新,提供了更稳定、高效的性能和功能。 【描述】"torque-6.1.2.tar.gz...

    torque admin guide

    本文将基于给定文件内容,针对Torque管理指南进行介绍。 1. Torque概述 Torque是一个开放源代码的集群管理工具,它负责资源调度、作业管理和资源监控。它允许系统管理员高效地管理一个或多个计算节点。Torque使用...

    Torque游戏引擎指南

    在Torque中,游戏对象是通过称为"game objects"的实体来表示的,它们可以是角色、武器、环境物体等。这些对象可以通过脚本进行定制,包括行为、交互性和视觉效果。Torque支持Torque Script语言,这是一种类似C++的...

    TORQUE_Administrator's_Guide

    - **TORQUE**:这是一种广泛使用的作业调度系统,主要用于管理集群中的计算任务。最初被称为 OpenPBS。 - **适用版本**:本指南针对的是 TORQUE 3.0.0 版本。 #### 二、安装与配置 ##### 2.1 安装 - **安装过程**:...

    Torque游戏实战开发I

    - **Torque简介**:本书首先介绍了Torque游戏引擎的基本情况,包括引擎特点、应用环境以及版本信息。 - **游戏策划主要内容**:详细阐述了游戏设计过程中的核心概念,为游戏开发打下基础。 - **安装TorqueSDK**:为...

    Torque+Pro最新汉化修订增补版软件.zip

    这份说明通常会详细介绍如何安装软件、设置OBD适配器、连接车辆以及如何解读和使用各项数据。对于初次接触此类应用的用户来说,这是一份非常有价值的指南,可以帮助他们快速掌握软件的使用技巧。 总的来说,"Torque...

    torque入门教程

    在Torque中,你可以创建导航网格(NavMesh),这是一个覆盖游戏世界的二维网格,用于AI计算路径。首先,你需要将游戏场景导入Torque,然后使用编辑器工具生成或手动绘制导航网格。每个网格节点代表AI可以行走的区域...

    torque文档--torqueAdminGuide

    文档首先提供了关于Torque基本架构的概述,包括ResourceManager的安装流程、计算节点的配置以及服务初始化和服务器配置。在安装部分,管理员可以了解到如何安装Torque资源管理器,并根据服务器和节点的具体需要进行...

    作业提交系统Torque个人安装总结

    【作业提交系统Torque个人安装总结】 Torque(也称为pbs torque)是一种广泛使用的作业调度系统,源于历史悠久的...在日常使用中,用户应根据实际需求调整队列设置,优化资源分配,以实现高效、公平的集群资源使用。

    Torque脚本帮助说明书

    在Torque中,开发者可以利用丰富的图形库和物理引擎来构建沉浸式的游戏体验。 - **游戏运行调用过程**:游戏从启动到运行,涉及到一系列的调用流程,包括初始化、加载资源、网络同步等。理解这一过程对于优化游戏...

    Torque 基础学习

    在Torque中,模型对象是构成游戏世界的基础元素。通过导入3D模型,开发者可以创建角色、车辆、建筑等各种物体。Torque支持多种格式的3D模型,如Collada或3DS。导入模型后,可以使用Torque的编辑工具调整模型的位置、...

    Torque安卓手机

    3. **蓝牙连接**:在"Torque"应用中,用户可以通过蓝牙连接手机与ELM327适配器,实现无线通信。这种方式避免了线缆的束缚,让数据读取更加便捷。 4. **应用功能**: - **实时数据流**:显示车辆关键性能参数,如...

    Torque快速入门教程

    Torque是一个Apache的公开源代码项目,主要功能是实现对数据库的访问,方式是通过生成访问数据库的资源(包括创建数据库、表和初始化表的sql语句)和java代码、提供使用这些代码访问数据库的运行时(runtime)环境。...

    torque 游戏引擎入门

    - **使用Torque实现游戏梦想**:通过一系列实例教学,本书将引导读者逐步掌握使用Torque开发游戏的基本技能,包括场景构建、角色设计、物理效果模拟等方面的知识。 #### 四、Torque游戏引擎的核心特性 - **游戏...

    Torque3D规范及说明书

    《Torque3D规范及说明书》是一份详尽的技术文档,旨在为开发者提供关于Torque 3D游戏引擎的深入理解和使用指导。Torque 3D是一款强大的开源游戏开发工具,它允许开发者创建高质量的3D游戏和应用,尤其适合那些希望...

    torque4官方文档

    根据提供的信息,我们可以深入探讨Torque4的相关知识点,特别是其架构、配置以及作业提交与管理等方面。 ### Torque4概述 #### 架构概览 Torque4是一种高性能的作业调度系统,它由一个管理节点(称为服务器)和多...

Global site tag (gtag.js) - Google Analytics