Coverage Report - org.apache.ojb.broker.accesslayer.conversions.Calendar2DateFieldConversion
 
Classes in this File Line Coverage Branch Coverage Complexity
Calendar2DateFieldConversion
N/A
N/A
3
 
 1  
 package org.apache.ojb.broker.accesslayer.conversions;
 2  
 
 3  
 /* Copyright 2004-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import java.sql.Date;
 19  
 import java.util.Calendar;
 20  
 import java.util.GregorianCalendar;
 21  
 
 22  
 /**
 23  
  * This implementation of the {@link FieldConversion} interface converts
 24  
  * between {@link java.util.Calendar} and {@link java.sql.Date}. When
 25  
  * convert sql to java always a {@link java.util.GregorianCalendar}
 26  
  * object is returned.
 27  
  *
 28  
  * @author Guillaume Nodet
 29  
  * @version $Id: Calendar2DateFieldConversion.java,v 1.1 2007-08-24 22:17:31 ewestfal Exp $
 30  
  */
 31  
 public class Calendar2DateFieldConversion implements FieldConversion
 32  
 {
 33  
     /**
 34  
      * @see FieldConversion#javaToSql(Object)
 35  
      */
 36  
     public Object javaToSql(Object source)
 37  
     {
 38  
         if (source instanceof Calendar)
 39  
         {
 40  
             // only valid >= JDK 1.4
 41  
             // return new Date(((Calendar) source).getTimeInMillis());
 42  
             return new Date(((Calendar) source).getTime().getTime());
 43  
         }
 44  
         else
 45  
         {
 46  
             return source;
 47  
         }
 48  
     }
 49  
 
 50  
     /**
 51  
      * @see FieldConversion#sqlToJava(Object)
 52  
      */
 53  
     public Object sqlToJava(Object source)
 54  
     {
 55  
         if (source instanceof Date)
 56  
         {
 57  
             GregorianCalendar cal = new GregorianCalendar();
 58  
             cal.setTime(((Date) source));
 59  
             return cal;
 60  
         }
 61  
         else
 62  
         {
 63  
             return source;
 64  
         }
 65  
     }
 66  
 }
 67  
 
 68