use of org.wso2.carbon.database.utils.jdbc.JdbcTemplate in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method getAllTemplates.
/**
* List {@link TemplateInfo} items for a given search criteria.
*
* @param tenantId Tenant Id to be searched.
* @param limit Maximum number of results expected.
* @param offset Result offset.
* @return List of {@link TemplateInfo} entries.
* @throws TemplateManagementException If error occurs while searching the Templates.
*/
public List<TemplateInfo> getAllTemplates(Integer tenantId, Integer limit, Integer offset) throws TemplateManagementException {
List<TemplateInfo> templates;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String query;
if (isH2DB() || isMySQLDB() || isPostgreSQLDB()) {
query = LIST_PAGINATED_TEMPLATES_MYSQL;
} else if (isDB2DB()) {
query = LIST_PAGINATED_TEMPLATES_DB2;
int initialOffset = offset;
offset = offset + limit;
limit = initialOffset + 1;
} else if (isMSSqlDB()) {
int initialOffset = offset;
offset = limit + offset;
limit = initialOffset + 1;
query = LIST_PAGINATED_TEMPLATES_MSSQL;
} else {
// oracle
query = LIST_PAGINATED_TEMPLATES_ORACLE;
limit = offset + limit;
}
int finalLimit = limit;
int finalOffset = offset;
templates = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> new TemplateInfo(resultSet.getString(1), resultSet.getString(2)), preparedStatement -> {
preparedStatement.setInt(1, tenantId);
preparedStatement.setInt(2, finalLimit);
preparedStatement.setInt(3, finalOffset);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_PAGINATED_LIST_TEMPLATES.getMessage(), tenantId, limit, offset), ERROR_CODE_PAGINATED_LIST_TEMPLATES.getCode(), e);
}
return templates;
}
use of org.wso2.carbon.database.utils.jdbc.JdbcTemplate in project carbon-identity-framework by wso2.
the class ApplicationTemplateDAOImpl method deleteApplicationTemplate.
@Override
public void deleteApplicationTemplate(String templateName, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug(String.format("Deleting application template: %s in tenant: %s", templateName, tenantDomain));
}
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(DELETE_SP_TEMPLATE_BY_NAME, preparedStatement -> {
preparedStatement.setString(1, templateName);
preparedStatement.setInt(2, getTenantID(tenantDomain));
});
} catch (DataAccessException e) {
throw new IdentityApplicationManagementException(String.format("An error occurred while deleting the " + "application template : %s in tenant: %s", templateName, tenantDomain), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.JdbcTemplate in project carbon-identity-framework by wso2.
the class ApplicationTemplateDAOImpl method updateApplicationTemplate.
@Override
public void updateApplicationTemplate(String templateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug(String.format("Updating application template: %s in tenant: %s", spTemplate.getName(), tenantDomain));
}
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(UPDATE_SP_TEMPLATE_BY_NAME, preparedStatement -> {
preparedStatement.setString(1, spTemplate.getName());
preparedStatement.setString(2, spTemplate.getDescription());
try {
setBlobValue(spTemplate.getContent(), preparedStatement, 3);
} catch (IOException e) {
throw new SQLException(String.format("Could not set application template: %s content as " + "a Blob in tenant: %s.", spTemplate.getName(), tenantDomain), e);
}
preparedStatement.setString(4, templateName);
preparedStatement.setInt(5, getTenantID(tenantDomain));
});
} catch (DataAccessException e) {
throw new IdentityApplicationManagementException(String.format("An error occurred while updating the" + " application template : %s in tenant: %s", spTemplate.getName(), tenantDomain), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.JdbcTemplate in project carbon-identity-framework by wso2.
the class DefaultAuthSeqMgtDAOImpl method doGetDefaultAuthSeq.
private DefaultAuthenticationSequence doGetDefaultAuthSeq(String sequenceName, String tenantDomain, JdbcTemplate jdbcTemplate) throws DataAccessException {
return jdbcTemplate.fetchSingleRecord(GET_DEFAULT_SEQ, (resultSet, rowNumber) -> {
DefaultAuthenticationSequence sequence = new DefaultAuthenticationSequence();
sequence.setName(resultSet.getString(1));
sequence.setDescription(resultSet.getString(2));
try {
byte[] requestBytes = resultSet.getBytes(3);
ByteArrayInputStream bais = new ByteArrayInputStream(requestBytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Object objectRead = ois.readObject();
if (objectRead instanceof LocalAndOutboundAuthenticationConfig) {
sequence.setContent((LocalAndOutboundAuthenticationConfig) objectRead);
}
} catch (IOException | ClassNotFoundException e) {
throw new SQLException("Could not get content of default authentication sequence as a " + "Blob.", e);
}
return sequence;
}, (PreparedStatement preparedStatement) -> {
preparedStatement.setString(1, sequenceName);
preparedStatement.setInt(2, getTenantID(tenantDomain));
});
}
use of org.wso2.carbon.database.utils.jdbc.JdbcTemplate in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getAttributeByKey.
/**
* {@inheritDoc}
*/
@Override
public Attribute getAttributeByKey(String resourceId, String attributeKey) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
return jdbcTemplate.fetchSingleRecord(SQLConstants.GET_ATTRIBUTE_SQL, (resultSet, rowNumber) -> new Attribute(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY), resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE), resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)), preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, attributeKey);
preparedStatement.setString(++initialParameterIndex, resourceId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_ATTRIBUTE, attributeKey, e);
}
}
Aggregations