001    package org.apache.ojb.broker.query;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    
019    /**
020     * represents a search by criteria.
021     * "find all articles where article.price > 100"
022     * could be represented as:
023     *
024     * Criteria crit = new Criteria();
025     * crit.addGreaterThan("price", new Double(100));
026     * Query qry = new QueryByCriteria(Article.class, crit);
027     *
028     * The PersistenceBroker can retrieve Objects by Queries as follows:
029     *
030     * PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker();
031     * Collection col = broker.getCollectionByQuery(qry);
032     *
033     * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
034     * @version $Id: QueryByMtoNCriteria.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
035     */
036    
037    public class QueryByMtoNCriteria extends QueryByCriteria implements MtoNQuery
038    {
039        private String indirectionTable;
040    
041            /**
042             * return indirectionTable
043             */ 
044        public String getIndirectionTable()
045        {
046            return  indirectionTable;
047        }
048    
049        /**
050         * Build a Query for class targetClass with criteria.
051         * Criteriy may be null (will result in a query returning ALL objects from a table)
052         */
053        public QueryByMtoNCriteria(Class targetClass, String indirectionTable, Criteria criteria)
054        {
055            this(targetClass, indirectionTable, criteria, false);
056        }
057    
058        /**
059         * Build a Query for class targetClass with criteria.
060         * Criteriy may be null (will result in a query returning ALL objects from a table)
061         */
062        public QueryByMtoNCriteria(Class targetClass, String indirectionTable, Criteria criteria, boolean distinct)
063        {
064            super(targetClass , criteria, distinct);
065            this.indirectionTable = indirectionTable;
066        }
067    
068        /**
069         * Insert the method's description here.
070         * Creation date: (07.02.2001 22:01:55)
071         * @return java.lang.String
072         */
073        public String toString()
074        {
075            return "Query from " + indirectionTable + " where " + getCriteria();
076        }
077    
078    }