use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL 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;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class ApiMgtDAO method getApplicationByName.
/**
* Fetches an Application by name.
*
* @param applicationName Name of the Application
* @param userId Name of the User.
* @param groupId Group ID
* @throws APIManagementException
*/
public Application getApplicationByName(String applicationName, String userId, String groupId) throws APIManagementException {
// mysql> select APP.APPLICATION_ID, APP.NAME, APP.SUBSCRIBER_ID,APP.APPLICATION_TIER,APP.CALLBACK_URL,APP
// .DESCRIPTION,
// APP.APPLICATION_STATUS from AM_SUBSCRIBER as SUB,AM_APPLICATION as APP
// where SUB.user_id='admin' AND APP.name='DefaultApplication' AND SUB.SUBSCRIBER_ID=APP.SUBSCRIBER_ID;
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int applicationId = 0;
Application application = null;
try {
connection = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_APPLICATION_BY_NAME_PREFIX;
String whereClause = " WHERE SUB.USER_ID =? AND APP.NAME=? AND SUB.SUBSCRIBER_ID=APP.SUBSCRIBER_ID";
String whereClauseCaseInSensitive = " WHERE LOWER(SUB.USER_ID) =LOWER(?) AND APP.NAME=? AND SUB" + "" + ".SUBSCRIBER_ID=APP.SUBSCRIBER_ID";
String whereClauseWithGroupId = " WHERE (APP.GROUP_ID = ? OR ((APP.GROUP_ID='' OR APP.GROUP_ID IS NULL)" + " AND SUB.USER_ID = ?)) AND " + "APP.NAME = ? AND SUB.SUBSCRIBER_ID = APP.SUBSCRIBER_ID";
String whereClauseWithGroupIdCaseInSensitive = " WHERE (APP.GROUP_ID = ? OR ((APP.GROUP_ID='' OR APP.GROUP_ID IS NULL)" + " AND LOWER(SUB.USER_ID) = LOWER(?))) AND " + "APP.NAME = ? AND SUB.SUBSCRIBER_ID = APP.SUBSCRIBER_ID";
String whereClauseWithMultiGroupId = " WHERE ((APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM " + "AM_APPLICATION_GROUP_MAPPING WHERE GROUP_ID IN ($params) AND TENANT = ?)) OR SUB.USER_ID = ? " + "OR (APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM AM_APPLICATION WHERE GROUP_ID = ?))) " + "AND APP.NAME = ? AND SUB.SUBSCRIBER_ID = APP.SUBSCRIBER_ID";
String whereClauseWithMultiGroupIdCaseInSensitive = " WHERE ((APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM " + "AM_APPLICATION_GROUP_MAPPING WHERE GROUP_ID IN ($params) AND TENANT = ?)) " + "OR LOWER(SUB.USER_ID) = LOWER(?) " + "OR (APP.APPLICATION_ID IN (SELECT APPLICATION_ID FROM AM_APPLICATION WHERE GROUP_ID = " + "?))) " + "AND APP.NAME = ? AND SUB.SUBSCRIBER_ID = APP.SUBSCRIBER_ID";
if (groupId != null && !"null".equals(groupId) && !groupId.isEmpty()) {
if (multiGroupAppSharingEnabled) {
Subscriber subscriber = getSubscriber(userId);
String tenantDomain = MultitenantUtils.getTenantDomain(subscriber.getName());
if (forceCaseInsensitiveComparisons) {
query = query + whereClauseWithMultiGroupIdCaseInSensitive;
} else {
query = query + whereClauseWithMultiGroupId;
}
String[] groupIds = groupId.split(",");
int parameterIndex = groupIds.length;
prepStmt = fillQueryParams(connection, query, groupIds, 1);
prepStmt.setString(++parameterIndex, tenantDomain);
prepStmt.setString(++parameterIndex, userId);
prepStmt.setString(++parameterIndex, tenantDomain + '/' + groupId);
prepStmt.setString(++parameterIndex, applicationName);
} else {
if (forceCaseInsensitiveComparisons) {
query = query + whereClauseWithGroupIdCaseInSensitive;
} else {
query = query + whereClauseWithGroupId;
}
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, groupId);
prepStmt.setString(2, userId);
prepStmt.setString(3, applicationName);
}
} else {
if (forceCaseInsensitiveComparisons) {
query = query + whereClauseCaseInSensitive;
} else {
query = query + whereClause;
}
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, userId);
prepStmt.setString(2, applicationName);
}
rs = prepStmt.executeQuery();
while (rs.next()) {
String subscriberId = rs.getString("SUBSCRIBER_ID");
String subscriberName = rs.getString("USER_ID");
Subscriber subscriber = new Subscriber(subscriberName);
subscriber.setId(Integer.parseInt(subscriberId));
application = new Application(applicationName, subscriber);
application.setOwner(rs.getString("CREATED_BY"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setCallbackUrl(rs.getString("CALLBACK_URL"));
applicationId = rs.getInt("APPLICATION_ID");
application.setId(applicationId);
application.setTier(rs.getString("APPLICATION_TIER"));
application.setUUID(rs.getString("UUID"));
application.setGroupId(rs.getString("GROUP_ID"));
application.setOwner(rs.getString("CREATED_BY"));
application.setTokenType(rs.getString("TOKEN_TYPE"));
if (multiGroupAppSharingEnabled) {
setGroupIdInApplication(connection, application);
}
if (application != null) {
Map<String, String> applicationAttributes = getApplicationAttributes(connection, applicationId);
application.setApplicationAttributes(applicationAttributes);
}
}
} catch (SQLException e) {
handleException("Error while obtaining details of the Application : " + applicationName, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return application;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class SQLConstantManagerFactory method initializeSQLConstantManager.
/**
* This method initialize when server start up. And select relevant DB dirver and load the const class.
* @throws APIManagementException
*/
public static void initializeSQLConstantManager() throws APIManagementException {
Connection connection = null;
try {
connection = APIMgtDBUtil.getConnection();
if (connection.getMetaData().getDriverName().contains("MySQL") || connection.getMetaData().getDriverName().contains("H2")) {
sqlConstantsH2MySQL = new SQLConstantsH2MySQL();
dbType = "h2mysql";
} else if (connection.getMetaData().getDatabaseProductName().contains("DB2")) {
sqlConstantsDB2 = new SQLConstantsDB2();
dbType = "db2";
} else if (connection.getMetaData().getDriverName().contains("MS SQL")) {
dbType = "mssql";
sqlConstantsMSSQL = new SQLConstantsMSSQL();
} else if (connection.getMetaData().getDriverName().contains("Microsoft")) {
dbType = "mssql";
sqlConstantsMSSQL = new SQLConstantsMSSQL();
} else if (connection.getMetaData().getDriverName().contains("PostgreSQL")) {
dbType = "postgre";
sqlConstantPostgreSQL = new SQLConstantPostgreSQL();
} else if (connection.getMetaData().getDriverName().contains("Oracle")) {
dbType = "oracle";
sqlConstantOracle = new SQLConstantOracle();
} else {
log.error("Could not find DB type to load constants");
throw new APIManagementException("Error occurred while initializing SQL Constants Manager");
}
} catch (SQLException e) {
log.error("Error occurred while initializeSQLConstantManager");
throw new APIManagementException("Error occurred while initializing SQL Constants Manager", e);
} finally {
APIMgtDBUtil.closeAllConnections(null, connection, null);
}
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-business-process by wso2.
the class AbstractJPAVendorAdapter method determineDbType.
protected DatabaseType determineDbType() {
Connection con = null;
DatabaseType dbType = null;
try {
con = getDBConnection();
DatabaseMetaData metaData = con.getMetaData();
if (metaData != null) {
String dbProductName = metaData.getDatabaseProductName().toLowerCase();
int dbMajorVer = metaData.getDatabaseMajorVersion();
if (log.isDebugEnabled()) {
log.debug("Using database " + dbProductName + " major version " + dbMajorVer);
}
if (dbProductName.contains("db2")) {
dbType = DatabaseType.DB2;
} else if (dbProductName.contains("oracle")) {
dbType = DatabaseType.ORACLE;
} else if (dbProductName.contains("derby")) {
dbType = DatabaseType.DERBY;
} else if (dbProductName.contains("h2")) {
dbType = DatabaseType.H2;
} else if (dbProductName.contains("hsql")) {
dbType = DatabaseType.HSQL;
} else if (dbProductName.contains("microsoft sql")) {
dbType = DatabaseType.SQL_SERVER;
} else if (dbProductName.contains("mysql")) {
dbType = DatabaseType.MYSQL;
} else if (dbProductName.contains("postgresql")) {
dbType = DatabaseType.POSTGRESQL;
} else if (dbProductName.contains("sybase")) {
dbType = DatabaseType.SYBASE;
}
}
} catch (SQLException e) {
log.warn("Unable to determine database dialect.", e);
} finally {
close(con);
}
return dbType;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-business-process by wso2.
the class AbstractJPAVendorAdapter method determineDbType.
protected DatabaseType determineDbType() {
Connection con = null;
DatabaseType dbType = null;
try {
con = getDBConnection();
DatabaseMetaData metaData = con.getMetaData();
if (metaData != null) {
String dbProductName = metaData.getDatabaseProductName().toLowerCase();
int dbMajorVer = metaData.getDatabaseMajorVersion();
if (log.isDebugEnabled()) {
log.debug("Using database " + dbProductName + " major version " + dbMajorVer);
}
if (dbProductName.contains("db2")) {
dbType = DatabaseType.DB2;
} else if (dbProductName.contains("oracle")) {
dbType = DatabaseType.ORACLE;
} else if (dbProductName.contains("derby")) {
dbType = DatabaseType.DERBY;
} else if (dbProductName.contains("h2")) {
dbType = DatabaseType.H2;
} else if (dbProductName.contains("hsql")) {
dbType = DatabaseType.HSQL;
} else if (dbProductName.contains("microsoft sql")) {
dbType = DatabaseType.SQL_SERVER;
} else if (dbProductName.contains("mysql")) {
dbType = DatabaseType.MYSQL;
} else if (dbProductName.contains("postgresql")) {
dbType = DatabaseType.POSTGRESQL;
} else if (dbProductName.contains("sybase")) {
dbType = DatabaseType.SYBASE;
}
}
} catch (SQLException e) {
log.warn("Unable to determine database dialect.", e);
} finally {
close(con);
}
return dbType;
}
Aggregations