001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone.types; 021 022import java.math.BigDecimal; 023 024/** 025 * Conversion type from {@code Java Long} to {@code JDBC NUMERIC}. This conversion has default usage. 026 * 027 * @author Alisson Gomes 028 * @since 0.6.0 029 */ 030public class LongNumericType implements Convertible<Long, BigDecimal> 031{ 032 public LongNumericType() 033 { 034 } 035 036 public LongNumericType(String pattern) 037 { 038 } 039 040 @Override 041 public BigDecimal toJdbc(Long attribute) 042 { 043 if (attribute == null) 044 return null; 045 046 return new BigDecimal(attribute); 047 } 048 049 @Override 050 public Long toAttribute(BigDecimal jdbc) 051 { 052 if (jdbc == null) 053 return null; 054 055 return jdbc.longValue(); 056 } 057 058 @Override 059 public Class<Long> getType() 060 { 061 return Long.class; 062 } 063 064 @Override 065 public ColumnType getColumnType() 066 { 067 return JdbcType.NUMERIC; 068 } 069 070 @Override 071 public String toString() 072 { 073 return "LongBigDecimalType [type=" 074 + getType() + ", columnType=" + getColumnType() + "]"; 075 } 076}