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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongenerateKeyPair
(String publicFile, String privateFile, boolean savePrivate) void
generateTwoWayKey
(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 aMap
of 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 Key
void
outputCsv
(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:DAOUtils
An array of strings to eliminate from database search queries.- Specified by:
getStopWords
in interfaceDAOUtils
-
getList
Description copied from interface:DAOUtils
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. -
getQuotedList
Description copied from interface:DAOUtils
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.- Specified by:
getQuotedList
in 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:DAOUtils
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.- Specified by:
getListFromResultSet
in 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:DAOUtils
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.- Specified by:
getListFromCollection
in 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:DAOUtils
Given a Collection of Strings, returns a String list representing each element's value in the incoming Collection.- Specified by:
getListFromStringCollection
in 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:DAOUtils
Given a ResultSet and a field name for a field, returns a Collection of Strings representing each field value in the ResultSet.- Specified by:
getCollectionFromResultSet
in 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:DAOUtils
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.- Specified by:
getCollectionFromCollection
in 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:DAOUtils
Given a Collection of Strings, returns a collection of Integers corresponding to the strings.- Specified by:
getIntegersFromStrings
in interfaceDAOUtils
- Parameters:
collection
- A collection of Strings- Returns:
- A collection of Integers
-
getCollectionFromBeans
Description copied from interface:DAOUtils
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.- Specified by:
getCollectionFromBeans
in 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:DAOUtils
Retrieves a string indicating the number of rows and columns returned from aResultSet
.- Specified by:
getDebugMessage
in interfaceDAOUtils
- Parameters:
resultSet
- TheResultSet
to 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:DAOUtils
Given aMap
of string keys, returns a single string that can be used as a list in an SQL expression. Each of the elements of the incomingMap
are quoted and separated by commas.- Specified by:
getQuotedList
in interfaceDAOUtils
- Parameters:
map
- TheMap
to convert into a quoted string.- Returns:
- A string that can be used as a list in an SQL expression.
-
outputCsv
Description copied from interface:DAOUtils
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.- Specified by:
outputCsv
in interfaceDAOUtils
- Parameters:
data
- List of String arrays or Object arrays.out
- The stream to write to.- Throws:
IOException
-
prepareSearchString
Description copied from interface:DAOUtils
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.- Specified by:
prepareSearchString
in interfaceDAOUtils
- Returns:
- A string acceptable for a LIKE expression.
-
getEncrypted
Description copied from interface:DAOUtils
Encrypts a string using the given encryption type.- Specified by:
getEncrypted
in 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:
getEncrypted
in interfaceDAOUtils
-
getDecrypted
Description copied from interface:DAOUtils
Decrypts a string using the given encryption type.- Specified by:
getDecrypted
in interfaceDAOUtils
- Parameters:
stringToDecrypt
- The String to decrypt.encryptionType
- "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".- Returns:
- The decrypted string
-
generateTwoWayKey
- Specified by:
generateTwoWayKey
in interfaceDAOUtils
- Throws:
Exception
-
generateKeyPair
public String generateKeyPair(String publicFile, String privateFile, boolean savePrivate) throws Exception - Specified by:
generateKeyPair
in interfaceDAOUtils
- Throws:
Exception
-
saveKey
- Throws:
Exception
-
loadKey
- Throws:
Exception
-