org.LexGrid.util.sql
Class DBUtility

java.lang.Object
  extended by org.LexGrid.util.sql.DBUtility

public class DBUtility
extends java.lang.Object

This class holds many utility type methods for common DB related tasks - getting booleans out of a SQL server, escaping things for LDAP, etc.

Author:
Dan Armbrust

Constructor Summary
DBUtility()
           
 
Method Summary
static void AddUTF8PropToDBConnectionProperties(java.util.Properties props, java.lang.String URL)
           
static java.lang.String computeNextIdentifier(java.lang.String currentIdentifier)
          Construct the next identifier to use after the given identifier.
static java.sql.Connection connectToDatabase(java.lang.String server, java.lang.String driver, java.lang.String user, java.lang.String password)
           
static void createDatabase(java.lang.String DBUrl, java.lang.String driver, java.lang.String dbName, java.lang.String username, java.lang.String password, boolean useLexGridCharSet)
           
static boolean doesDBExist(java.lang.String server, java.lang.String driver, java.lang.String dbName, java.lang.String parameters, java.lang.String username, java.lang.String password)
           
static void dropDatabase(java.lang.String DBUrl, java.lang.String driver, java.lang.String dbName, java.lang.String username, java.lang.String password)
           
static java.lang.String escapeLdapCode(java.lang.String string)
           
static java.lang.String escapeLdapDN(java.lang.String string)
           
static java.lang.String escapeLdapDN(java.lang.String string, boolean escapeCommas)
           
static boolean getbooleanFromResultSet(java.sql.ResultSet results, java.lang.String column)
           
static java.lang.Boolean getBooleanFromResultSet(java.sql.ResultSet results, java.lang.String columnName)
           
static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement, int colNumber, java.lang.Boolean value)
          simplified call to setBooleanOnPreparedStatement.
static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement, int colNumber, java.lang.Boolean value, boolean isSqlLite)
          simplified call to setBooleanOnPreparedStatement.
static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement, int colNumber, java.lang.Boolean value, boolean isSqlLite, java.lang.String databaseType)
          Sets booleans properly in the LexGrid world.
static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement, int colNumber, java.lang.Boolean value, java.lang.String databaseType)
          simplified call to setBooleanOnPreparedStatement.
static boolean validLocalName(java.lang.String name)
          Checks the validity of the Local Name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBUtility

public DBUtility()
Method Detail

connectToDatabase

public static java.sql.Connection connectToDatabase(java.lang.String server,
                                                    java.lang.String driver,
                                                    java.lang.String user,
                                                    java.lang.String password)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

validLocalName

public static boolean validLocalName(java.lang.String name)
Checks the validity of the Local Name

Parameters:
name - Local Name to check
Returns:
true if valid, false otherwise

escapeLdapDN

public static java.lang.String escapeLdapDN(java.lang.String string,
                                            boolean escapeCommas)

escapeLdapDN

public static java.lang.String escapeLdapDN(java.lang.String string)

escapeLdapCode

public static java.lang.String escapeLdapCode(java.lang.String string)

setBooleanOnPreparedStatment

public static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement,
                                                int colNumber,
                                                java.lang.Boolean value)
                                         throws java.sql.SQLException
simplified call to setBooleanOnPreparedStatement. Passes in false and null for the last two parameters.

Parameters:
statement -
colNumber -
value -
Throws:
java.sql.SQLException

setBooleanOnPreparedStatment

public static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement,
                                                int colNumber,
                                                java.lang.Boolean value,
                                                boolean isSqlLite)
                                         throws java.sql.SQLException
simplified call to setBooleanOnPreparedStatement. Passes in null for databaseType

Parameters:
statement -
colNumber -
value -
Throws:
java.sql.SQLException

setBooleanOnPreparedStatment

public static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement,
                                                int colNumber,
                                                java.lang.Boolean value,
                                                java.lang.String databaseType)
                                         throws java.sql.SQLException
simplified call to setBooleanOnPreparedStatement. Passes in false for "isSqlLite"

Parameters:
statement -
colNumber -
value -
Throws:
java.sql.SQLException

setBooleanOnPreparedStatment

public static void setBooleanOnPreparedStatment(java.sql.PreparedStatement statement,
                                                int colNumber,
                                                java.lang.Boolean value,
                                                boolean isSqlLite,
                                                java.lang.String databaseType)
                                         throws java.sql.SQLException
Sets booleans properly in the LexGrid world.

Parameters:
statement -
colNumber -
value -
isSqlLite - - using sqlLite tables? Set to true if the answer is yes.
databaseType - - optional. Set to null or "" if you don't know it.
Throws:
java.sql.SQLException

getBooleanFromResultSet

public static java.lang.Boolean getBooleanFromResultSet(java.sql.ResultSet results,
                                                        java.lang.String columnName)
                                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

getbooleanFromResultSet

public static boolean getbooleanFromResultSet(java.sql.ResultSet results,
                                              java.lang.String column)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

AddUTF8PropToDBConnectionProperties

public static void AddUTF8PropToDBConnectionProperties(java.util.Properties props,
                                                       java.lang.String URL)

createDatabase

public static void createDatabase(java.lang.String DBUrl,
                                  java.lang.String driver,
                                  java.lang.String dbName,
                                  java.lang.String username,
                                  java.lang.String password,
                                  boolean useLexGridCharSet)
                           throws java.lang.Exception
Throws:
java.lang.Exception

doesDBExist

public static boolean doesDBExist(java.lang.String server,
                                  java.lang.String driver,
                                  java.lang.String dbName,
                                  java.lang.String parameters,
                                  java.lang.String username,
                                  java.lang.String password)

dropDatabase

public static void dropDatabase(java.lang.String DBUrl,
                                java.lang.String driver,
                                java.lang.String dbName,
                                java.lang.String username,
                                java.lang.String password)
                         throws java.lang.Exception
Throws:
java.lang.Exception

computeNextIdentifier

public static java.lang.String computeNextIdentifier(java.lang.String currentIdentifier)
                                              throws java.lang.Exception
Construct the next identifier to use after the given identifier. Expects (and returns) a 2 character string - using the characters a-z in the first position and the characters a-z and 0-9 in the second position. Case insensitive. Wraps if it gets to zz. Starts with a0 (if no identifier is provided)

Parameters:
currentIdentifier -
Returns:
Throws:
java.lang.Exception - if it doesn't understand the identifier.

Copyright: (c) 2004-2006 Mayo Foundation for Medical Education and Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the triple-shield Mayo logo are trademarks and service marks of MFMER.