com.tekann.codegen.pda.util
Class PDADBUtil

java.lang.Object
  extended by com.tekann.codegen.pda.util.PDADBUtil

public class PDADBUtil
extends java.lang.Object

Class that has some useful methods.

Author:
Guilherme Frantz

Constructor Summary
PDADBUtil()
           
 
Method Summary
static totalcross.util.Date formatDate(java.lang.String dateValue)
          Converts the passed date String to totalcross.util.Date.
static totalcross.sys.Time formatDatetimeToLitebase(java.lang.String datetime)
          Converts the passed date String to totalcross.sys.Time.
static totalcross.sys.Time formatDatetimeToLitebase(java.lang.String datetime, byte dateFormat)
          The format of the passed datetime must be in the passed dateFormat.
static java.lang.String formatValue(boolean value)
          Converts a boolean to 0 or 1.
static java.lang.String formatValue(totalcross.util.Date dateValue)
          Formats the Date to the Settings.DATE_YMD format
static java.lang.String formatValue(totalcross.util.Date dateValue, byte format)
          Formats the passed Date to the given format.
static java.lang.String formatValue(double value)
          Format double to String.
static java.lang.String formatValue(int value)
          Format int to String.
static java.lang.Object formatValue(int pdaType, byte[] value)
          Format value by type.
static java.lang.String formatValue(long value)
          Format long to String.
static java.lang.String formatValue(java.lang.String value)
          Do nothing, just return the passing argument.
static java.lang.String formatValue(totalcross.sys.Time value, byte format)
          Format the given Time to the passed format.
static java.lang.String formatValue(totalcross.sys.Time value, byte format, java.lang.String millisSeparator, boolean showMillis)
          Format the given Time to the passed format.
static java.lang.String formatValue(TKNBoolean value)
          Converts a boolean to 0 or 1.
static java.lang.String formatValue(TKNDouble value)
          Format double to String.
static java.lang.String formatValue(TKNInteger value)
          Format int to String.
static java.lang.String formatValue(TKNLong value)
          Format long to String.
static java.lang.String formatValueToMD5(java.lang.String value)
          Encripts the sent string and returns a hex string in the MD5 format.
static java.lang.String getFormattedValue(int fieldDataTypeId, java.lang.Object value)
          If the fieldDataTypeId is a literal then the value will be returned between single quote, for instance: 'value'.
static java.lang.String getPreparedStatementSetByType(int fieldDataTypeId)
          Get the set as a String for the passed field data type argument.
static boolean isDateTimeValid(java.lang.String dateTimeValue)
          Tests if the passed date time value is correctly formated.
static boolean isDateValid(java.lang.String dateValue)
          Tests if the passed date value is correctly formated.
static void setPreparedStatementValue(int fieldDataTypeId, java.lang.Object value, int valueIndex, litebase.PreparedStatement preparedStatement)
          Set the prepared statement according to the field data type passed as argument.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDADBUtil

public PDADBUtil()
Method Detail

formatDate

public static totalcross.util.Date formatDate(java.lang.String dateValue)
                                       throws java.lang.Exception
Converts the passed date String to totalcross.util.Date. The date argument must be in the format yyyy/MM/dd or dd/MM/yyyy

Parameters:
date -
Returns:
The formated totalcross.util.Date
Throws:
java.lang.Exception

formatDatetimeToLitebase

public static totalcross.sys.Time formatDatetimeToLitebase(java.lang.String datetime,
                                                           byte dateFormat)
                                                    throws java.lang.Exception
The format of the passed datetime must be in the passed dateFormat.

Parameters:
datetime - The datetime
dateFormat - The desired format: Settings.DATE_YMD, Settings.DATE_DMY or Settings.DATE_MDY
Returns:
Throws:
java.lang.Exception

formatDatetimeToLitebase

public static totalcross.sys.Time formatDatetimeToLitebase(java.lang.String datetime)
                                                    throws java.lang.Exception
Converts the passed date String to totalcross.sys.Time.
The datetime format can be in the three supported
by TotalCross: Settings.DATE_YMD, Settings.DATE_DMY or Settings.DATE_MDY

Parameters:
datetime -
Returns:
The formatted totalcross.sys.Time
Throws:
java.lang.Exception

