1 package org.apache.torque.util;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.lang.builder.EqualsBuilder;
23 import org.apache.commons.lang.builder.HashCodeBuilder;
24
25 /**
26 * A value plus its JDBC type.
27 *
28 * @version $Id: JdbcTypedValue.java 1388656 2012-09-21 19:59:16Z tfischer $
29 */
30 public class JdbcTypedValue
31 {
32 /** The JDBC type as in <code>java.sql.Types</code>. **/
33 private int jdbcType;
34
35 /** The value; may be null. */
36 private Object value;
37
38 /**
39 * Constructor.
40 *
41 * @param jdbcType The JDBC type as in <code>java.sql.Types</code>.
42 * @param value The value; may be null.
43 */
44 public JdbcTypedValue(Object value, int jdbcType)
45 {
46 this.jdbcType = jdbcType;
47 this.value = value;
48 }
49
50 /**
51 * Returns the JDBC type as in <code>java.sql.Types</code>.
52 *
53 * @return the JDBC type of the value.
54 */
55 public int getJdbcType()
56 {
57 return jdbcType;
58 }
59
60 /**
61 * Sets the JDBC type as in <code>java.sql.Types</code>.
62 *
63 * @param jdbcType the JDBC type of the value.
64 */
65 public void setJdbcType(int jdbcType)
66 {
67 this.jdbcType = jdbcType;
68 }
69
70 /**
71 * Returns the value.
72 *
73 * @return value the value, or null.
74 */
75 public Object getValue()
76 {
77 return value;
78 }
79
80 /**
81 * Sets the value.
82 *
83 * @param value the value, may be null.
84 */
85 public void setValue(Object value)
86 {
87 this.value = value;
88 }
89
90 @Override
91 public int hashCode()
92 {
93 HashCodeBuilder hashCodeBuilder = new HashCodeBuilder()
94 .append(jdbcType)
95 .append(value);
96 return hashCodeBuilder.toHashCode();
97 }
98
99 @Override
100 public boolean equals(Object obj)
101 {
102 if (this == obj)
103 {
104 return true;
105 }
106 if (obj == null)
107 {
108 return false;
109 }
110 if (getClass() != obj.getClass())
111 {
112 return false;
113 }
114 JdbcTypedValue other = (JdbcTypedValue) obj;
115 EqualsBuilder equalsBuilder = new EqualsBuilder()
116 .append(jdbcType, other.jdbcType)
117 .append(value, other.value);
118 return equalsBuilder.isEquals();
119 }
120
121 @Override
122 public String toString()
123 {
124 return "JdbcTypedValue [jdbcType=" + jdbcType
125 + ", value=" + value + "]";
126 }
127 }