01: /**********************************************************************
02: Copyright (c) 2003 Andy Jefferson 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: Contributors:
16: ...
17: **********************************************************************/package org.jpox.store.expression;
18:
19: import java.util.Arrays;
20:
21: import org.jpox.store.DatastoreAdapter;
22: import org.jpox.store.mapping.JavaTypeMapping;
23:
24: /**
25: * Literal for binary object.
26: *
27: * @version $Revision: 1.8 $
28: **/
29: public class BinaryLiteral extends BinaryExpression implements Literal {
30: private final byte[] value;
31:
32: /**
33: * Creates a binary literal
34: * @param qs the QueryExpression
35: * @param mapping the mapping
36: * @param value the binary value
37: */
38: public BinaryLiteral(QueryExpression qs, JavaTypeMapping mapping,
39: byte[] value) {
40: super (qs);
41: this .mapping = mapping;
42: this .value = value;
43: DatastoreAdapter dba = qs.getStoreManager()
44: .getDatastoreAdapter();
45: st
46: .appendParameter(dba
47: .getMapping(byte[].class, qs.getStoreManager(),
48: qs.getClassLoaderResolver()), value);
49: }
50:
51: public BooleanExpression eq(ScalarExpression expr) {
52: if (expr instanceof BinaryLiteral) {
53: return new BooleanLiteral(qs, mapping, Arrays.equals(value,
54: ((BinaryLiteral) expr).value));
55: } else {
56: return super .eq(expr);
57: }
58: }
59:
60: public BooleanExpression noteq(ScalarExpression expr) {
61: if (expr instanceof BinaryLiteral) {
62: return new BooleanLiteral(qs, mapping, !Arrays.equals(
63: value, ((BinaryLiteral) expr).value));
64: } else {
65: return super .noteq(expr);
66: }
67: }
68:
69: public Object getValue() {
70: return value;
71: }
72:
73: /**
74: * Method to save a "raw" value that this literal represents.
75: * This value differs from the literal value since that is of the same type as this literal.
76: * @param val The raw value
77: */
78: public void setRawValue(Object val) {
79: // Dont support raw value for binary literals
80: }
81:
82: /**
83: * Accessor for the "raw" value that this literal represents.
84: * This value differs from the literal value since that is of the same type as this literal.
85: * @return The raw value
86: */
87: public Object getRawValue() {
88: return null; // Dont support raw value for binary literals
89: }
90: }
|