Search in sources :

Example 21 with DataAccessException

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

the class StandardActionDAO method getPreviousValues.

@Override
public Map<String, List<PreviousValue>> getPreviousValues(String componentId) {
    Map<String, List<PreviousValue>> previousValues = new LinkedHashMap<>();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_PREVIOUSLY_CONFIGURED_FIELDS);
        statement.setString(1, componentId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        while (rs.next()) {
            final String property = rs.getString("NAME");
            previousValues.put(property, getPreviousValuesForProperty(componentId, property));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return previousValues;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with DataAccessException

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

the class StandardActionDAO method getPurgeDetails.

private PurgeDetails getPurgeDetails(Integer actionId) throws DataAccessException {
    FlowChangePurgeDetails purgeDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_PURGE_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            purgeDetails = new FlowChangePurgeDetails();
            purgeDetails.setEndDate(new Date(rs.getTimestamp("END_DATE").getTime()));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return purgeDetails;
}
Also used : FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 23 with DataAccessException

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

the class StandardActionDAO method getMoveDetails.

private MoveDetails getMoveDetails(Integer actionId) throws DataAccessException {
    FlowChangeMoveDetails moveDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_MOVE_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            moveDetails = new FlowChangeMoveDetails();
            moveDetails.setGroupId(rs.getString("GROUP_ID"));
            moveDetails.setGroup(rs.getString("GROUP_NAME"));
            moveDetails.setPreviousGroupId(rs.getString("PREVIOUS_GROUP_ID"));
            moveDetails.setPreviousGroup(rs.getString("PREVIOUS_GROUP_NAME"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return moveDetails;
}
Also used : SQLException(java.sql.SQLException) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 24 with DataAccessException

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

the class StandardActionDAO method getRemoteProcessGroupDetails.

private RemoteProcessGroupDetails getRemoteProcessGroupDetails(Integer actionId) throws DataAccessException {
    FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_REMOTE_PROCESS_GROUP_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
            remoteProcessGroupDetails.setUri(rs.getString("URI"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return remoteProcessGroupDetails;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 25 with DataAccessException

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

the class StandardKeyDAO method createKey.

@Override
public Key createKey(final String identity) {
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        final String keyValue = UUID.randomUUID().toString();
        // add each authority for the specified user
        statement = connection.prepareStatement(INSERT_KEY, Statement.RETURN_GENERATED_KEYS);
        statement.setString(1, identity);
        statement.setString(2, keyValue);
        // insert the key
        int updateCount = statement.executeUpdate();
        rs = statement.getGeneratedKeys();
        // verify the results
        if (updateCount == 1 && rs.next()) {
            final Key key = new Key();
            key.setId(rs.getInt(1));
            key.setIdentity(identity);
            key.setKey(keyValue);
            return key;
        } else {
            throw new DataAccessException("Unable to add key for user.");
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
}
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)

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