Class DAOUtilsImpl

java.lang.Object
com.softslate.commerce.daos.core.DAOUtilsImpl
All Implemented Interfaces:
DAOUtils

public class DAOUtilsImpl extends Object implements DAOUtils
Holds various utility methods for use by DAOs.
Author:
David Tobey
  • Field Details

    • log

      static org.apache.commons.logging.Log log
    • stopWords

      public String[] stopWords
  • Constructor Details

    • DAOUtilsImpl

      public DAOUtilsImpl()
  • Method Details

    • getStopWords

      public String[] getStopWords()
      Description copied from interface: DAOUtils
      An array of strings to eliminate from database search queries.
      Specified by:
      getStopWords in interface DAOUtils
    • getList

      public String getList(String[] stringArray)
      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.
      Specified by:
      getList in interface DAOUtils
      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.
    • getQuotedList

      public String getQuotedList(String[] stringArray)
      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 interface DAOUtils
      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

      public String getListFromResultSet(ResultSet resultSet, String field) throws SQLException
      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 interface DAOUtils
      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

      public String getListFromCollection(Collection collection, String field)
      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 interface DAOUtils
      Parameters:
      collection - The Collection holding the values.
      Returns:
      A string that can be used as a list in an SQL expression.
    • getListFromStringCollection

      public String getListFromStringCollection(Collection collection)
      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 interface DAOUtils
      Parameters:
      collection - The Collection holding the values.
      Returns:
      A string that can be used as a list in an SQL expression.
    • getCollectionFromResultSet

      public Collection getCollectionFromResultSet(ResultSet resultSet, String field) throws SQLException
      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 interface DAOUtils
      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

      public Collection getCollectionFromCollection(Collection collection, String field)
      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 interface DAOUtils
      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

      public Collection getIntegersFromStrings(Collection collection)
      Description copied from interface: DAOUtils
      Given a Collection of Strings, returns a collection of Integers corresponding to the strings.
      Specified by:
      getIntegersFromStrings in interface DAOUtils
      Parameters:
      collection - A collection of Strings
      Returns:
      A collection of Integers
    • getCollectionFromBeans

      public Collection getCollectionFromBeans(Collection collection, String field) throws Exception
      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 interface DAOUtils
      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

      public String getDebugMessage(ResultSet resultSet) throws SQLException
      Description copied from interface: DAOUtils
      Retrieves a string indicating the number of rows and columns returned from a ResultSet.
      Specified by:
      getDebugMessage in interface DAOUtils
      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:
      SQLException
    • getQuotedList

      public String getQuotedList(Map map)
      Description copied from interface: DAOUtils
      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.
      Specified by:
      getQuotedList in interface DAOUtils
      Parameters:
      map - The Map to convert into a quoted string.
      Returns:
      A string that can be used as a list in an SQL expression.
    • outputCsv

      public void outputCsv(Collection data, Writer out) throws IOException
      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 interface DAOUtils
      Parameters:
      data - List of String arrays or Object arrays.
      out - The stream to write to.
      Throws:
      IOException
    • prepareSearchString

      public String prepareSearchString(String searchString)
      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 interface DAOUtils
      Returns:
      A string acceptable for a LIKE expression.
    • getEncrypted

      public String getEncrypted(String stringToEncrypt, String encryptionType, String publicKeyFile)
      Description copied from interface: DAOUtils
      Encrypts a string using the given encryption type.
      Specified by:
      getEncrypted in interface DAOUtils
      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 interface DAOUtils
    • getDecrypted

      public String getDecrypted(String stringToDecrypt, String encryptionType, String privateKeyFile)
      Description copied from interface: DAOUtils
      Decrypts a string using the given encryption type.
      Specified by:
      getDecrypted in interface DAOUtils
      Parameters:
      stringToDecrypt - The String to decrypt.
      encryptionType - "noEncryption", "keyPairStore", "keyPairNoStore", or "oneWay".
      Returns:
      The decrypted string
    • generateTwoWayKey

      public void generateTwoWayKey(String keyFile) throws Exception
      Specified by:
      generateTwoWayKey in interface DAOUtils
      Throws:
      Exception
    • generateKeyPair

      public String generateKeyPair(String publicFile, String privateFile, boolean savePrivate) throws Exception
      Specified by:
      generateKeyPair in interface DAOUtils
      Throws:
      Exception
    • saveKey

      private void saveKey(String filename, byte[] contents) throws Exception
      Throws:
      Exception
    • loadKey

      private Key loadKey(String filename, boolean isPublic) throws Exception
      Throws:
      Exception