TypeSmallInt.java :  » Database-DBMS » Quadcap-Embeddable-Database » com » quadcap » sql » types » Java Open Source

Java Open Source » Database DBMS » Quadcap Embeddable Database 
Quadcap Embeddable Database » com » quadcap » sql » types » TypeSmallInt.java
package com.quadcap.sql.types;

/* Copyright 1999 - 2003 Quadcap Software.  All rights reserved.
 *
 * This software is distributed under the Quadcap Free Software License.
 * This software may be used or modified for any purpose, personal or
 * commercial.  Open Source redistributions are permitted.  Commercial
 * redistribution of larger works derived from, or works which bundle
 * this software requires a "Commercial Redistribution License"; see
 * http://www.quadcap.com/purchase.
 *
 * Redistributions qualify as "Open Source" under  one of the following terms:
 *   
 *    Redistributions are made at no charge beyond the reasonable cost of
 *    materials and delivery.
 *
 *    Redistributions are accompanied by a copy of the Source Code or by an
 *    irrevocable offer to provide a copy of the Source Code for up to three
 *    years at the cost of materials and delivery.  Such redistributions
 *    must allow further use, modification, and redistribution of the Source
 *    Code under substantially the same terms as this license.
 *
 * Redistributions of source code must retain the copyright notices as they
 * appear in each source code file, these license terms, and the
 * disclaimer/limitation of liability set forth as paragraph 6 below.
 *
 * Redistributions in binary form must reproduce this Copyright Notice,
 * these license terms, and the disclaimer/limitation of liability set
 * forth as paragraph 6 below, in the documentation and/or other materials
 * provided with the distribution.
 *
 * The Software is provided on an "AS IS" basis.  No warranty is
 * provided that the Software is free of defects, or fit for a
 * particular purpose.  
 *
 * Limitation of Liability. Quadcap Software shall not be liable
 * for any damages suffered by the Licensee or any third party resulting
 * from use of the Software.
 */

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import com.quadcap.util.Debug;

/**
 * The SQL <b>SMALLINT</b> type.
 *
 * @author Stan Bailes
 */
public class TypeSmallInt implements Type, Externalizable {
    public static final TypeSmallInt typeSmallInt = new TypeSmallInt();

    public TypeSmallInt() {}
    
    public String getTypeName() {
  return "SMALLINT";
    }

    public int getJDBCType() { return Types.SMALLINT; }

    public String getJDBCClassName() { return "java.lang.Short"; }

    public int getPrecision() { return 16; }

    public int getScale() { return 0; }

    public int getMaxPrecision() { return 16; }

    public int getMinScale() { return 0; }

    public int getMaxScale() { return 0; }

    public boolean isCharType() { return false; }

    public boolean isCaseSensitive() { return false; }

    public boolean isCurrency() { return false; }

    public boolean isSigned() { return true; }

    public int getDisplayWidth() { return 6; }
    
    public String toString() {
  return "SMALLINT";
    }

    /**
     * We don't bother serializing the data, since Java serialization is
     * only used for the type portion of a table column.
     */
    public void readExternal(ObjectInput in) {
    }
    
    public void writeExternal(ObjectOutput out) {
    }

    public Value convert(Value v) throws ValueException {
  return v.convert(this);
    }

    /**
     * Utility method to help convert numbers to SMALLINTs
     */
    public static ValueShort convertNumber(long n) throws ValueException {
        if (n >= Short.MIN_VALUE && n <= Short.MAX_VALUE) {
            return new ValueShort((short)n);
        }
        throw new ValueException("Can't convert to SMALLINT: " + n);
    }

    /**
     * Utility method to help convert floats to SMALLINT
     */
    public static ValueShort convertNumber(float n) throws ValueException {
        if (n >= Short.MIN_VALUE && n <= Short.MAX_VALUE) {
            return new ValueShort((short)n);
        }
        throw new ValueException("Can't convert to SMALLINT: " + n);
    }

    /**
     * Utility method to help convert doubles to SMALLINTs
     */
    public static ValueShort convertNumber(double n) throws ValueException {
        if (n >= Short.MIN_VALUE && n <= Short.MAX_VALUE) {
            return new ValueShort((short)n);
        }
        throw new ValueException("Can't convert to SMALLINT: " + n);
    }

    public String getCreateParams() {
        return null;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.