use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.
the class UserSessionStore method storeAppSessionDataIfNotExist.
/**
* Method to store app session data if the particular app session is not already exists in the database.
*
* @param sessionId Id of the authenticated session.
* @param subject Username in application.
* @param appID Id of the application.
* @param inboundAuth Protocol used in the app.
* @throws DataAccessException if an error occurs when storing the authenticated user details to the database.
* @deprecated Please use storeAppSessionData method instead.
*/
@Deprecated
public void storeAppSessionDataIfNotExist(String sessionId, String subject, int appID, String inboundAuth) throws DataAccessException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
try {
jdbcTemplate.withTransaction(template -> {
Integer recordCount = template.fetchSingleRecord(SQLQueries.SQL_CHECK_IDN_AUTH_SESSION_APP_INFO, (resultSet, rowNumber) -> resultSet.getInt(1), preparedStatement -> {
preparedStatement.setString(1, sessionId);
preparedStatement.setString(2, subject);
preparedStatement.setInt(3, appID);
preparedStatement.setString(4, inboundAuth);
});
if (recordCount == null) {
storeAppSessionData(sessionId, subject, appID, inboundAuth);
}
return null;
});
} catch (TransactionException e) {
throw new DataAccessException("Error while storing application data of session id: " + sessionId + ", subject: " + subject + ", app Id: " + appID + ", protocol: " + inboundAuth + ".", e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method isResourceExists.
private boolean isResourceExists(Resource resource, String resourceTypeId) throws TransactionException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
String resourceId = jdbcTemplate.withTransaction(template -> template.fetchSingleRecord(GET_RESOURCE_ID_BY_NAME_SQL, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID), preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resource.getResourceName());
preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
}));
return resourceId != null;
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method addAttribute.
/**
* {@inheritDoc}
*/
@Override
public void addAttribute(String attributeId, String resourceId, Attribute attribute) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.withTransaction(template -> {
template.executeUpdate(SQLConstants.INSERT_ATTRIBUTE_MYSQL, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, attributeId);
preparedStatement.setString(++initialParameterIndex, resourceId);
preparedStatement.setString(++initialParameterIndex, attribute.getKey());
preparedStatement.setString(++initialParameterIndex, attribute.getValue());
});
template.executeUpdate(SQLConstants.UPDATE_LAST_MODIFIED_SQL, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setTimestamp(initialParameterIndex, new java.sql.Timestamp(new Date().getTime()), calendar);
preparedStatement.setString(++initialParameterIndex, resourceId);
});
return null;
});
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_INSERT_ATTRIBUTE, attribute.getKey(), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method replaceResource.
/**
* {@inheritDoc}
*/
@Override
public void replaceResource(Resource resource) throws ConfigurationManagementException {
String resourceTypeId = getResourceTypeByName(resource.getResourceType()).getId();
Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
Timestamp createdTime = jdbcTemplate.withTransaction(template -> {
boolean isAttributeExists = resource.getAttributes() != null;
if (isH2DB()) {
updateMetadataForH2(resource, resourceTypeId, isAttributeExists, currentTime, useCreatedTimeField());
} else {
updateMetadataForMYSQL(resource, resourceTypeId, isAttributeExists, currentTime, useCreatedTimeField());
}
// Insert attributes.
if (isAttributeExists) {
// Delete existing attributes.
template.executeUpdate(DELETE_RESOURCE_ATTRIBUTES_SQL, preparedStatement -> preparedStatement.setString(1, resource.getResourceId()));
insertResourceAttributes(template, resource);
}
if (useCreatedTimeField()) {
return getCreatedTimeInResponse(resource, resourceTypeId);
} else {
return null;
}
});
resource.setLastModified(currentTime.toInstant().toString());
if (createdTime != null) {
resource.setCreatedTime(createdTime.toInstant().toString());
}
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_REPLACE_RESOURCE, resource.getResourceName(), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeClaimMappingDAOImpl method getScopeId.
private int getScopeId(String scope, int tenantId) throws IdentityOAuth2Exception {
Integer scopeId;
try {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
scopeId = jdbcTemplate.withTransaction(template -> template.fetchSingleRecord(SQLQueries.GET_IDN_OIDC_SCOPE_ID, (resultSet, rowNumber) -> resultSet.getInt(1), preparedStatement -> {
preparedStatement.setString(1, scope);
preparedStatement.setInt(2, tenantId);
preparedStatement.setString(3, Oauth2ScopeConstants.SCOPE_TYPE_OIDC);
}));
if (scopeId == null) {
scopeId = -1;
}
if (log.isDebugEnabled()) {
log.debug("Scope id: " + scopeId + "is returned for the tenant: " + tenantId + "and scope: " + scope);
}
} catch (TransactionException e) {
String errorMessage = "Error fetching data for oidc scope: " + scope;
throw new IdentityOAuth2Exception(errorMessage, e);
}
return scopeId;
}
Aggregations