use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException 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.exceptions.DataAccessException 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);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method addResourceType.
/**
* {@inheritDoc}
*/
@Override
public void addResourceType(ResourceType resourceType) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeInsert(SQLConstants.INSERT_RESOURCE_TYPE_SQL, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resourceType.getId());
preparedStatement.setString(++initialParameterIndex, resourceType.getName());
preparedStatement.setString(++initialParameterIndex, resourceType.getDescription());
}, resourceType, false);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_ADD_RESOURCE_TYPE, resourceType.getName(), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getResourcesByType.
@Override
public List<Resource> getResourcesByType(int tenantId, String resourceTypeId) throws ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String resourceTypeName = jdbcTemplate.fetchSingleRecord(SQLConstants.GET_RESOURCE_TYPE_BY_ID_SQL, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME), preparedStatement -> preparedStatement.setString(1, resourceTypeId));
return jdbcTemplate.executeQuery(GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL, (LambdaExceptionUtils.rethrowRowMapper((resultSet, rowNumber) -> {
String resourceId = resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID);
String resourceName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME);
String resourceLastModified = resultSet.getString(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED);
String resourceCreatedTime = resultSet.getString(DB_SCHEMA_COLUMN_NAME_CREATED_TIME);
String resourceHasFile = resultSet.getString(DB_SCHEMA_COLUMN_NAME_HAS_FILE);
if (StringUtils.equals(resourceHasFile, "1") && (isOracleDB() || isMSSqlDB() || isDB2DB())) {
resourceHasFile = "true";
}
String resourceHasAttribute = resultSet.getString(DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE);
Resource resource = new Resource();
resource.setCreatedTime(resourceCreatedTime);
resource.setHasAttribute(Boolean.valueOf(resourceHasAttribute));
resource.setResourceId(resourceId);
resource.setResourceName(resourceName);
resource.setLastModified(resourceLastModified);
resource.setHasFile(Boolean.valueOf(resourceHasFile));
resource.setTenantDomain(IdentityTenantUtil.getTenantDomain(tenantId));
resource.setFiles(getFiles(resourceId, resourceTypeName, resourceName));
resource.setAttributes(getAttributesByResourceId(resourceId));
return resource;
})), preparedStatement -> {
preparedStatement.setString(1, resourceTypeId);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_RESOURCES_DOES_NOT_EXISTS, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method insertResourceAttributes.
private void insertResourceAttributes(Template<?> template, Resource resource) throws DataAccessException, ConfigurationManagementClientException {
// Create sql query for attribute parameters.
String attributesQuery = buildQueryForAttributes(resource);
template.executeInsert(attributesQuery, preparedStatement -> {
int attributeUpdateParameterIndex = 0;
for (Attribute attribute : resource.getAttributes()) {
preparedStatement.setString(++attributeUpdateParameterIndex, generateUniqueID());
preparedStatement.setString(++attributeUpdateParameterIndex, resource.getResourceId());
preparedStatement.setString(++attributeUpdateParameterIndex, attribute.getKey());
preparedStatement.setString(++attributeUpdateParameterIndex, attribute.getValue());
}
}, resource, false);
}
Aggregations