IntegerType.java :  » Database-ORM » Ammentos » it » biobytes » ammentos » fieldtypes » Java Open Source

Java Open Source » Database ORM » Ammentos 
Ammentos » it » biobytes » ammentos » fieldtypes » IntegerType.java
/*
 *   Copyright 2006 Davide Deidda
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/*
 * SqlInteger.java
 *
 * Created on 4 dicembre 2003, 23.41
 */

package it.biobytes.ammentos.fieldtypes;


import java.sql.Types;

import it.biobytes.ammentos.*;

import it.biobytes.ammentos.util.*;

/**
 *
 * @author  davide
 */
public class IntegerType implements FieldType
{
  
  public String formatValue(Object value)
  {
    String res = null;
    if ( value != null )
      res = value.toString();
    return res;
  }
  
  
  public Object loadValue( java.sql.ResultSet rs, Field field) throws java.sql.SQLException
  {
    Object res = null;
    res = new Integer( rs.getInt( field.getName() ) );
    if ( rs.wasNull() ) res = null;
    return res;
  }
  
  public Object parseValue(String str) throws PersistenceException
  {
    return Integer.valueOf( str );
  }
  
  public void setParamValue(Object fieldValue, java.sql.PreparedStatement pstmt, int paramIndex) throws java.sql.SQLException
  {
    pstmt.setInt( paramIndex, ( ( Integer )fieldValue ).intValue() );
  }
  
  public Object generateValue() throws PersistenceException
  {
    return new Integer( Sequencer.nextInt() );    
  }
  
  public boolean isNumeric()
  {
    return true;
  }  
  
  public Object[] getPossibleValues()
  {
    return null;
  }

  /**
   * Returns the sum of the provided values, or null if summing is not possible
   * 
   * @param value1  First value to add
   * @param value2  Second value to add
   */
  public Object addValues(Object value1, Object value2)
  {
    int v1 = ( Integer )value1;
    int v2 = ( Integer )value2;
    return ( v1 + v2 );
  }

  /**
   * Gets the underlying mapped Java class represented from elements of this
   * type
   * 
   * @return the Java class mapped from this FieldType
   */
  public Class getMappedClass()
  {
    return Integer.TYPE;
  }
  
  public int getSqlType()
  {
    return Types.INTEGER;
  }
}
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.