com.isti.util.database
Class DatabaseUtil

java.lang.Object
  extended by com.isti.util.database.DatabaseUtil

public class DatabaseUtil
extends java.lang.Object


Field Summary
static java.lang.String ASCII_DOUBLE_PRECISION
           
static java.lang.String ASCII_DOUBLE_PRECISION_ALT
           
static java.lang.String ASCII_INTEGER
           
static java.lang.String ASCII_INTEGER_ALT
           
static java.lang.String ASCII_SINGLE_PRECISION
           
static java.lang.String ASCII_SINGLE_PRECISION_ALT
           
static java.lang.String EMPTY_TEXT
           
static java.lang.String FROM_TEXT
           
static java.lang.String NORESS_GAIN_RANGED
           
static java.lang.String ORDER_BY_TEXT
           
static java.lang.String PROPERTY_HOST_NAME
           
static java.lang.String PROPERTY_PASS_WORD
           
static java.lang.String PROPERTY_PORT
           
static java.lang.String PROPERTY_SID
           
static java.lang.String PROPERTY_USER_NAME
           
static java.lang.String SELECT_ALL_TEXT
           
static java.lang.String SELECT_DISTINCT_TEXT
           
static java.lang.String SUN_IEEE_DOUBLE_PRECISION_REAL
           
static java.lang.String SUN_IEEE_INTEGER
           
static java.lang.String SUN_IEEE_SHORT_INTEGER
           
static java.lang.String SUN_IEEE_SINGLE_PRECISION_REAL
           
static java.lang.String VAX_IEEE_DOUBLE_PRECISION_REAL
           
static java.lang.String VAX_IEEE_INTEGER
           
static java.lang.String VAX_IEEE_SHORT_INTEGER
           
static java.lang.String VAX_IEEE_SINGLE_PRECISION_REAL
           
static java.lang.String WHERE_TEXT_BEGIN
           
static java.lang.String WHERE_TEXT_END
           
 
Constructor Summary
protected DatabaseUtil()
           
 
Method Summary
static java.lang.String combineClauses(java.lang.String selectText, java.lang.String fromText, java.lang.String whereText, java.lang.String orderByText)
          Combines the clauses to create the sql statement for a query.
static double convertToFrequency(double val, boolean periodFlag)
          convert value to frequency if needed
static double convertToPeriod(double val, boolean periodFlag)
          convert value to period if needed
static double convertToVel(double val, double p)
          convert the noise value from Acceleration to Velocity value (low or high) and period
static double convertToVel(double val, double p, boolean velocityFlag)
          convert the noise value from Acceleration to Velocity value (low or high) and period if needed
static byte getByte(java.util.Map map, java.lang.String columnName)
          Gets a byte value from the database map.
static java.lang.String getColumnPrefix(java.lang.String tablePrefix)
           
static java.lang.String getColumnText(java.lang.String[] columnNames, java.lang.String columnName)
           
static double getDouble(java.util.Map map, java.lang.String columnName)
          Gets a double value from the database map.
static float getFloat(java.util.Map map, java.lang.String columnName)
          Gets a float value from the database map.
static java.lang.String getFromClause(java.lang.String text, java.lang.String tableName, java.lang.String tablePrefix)
           
static java.lang.String getHostName(java.util.Properties info)
           
static int getInt(java.util.Map map, java.lang.String columnName)
          Gets a int value from the database map.
static long getLong(java.util.Map map, java.lang.String columnName)
          Gets a long value from the database map.
static java.lang.Object getObject(java.util.Map map, java.lang.String columnName)
          Gets a Object value from the database map.
static java.lang.String getOrderByClause(java.lang.String text, java.lang.String[] columnNames, int orderCount)
           
static java.lang.String getPassWord(java.util.Properties info)
           
static java.lang.String getPassWord(java.util.Properties info, java.lang.String defaultPassWord)
           
static int getPort(java.util.Properties info)
           
static java.lang.String getSelectClause(java.lang.String text, java.lang.String[] columnNames)
           
static java.lang.String getSelectClause(java.lang.String text, java.lang.String[] columnNames, int selectCount)
           
static short getShort(java.util.Map map, java.lang.String columnName)
          Gets a short value from the database map.
static java.lang.String getSid(java.util.Properties info)
           
static java.lang.String getString(java.util.Map map, java.lang.String columnName)
          Gets a String value from the database map.
