DLV
Class ConversionType

java.lang.Object
  extended byDLV.ConversionType

public final class ConversionType
extends java.lang.Object

The class that defines the constants that are used to identify generic DLV Wrapper types.

The Predicate class implements a JDBC-like interface. In order to implement some JDBC-like methods it is necessary to have some meta-information about types of arguments (see PredicateMetaData).
Datalog languages do not have types; but, from a relational database point of view (predicate are tables), table arguments have a type.
Commercial relational databases handle several types. Sun provided a Java-view of database types for JDBC named JDBC Types. (see java.sql.Types)
Using that convention, JDBC can offer an automatic conversion from Java objects to relational database argument types (Eg. you can handle dates by using the java.sql.Date class).
Like JDBC, this library provide a Java-view of DLV types named DLV Wrapper Types.
Altough in DLV only three types of argument are available, (constant string, positive integer, quoted string)
this library allows to use a richer set of types, by using a standard encoding for types not supported by DLV.
In the following table are described DLV Wrapper Types and their real encoding.

DBNULL_CLASS
DLV Wrapper Types Conversion Example
BIGDECIMAL quoted string example("102678397373") 102678397373
BOOLEAN constant string example(true) true
CONST_BYTE positive integer example(23) 23
CONST_INT positive integer example(2400) 2400
CONST_LONG positive integer example(25000) 25000
CONST_SHORT positive integer example(100) 100
STRING constant or quoted string (a valid DLV constant) example(string). example("string"). string
DATE quoted string example("2004-01-10") 10 Jan 2004
QUOTED_BYTE quoted string example("23") 23
QUOTED_DOUBLE quoted string example("23.4") 23.4
QUOTED_FLOAT quoted string example("10.5") 10.5
QUOTED_INT quoted string example("10") 10
QUOTED_LONG quoted string example("10000") 10000
QUOTED_SHORT quoted string example("2") 2
QUOTED_STRING quoted string example("quoted string") quoted string
ROUND_DOUBLE positive integer example(101) 100.6
ROUND_FLOAT positive integer example(11) 10.6
TIME quoted string example("17:03:22") 17:03:22
TRUNC_DOUBLE positive integer example(100) 100.6
TRUNC_FLOAT positive integer example(10) 10.6
NULL the string constant representing database null values in DLV see DBNULL example(null) null
OBJECT java object (feature not implemented yet) may throw exceptions when used
UNIMPLEMENTED feature not implemented yet may throw exceptions when used
Note that:
- if the specified argument must be translated in a positive integer the library always computes the absolute value (eg. -10 is translated in 10)
- if the specified argument must be translated in a quoted string the standard java toString() method is used.
- real numbers (float and double) can be rounded or truncated (Es. 10.5 rounded is 11, truncated is 10).

Note that DLV Wrapper Types are automatically handled by a Predicate class instance.
The default type is ConversionType.STRING, if you want to customize standard translation you must set a PredicateMetaData descriptor (see PredicateMetaData). (This mechanism allows to handle a java.util.Date object for in-memory operation and you can "save" it in a predicate argument).
An automatic conversion from JDBC Types and DLV Wrapper Types is provided by sqlToDlvTypes(int).

Version:
3.0
Author:
Francesco Ricca
See Also:
java.sql.ResultSet, java.sql.Types, PredicateMetaData

Nested Class Summary
static class ConversionType.DBNull
          The static class identifying the DLV term used to identify database null values.
 
Field Summary
static byte BIGDECIMAL
          The constant identifying the DLV Wrapper type BIGDECIMAL.
static byte BOOLEAN
          The constant identifying the DLV Wrapper type BOOLEAN.
static byte CONST_BYTE
          The constant identifying the DLV Wrapper type CONST_BYTE.
static byte CONST_INT
          The constant identifying the DLV Wrapper type CONST_INT.
static byte CONST_LONG
          The constant identifying the DLV Wrapper type CONST_LONG.
