com.softslate.commerce.daos.core
Class DAOUtils

java.lang.Object
  extended bycom.softslate.commerce.daos.core.DAOUtils

public class DAOUtils
extends java.lang.Object

Holds various utility methods for use by DAOs.

Author:
David Tobey

Field Summary
(package private) static org.apache.commons.logging.Log log
           
static java.lang.String[] stopWords
          An array of strings to eliminate from database search queries.
 
Constructor Summary
DAOUtils()
           
 
Method Summary
static java.lang.String generateKeyPair(java.lang.String publicFile, java.lang.String privateFile, boolean savePrivate)
           
static void generateTwoWayKey(java.lang.String keyFile)
           
static java.util.Collection getCollectionFromCollection(java.util.Collection collection, java.lang.String field)
          Given a Collection of Maps representing a ResultSet, and a field name for a field, returns a Collection of Strings representing each field's value in the incoming Collection.
static java.util.Collection getCollectionFromResultSet(java.sql.ResultSet resultSet, java.lang.String field)
          Given a ResultSet and a field name for a field, returns a Collection of Strings representing each field value in the ResultSet.
static java.lang.String getDebugMessage(java.sql.ResultSet resultSet)
          Retrieves a string indicating the number of rows and columns returned from a ResultSet.
static java.lang.String getDecrypted(java.lang.String stringToDecrypt, java.lang.String encryptionType, java.lang.String privateKeyFile)
          Decrypts a string using the given encryption type.
static java.lang.String getEncrypted(java.lang.String stringToEncrypt, java.lang.String encryptionType, java.lang.String publicKeyFile)
          Encrypts a string using the given encryption type.
static java.lang.String getList(java.lang.String[] stringArray)
          Given an array of strings, returns a single string that can be used as a list in an SQL expression.
static java.lang.String getListFromCollection(java.util.Collection collection, java.lang.String field)
          Given a Collection of Maps representing a ResultSet, and a field name for a field, returns a String list representing each field's value in the incoming Collection.
static java.lang.String getListFromResultSet(java.sql.ResultSet resultSet, java.lang.String field)
          Given a ResultSet and a field name, returns a single string that can be used as a list in an SQL expression.
static java.lang.String getQuotedList(java.util.Map map)
          Given a Map of string keys, returns a single string that can be used as a list in an SQL expression.
static java.lang.String getQuotedList(java.lang.String[] stringArray)
          Given an array of strings, returns a single string that can be used as a list in an SQL expression.
private static java.security.Key loadKey(java.lang.String filename, boolean isPublic)
           
static void outputCsv(java.util.Collection data, java.io.Writer out)
          Outputs a matrix of strings as comma-separated values.
static java.lang.String prepareSearchString(java.lang.String searchString)
          Prepares a string for insertion into an SQL search expression.
private static void saveKey(java.lang.String filename, byte[] contents)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.commons.logging.Log log

stopWords

public static java.lang.String[] stopWords
An array of strings to eliminate from database search queries.

Constructor Detail

DAOUtils

public DAOUtils()
Method Detail

getList

public static java.lang.String getList(java.lang.String[] stringArray)
                                throws java.lang.Exception
Given an array of strings, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incoming array are separated by commas.

Parameters:
stringArray - The array of strings to convert into a comma-separated list.
Returns:
A string that can be used as a list in an SQL expression.
Throws:
java.lang.Exception

getQuotedList

public static java.lang.String getQuotedList(java.lang.String[] stringArray)
                                      throws java.lang.Exception
Given an array of strings, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incoming array are quoted and separated by commas.

Parameters:
stringArray - The array of strings to convert into a quoted string.
Returns:
A string that can be used as a list in an SQL expression.
Throws:
java.lang.Exception

getListFromResultSet

public static java.lang.String getListFromResultSet(java.sql.ResultSet resultSet,
                                                    java.lang.String field)
                                             throws java.sql.SQLException
Given a ResultSet and a field name, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incoming ResultSet corresponding to the given field are separated by commas. Helpful for older databases that do not support sub queries.

Parameters:
resultSet - The ResultSet holding the values.
field - The name of the field whose values are to be returned in a list.
Returns:
@throws SQLException
Throws:
java.sql.SQLException

getListFromCollection