static double getTimeInSeconds(java.util.Calendar cal)
           
static java.lang.String getUserName(java.util.Properties info)
           
static java.lang.String getWhereClause(java.lang.String text, java.lang.String[] fullColumnNames)
          Gets the where clause for the specified value.
static java.lang.String getWhereClause(java.lang.String text, java.lang.String columnName, int[] columnValues)
          Gets the where clause for the specified value.
static java.lang.String getWhereClause(java.lang.String text, java.lang.String columnName, int columnBeginValue, int columnEndValue)
          Gets the where clause for the specified value.
static java.lang.String getWhereClause(java.lang.String text, java.lang.String columnName, java.lang.String columnText)
          Gets the where clause for the specified value.
static java.lang.String getWhereClause(java.lang.String text, java.lang.String columnName, java.lang.String columnText, boolean wildCardFlag)
          Gets the where clause for the specified value.
static java.lang.String getWhereClause(java.lang.String text, java.lang.String columnName, java.lang.String columnBeginText, java.lang.String columnEndText)
          Gets the where clause for the specified value.
static double invertValue(double d)
          Inverts the value.
static void setHostName(java.util.Properties info, java.lang.String hostName)
          Set host name
static void setPassWord(java.util.Properties info, java.lang.String passWord)
          Set pass word
static void setPort(java.util.Properties info, java.lang.String port)
          Set port
static void setSid(java.util.Properties info, java.lang.String sid)
          Set sid
static void setUserName(java.util.Properties info, java.lang.String userName)
          Set user name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_TEXT

public static final java.lang.String EMPTY_TEXT
See Also:
Constant Field Values

SELECT_DISTINCT_TEXT

public static final java.lang.String SELECT_DISTINCT_TEXT
See Also:
Constant Field Values

SELECT_ALL_TEXT

public static final java.lang.String SELECT_ALL_TEXT
See Also:
Constant Field Values

FROM_TEXT

public static final java.lang.String FROM_TEXT
See Also:
Constant Field Values

WHERE_TEXT_BEGIN

public static final java.lang.String WHERE_TEXT_BEGIN
See Also:
Constant Field Values

WHERE_TEXT_END

public static final java.lang.String WHERE_TEXT_END
See Also:
Constant Field Values

ORDER_BY_TEXT

public static final java.lang.String ORDER_BY_TEXT
See Also:
Constant Field Values

ASCII_SINGLE_PRECISION

public static final java.lang.String ASCII_SINGLE_PRECISION
See Also:
Constant Field Values

ASCII_DOUBLE_PRECISION

public static final java.lang.String ASCII_DOUBLE_PRECISION
See Also:
Constant Field Values

ASCII_INTEGER

public static final java.lang.String ASCII_INTEGER
See Also:
Constant Field Values

ASCII_SINGLE_PRECISION_ALT

public static final java.lang.String ASCII_SINGLE_PRECISION_ALT
See Also:
Constant Field Values

ASCII_DOUBLE_PRECISION_ALT

public static final java.lang.String ASCII_DOUBLE_PRECISION_ALT
See Also:
Constant Field Values

ASCII_INTEGER_ALT

public static final java.lang.String ASCII_INTEGER_ALT
See Also:
Constant Field Values

SUN_IEEE_SINGLE_PRECISION_REAL

public static final java.lang.String SUN_IEEE_SINGLE_PRECISION_REAL
See Also:
Constant Field Values

SUN_IEEE_DOUBLE_PRECISION_REAL

public static final java.lang.String SUN_IEEE_DOUBLE_PRECISION_REAL
See Also:
Constant Field Values

SUN_IEEE_INTEGER

public static final java.lang.String SUN_IEEE_INTEGER
See Also:
Constant Field Values

SUN_IEEE_SHORT_INTEGER

public static final java.lang.String SUN_IEEE_SHORT_INTEGER
See Also:
Constant Field Values

VAX_IEEE_SINGLE_PRECISION_REAL

public static final java.lang.String VAX_IEEE_SINGLE_PRECISION_REAL
See Also:
Constant Field Values

VAX_IEEE_DOUBLE_PRECISION_REAL

public static final java.lang.String VAX_IEEE_DOUBLE_PRECISION_REAL
See Also:
Constant Field Values

VAX_IEEE_INTEGER