formatValue

public static java.lang.String formatValue(boolean value)
Converts a boolean to 0 or 1.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(TKNBoolean value)
Converts a boolean to 0 or 1.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(totalcross.util.Date dateValue,
                                           byte format)
Formats the passed Date to the given format.

Parameters:
dateValue -
format - Can be one of the following constants in totalcross.sys.Settings: DATE_MDY, DATE_DMY, DATE_YMD;
Returns:
A formatted String

formatValue

public static java.lang.String formatValue(totalcross.util.Date dateValue)
Formats the Date to the Settings.DATE_YMD format

Parameters:
dateValue -
Returns:
A String

formatValue

public static java.lang.String formatValue(double value)
Format double to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(TKNDouble value)
Format double to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(int value)
Format int to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(TKNInteger value)
Format int to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(long value)
Format long to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(TKNLong value)
Format long to String.

Parameters:
value -
Returns:
A String

formatValue

public static java.lang.String formatValue(java.lang.String value)
Do nothing, just return the passing argument.

Parameters:
value -
Returns:
A String

formatValueToMD5

public static java.lang.String formatValueToMD5(java.lang.String value)
Encripts the sent string and returns a hex string in the MD5 format.

Parameters:
value -
Returns:
String

formatValue

public static java.lang.String formatValue(totalcross.sys.Time value,
                                           byte format)
Format the given Time to the passed format.

Parameters:
value -
format - It can be one of them: totalcross.sys.Settings.DATE_DMY; totalcross.sys.Settings.DATE_MDY; totalcross.sys.Settings.DATE_YMD;
Returns:
A String

formatValue

public static java.lang.String formatValue(totalcross.sys.Time value,
                                           byte format,
                                           java.lang.String millisSeparator,
                                           boolean showMillis)
Format the given Time to the passed format.

Parameters:
value -
format - It can be one of them: totalcross.sys.Settings.DATE_DMY; totalcross.sys.Settings.DATE_MDY; totalcross.sys.Settings.DATE_YMD;
millisSeparator - By default is ":", but you can put whatever you want
Returns:
A String

getFormattedValue

public static java.lang.String getFormattedValue(int fieldDataTypeId,
                                                 java.lang.Object value)
If the fieldDataTypeId is a literal then the value will be returned between single quote, for instance: 'value'.

Parameters:
fieldDataTypeId -
value -
Returns:
A String

getPreparedStatementSetByType

public static java.lang.String getPreparedStatementSetByType(int fieldDataTypeId)
Get the set as a String for the passed field data type argument. For instance:
case IFieldDataType.INTEGER:
return "setInt";

Parameters:
fieldDataTypeId - Values that belongs to PDADBUtil. Ex.: PDADBUtil.INTEGER
Returns:
A String

setPreparedStatementValue

public static void setPreparedStatementValue(int fieldDataTypeId,
                                             java.lang.Object value,
                                             int valueIndex,
                                             litebase.PreparedStatement preparedStatement)
                                      throws totalcross.sys.InvalidNumberException,
                                             totalcross.util.InvalidDateException
Set the prepared statement according to the field data type passed as argument. For instance:
case IFieldDataType.INTEGER:
preparedStatement.setInt(valueIndex, Convert.toInt(value.toString()));

Parameters:
fieldDataTypeId - Values that belongs to PDADBUtil. Ex.: PDADBUtil.INTEGER
value -
valueIndex -
preparedStatement -
Throws:
totalcross.sys.InvalidNumberException
totalcross.util.InvalidDateException

isDateTimeValid

public static boolean isDateTimeValid(java.lang.String dateTimeValue)
Tests if the passed date time value is correctly formated.

Parameters:
dateTimeValue -
Returns:
A boolean

isDateValid

public static boolean isDateValid(java.lang.String dateValue)
Tests if the passed date value is correctly formated.

Parameters:
dateValue -
Returns:
A boolean

formatValue

public static java.lang.Object formatValue(int pdaType,
                                           byte[] value)
                                    throws java.lang.Exception
Format value by type.

Parameters:
pdaType -
value -
Returns:
An Object
Throws:
java.lang.Exception