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    import java.util.Map;
019    
020    /**
021     * Query for Reports. 
022     * Supports selection of a subset of attributes.
023     * 
024     * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
025     * @version $Id: ReportQueryByCriteria.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
026     */
027    public class ReportQueryByCriteria extends QueryByCriteria implements ReportQuery
028    {
029            // define the attributes (columns) to be selected for reports
030            private String[] m_attributes = null;
031    
032        // define the Jdbc-Types of the columns to be selected for reports
033        private int[] m_jdbcTypes = null;
034    
035        // define the additional attributes (columns) to be used for the join
036        private String[] m_joinAttributes = null;
037        
038        // attribute -> FieldDescriptor
039        private Map m_attrToFld = null;
040    
041            /**
042             * Constructor for ReportQueryByCriteria.
043             * @param targetClass
044             * @param attributes[]
045             * @param criteria
046             * @param distinct
047             */
048            public ReportQueryByCriteria(Class targetClass, String[] attributes, Criteria criteria, boolean distinct)
049            {
050                    super(targetClass, criteria, distinct);
051                    setAttributes(attributes);
052            }
053    
054            /**
055             * Constructor for ReportQueryByCriteria.
056             * @param targetClass
057             * @param attributes[]
058             * @param criteria
059             */
060            public ReportQueryByCriteria(Class targetClass, String[] attributes, Criteria criteria)
061            {
062                    this(targetClass, attributes, criteria, false);
063            }
064    
065            /**
066             * Constructor for ReportQueryByCriteria.
067             * @param targetClass
068             * @param criteria
069             */
070            public ReportQueryByCriteria(Class targetClass, Criteria criteria)
071            {
072                    this(targetClass, null, criteria, false);
073            }
074    
075            /**
076             * Constructor for ReportQueryByCriteria.
077             * @param targetClass
078             * @param criteria
079             * @param distinct
080             */
081            public ReportQueryByCriteria(Class targetClass, Criteria criteria, boolean distinct)
082            {
083                    this(targetClass, null, criteria, distinct);
084            }
085    
086            /**
087             * Gets the columns.
088             * @return Returns a String[]
089         * @deprecated use getAttributes()
090             */
091            public String[] getColumns()
092            {
093                    return getAttributes();
094            }
095    
096            /**
097             * Sets the columns.
098             * @param columns The columns to set
099         * @deprecated use setAttributes()
100             */
101            public void setColumns(String[] columns)
102            {
103                    setAttributes(columns);
104            }
105    
106        /**
107         * Gets the attributes to be selected.</br>
108         * Attributes are translated into db-columns
109         * @return the attributes to be selected
110         */
111        public String[] getAttributes()
112        {
113            return m_attributes;
114        }
115    
116        /**
117         * Sets the attributes to be selected.</br>
118         * Attributes are translated into db-columns
119         * @param attributes The attributes to set
120         */
121        public void setAttributes(String[] attributes)
122        {
123            m_attributes = attributes;
124        }
125        
126        /**
127         * @return Returns the jdbcTypes.
128         */
129        public int[] getJdbcTypes()
130        {
131            return m_jdbcTypes;
132        }
133    
134        /**
135         * @param jdbcTypes The jdbcTypes to set.
136         */
137        public void setJdbcTypes(int[] jdbcTypes)
138        {
139            this.m_jdbcTypes = jdbcTypes;
140        }
141    
142        /**
143         * @return Returns the joinAttributes.
144         */
145        public String[] getJoinAttributes()
146        {
147            return m_joinAttributes;
148        }
149    
150        /**
151         * @param joinAttributes The joinAttributes to set.
152         */
153        public void setJoinAttributes(String[] joinAttributes)
154        {
155            m_joinAttributes = joinAttributes;
156        }
157        
158        /**
159         * @see java.lang.Object#toString()
160         */
161        public String toString()
162        {
163            String[] cols = getAttributes();
164            StringBuffer buf = new StringBuffer("ReportQuery from ");
165            buf.append(getSearchClass() + " ");
166            if (cols != null)
167            {
168                for (int i = 0; i < cols.length; i++)
169                {
170                    buf.append(cols[i] + " ");
171                }
172            }
173            if (getCriteria() != null && !getCriteria().isEmpty())
174            {
175                buf.append(" where " + getCriteria());
176            }
177    
178            return buf.toString();
179        }
180    
181        public Map getAttributeFieldDescriptors()
182        {
183            return m_attrToFld;
184        }
185    
186        public void setAttributeFieldDescriptors(Map attrToFld)
187        {
188            m_attrToFld = attrToFld;
189        }
190    
191    
192        
193    }