Search in sources :

Example 56 with APIMgtDAOException

use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.

the class DAOFactory method getTagDAO.

public static TagDAO getTagDAO() throws APIMgtDAOException {
    TagDAO tagDAO = null;
    try (Connection connection = DAOUtil.getConnection()) {
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains(MYSQL) || driverName.contains(H2)) {
            tagDAO = new TagDAOImpl();
        } else if (driverName.contains(DB2)) {
        } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
            tagDAO = new TagDAOImpl();
        } else if (driverName.contains(POSTGRE)) {
            tagDAO = new TagDAOImpl();
        } else if (driverName.contains(ORACLE)) {
            tagDAO = new TagDAOImpl();
        } else {
            throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting TagDAO", e);
    }
    setup();
    return tagDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) TagDAO(org.wso2.carbon.apimgt.core.dao.TagDAO) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 57 with APIMgtDAOException

use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.

the class DAOFactory method getFunctionDAO.

/**
 * To get the FunctionDAO object. Depends on different vendors.
 *
 * @return FunctionDAO object
 * @throws APIMgtDAOException In case of unhandled DB type or SQLException
 */
public static FunctionDAO getFunctionDAO() throws APIMgtDAOException {
    FunctionDAO functionDAO = null;
    try (Connection connection = DAOUtil.getConnection()) {
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains(MYSQL) || driverName.contains(H2)) {
            functionDAO = new FunctionDAOImpl();
        } else if (driverName.contains(DB2)) {
        } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
            functionDAO = new FunctionDAOImpl();
        } else if (driverName.contains(POSTGRE)) {
            functionDAO = new FunctionDAOImpl();
        } else if (driverName.contains(ORACLE)) {
            functionDAO = new FunctionDAOImpl();
        } else {
            throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting FunctionDAO", e);
    }
    setup();
    return functionDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) FunctionDAO(org.wso2.carbon.apimgt.core.dao.FunctionDAO)

Example 58 with APIMgtDAOException

use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.

the class DAOFactory method getAnalyticsDaoImplForVendor.

private static AnalyticsDAO getAnalyticsDaoImplForVendor(Connection connection) throws SQLException, APIMgtDAOException {
    AnalyticsDAO analyticsDAO = null;
    String driverName = connection.getMetaData().getDriverName();
    if (driverName.contains(MYSQL) || driverName.contains(H2)) {
        analyticsDAO = new AnalyticsDAOImpl();
    } else if (driverName.contains(DB2)) {
    } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
        analyticsDAO = new AnalyticsDAOImpl();
    } else if (driverName.contains(POSTGRE)) {
        analyticsDAO = new AnalyticsDAOImpl();
    } else if (driverName.contains(ORACLE)) {
        analyticsDAO = new AnalyticsDAOImpl();
    } else {
        throw new APIMgtDAOException("Unhandled DB Type detected");
    }
    return analyticsDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)

Example 59 with APIMgtDAOException

use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.

the class DAOFactory method getApiDAO.

public static ApiDAO getApiDAO() throws APIMgtDAOException {
    ApiDAO apiDAO = null;
    if (System.getProperty(EDITOR_MODE) != null) {
        String filePath;
        if ((filePath = System.getProperty(EDITOR_SAVE_PATH)) != null) {
            apiDAO = new ApiFileDAOImpl(filePath);
            return apiDAO;
        } else {
            throw new APIMgtDAOException("Editor archive storage path not provided", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    }
    try (Connection connection = DAOUtil.getConnection()) {
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains(MYSQL)) {
            apiDAO = new ApiDAOImpl(new MysqlSQLStatements());
        } else if (driverName.contains(H2)) {
            apiDAO = new ApiDAOImpl(new H2SQLStatements());
        } else if (driverName.contains(DB2)) {
        } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
            apiDAO = new ApiDAOImpl(new MssqlSQLStatements());
        } else if (driverName.contains(POSTGRE)) {
            apiDAO = new ApiDAOImpl(new PostgresSQLStatements());
        } else if (driverName.contains(ORACLE)) {
            apiDAO = new ApiDAOImpl(new OracleSQLStatements());
        } else {
            throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting ApiDAO", e);
    }
    setup();
    return apiDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Example 60 with APIMgtDAOException

use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.

the class DAOFactory method getPolicyDAO.

public static PolicyDAO getPolicyDAO() throws APIMgtDAOException {
    PolicyDAO policyDAO = null;
    try (Connection connection = DAOUtil.getConnection()) {
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains(MYSQL) || driverName.contains(H2)) {
            policyDAO = new PolicyDAOImpl();
        } else if (driverName.contains(DB2)) {
        } else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
            policyDAO = new PolicyDAOImpl();
        } else if (driverName.contains(POSTGRE)) {
            policyDAO = new PolicyDAOImpl();
        } else if (driverName.contains(ORACLE)) {
            policyDAO = new PolicyDAOImpl();
        } else {
            throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting PolicyDAO", e);
    }
    setup();
    return policyDAO;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)333 SQLException (java.sql.SQLException)190 Connection (java.sql.Connection)144 PreparedStatement (java.sql.PreparedStatement)127 Test (org.testng.annotations.Test)84 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)72 ResultSet (java.sql.ResultSet)70 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)57 API (org.wso2.carbon.apimgt.core.models.API)57 ArrayList (java.util.ArrayList)49 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)35 Application (org.wso2.carbon.apimgt.core.models.Application)24 HashMap (java.util.HashMap)23 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)22 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)21 BeforeTest (org.testng.annotations.BeforeTest)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)20 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)20 IOException (java.io.IOException)19 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)17