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

📄 basepeer.java

📁 torque服务器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            {                String join1 = (String) join.get(i);                String join2 = (String) criteria.getJoinR().get(i);                if (join1.indexOf('.') == -1)                {                    throwMalformedColumnNameException("join", join1);                }                if (join2.indexOf('.') == -1)                {                    throwMalformedColumnNameException("join", join2);                }                String tableName = join1.substring(0, join1.indexOf('.'));                String table = criteria.getTableForAlias(tableName);                if (table != null)                {                    fromClause.add(new StringBuffer(                            tableName.length() + table.length() + 1)                            .append(table)                            .append(' ')                            .append(tableName)                            .toString());                }                else                {                    fromClause.add(tableName);                }                int dot = join2.indexOf('.');                tableName = join2.substring(0, dot);                table = criteria.getTableForAlias(tableName);                if (table != null)                {                    fromClause.add(new StringBuffer(                            tableName.length() + table.length() + 1)                            .append(table)                            .append(' ')                            .append(tableName)                            .toString());                }                else                {                    fromClause.add(tableName);                    table = tableName;                }                boolean ignorCase = (criteria.isIgnoreCase()                        && (dbMap                            .getTable(table)                            .getColumn(join2.substring(dot + 1, join2.length()))                            .getType()                            instanceof String));                whereClause.add(                    SqlExpression.buildInnerJoin(join1, join2, ignorCase, db));            }        }        // need to allow for multiple group bys        if (groupBy != null && groupBy.size() > 0)        {            for (int i = 0; i < groupBy.size(); i++)            {                String groupByColumn = (String) groupBy.get(i);                if (groupByColumn.indexOf('.') == -1)                {                    throwMalformedColumnNameException("group by",                            groupByColumn);                }                groupByClause.add(groupByColumn);            }        }        Criteria.Criterion having = criteria.getHaving();        if (having != null)        {            //String groupByString = null;            query.setHaving(having.toString());        }        if (orderBy != null && orderBy.size() > 0)        {            // Check for each String/Character column and apply            // toUpperCase().            for (int i = 0; i < orderBy.size(); i++)            {                String orderByColumn = (String) orderBy.get(i);                if (orderByColumn.indexOf('.') == -1)                {                    throwMalformedColumnNameException("order by",                            orderByColumn);                }                String tableName =                    orderByColumn.substring(0, orderByColumn.indexOf('.'));                String table = criteria.getTableForAlias(tableName);                if (table == null)                {                    table = tableName;                }                // See if there's a space (between the column list and sort                // order in ORDER BY table.column DESC).                int spacePos = orderByColumn.indexOf(' ');                String columnName;                if (spacePos == -1)                {                    columnName =                        orderByColumn.substring(orderByColumn.indexOf('.') + 1);                }                else                {                    columnName = orderByColumn.substring(                            orderByColumn.indexOf('.') + 1, spacePos);                }                ColumnMap column = dbMap.getTable(table).getColumn(columnName);                if (column.getType() instanceof String)                {                    if (spacePos == -1)                    {                        orderByClause.add(                                db.ignoreCaseInOrderBy(orderByColumn));                    }                    else                    {                        orderByClause.add(db.ignoreCaseInOrderBy(                                orderByColumn.substring(0, spacePos))                                + orderByColumn.substring(spacePos));                    }                    selectClause.add(                        db.ignoreCaseInOrderBy(table + '.' + columnName));                }                else                {                    orderByClause.add(orderByColumn);                }            }        }        // Limit the number of rows returned.        int limit = criteria.getLimit();        int offset = criteria.getOffset();        String limitString = null;        if (offset > 0 && db.supportsNativeOffset())        {            switch (db.getLimitStyle())            {                case DB.LIMIT_STYLE_MYSQL :                    limitString = new StringBuffer()                            .append(offset)                            .append(", ")                            .append(limit)                            .toString();                    break;                case DB.LIMIT_STYLE_POSTGRES :                    limitString = new StringBuffer()                            .append(limit)                            .append(" offset ")                            .append(offset)                            .toString();                    break;            }            // The following is now done in createQueryString() to enable this            // method to be used as part of Criteria.toString() without altering            // the criteria itself.  The commented code is retained here to            // make it easier to understand how the criteria is built into a            // query.            // Now set the criteria's limit and offset to return the            // full resultset since the results are limited on the            // server.            //criteria.setLimit(-1);            //criteria.setOffset(0);        }        else if (limit > 0 && db.supportsNativeLimit()                 && db.getLimitStyle() != DB.LIMIT_STYLE_ORACLE)        {            limitString = String.valueOf(limit);            // The following is now done in createQueryString() to enable this            // method to be used as part of Criteria.toString() without altering            // the criteria itself.  The commented code is retained here to            // make it easier to understand how the criteria is built into a            // query.            // Now set the criteria's limit to return the full            // resultset since the results are limited on the server.            //criteria.setLimit(-1);        }        if (limitString != null)        {            query.setLimit(limitString);        }        return query;    }    /**     * Returns all results.     *     * @param criteria A Criteria.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List doSelect(Criteria criteria) throws TorqueException    {        Connection con = null;        List results = null;        try        {            con = Transaction.beginOptional(                    criteria.getDbName(),                    criteria.isUseTransaction());            results = doSelect(criteria, con);            Transaction.commit(con);        }        catch (Exception e)        {            Transaction.safeRollback(con);            throwTorqueException(e);        }        return results;    }    /**     * Returns all results.     *     * @param criteria A Criteria.     * @param con A Connection.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List doSelect(Criteria criteria, Connection con)        throws TorqueException    {        return executeQuery(            createQueryString(criteria),            criteria.getOffset(),            criteria.getLimit(),            criteria.isSingleRecord(),            con);    }    /**     * Utility method which executes a given sql statement.  This     * method should be used for select statements only.  Use     * executeStatement for update, insert, and delete operations.     *     * @param queryString A String with the sql statement to execute.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(String queryString) throws TorqueException    {        return executeQuery(queryString, Torque.getDefaultDB(), false);    }    /**     * Utility method which executes a given sql statement.  This     * method should be used for select statements only.  Use     * executeStatement for update, insert, and delete operations.     *     * @param queryString A String with the sql statement to execute.     * @param dbName The database to connect to.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(String queryString, String dbName)        throws TorqueException    {        return executeQuery(queryString, dbName, false);    }    /**     * Method for performing a SELECT.  Returns all results.     *     * @param queryString A String with the sql statement to execute.     * @param dbName The database to connect to.     * @param singleRecord Whether or not we want to select only a     * single record.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(        String queryString,        String dbName,        boolean singleRecord)        throws TorqueException    {        return executeQuery(queryString, 0, -1, dbName, singleRecord);    }    /**     * Method for performing a SELECT.  Returns all results.     *     * @param queryString A String with the sql statement to execute.     * @param singleRecord Whether or not we want to select only a     * single record.     * @param con A Connection.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(        String queryString,        boolean singleRecord,        Connection con)        throws TorqueException    {        return executeQuery(queryString, 0, -1, singleRecord, con);    }    /**     * Method for performing a SELECT.     *     * @param queryString A String with the sql statement to execute.     * @param start The first row to return.     * @param numberOfResults The number of rows to return.     * @param dbName The database to connect to.     * @param singleRecord Whether or not we want to select only a     * single record.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(        String queryString,        int start,        int numberOfResults,        String dbName,        boolean singleRecord)        throws TorqueException    {        Connection db = null;        List results = null;        try        {            db = Torque.getConnection(dbName);            // execute the query            results = executeQuery(                    queryString,                    start,                    numberOfResults,                    singleRecord,                    db);        }        finally        {            Torque.closeConnection(db);        }        return results;    }    /**     * Method for performing a SELECT.  Returns all results.     *     * @param queryString A String with the sql statement to execute.     * @param start The first row to return.     * @param numberOfResults The number of rows to return.     * @param singleRecord Whether or not we want to select only a     * single record.     * @param con A Connection.     * @return List of Record objects.     * @throws TorqueException Any exceptions caught during processing will be     *         rethrown wrapped into a TorqueException.     */    public static List executeQuery(        String queryString,        int start,        int numberOfResults,        boolean singleRecord,        Connection con)        throws TorqueException    {        QueryDataSet qds = null;        List results = Collections.EMPTY_LIST;        try        {

⌨️ 快捷键说明

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