Class APIMgtDBUtil


  • public final class APIMgtDBUtil
    extends Object
    • Constructor Detail

      • APIMgtDBUtil

        public APIMgtDBUtil()
    • Method Detail

      • initialize

        public static void initialize()
                               throws org.wso2.carbon.apimgt.api.APIManagerDatabaseException
        Initializes the data source
        Throws:
        org.wso2.carbon.apimgt.api.APIManagementException - if an error occurs while loading DB configuration
        org.wso2.carbon.apimgt.api.APIManagerDatabaseException
      • getConnection

        public static Connection getConnection()
                                        throws SQLException
        Utility method to get a new database connection
        Returns:
        Connection
        Throws:
        SQLException - if failed to get Connection
      • closeAllConnections

        public static void closeAllConnections​(PreparedStatement preparedStatement,
                                               Connection connection,
                                               ResultSet resultSet)
        Utility method to close the connection streams.
        Parameters:
        preparedStatement - PreparedStatement
        connection - Connection
        resultSet - ResultSet
      • closeStatement

        public static void closeStatement​(PreparedStatement preparedStatement)
        Close PreparedStatement
        Parameters:
        preparedStatement - PreparedStatement
      • getStringFromInputStream

        public static String getStringFromInputStream​(InputStream is)
        Function converts IS to String Used for handling blobs
        Parameters:
        is - - The Input Stream
        Returns:
        - The inputStream as a String
      • getBytesFromInputStream

        public static byte[] getBytesFromInputStream​(InputStream is)
        Function converts IS to byte[] Used for handling inputstreams
        Parameters:
        is - - The Input Stream
        Returns:
        - The inputStream as a byte array
      • setAutoCommit

        public static void setAutoCommit​(Connection dbConnection,
                                         boolean autoCommit)
        Set autocommit state of the connection
        Parameters:
        dbConnection - Connection
        autoCommit - autoCommitState
      • rollbackConnection

        public static void rollbackConnection​(Connection connection,
                                              String error,
                                              SQLException e)
                                       throws SQLException
        Handle connection rollback logic. Rethrow original exception so that it can be handled centrally.
        Parameters:
        connection - Connection
        error - Error message to be logged
        e - Original SQLException
        Throws:
        SQLException
      • mergeRevisionDeploymentDTOs

        public static List<org.wso2.carbon.apimgt.api.model.APIRevisionDeployment> mergeRevisionDeploymentDTOs​(ResultSet rs)
                                                                                                        throws org.wso2.carbon.apimgt.api.APIManagementException,
                                                                                                               SQLException
        Handle connection rollback logic. Rethrow original exception so that it can be handled centrally.
        Parameters:
        rs - result set
        Throws:
        SQLException - sql exception
        org.wso2.carbon.apimgt.api.APIManagementException - api management exception
      • convertJSONStringToMap

        public static Map<String,​Object> convertJSONStringToMap​(String jsonString)
                                                               throws org.wso2.carbon.apimgt.api.APIManagementException
        Converts a JSON Object String to a String Map
        Parameters:
        jsonString - JSON String
        Returns:
        String Map
        Throws:
        org.wso2.carbon.apimgt.api.APIManagementException - if errors occur during parsing the json string