| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| OjbCharBooleanFieldAIConversion |
|
| 7.5;7.5 |
| 1 | /* | |
| 2 | * Copyright 2006-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.kns.util; | |
| 17 | ||
| 18 | import org.apache.ojb.broker.accesslayer.conversions.FieldConversion; | |
| 19 | ||
| 20 | /** | |
| 21 | * This class converts the "A" or "I" value from the database into a true or false in Java. | |
| 22 | * | |
| 23 | * | |
| 24 | */ | |
| 25 | 0 | public class OjbCharBooleanFieldAIConversion implements FieldConversion { |
| 26 | private static final String TRUE = "A"; | |
| 27 | private static final String FALSE = "I"; | |
| 28 | ||
| 29 | /** | |
| 30 | * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object) | |
| 31 | */ | |
| 32 | public Object javaToSql(Object source) { | |
| 33 | 0 | if (source instanceof Boolean) { |
| 34 | 0 | if (source.equals(Boolean.TRUE)) { |
| 35 | 0 | return TRUE; |
| 36 | } | |
| 37 | else { | |
| 38 | 0 | return FALSE; |
| 39 | } | |
| 40 | } | |
| 41 | 0 | else if (source instanceof String) { |
| 42 | 0 | if ("Y".equalsIgnoreCase((String)source)) { |
| 43 | 0 | return TRUE; |
| 44 | } | |
| 45 | 0 | else if ("N".equalsIgnoreCase((String)source)) { |
| 46 | 0 | return FALSE; |
| 47 | } | |
| 48 | } | |
| 49 | 0 | return source; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object) | |
| 54 | */ | |
| 55 | public Object sqlToJava(Object source) { | |
| 56 | 0 | if (source instanceof String) { |
| 57 | 0 | if (TRUE.equals(source)) { |
| 58 | 0 | return Boolean.TRUE; |
| 59 | } | |
| 60 | else { | |
| 61 | 0 | return Boolean.FALSE; |
| 62 | } | |
| 63 | } | |
| 64 | else { | |
| 65 | 0 | return source; |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | } |