use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.
the class TokenDataStore method create.
/**
* Create an object. The id field will be populated with the resulting identifier.
*
* @param obj The object being created.
* @throws ServerException When an error occurs during creation.
*/
public void create(T obj) throws ServerException {
Token token = adapter.toToken(obj);
SyncResultHandler<Token> handler = new SyncResultHandler<Token>();
try {
taskExecutor.execute(token.getTokenId(), taskFactory.create(token, handler));
handler.getResults();
} catch (ServerException e) {
throw e;
} catch (DataLayerException e) {
if (debug.warningEnabled()) {
debug.warning("Unable to create token corresponding", e);
}
throw new ServerException("Could not create token in token data store: " + e.getMessage());
}
}
use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.
the class TokenDataStore method update.
/**
* Update a given instance.
*
* @param obj The object being updated.
* @throws ServerException When the object cannot be found, or an error occurs during update.
*/
public void update(T obj) throws NotFoundException, ServerException {
SyncResultHandler<Token> handler = new SyncResultHandler<Token>();
Token token = adapter.toToken(obj);
try {
// Check it exists
read(token.getTokenId());
// Update it
taskExecutor.execute(token.getTokenId(), taskFactory.update(token, handler));
handler.getResults();
} catch (ServerException e) {
throw e;
} catch (NotFoundException e) {
throw e;
} catch (DataLayerException e) {
if (debug.warningEnabled()) {
debug.warning("Unable to create token corresponding", e);
}
throw new ServerException("Could not create token in token data store: " + e.getMessage());
}
}
use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.
the class PooledTaskExecutor method execute.
@Override
public void execute(String tokenId, Task task) throws DataLayerException {
try {
debug("Polling pool for an executor");
semaphore.acquire();
} catch (InterruptedException e) {
Thread.interrupted();
throw new DataLayerException("Interrupted while waiting for executor - cannot continue", e);
}
SimpleTaskExecutor executor = pool.poll();
if (executor == null) {
executor = createExecutor();
}
try {
debug("Got an executor - executing task");
executor.execute(tokenId, task);
} finally {
debug("Returning executor to the pool");
if (pool.add(executor)) {
semaphore.release();
}
}
}
use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.
the class ReaperConnection method initConnection.
/**
* If this is the first call, then initialise the connection.
*
* @throws org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException If there was an error getting the connection.
*/
private void initConnection() throws LdapInitializationFailedException {
if (connection == null) {
try {
connection = factory.create();
impl.setConnection(connection);
} catch (DataLayerException e) {
throw new LdapInitializationFailedException(e);
}
}
}
use of org.forgerock.openam.sm.datalayer.api.DataLayerException in project OpenAM by OpenRock.
the class RemoveReferralsStep method deleteExistingReferrals.
private void deleteExistingReferrals() throws UpgradeException {
try (Connection connection = getConnection()) {
for (DN referral : referralsToBeRemoved) {
UpgradeProgress.reportStart(AUDIT_REMOVING_REFERRAL_START, referral);
DeleteRequest request = LDAPRequests.newDeleteRequest(referral);
connection.delete(request);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
}
} catch (DataLayerException | LdapException e) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException("Failed to delete referrals", e);
}
}
Aggregations