public static final java.lang.String VAX_IEEE_INTEGER
See Also:
Constant Field Values

VAX_IEEE_SHORT_INTEGER

public static final java.lang.String VAX_IEEE_SHORT_INTEGER
See Also:
Constant Field Values

NORESS_GAIN_RANGED

public static final java.lang.String NORESS_GAIN_RANGED
See Also:
Constant Field Values

PROPERTY_HOST_NAME

public static final java.lang.String PROPERTY_HOST_NAME
See Also:
Constant Field Values

PROPERTY_PORT

public static final java.lang.String PROPERTY_PORT
See Also:
Constant Field Values

PROPERTY_SID

public static final java.lang.String PROPERTY_SID
See Also:
Constant Field Values

PROPERTY_USER_NAME

public static final java.lang.String PROPERTY_USER_NAME
See Also:
Constant Field Values

PROPERTY_PASS_WORD

public static final java.lang.String PROPERTY_PASS_WORD
See Also:
Constant Field Values
Constructor Detail

DatabaseUtil

protected DatabaseUtil()
Method Detail

invertValue

public static double invertValue(double d)
Inverts the value.

Parameters:
d - value
Returns:
inverse of the value.

convertToFrequency

public static double convertToFrequency(double val,
                                        boolean periodFlag)
convert value to frequency if needed

Parameters:
val - value
periodFlag - true if period
Returns:
frequency value

convertToPeriod

public static double convertToPeriod(double val,
                                     boolean periodFlag)
convert value to period if needed

Parameters:
val - value
periodFlag - true if period
Returns:
period value

convertToVel

public static double convertToVel(double val,
                                  double p)
convert the noise value from Acceleration to Velocity value (low or high) and period

Parameters:
val - acceleration value
p - peroid
Returns:
velocity value

convertToVel

public static double convertToVel(double val,
                                  double p,
                                  boolean velocityFlag)
convert the noise value from Acceleration to Velocity value (low or high) and period if needed

Parameters:
val - acceleration value
p - peroid
velocityFlag - true for velocity
Returns:
velocity value

getTimeInSeconds

public static double getTimeInSeconds(java.util.Calendar cal)
Parameters:
cal - calendar
Returns:
the time in seconds

getObject

public static java.lang.Object getObject(java.util.Map map,
                                         java.lang.String columnName)
Gets a Object value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
Object value
Throws:
java.lang.NullPointerException - if the value was not found.

getString

public static java.lang.String getString(java.util.Map map,
                                         java.lang.String columnName)
Gets a String value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
String value
Throws:
java.lang.NullPointerException - if the value was not found.

getByte

public static byte getByte(java.util.Map map,
                           java.lang.String columnName)
Gets a byte value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
byte value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

getDouble

public static double getDouble(java.util.Map map,
                               java.lang.String columnName)
                        throws java.lang.NumberFormatException
Gets a double value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
double value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

getFloat

public static float getFloat(java.util.Map map,
                             java.lang.String columnName)
Gets a float value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
float value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

getInt

public static int getInt(java.util.Map map,
                         java.lang.String columnName)
Gets a int value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
int value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

getLong

public static long getLong(java.util.Map map,
                           java.lang.String columnName)
Gets a long value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
long value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

getShort

public static short getShort(java.util.Map map,
                             java.lang.String columnName)
Gets a short value from the database map.

Parameters:
map - database map
columnName - database column name
Returns:
short value
Throws:
java.lang.NullPointerException - if the value was not found.
java.lang.NumberFormatException - if the string does not contain a parsable number.

setHostName

public static final void setHostName(java.util.Properties info,
                                     java.lang.String hostName)
Set host name

Parameters:
info - properties information
hostName - host name

setPort

public static final void setPort(java.util.Properties info,
                                 java.lang.String port)
Set port

Parameters:
info - properties information
port - port value

setSid

public static final void setSid(java.util.Properties info,
                                java.lang.String sid)
Set sid

Parameters:
info - properties information
sid - sid value

setUserName

public static final void setUserName(java.util.Properties info,
                                     java.lang.String userName)
Set user name

Parameters:
info - properties information
userName - user name

setPassWord

public static final void setPassWord(java.util.Properties info,
                                     java.lang.String passWord)
Set pass word

Parameters:
info - properties information
passWord - pass word

getHostName

public static final java.lang.String getHostName(java.util.Properties info)
                                          throws java.lang.InstantiationException
