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

📄 criteria.java

📁 torque服务器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package org.apache.torque.util;/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and *    "Apache Turbine" must not be used to endorse or promote products *    derived from this software without prior written permission. For *    written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    "Apache Turbine", nor may "Apache" appear in their name, without *    prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */import java.io.Serializable;import java.lang.reflect.Array;import java.math.BigDecimal;import java.util.ArrayList;import java.util.Arrays;import java.util.GregorianCalendar;import java.util.HashMap;import java.util.Hashtable;import java.util.Iterator;import java.util.List;import java.util.Map;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.adapter.DB;import org.apache.torque.om.DateKey;import org.apache.torque.om.ObjectKey;/** * This is a utility class that is used for retrieving different types * of values from a hashtable based on a simple name string.  This * class is meant to minimize the amount of casting that needs to be * done when working with Hashtables. * * NOTE: other methods will be added as needed and as time permits. * * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> * @author <a href="mailto:eric@dobbse.net">Eric Dobbs</a> * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> * @author <a href="mailto:sam@neurogrid.com">Sam Joseph</a> * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a> * @version $Id: Criteria.java,v 1.42 2003/06/24 09:47:30 mpoeschl Exp $ */public class Criteria extends Hashtable{    /** Comparison type. */    public static final SqlEnum EQUAL = SqlEnum.EQUAL;    /** Comparison type. */    public static final SqlEnum NOT_EQUAL = SqlEnum.NOT_EQUAL;    /** Comparison type. */    public static final SqlEnum ALT_NOT_EQUAL = SqlEnum.ALT_NOT_EQUAL;    /** Comparison type. */    public static final SqlEnum GREATER_THAN = SqlEnum.GREATER_THAN;    /** Comparison type. */    public static final SqlEnum LESS_THAN = SqlEnum.LESS_THAN;    /** Comparison type. */    public static final SqlEnum GREATER_EQUAL = SqlEnum.GREATER_EQUAL;    /** Comparison type. */    public static final SqlEnum LESS_EQUAL = SqlEnum.LESS_EQUAL;    /** Comparison type. */    public static final SqlEnum LIKE = SqlEnum.LIKE;    /** Comparison type. */    public static final SqlEnum NOT_LIKE = SqlEnum.NOT_LIKE;    /** Comparison type. */    public static final SqlEnum CUSTOM = SqlEnum.CUSTOM;    /** Comparison type. */    public static final SqlEnum DISTINCT = SqlEnum.DISTINCT;    /** Comparison type. */    public static final SqlEnum IN = SqlEnum.IN;    /** Comparison type. */    public static final SqlEnum NOT_IN = SqlEnum.NOT_IN;    /** Comparison type. */    public static final SqlEnum ALL = SqlEnum.ALL;    /** Comparison type. */    public static final SqlEnum JOIN = SqlEnum.JOIN;    /** "Order by" qualifier - ascending */    private static final SqlEnum ASC = SqlEnum.ASC;    /** "Order by" qualifier - descending */    private static final SqlEnum DESC = SqlEnum.DESC;    /** "IS NULL" null comparison */    public static final SqlEnum ISNULL = SqlEnum.ISNULL;    /** "IS NOT NULL" null comparison */    public static final SqlEnum ISNOTNULL = SqlEnum.ISNOTNULL;    /** "CURRENT_DATE" ANSI SQL function */    public static final SqlEnum CURRENT_DATE = SqlEnum.CURRENT_DATE;    /** "CURRENT_TIME" ANSI SQL function */    public static final SqlEnum CURRENT_TIME = SqlEnum.CURRENT_TIME;    private static final int DEFAULT_CAPACITY = 10;    private boolean ignoreCase = false;    private boolean singleRecord = false;    private boolean cascade = false;    private UniqueList selectModifiers = new UniqueList();    private UniqueList selectColumns = new UniqueList();    private UniqueList orderByColumns = new UniqueList();    private UniqueList groupByColumns = new UniqueList();    private Criterion having = null;    private Hashtable asColumns = new Hashtable(8);    private ArrayList joinL = null;    private ArrayList joinR = null;    /** The name of the database. */    private String dbName;    /** The name of the database as given in the contructor. */    private String originalDbName;    /**     * To limit the number of rows to return.  <code>-1</code> means return all     * rows.     */    private int limit = -1;    /** To start the results at a row other than the first one. */    private int offset = 0;    private HashMap aliases = null;    private boolean useTransaction = false;    /** the log. */    private static Log log = LogFactory.getLog(Criteria.class);    /**     * Creates a new instance with the default capacity.     */    public Criteria()    {        this(DEFAULT_CAPACITY);    }    /**     * Creates a new instance with the specified capacity.     *     * @param initialCapacity An int.     */    public Criteria(int initialCapacity)    {        this(Torque.getDefaultDB(), initialCapacity);    }    /**     * Creates a new instance with the default capacity which corresponds to     * the specified database.     *     * @param dbName The dabase name.     */    public Criteria(String dbName)    {        this(dbName, DEFAULT_CAPACITY);    }    /**     * Creates a new instance with the specified capacity which corresponds to     * the specified database.     *     * @param dbName          The dabase name.     * @param initialCapacity The initial capacity.     */    public Criteria(String dbName, int initialCapacity)    {        super(initialCapacity);        this.dbName = dbName;        this.originalDbName = dbName;    }    /**     * Brings this criteria back to its initial state, so that it     * can be reused as if it was new. Except if the criteria has grown in     * capacity, it is left at the current capacity.     */    public void clear()    {        super.clear();        ignoreCase = false;        singleRecord = false;        cascade = false;        selectModifiers.clear();        selectColumns.clear();        orderByColumns.clear();        groupByColumns.clear();        having = null;        asColumns.clear();        joinL = null;        joinR = null;        dbName = originalDbName;        offset = 0;        limit = -1;        aliases = null;        useTransaction = false;    }    /**     * Add an AS clause to the select columns. Usage:     * <p>     * <code>     *     * Criteria myCrit = new Criteria();     * myCrit.addAsColumn("alias", "ALIAS("+MyPeer.ID+")");     *     * </code>     *     * @param name  wanted Name of the column     * @param clause SQL clause to select from the table     *     * If the name already exists, it is replaced by the new clause.     *     * @return A modified Criteria object.     */    public Criteria addAsColumn(String name, String clause)    {        asColumns.put(name, clause);        return this;    }    /**     * Get the column aliases.     *     * @return A Hashtable which map the column alias names     * to the alias clauses.     */    public Hashtable getAsColumns()    {        return asColumns;    }    /**     * Allows one to specify an alias for a table that can     * be used in various parts of the SQL.     *     * @param alias a <code>String</code> value     * @param table a <code>String</code> value     */    public void addAlias(String alias, String table)    {        if (aliases == null)        {            aliases = new HashMap(8);        }        aliases.put(alias, table);    }    /**     * Returns the table name associated with an alias.     *     * @param alias a <code>String</code> value     * @return a <code>String</code> value     */    public String getTableForAlias(String alias)    {        if (aliases == null)        {            return null;        }        return (String) aliases.get(alias);    }    /**     * Does this Criteria Object contain the specified key?     *     * @param table The name of the table.     * @param column The name of the column.     * @return True if this Criteria Object contain the specified key.     */    public boolean containsKey(String table, String column)    {        return containsKey(table + '.' + column);    }    /**     * Convenience method to return value as a boolean.     *     * @param column String name of column.     * @return A boolean.     */    public boolean getBoolean(String column)    {        return ((Boolean) getCriterion(column).getValue()).booleanValue();    }    /**     * Convenience method to return value as a boolean.     *     * @param table String name of table.     * @param column String name of column.     * @return A boolean.     */    public boolean getBoolean(String table, String column)    {        return getBoolean(new StringBuffer(table.length() + column.length() + 1)                .append(table).append('.').append(column)                .toString());    }    /**     * Will force the sql represented by this criteria to be executed within     * a transaction.  This is here primarily to support the oid type in     * postgresql.  Though it can be used to require any single sql statement     * to use a transaction.     */    public void setUseTransaction(boolean v)    {        useTransaction = v;    }    /**     * called by BasePeer to determine whether the sql command specified by     * this criteria must be wrapped in a transaction.     *     * @return a <code>boolean</code> value     */    protected boolean isUseTransaction()    {        return useTransaction;    }    /**     * Method to return criteria related to columns in a table.     *     * @param column String name of column.     * @return A Criterion.     */    public Criterion getCriterion(String column)    {        return (Criterion) super.get(column);    }    /**     * Method to return criteria related to a column in a table.     *     * @param table String name of table.     * @param column String name of column.     * @return A Criterion.     */    public Criterion getCriterion(String table, String column)    {        return getCriterion(                new StringBuffer(table.length() + column.length() + 1)                .append(table).append('.').append(column)                .toString());    }    /**     * Method to return criterion that is not added automatically     * to this Criteria.  This can be used to chain the     * Criterions to form a more complex where clause.     *     * @param column String full name of column (for example TABLE.COLUMN).     * @return A Criterion.     */    public Criterion getNewCriterion(String column, Object value,            SqlEnum comparison)    {        return new Criterion(column, value, comparison);    }    /**     * Method to return criterion that is not added automatically     * to this Criteria.  This can be used to chain the     * Criterions to form a more complex where clause.     *     * @param table String name of table.     * @param column String name of column.     * @return A Criterion.     */    public Criterion getNewCriterion(String table, String column,                                     Object value, SqlEnum comparison)    {        return new Criterion(table, column, value, comparison);    }    /**     * This method adds a prepared Criterion object to the Criteria.     * You can get a new, empty Criterion object with the     * getNewCriterion() method. If a criterion for the requested column     * already exists, it is replaced. This is used as follows:     *     * <p>     * <code>     * Criteria crit = new Criteria();     * Criteria.Criterion c = crit

⌨️ 快捷键说明

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