use of org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.LIST_PAGINATED_TEMPLATES_ORACLE 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;
}
Aggregations