Save This Page
Home » Hibernate-3.3.2.GA » org.hibernate » type » [javadoc | source]
    1   /*
    2    * Hibernate, Relational Persistence for Idiomatic Java
    3    *
    4    * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
    5    * indicated by the @author tags or express copyright attribution
    6    * statements applied by the authors.  All third-party contributions are
    7    * distributed under license by Red Hat Middleware LLC.
    8    *
    9    * This copyrighted material is made available to anyone wishing to use, modify,
   10    * copy, or redistribute it subject to the terms and conditions of the GNU
   11    * Lesser General Public License, as published by the Free Software Foundation.
   12    *
   13    * This program is distributed in the hope that it will be useful,
   14    * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15    * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   16    * for more details.
   17    *
   18    * You should have received a copy of the GNU Lesser General Public License
   19    * along with this distribution; if not, write to:
   20    * Free Software Foundation, Inc.
   21    * 51 Franklin Street, Fifth Floor
   22    * Boston, MA  02110-1301  USA
   23    *
   24    */
   25   package org.hibernate.type;
   26   
   27   import java.io.Serializable;
   28   import java.sql.PreparedStatement;
   29   import java.sql.ResultSet;
   30   import java.sql.SQLException;
   31   import java.sql.Types;
   32   import java.util.Comparator;
   33   
   34   import org.hibernate.util.ComparableComparator;
   35   import org.hibernate.dialect.Dialect;
   36   import org.hibernate.engine.SessionImplementor;
   37   
   38   /**
   39    * <tt>long</tt>: A type that maps an SQL BIGINT to a Java Long.
   40    * @author Gavin King
   41    */
   42   public class LongType extends PrimitiveType implements DiscriminatorType, VersionType {
   43   
   44   	private static final Long ZERO = new Long(0);
   45   
   46   	public Serializable getDefaultValue() {
   47   		return ZERO;
   48   	}
   49   	
   50   	public Object get(ResultSet rs, String name) throws SQLException {
   51   		return new Long( rs.getLong(name) );
   52   	}
   53   
   54   	public Class getPrimitiveClass() {
   55   		return long.class;
   56   	}
   57   
   58   	public Class getReturnedClass() {
   59   		return Long.class;
   60   	}
   61   
   62   	public void set(PreparedStatement st, Object value, int index)
   63   	throws SQLException {
   64   
   65   		st.setLong( index, ( (Long) value ).longValue() );
   66   	}
   67   
   68   	public int sqlType() {
   69   		return Types.BIGINT;
   70   	}
   71   
   72   	public String getName() { return "long"; }
   73   
   74   	public Object stringToObject(String xml) throws Exception {
   75   		return new Long(xml);
   76   	}
   77   
   78   	public Object next(Object current, SessionImplementor session) {
   79   		return new Long( ( (Long) current ).longValue() + 1 );
   80   	}
   81   
   82   	public Object seed(SessionImplementor session) {
   83   		return ZERO;
   84   	}
   85   
   86   	public Comparator getComparator() {
   87   		return ComparableComparator.INSTANCE;
   88   	}
   89   	
   90   	public String objectToSQLString(Object value, Dialect dialect) throws Exception {
   91   		return value.toString();
   92   	}
   93   
   94   	public Object fromStringValue(String xml) {
   95   		return new Long(xml);
   96   	}
   97   
   98   
   99   }

Save This Page
Home » Hibernate-3.3.2.GA » org.hibernate » type » [javadoc | source]