Coverage Report - org.seasar.cubby.converter.impl.SqlTimestampConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
SqlTimestampConverter
54%
6/11
25%
1/4
2.333
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.converter.impl;
 17  
 
 18  
 import java.util.Date;
 19  
 
 20  
 import org.seasar.cubby.converter.ConversionException;
 21  
 import org.seasar.cubby.converter.ConversionHelper;
 22  
 
 23  
 /**
 24  
  * {@link java.sql.Timestamp}への変換を行うコンバータです。
 25  
  * <p>
 26  
  * 変換元のオブジェクトの文字列表現をフォーマットに従って{@link java.sql.Timestamp}に変換した結果を変換先とします。
 27  
  * </p>
 28  
  * 
 29  
  * @author baba
 30  
  */
 31  19
 public class SqlTimestampConverter extends AbstractDateConverter {
 32  
 
 33  
         /**
 34  
          * {@inheritDoc}
 35  
          */
 36  
         public Class<?> getObjectType() {
 37  149
                 return java.sql.Timestamp.class;
 38  
         }
 39  
 
 40  
         /**
 41  
          * {@inheritDoc}
 42  
          */
 43  
         public Object convertToObject(final Object value,
 44  
                         final Class<?> objectType, final ConversionHelper helper)
 45  
                         throws ConversionException {
 46  6
                 if (value == null) {
 47  0
                         return null;
 48  
                 }
 49  6
                 final String pattern = helper.getFormatPattern().getTimestampPattern();
 50  6
                 final Date date = toDate(value.toString(), pattern);
 51  4
                 return new java.sql.Timestamp(date.getTime());
 52  
         }
 53  
 
 54  
         /**
 55  
          * {@inheritDoc}
 56  
          */
 57  
         public String convertToString(final Object value,
 58  
                         final ConversionHelper helper) {
 59  0
                 if (value == null) {
 60  0
                         return null;
 61  
                 }
 62  0
                 final String pattern = helper.getFormatPattern().getTimestampPattern();
 63  0
                 return toString((java.sql.Timestamp) value, pattern);
 64  
         }
 65  
 
 66  
 }