Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OjbKualiDecimalFieldConversion |
|
| 2.0;2 |
1 | /* | |
2 | * Copyright 2005-2008 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.core.framework.persistence.ojb.conversion; | |
17 | ||
18 | import java.math.BigDecimal; | |
19 | ||
20 | import org.apache.ojb.broker.accesslayer.conversions.FieldConversion; | |
21 | import org.kuali.rice.core.util.type.KualiDecimal; | |
22 | ||
23 | ||
24 | /** | |
25 | * This class converts NUMERIC fields from the database into KualiDecimal instances, and vice-versa. | |
26 | * | |
27 | * | |
28 | */ | |
29 | ||
30 | 2 | public class OjbKualiDecimalFieldConversion implements FieldConversion { |
31 | private static final long serialVersionUID = 2450111778124335242L; | |
32 | ||
33 | /** | |
34 | * @see FieldConversion#javaToSql(Object) | |
35 | */ | |
36 | public Object javaToSql(Object source) { | |
37 | 0 | Object converted = source; |
38 | ||
39 | 0 | if (source instanceof KualiDecimal) { |
40 | 0 | converted = ((KualiDecimal) source).bigDecimalValue(); |
41 | } | |
42 | ||
43 | 0 | return converted; |
44 | } | |
45 | ||
46 | /** | |
47 | * @see FieldConversion#sqlToJava(Object) | |
48 | */ | |
49 | public Object sqlToJava(Object source) { | |
50 | 0 | Object converted = source; |
51 | ||
52 | 0 | if (source instanceof BigDecimal) { |
53 | 0 | converted = new KualiDecimal((BigDecimal) source); |
54 | } | |
55 | ||
56 | 0 | return converted; |
57 | } | |
58 | } |