static byte CONST_SHORT
          The constant identifying the DLV Wrapper type CONST_SHORT.
static byte DATE
          The constant identifying the DLV Wrapper type DATE.
static java.lang.String DBNULL
          The constant identifying the DLV term used to identify database null values.
static ConversionType.DBNull DBNULL_CLASS
          The statc class instance identifying the DLV term used to identify database null values.
static byte NULL
          The constant identifying the DLV Wrapper type NULL.
static byte OBJECT
          The constant identifying the DLV Wrapper type OBJECT.
static byte QUOTED_BYTE
          The constant identifying the DLV Wrapper type QUOTED_BYTE.
static byte QUOTED_DOUBLE
          The constant identifying the DLV Wrapper type QUOTED_DOUBLE.
static byte QUOTED_FLOAT
          The constant identifying the DLV Wrapper type QUOTED_FLOAT.
static byte QUOTED_INT
          The constant identifying the DLV Wrapper type QUOTED_INT.
static byte QUOTED_LONG
          The constant identifying the DLV Wrapper type QUOTED_LONG.
static byte QUOTED_SHORT
          The constant identifying the DLV Wrapper type QUOTED_SHORT.
static byte ROUND_DOUBLE
          The constant identifying the DLV Wrapper type ROUND_DOUBLE.
static byte ROUND_FLOAT
          The constant identifying the DLV Wrapper type ROUND_FLOAT.
static byte STRING
          The constant identifying the DLV Wrapper type STRING (which is QUOTED_STRING).
static byte TIME
          The constant identifying the DLV Wrapper type TIME.
static byte TRUNC_DOUBLE
          The constant identifying the DLV Wrapper type TRUNC_DOUBLE.
static byte TRUNC_FLOAT
          The constant identifying the DLV Wrapper type TRUNC_FLOAT.
static byte UNIMPLEMENTED
          The constant identifying the DLV Wrapper type UNIMPLEMENTED.
 
Constructor Summary
ConversionType()
           
 
Method Summary
static java.lang.String cutQuotes(java.lang.String s)
           
static boolean isConst(java.lang.String s)
           
static boolean isQuoted(java.lang.String s)
           
static boolean isValid(java.lang.String s)
           
static byte sqlToDlvTypes(int sqlType)
          This function converts SQL type code in a DLV Wrapper type code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBNULL_CLASS

public static final ConversionType.DBNull DBNULL_CLASS
The statc class instance identifying the DLV term used to identify database null values.


DBNULL

public static final java.lang.String DBNULL
The constant identifying the DLV term used to identify database null values.

See Also:
Constant Field Values

UNIMPLEMENTED

public static final byte UNIMPLEMENTED
The constant identifying the DLV Wrapper type UNIMPLEMENTED.

See Also:
Constant Field Values

STRING

public static final byte STRING
The constant identifying the DLV Wrapper type STRING (which is QUOTED_STRING).

See Also:
Constant Field Values

BOOLEAN

public static final byte BOOLEAN
The constant identifying the DLV Wrapper type BOOLEAN.

See Also:
Constant Field Values

BIGDECIMAL

public static final byte BIGDECIMAL
The constant identifying the DLV Wrapper type BIGDECIMAL.

See Also:
Constant Field Values

DATE

public static final byte DATE
The constant identifying the DLV Wrapper type DATE.

See Also:
Constant Field Values

TIME

public static final byte TIME
The constant identifying the DLV Wrapper type TIME.

See Also:
Constant Field Values

QUOTED_DOUBLE

public static final byte QUOTED_DOUBLE
The constant identifying the DLV Wrapper type QUOTED_DOUBLE.

See Also:
Constant Field Values

TRUNC_DOUBLE

public static final byte TRUNC_DOUBLE
The constant identifying the DLV Wrapper type TRUNC_DOUBLE.

See Also:
Constant Field Values

ROUND_DOUBLE

