Package com.softslate.commerce.daos.core
Class DAOUtilsImpl
java.lang.Object
com.softslate.commerce.daos.core.DAOUtilsImpl
- All Implemented Interfaces:
DAOUtils
Holds various utility methods for use by DAOs.
- Author:
- David Tobey
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerateKeyPair(String publicFile, String privateFile, boolean savePrivate) voidgenerateTwoWayKey(String keyFile) getCollectionFromBeans(Collection collection, String field) Given a Collection of beans representing a ResultSet, and a field name for a field, returns a Collection of Integers representing each field's value in the incoming Collection.getCollectionFromCollection(Collection collection, 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.getCollectionFromResultSet(ResultSet resultSet, String field) Given a ResultSet and a field name for a field, returns a Collection of Strings representing each field value in the ResultSet.getDebugMessage(ResultSet resultSet) Retrieves a string indicating the number of rows and columns returned from aResultSet.getDecrypted(String stringToDecrypt, String encryptionType, String privateKeyFile) Decrypts a string using the given encryption type.getEncrypted(String stringToEncrypt, String encryptionType, String publicKeyFile) Encrypts a string using the given encryption type.getEncrypted(String stringToEncrypt, String encryptionType, String publicKeyFile, String oneWayAlgorithm) getIntegersFromStrings(Collection collection) Given a Collection of Strings, returns a collection of Integers corresponding to the strings.Given an array of strings, returns a single string that can be used as a list in an SQL expression.getListFromCollection(Collection collection, 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.getListFromResultSet(ResultSet resultSet, String field) Given a ResultSet and a field name, returns a single string that can be used as a list in an SQL expression.getListFromStringCollection(Collection collection) Given a Collection of Strings, returns a String list representing each element's value in the incoming Collection.getQuotedList(String[] stringArray) Given an array of strings, returns a single string that can be used as a list in an SQL expression.getQuotedList(Map map) Given aMapof string keys, returns a single string that can be used as a list in an SQL expression.String[]An array of strings to eliminate from database search queries.private KeyvoidoutputCsv(Collection data, Writer out) Outputs a matrix of strings as comma-separated values.prepareSearchString(String searchString) Prepares a string for insertion into an SQL search expression.private void
-
Field Details
-
log
static org.apache.commons.logging.Log log -
stopWords
-
-
Constructor Details
-
DAOUtilsImpl
public DAOUtilsImpl()
-
-
Method Details
-
getStopWords
Description copied from interface:DAOUtilsAn array of strings to eliminate from database search queries.- Specified by:
getStopWordsin interfaceDAOUtils
-
getList
Description copied from interface:DAOUtilsGiven 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. -
getQuotedList
Description copied from interface:DAOUtilsGiven 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.- Specified by:
getQuotedListin interfaceDAOUtils- 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.
-
getListFromResultSet
Description copied from interface:DAOUtilsGiven 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.- Specified by:
getListFromResultSetin interfaceDAOUtils- Parameters:
resultSet- The ResultSet holding the values.field- The name of the field whose values are to be returned in a list.- Returns:
- A string that can be used as a list in an SQL expression
- Throws:
SQLException
-
getListFromCollection
Description copied from interface:DAOUtilsGiven 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.- Specified by:
getListFromCollectionin interfaceDAOUtils- Parameters:
collection- The Collection holding the values.- Returns:
- A string that can be used as a list in an SQL expression.
-
getListFromStringCollection
Description copied from interface:DAOUtilsGiven a Collection of Strings, returns a String list representing each element's value in the incoming Collection.- Specified by:
getListFromStringCollectionin interfaceDAOUtils- Parameters:
collection- The Collection holding the values.- Returns:
- A string that can be used as a list in an SQL expression.
-
getCollectionFromResultSet
Description copied from interface:DAOUtilsGiven a ResultSet and a field name for a field, returns a Collection of Strings representing each field value in the ResultSet.- Specified by:
getCollectionFromResultSetin interfaceDAOUtils- Parameters:
resultSet- The ResultSet holding the values.field- The name of the field whose values are to be returned in a Colleciton.- Returns:
- A Collection of Strings representing each field value in the ResultSet
- Throws:
SQLException
-
getCollectionFromCollection
Description copied from interface:DAOUtilsGiven 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.- Specified by:
getCollectionFromCollectionin interfaceDAOUtils- Parameters:
collection- The Collection holding the values.field- The name of the field whose values are to be returned in a Collection.- Returns:
- A Collection of Strings representing each field's value in the incoming Collection
-
getIntegersFromStrings
Description copied from interface:DAOUtilsGiven a Collection of Strings, returns a collection of Integers corresponding to the strings.- Specified by:
getIntegersFromStringsin interfaceDAOUtils- Parameters:
collection- A collection of Strings- Returns:
- A collection of Integers
-
getCollectionFromBeans
Description copied from interface:DAOUtilsGiven a Collection of beans representing a ResultSet, and a field name for a field, returns a Collection of Integers representing each field's value in the incoming Collection.- Specified by:
getCollectionFromBeansin interfaceDAOUtils- Parameters:
collection- The Collection holding the values.field- The name of the field whose values are to be returned in a Collection.- Returns:
- a Collection of Integers
- Throws:
Exception
-
getDebugMessage
Description copied from interface:DAOUtilsRetrieves a string indicating the number of rows and columns returned from aResultSet.- Specified by:
getDebugMessagein interfaceDAOUtils- Parameters:
resultSet- TheResultSetto produce a debugging message for.- Returns:
- A string indicating the number of rows and columns returned from
a
ResultSet. - Throws:
SQLException
-
getQuotedList
Description copied from interface:DAOUtilsGiven aMapof string keys, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incomingMapare quoted and separated by commas.- Specified by:
getQuotedListin interfaceDAOUtils- Parameters:
map- TheMapto convert into a quoted string.- Returns:
- A string that can be used as a list in an SQL expression.
-
outputCsv
Description copied from interface:DAOUtilsOutputs 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.- Specified by:
outputCsvin interfaceDAOUtils- Parameters:
data- List of String arrays or Object arrays.out- The stream to write to.- Throws:
IOException
-
prepareSearchString
Description copied from interface:DAOUtilsPrepares 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.- Specified by:
prepareSearchStringin interfaceDAOUtils- Returns:
- A string acceptable for a LIKE expression.
-
getEncrypted
Description copied from interface:DAOUtilsEncrypts a string using the given encryption type.- Specified by:
getEncryptedin interfaceDAOUtils- Parameters:
stringToEncrypt- The String to encrypt.encryptionType- "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".- Returns:
- The encrypted string
-
getEncrypted
public String getEncrypted(String stringToEncrypt, String encryptionType, String publicKeyFile, String oneWayAlgorithm) - Specified by:
getEncryptedin interfaceDAOUtils
-
getDecrypted
Description copied from interface:DAOUtilsDecrypts a string using the given encryption type.- Specified by:
getDecryptedin interfaceDAOUtils- Parameters:
stringToDecrypt- The String to decrypt.encryptionType- "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".- Returns:
- The decrypted string
-
generateTwoWayKey
- Specified by:
generateTwoWayKeyin interfaceDAOUtils- Throws:
Exception
-
generateKeyPair
public String generateKeyPair(String publicFile, String privateFile, boolean savePrivate) throws Exception - Specified by:
generateKeyPairin interfaceDAOUtils- Throws:
Exception
-
saveKey
- Throws:
Exception
-
loadKey
- Throws:
Exception
-