Parameters:
info - properties information
Returns:
host name
Throws:
java.lang.InstantiationException - if the information was not found.

getPort

public static final int getPort(java.util.Properties info)
                         throws java.lang.InstantiationException
Parameters:
info - properties information
Returns:
port
Throws:
java.lang.InstantiationException - if the information was not found.

getSid

public static final java.lang.String getSid(java.util.Properties info)
                                     throws java.lang.InstantiationException
Parameters:
info - properties information
Returns:
sid
Throws:
java.lang.InstantiationException - if the information was not found.

getUserName

public static final java.lang.String getUserName(java.util.Properties info)
                                          throws java.lang.InstantiationException
Parameters:
info - properties information
Returns:
user name
Throws:
java.lang.InstantiationException - if the information was not found.

getPassWord

public static final java.lang.String getPassWord(java.util.Properties info)
                                          throws java.lang.InstantiationException
Parameters:
info - properties information
Returns:
pass word or user name if no pass word exists
Throws:
java.lang.InstantiationException - if the information was not found.

getPassWord

public static final java.lang.String getPassWord(java.util.Properties info,
                                                 java.lang.String defaultPassWord)
                                          throws java.lang.InstantiationException
Parameters:
info - properties information
defaultPassWord - default pass word
Returns:
pass word
Throws:
java.lang.InstantiationException - if the information was not found.

getColumnPrefix

public static java.lang.String getColumnPrefix(java.lang.String tablePrefix)
Parameters:
tablePrefix - table prefix
Returns:
the column prefix

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String columnName,
                                              java.lang.String columnText)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
columnName - column name
columnText - column text
Returns:
the where clause or null if empty text

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String columnName,
                                              java.lang.String columnText,
                                              boolean wildCardFlag)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
columnName - column name
columnText - column text
wildCardFlag - true to check for wild cards ('%' or '_'), false otherwise.
Returns:
the where clause or null if empty text

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String columnName,
                                              int[] columnValues)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
columnName - column name
columnValues - array of column values
Returns:
the where clause or null if empty text

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String columnName,
                                              int columnBeginValue,
                                              int columnEndValue)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
columnName - column name
columnBeginValue - column begin value
columnEndValue - column end value
Returns:
the where clause or null if empty text

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String[] fullColumnNames)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
fullColumnNames - array of full column names
Returns:
the where clause or null if empty text

getWhereClause

public static java.lang.String getWhereClause(java.lang.String text,
                                              java.lang.String columnName,
                                              java.lang.String columnBeginText,
                                              java.lang.String columnEndText)
Gets the where clause for the specified value.

Parameters:
text - text for the entire where clause
columnName - column name
columnBeginText - column begin text
columnEndText - column end text
Returns:
the where clause or null if empty text

getSelectClause

public static java.lang.String getSelectClause(java.lang.String text,
                                               java.lang.String[] columnNames)
Parameters:
text - select text
columnNames - column names
Returns:
the select clause

getSelectClause

public static java.lang.String getSelectClause(java.lang.String text,
                                               java.lang.String[] columnNames,
                                               int selectCount)
Parameters:
text - select text
columnNames - column names
selectCount - selection count
Returns:
the select clause

getFromClause

public static java.lang.String getFromClause(java.lang.String text,
                                             java.lang.String tableName,
                                             java.lang.String tablePrefix)
Parameters:
text - from text
tableName - table name
tablePrefix - table prefix
Returns:
the from clause

getOrderByClause

public static java.lang.String getOrderByClause(java.lang.String text,
                                                java.lang.String[] columnNames,
                                                int orderCount)
Parameters:
text - select text
columnNames - column names
orderCount - number of columns to use for ordering
Returns:
the order by clause

combineClauses

public static java.lang.String combineClauses(java.lang.String selectText,
                                              java.lang.String fromText,
                                              java.lang.String whereText,
                                              java.lang.String orderByText)
Combines the clauses to create the sql statement for a query.

Parameters:
selectText - select text
fromText - from text
whereText - where text
orderByText - order by text
Returns:
the sql statement
See Also:
executeQuery

getColumnText

public static java.lang.String getColumnText(java.lang.String[] columnNames,
                                             java.lang.String columnName)
Parameters:
columnNames - array of column names
columnName - column name
Returns:
the column text for the specified column or null if none.