public static final byte ROUND_DOUBLE
The constant identifying the DLV Wrapper type ROUND_DOUBLE.

See Also:
Constant Field Values

QUOTED_FLOAT

public static final byte QUOTED_FLOAT
The constant identifying the DLV Wrapper type QUOTED_FLOAT.

See Also:
Constant Field Values

TRUNC_FLOAT

public static final byte TRUNC_FLOAT
The constant identifying the DLV Wrapper type TRUNC_FLOAT.

See Also:
Constant Field Values

ROUND_FLOAT

public static final byte ROUND_FLOAT
The constant identifying the DLV Wrapper type ROUND_FLOAT.

See Also:
Constant Field Values

QUOTED_INT

public static final byte QUOTED_INT
The constant identifying the DLV Wrapper type QUOTED_INT.

See Also:
Constant Field Values

CONST_INT

public static final byte CONST_INT
The constant identifying the DLV Wrapper type CONST_INT.

See Also:
Constant Field Values

QUOTED_LONG

public static final byte QUOTED_LONG
The constant identifying the DLV Wrapper type QUOTED_LONG.

See Also:
Constant Field Values

CONST_LONG

public static final byte CONST_LONG
The constant identifying the DLV Wrapper type CONST_LONG.

See Also:
Constant Field Values

QUOTED_SHORT

public static final byte QUOTED_SHORT
The constant identifying the DLV Wrapper type QUOTED_SHORT.

See Also:
Constant Field Values

CONST_SHORT

public static final byte CONST_SHORT
The constant identifying the DLV Wrapper type CONST_SHORT.

See Also:
Constant Field Values

QUOTED_BYTE

public static final byte QUOTED_BYTE
The constant identifying the DLV Wrapper type QUOTED_BYTE.

See Also:
Constant Field Values

CONST_BYTE

public static final byte CONST_BYTE
The constant identifying the DLV Wrapper type CONST_BYTE.

See Also:
Constant Field Values

OBJECT

public static final byte OBJECT
The constant identifying the DLV Wrapper type OBJECT.

See Also:
Constant Field Values

NULL

public static final byte NULL
The constant identifying the DLV Wrapper type NULL.

See Also:
Constant Field Values
Constructor Detail

ConversionType

public ConversionType()
Method Detail

sqlToDlvTypes

public static byte sqlToDlvTypes(int sqlType)
This function converts SQL type code in a DLV Wrapper type code.
The performed translation is described in the following table:

SQL Type DLV Wrapper type
CHAR STRING
DATE DATE
FLOAT ROUND_FLOAT
DECIMAL ROUND_FLOAT
DOUBLE ROUND_FLOAT
NUMERIC ROUND_FLOAT
REAL ROUND_FLOAT
BIGINT CONST_LONG
VARBINARY CONST_LONG
LONGVARBINARY CONST_LONG
INTEGER CONST_INT
SMALLINT CONST_INT
TINYINT CONST_INT
BINARY STRING
BIT STRING
TIME TIME
VARCHAR STRING
LONGVARCHAR STRING
NULL UNIMPLEMENTED
DISTINCT UNIMPLEMENTED
OTHER UNIMPLEMENTED
JAVA_OBJECT OBJECT
REF UNIMPLEMENTED
STRUCT UNIMPLEMENTED
TIMESTAMP UNIMPLEMENTED
BLOB UNIMPLEMENTED
CLOB UNIMPLEMENTED
ARRAY UNIMPLEMENTED
NULL NULL

Parameters:
sqlType - an SQL type from java.sql.Types
Returns:
The DLV Wrapper type which corresponds tho the specified JDBC Type.
See Also:
java.sql.Types.

isValid

public static boolean isValid(java.lang.String s)

isConst

public static boolean isConst(java.lang.String s)

isQuoted

public static boolean isQuoted(java.lang.String s)

cutQuotes

public static java.lang.String cutQuotes(java.lang.String s)