01: /**********************************************************************
02: Copyright (c) 2002 Kelly Grizzle (TJDO) and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: 2002 Mike Martin (TJDO)
18: 2003 Andy Jefferson - coding standards
19: 2004 Erik Bengtson - included a check "is null" on getObject method
20: ...
21: **********************************************************************/package org.jpox.store.mapping;
22:
23: import org.jpox.ClassLoaderResolver;
24: import org.jpox.store.expression.CharacterExpression;
25: import org.jpox.store.expression.CharacterLiteral;
26: import org.jpox.store.expression.LogicSetExpression;
27: import org.jpox.store.expression.NumericExpression;
28: import org.jpox.store.expression.QueryExpression;
29: import org.jpox.store.expression.ScalarExpression;
30:
31: /**
32: * Mapping for Character type.
33: * In RDBMS, this mapping can be stored in INT or CHAR columns.
34: * The use of INT columns facilitates greater than, less than operations within queries etc.
35: *
36: * @version $Revision: 1.17 $
37: **/
38: public class CharacterMapping extends SingleFieldMapping implements
39: SimpleDatastoreRepresentation {
40: private static Character mappingSampleValue = new Character('0');
41:
42: public Object getSampleValue(ClassLoaderResolver clr) {
43: return mappingSampleValue;
44: }
45:
46: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
47: ScalarExpression expr = new CharacterLiteral(qs, this ,
48: ((Character) value).toString());
49: return expr;
50: }
51:
52: public ScalarExpression newScalarExpression(QueryExpression qs,
53: LogicSetExpression te) {
54: DatastoreMapping dsMapping = getDataStoreMapping(0);
55: if (dsMapping.isIntegerBased() || dsMapping.isDecimalBased()) {
56: ScalarExpression expr = new NumericExpression(qs, this , te);
57: return expr;
58: }
59:
60: // Assumed to be string based
61: ScalarExpression expr = new CharacterExpression(qs, this , te);
62: return expr;
63: }
64:
65: public Class getJavaType() {
66: return Character.class;
67: }
68:
69: /**
70: * Method to return the default length of this type in the datastore.
71: * Character(char will need a single character!
72: * @param index The index position
73: * @return The default length
74: */
75: public int getDefaultLength(int index) {
76: return 1;
77: }
78: }
|