Search in sources :

Example 11 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardKeyDAO method findLatestKeyByIdentity.

@Override
public Key findLatestKeyByIdentity(String identity) {
    if (identity == null) {
        throw new IllegalArgumentException("Specified identity cannot be null.");
    }
    Key key = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // add each authority for the specified user
        statement = connection.prepareStatement(SELECT_KEY_FOR_USER_BY_IDENTITY);
        statement.setString(1, identity);
        // execute the query
        rs = statement.executeQuery();
        // if the key was found, add it
        if (rs.next()) {
            key = new Key();
            key.setId(rs.getInt("ID"));
            key.setIdentity(rs.getString("IDENTITY"));
            key.setKey(rs.getString("KEY"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return key;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Key(org.apache.nifi.key.Key) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 12 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardAuditService method purgeActions.

@Override
public void purgeActions(Date end, Action purgeAction) {
    Transaction transaction = null;
    writeLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // purge the action database
        PurgeActionsAction purgeActions = new PurgeActionsAction(end, purgeAction);
        transaction.execute(purgeActions);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        writeLock.unlock();
    }
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) PurgeActionsAction(org.apache.nifi.admin.service.action.PurgeActionsAction) AdministrationException(org.apache.nifi.admin.service.AdministrationException) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 13 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardAuditService method getActions.

@Override
public History getActions(HistoryQuery query) {
    Transaction transaction = null;
    History history = null;
    readLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // seed the accounts
        GetActionsAction getActions = new GetActionsAction(query);
        history = transaction.execute(getActions);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        readLock.unlock();
    }
    return history;
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) GetActionsAction(org.apache.nifi.admin.service.action.GetActionsAction) History(org.apache.nifi.history.History) AdministrationException(org.apache.nifi.admin.service.AdministrationException) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 14 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardKeyService method getOrCreateKey.

@Override
public Key getOrCreateKey(String identity) {
    Transaction transaction = null;
    Key key = null;
    writeLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // get or create a key
        GetOrCreateKeyAction addActions = new GetOrCreateKeyAction(identity);
        key = transaction.execute(addActions);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        writeLock.unlock();
    }
    return key;
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) GetOrCreateKeyAction(org.apache.nifi.admin.service.action.GetOrCreateKeyAction) AdministrationException(org.apache.nifi.admin.service.AdministrationException) Key(org.apache.nifi.key.Key) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 15 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardKeyService method getKey.

@Override
public Key getKey(int id) {
    Transaction transaction = null;
    Key key = null;
    readLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // get the key
        GetKeyByIdAction addActions = new GetKeyByIdAction(id);
        key = transaction.execute(addActions);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        readLock.unlock();
    }
    return key;
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) GetKeyByIdAction(org.apache.nifi.admin.service.action.GetKeyByIdAction) AdministrationException(org.apache.nifi.admin.service.AdministrationException) Key(org.apache.nifi.key.Key) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Aggregations

DataAccessException (org.apache.nifi.admin.dao.DataAccessException)30 PreparedStatement (java.sql.PreparedStatement)22 SQLException (java.sql.SQLException)22 ResultSet (java.sql.ResultSet)14 AdministrationException (org.apache.nifi.admin.service.AdministrationException)8 Transaction (org.apache.nifi.admin.service.transaction.Transaction)8 TransactionException (org.apache.nifi.admin.service.transaction.TransactionException)8 Key (org.apache.nifi.key.Key)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 Component (org.apache.nifi.action.Component)3 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)3 ActionDetails (org.apache.nifi.action.details.ActionDetails)3 List (java.util.List)2 Action (org.apache.nifi.action.Action)2 Operation (org.apache.nifi.action.Operation)2 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)2 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)2 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)2