public static java.lang.String getListFromCollection(java.util.Collection collection,
                                                     java.lang.String field)
                                              throws java.lang.Exception
Given a Collection of Maps representing a ResultSet, and a field name for a field, returns a String list representing each field's value in the incoming Collection.

Parameters:
collection - The Collection holding the values.
Returns:
A string that can be used as a list in an SQL expression.
Throws:
java.lang.Exception

getCollectionFromResultSet

public static java.util.Collection getCollectionFromResultSet(java.sql.ResultSet resultSet,
                                                              java.lang.String field)
                                                       throws java.sql.SQLException
Given a ResultSet and a field name for a field, returns a Collection of Strings representing each field value in the ResultSet.

Parameters:
resultSet - The ResultSet holding the values.
field - The name of the field whose values are to be returned in a Colleciton.
Returns:
@throws SQLException
Throws:
java.sql.SQLException

getCollectionFromCollection

public static java.util.Collection getCollectionFromCollection(java.util.Collection collection,
                                                               java.lang.String field)
                                                        throws java.sql.SQLException
Given a Collection of Maps representing a ResultSet, and a field name for a field, returns a Collection of Strings representing each field's value in the incoming Collection.

Parameters:
collection - The Collection holding the values.
field - The name of the field whose values are to be returned in a Collection.
Returns:
@throws SQLException
Throws:
java.sql.SQLException

getDebugMessage

public static java.lang.String getDebugMessage(java.sql.ResultSet resultSet)
                                        throws java.sql.SQLException
Retrieves a string indicating the number of rows and columns returned from a ResultSet.

Parameters:
resultSet - The ResultSet to produce a debugging message for.
Returns:
A string indicating the number of rows and columns returned from a ResultSet.
Throws:
java.sql.SQLException

getQuotedList

public static java.lang.String getQuotedList(java.util.Map map)
                                      throws java.lang.Exception
Given a Map of string keys, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incoming Map are quoted and separated by commas.

Parameters:
map - The Map to convert into a quoted string.
Returns:
A string that can be used as a list in an SQL expression.
Throws:
java.lang.Exception

outputCsv

public static void outputCsv(java.util.Collection data,
                             java.io.Writer out)
                      throws java.io.IOException
Outputs a matrix of strings as comma-separated values. This implementation encloses problem values in double-quotes, prepends backslash to embedded double-quotes and backslashes, and represents embedded newlines as backslash-n.

Parameters:
data - List of String arrays or Object arrays.
out - The stream to write to.
Throws:
java.io.IOException

prepareSearchString

public static java.lang.String prepareSearchString(java.lang.String searchString)
Prepares a string for insertion into an SQL search expression. Adds % to the beginning and end of the string and in between each word. Also strips the string of characters dangerous to an SQL search expression.

Parameters:
searchString -
Returns:
A string acceptable for a LIKE expression.

getEncrypted

public static java.lang.String getEncrypted(java.lang.String stringToEncrypt,
                                            java.lang.String encryptionType,
                                            java.lang.String publicKeyFile)
                                     throws java.lang.Exception
Encrypts a string using the given encryption type.

Parameters:
stringToEncrypt - The String to encrypt.
encryptionType - "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".
Returns:
The encrypted string
Throws:
java.lang.Exception

getDecrypted

public static java.lang.String getDecrypted(java.lang.String stringToDecrypt,
                                            java.lang.String encryptionType,
                                            java.lang.String privateKeyFile)
                                     throws java.lang.Exception
Decrypts a string using the given encryption type.

Parameters:
stringToDecrypt - The String to decrypt.
encryptionType - "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".
Returns:
The decrypted string
Throws:
java.lang.Exception

generateTwoWayKey

public static void generateTwoWayKey(java.lang.String keyFile)
                              throws java.lang.Exception
Throws:
java.lang.Exception

generateKeyPair

public static java.lang.String generateKeyPair(java.lang.String publicFile,
                                               java.lang.String privateFile,
                                               boolean savePrivate)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

saveKey

private static void saveKey(java.lang.String filename,
                            byte[] contents)
                     throws java.lang.Exception
Throws:
java.lang.Exception

loadKey

private static java.security.Key loadKey(java.lang.String filename,
                                         boolean isPublic)
                                  throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © SoftSlate, Inc. 2003–2005