Coverage Report - org.apache.ojb.broker.accesslayer.conversions.Calendar2TimestampFieldConversion
 
Classes in this File Line Coverage Branch Coverage Complexity
Calendar2TimestampFieldConversion
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.Timestamp;
 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.Timestamp}. When
 25  
  * convert sql to java always a {@link java.util.GregorianCalendar} object
 26  
  * is returned.
 27  
  *
 28  
  * @author Guillaume Nodet
 29  
  * @version $Id: Calendar2TimestampFieldConversion.java,v 1.1 2007-08-24 22:17:31 ewestfal Exp $
 30  
  */
 31  
 public class Calendar2TimestampFieldConversion 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 Timestamp(((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 Timestamp)
 56  
         {
 57  
             GregorianCalendar cal = new GregorianCalendar();
 58  
             // only valid >= JDK 1.4
 59  
             // cal.setTimeInMillis(((Date) source).getTime());
 60  
             cal.setTime(((Timestamp) source));
 61  
             return cal;
 62  
         }
 63  
         else
 64  
         {
 65  
             return source;
 66  
         }
 67  
     }
 68  
 }
 69  
 
 70