KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > trans > TrimmingQualifierTranslator


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

19
20
21 package org.apache.cayenne.access.trans;
22
23 import java.sql.Types JavaDoc;
24
25 import org.apache.cayenne.map.DbAttribute;
26 import org.apache.cayenne.map.DbRelationship;
27
28 /**
29  * QualifierTranslator that allows translation of qualifiers that perform
30  * comparison with CHAR columns. Some databases require trimming the values for
31  * this to work.
32  *
33  * @author Andrus Adamchik
34  */

35 public class TrimmingQualifierTranslator extends QualifierTranslator {
36
37     protected String JavaDoc trimFunction;
38
39     /**
40      * Constructor for TrimmingQualifierTranslator.
41      */

42     protected TrimmingQualifierTranslator() {
43         super();
44     }
45
46     /**
47      * Constructor for TrimmingQualifierTranslator.
48      */

49     public TrimmingQualifierTranslator(
50         QueryAssembler queryAssembler,
51         String JavaDoc trimFunction) {
52         super(queryAssembler);
53         this.trimFunction = trimFunction;
54     }
55
56     /**
57      * Adds special handling of CHAR columns.
58      */

59     protected void processColumn(StringBuffer JavaDoc buf, DbAttribute dbAttr) {
60         if (dbAttr.getType() == Types.CHAR) {
61             buf.append(trimFunction).append("(");
62             super.processColumn(buf, dbAttr);
63             buf.append(')');
64         } else {
65             super.processColumn(buf, dbAttr);
66         }
67     }
68
69     /**
70      * Adds special handling of CHAR columns.
71      */

72     protected void processColumn(
73         StringBuffer JavaDoc buf,
74         DbAttribute dbAttr,
75         DbRelationship rel) {
76         if (dbAttr.getType() == Types.CHAR) {
77             buf.append(trimFunction).append("(");
78             super.processColumn(buf, dbAttr, rel);
79             buf.append(')');
80         } else {
81             super.processColumn(buf, dbAttr, rel);
82         }
83     }
84
85     /**
86      * Returns the trimFunction.
87      * @return String
88      */

89     public String JavaDoc getTrimFunction() {
90         return trimFunction;
91     }
92
93     /**
94      * Sets the trimFunction.
95      * @param trimFunction The trimFunction to set
96      */

97     public void setTrimFunction(String JavaDoc trimFunction) {
98         this.trimFunction = trimFunction;
99     }
100 }
101
Popular Tags