net.sf.farrago.type.runtime
Class EncodedSqlDecimal

java.lang.Object
  extended by net.sf.farrago.type.runtime.EncodedSqlDecimal
All Implemented Interfaces:
AssignableValue, DataValue

public abstract class EncodedSqlDecimal
extends Object
implements AssignableValue

Runtime type for decimal values. The usage of decimal values is highly restricted within the Farrago runtime. The operations allowed for decimals are:

The optimizer does not allow other operations to reach to the Farrago runtime. As usual, the method getNullableData returns an external data type, conforming to SQL standards.

Note: the code may be inefficient, since it relies on Java libraries for decimal support and allocates memory on a per row basis.

Since:
Dec 21, 2005
Version:
$Id: //open/dev/farrago/src/net/sf/farrago/type/runtime/EncodedSqlDecimal.java#19 $
Author:
jpham

Nested Class Summary
 class EncodedSqlDecimal.AssignableDecimal
          Class which assigns a value to an EncodedSqlDecimal.
 
Field Summary
static String ASSIGN_TO_METHOD_NAME
           
static String GET_PRECISION_METHOD_NAME
           
static String GET_SCALE_METHOD_NAME
           
private  EncodedSqlDecimal.AssignableDecimal helper
           
private  boolean isNull
           
static String NARROW_CAST_METHOD_NAME
           
private  long overflowValue
           
static String REINTERPRET_METHOD_NAME
           
 long value
           
static String VALUE_FIELD_NAME
           
 
Fields inherited from interface net.sf.farrago.type.runtime.AssignableValue
ASSIGNMENT_METHOD_NAME
 
Constructor Summary
EncodedSqlDecimal()
          Creates a runtime object
 
Method Summary
 void assignFrom(long l)
           
 void assignFrom(Object obj)
          Assigns value from an Object.
 void assignTo(NullablePrimitive.NullableLong target)
          Assigns the internal value of this decimal to a long variable
 Object getNullableData()
           
protected abstract  int getPrecision()
           
protected abstract  int getScale()
           
 boolean isNull()
           
 void narrowCast(Object o)
          Narrows an external BigDecimal value (potentially larger than the database can handle) into a native value.
 void reinterpret(long value)
          Encodes a long value as an EncodedSqlDecimal without an overflow check.
 void reinterpret(long value, boolean overflowCheck)
          Encodes a long value as an EncodedSqlDecimal, with an optional overflow check.
 void reinterpret(NullablePrimitive.NullableLong primitive)
          Encodes a long value as an EncodedSqlDecimal without an overflow check.
 void reinterpret(NullablePrimitive.NullableLong primitive, boolean overflowCheck)
          Encodes a long value as an EncodedSqlDecimal, with an optional overflow check.
 void setNull(boolean b)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GET_PRECISION_METHOD_NAME

public static final String GET_PRECISION_METHOD_NAME
See Also:
Constant Field Values

GET_SCALE_METHOD_NAME

public static final String GET_SCALE_METHOD_NAME
See Also:
Constant Field Values

REINTERPRET_METHOD_NAME

public static final String REINTERPRET_METHOD_NAME
See Also:
Constant Field Values

ASSIGN_TO_METHOD_NAME

public static final String ASSIGN_TO_METHOD_NAME
See Also:
Constant Field Values

VALUE_FIELD_NAME

public static final String VALUE_FIELD_NAME
See Also:
Constant Field Values

NARROW_CAST_METHOD_NAME

public static final String NARROW_CAST_METHOD_NAME
See Also:
Constant Field Values

isNull

private boolean isNull

value

public long value

helper

private EncodedSqlDecimal.AssignableDecimal helper

overflowValue

private long overflowValue
Constructor Detail

EncodedSqlDecimal

public EncodedSqlDecimal()
Creates a runtime object

Method Detail

getPrecision

protected abstract int getPrecision()
Returns:
the decimal precision of this number

getScale

protected abstract int getScale()
Returns:
the decimal scale of this number

isNull

public boolean isNull()

setNull

public void setNull(boolean b)

assignFrom

public void assignFrom(Object obj)
Description copied from interface: AssignableValue
Assigns value from an Object.

Specified by:
assignFrom in interface AssignableValue
Parameters:
obj - value to assign, or null to set null

assignFrom

public void assignFrom(long l)

getNullableData

public Object getNullableData()
Specified by:
getNullableData in interface DataValue
Returns:
an Object representation of this value's data, or null if this value is null

reinterpret

public void reinterpret(long value,
                        boolean overflowCheck)
Encodes a long value as an EncodedSqlDecimal, with an optional overflow check.

Parameters:
value - value to be encoded as an EncodedSqlDecimal
overflowCheck - whether to check for overflow

reinterpret

public void reinterpret(long value)
Encodes a long value as an EncodedSqlDecimal without an overflow check.

Parameters:
value - value to be encoded as an EncodedSqlDecimal

reinterpret

public void reinterpret(NullablePrimitive.NullableLong primitive,
                        boolean overflowCheck)
Encodes a long value as an EncodedSqlDecimal, with an optional overflow check.

Parameters:
primitive - value to be encoded as an EncodedSqlDecimal
overflowCheck - whether to check for overflow

reinterpret

public void reinterpret(NullablePrimitive.NullableLong primitive)
Encodes a long value as an EncodedSqlDecimal without an overflow check.

Parameters:
primitive - value to be encoded as an EncodedSqlDecimal

assignTo

public void assignTo(NullablePrimitive.NullableLong target)
Assigns the internal value of this decimal to a long variable

Parameters:
target - the variable to be assigned

toString

public String toString()
Overrides:
toString in class Object

narrowCast

public void narrowCast(Object o)
Narrows an external BigDecimal value (potentially larger than the database can handle) into a native value. Unsupported values are replaced with null.

Parameters:
o - the BigDecimal value