Class DBUtil


  • public class DBUtil
    extends Object
    This class will execute a set of drop and create DDL scripts against a supplied entity manager.
    • Method Detail

      • setEntityManager

        public void setEntityManager​(EntityManager em)
      • addDropPath

        public void addDropPath​(String dropPath)
      • addCreatePath

        public void addCreatePath​(String createPath)
      • getString

        protected String getString​(InputStream is)
                            throws IOException
        Turn the InputStream into a String for easier parsing for SQL statements.
        Parameters:
        is -
        Returns:
        string contents of SQL file
        Throws:
        IOException
      • getStatements

        protected List<String> getStatements​(String contents)
        Get list of SQL statements from the supplied string.
        Parameters:
        contents -
        Returns:
        list of distinct statements
        Throws:
        Exception
      • executeScript

        public int executeScript​(String path)
        Execute the SQL statements contained within the resource that is located by the path supplied. This path can be either a file path or resource path.
        Parameters:
        path -
        Returns:
        count of statements executed
        Throws:
        Exception
      • getSequenceNextVals

        public Map<String,​Number> getSequenceNextVals()
        Return the current nextVal for each sequence used by application.
        Returns:
        map of sequence nextVals
      • setSequenceNextVals

        public void setSequenceNextVals​(Map<String,​Number> sequenceVals)
        Updates the state of the provided sequence(s) to values provided
        Parameters:
        sequenceVals -
      • dropAll

        public Map<String,​Number> dropAll()
                                         throws RuntimeException
        Execute the drop script against the DB.
        Returns:
        map of sequence previous nextVal state
        Throws:
        RuntimeException - on errors like schema does not currently exist. In that case the caller must rollback the current transaction and begin a new one for the create();
      • createAll

        public int createAll​(Map<String,​Number> sequenceVals)
                      throws RuntimeException
        Execute the create script against the DB. Follow-up by altering the provided sequences to be their previous nextVal state. This is necessary when resetting schema while JPA provider has cached a block of sequence values from a previous execution.
        Returns:
        count of statements executed
        Throws:
        RuntimeException