com.agimatec.utility.fileimport
Class SqlUtil

java.lang.Object
  extended by com.agimatec.utility.fileimport.SqlUtil
All Implemented Interfaces:
Serializable

public class SqlUtil
extends Object
implements Serializable

Description: Utility class that helps to convert parameters during import processing (e.g. in groovy scripts).
User: roman.stumm
Date: 30.08.2007
Time: 11:59:08
Copyright: Agimatec GmbH

See Also:
Serialized Form

Constructor Summary
protected SqlUtil(int dbms)
           
 
Method Summary
 Object bool(boolean value)
           
 Object bool(String value)
          Oracle DOES NOT SUPPORT Boolean, so this method returns 1 or 0 (or null).
 Date date(String fieldName, String value)
          convert a value to a sql.Date
 void defDate(String fieldname, String dateFormat)
          define the format for a date field
 void defNumber(String fieldname, String numberFormat)
          define the format for a number field
 void defSequence(String fieldname, String sequenceName)
          define the call that a field gets its value from a sequence
static SqlUtil forConnection(Connection connection)
          Ermittele die Datenbank anhand der MetaData der Connection
static SqlUtil forHSQLDB()
          create an instance for HSQLDB syntax (affects sequences)
static SqlUtil forOracle()
          create an instance for oracle syntax (affects sequences)
static SqlUtil forPostgres()
          create an instance for postgres syntax (affects sequences)
 Object get(String fieldName)
          get the call for the given field.
static SqlUtil getDefault()
           
 boolean isHSQLDB()
           
 boolean isOracle()
           
 boolean isPostgres()
           
 boolean isTrue(String value)
           
 long nextVal(Connection connection, String fieldName)
          fetch the next value of the sequence, defined under this name
 String nullable(String value)
           
 Number number(String fieldName, String value)
           
 Time time(String fieldName, String value)
           
 Timestamp timestamp(String fieldName, String value)
           
 String trim(String value)
          a null-aware trim function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlUtil

protected SqlUtil(int dbms)
Method Detail

forConnection

public static SqlUtil forConnection(Connection connection)
                             throws SQLException
Ermittele die Datenbank anhand der MetaData der Connection

Throws:
SQLException

isOracle

public boolean isOracle()

isPostgres

public boolean isPostgres()

isHSQLDB

public boolean isHSQLDB()

forPostgres

public static SqlUtil forPostgres()
create an instance for postgres syntax (affects sequences)


forOracle

public static SqlUtil forOracle()
create an instance for oracle syntax (affects sequences)


forHSQLDB

public static SqlUtil forHSQLDB()
create an instance for HSQLDB syntax (affects sequences)


getDefault

public static SqlUtil getDefault()

defDate

public void defDate(String fieldname,
                    String dateFormat)
define the format for a date field

Parameters:
fieldname - - symbolic field name
dateFormat - - java.text.SimpleDateFormat pattern

defNumber

public void defNumber(String fieldname,
                      String numberFormat)
define the format for a number field

Parameters:
fieldname - - symbolic field name
numberFormat - - java.text.DecimalFormat pattern

defSequence

public void defSequence(String fieldname,
                        String sequenceName)
define the call that a field gets its value from a sequence

Parameters:
fieldname - - symbolic field name
sequenceName - - name of the sequence to be used

date

public Date date(String fieldName,
                 String value)
          throws ParseException
convert a value to a sql.Date

Parameters:
fieldName - - symbolic field name (must have a format registered with defDate())
value - - text value to be parsed to date, can be "" or null
Returns:
java.sql.Date or null
Throws:
ParseException

timestamp

public Timestamp timestamp(String fieldName,
                           String value)
                    throws ParseException
Throws:
ParseException

time

public Time time(String fieldName,
                 String value)
          throws ParseException
Throws:
ParseException

number

public Number number(String fieldName,
                     String value)
              throws ParseException
Throws:
ParseException

isTrue

public boolean isTrue(String value)

bool

public Object bool(String value)
Oracle DOES NOT SUPPORT Boolean, so this method returns 1 or 0 (or null). In case of Postgres, it returns true or false (or null)

Parameters:
value - null (for null), "1" (for true), "0" (for false), "true" (for true), "false" (for false)

bool

public Object bool(boolean value)

nullable

public String nullable(String value)

nextVal

public long nextVal(Connection connection,
                    String fieldName)
             throws SQLException
fetch the next value of the sequence, defined under this name

Throws:
SQLException

get

public Object get(String fieldName)
get the call for the given field. can be used to retrieve a sequence.nextvalue expression

Parameters:
fieldName - - symbolic field name
Returns:
defined call for the field
Throws:
ParseException

trim

public String trim(String value)
a null-aware trim function

Parameters:
value - - a string or null
Returns:
trimmed value or null


Copyright © 2008-2011. All Rights Reserved.