Class APIMgtDBUtil
- java.lang.Object
-
- org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil
-
public final class APIMgtDBUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description APIMgtDBUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)
Utility method to close the connection streams.static void
closeStatement(PreparedStatement preparedStatement)
Close PreparedStatementstatic Map<String,Object>
convertJSONStringToMap(String jsonString)
Converts a JSON Object String to a String Mapstatic byte[]
getBytesFromInputStream(InputStream is)
Function converts IS to byte[] Used for handling inputstreamsstatic Connection
getConnection()
Utility method to get a new database connectionstatic String
getStringFromInputStream(InputStream is)
Function converts IS to String Used for handling blobsstatic void
initialize()
Initializes the data sourcestatic List<org.wso2.carbon.apimgt.api.model.APIRevisionDeployment>
mergeRevisionDeploymentDTOs(ResultSet rs)
Handle connection rollback logic.static void
rollbackConnection(Connection connection, String error, SQLException e)
Handle connection rollback logic.static void
setAutoCommit(Connection dbConnection, boolean autoCommit)
Set autocommit state of the connection
-
-
-
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 configurationorg.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
- PreparedStatementconnection
- ConnectionresultSet
- 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
- ConnectionautoCommit
- 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
- Connectionerror
- Error message to be loggede
- 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 exceptionorg.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
-
-