Search in sources :

Example 6 with DataAccessException

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

the class StandardActionDAO method createAction.

@Override
public Action createAction(Action action) throws DataAccessException {
    if (action.getUserIdentity() == null) {
        throw new IllegalArgumentException("User cannot be null.");
    }
    if (action.getTimestamp() == null) {
        throw new IllegalArgumentException("Action timestamp cannot be null.");
    }
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // obtain a statement to insert to the action table
        statement = connection.prepareStatement(INSERT_ACTION, Statement.RETURN_GENERATED_KEYS);
        statement.setString(1, StringUtils.left(action.getUserIdentity(), 4096));
        statement.setString(2, action.getSourceId());
        statement.setString(3, StringUtils.left(action.getSourceName(), 1000));
        statement.setString(4, action.getSourceType().name());
        statement.setString(5, action.getOperation().name());
        statement.setTimestamp(6, new java.sql.Timestamp(action.getTimestamp().getTime()));
        // insert the action
        int updateCount = statement.executeUpdate();
        final FlowChangeAction createdAction = new FlowChangeAction();
        createdAction.setUserIdentity(action.getUserIdentity());
        createdAction.setSourceId(action.getSourceId());
        createdAction.setSourceName(action.getSourceName());
        createdAction.setSourceType(action.getSourceType());
        createdAction.setOperation(action.getOperation());
        createdAction.setTimestamp(action.getTimestamp());
        createdAction.setActionDetails(action.getActionDetails());
        createdAction.setComponentDetails(action.getComponentDetails());
        // get the action id
        rs = statement.getGeneratedKeys();
        if (updateCount == 1 && rs.next()) {
            createdAction.setId(rs.getInt(1));
        } else {
            throw new DataAccessException("Unable to insert action.");
        }
        // close the previous statement
        statement.close();
        // determine the type of component
        ComponentDetails componentDetails = createdAction.getComponentDetails();
        if (componentDetails instanceof FlowChangeExtensionDetails) {
            createExtensionDetails(createdAction.getId(), (ExtensionDetails) componentDetails);
        } else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
            createRemoteProcessGroupDetails(createdAction.getId(), (RemoteProcessGroupDetails) componentDetails);
        }
        // determine the type of action
        ActionDetails details = createdAction.getActionDetails();
        if (details instanceof FlowChangeConnectDetails) {
            createConnectDetails(createdAction.getId(), (ConnectDetails) details);
        } else if (details instanceof FlowChangeMoveDetails) {
            createMoveDetails(createdAction.getId(), (MoveDetails) details);
        } else if (details instanceof FlowChangeConfigureDetails) {
            createConfigureDetails(createdAction.getId(), (ConfigureDetails) details);
        } else if (details instanceof FlowChangePurgeDetails) {
            createPurgeDetails(createdAction.getId(), (PurgeDetails) details);
        }
        return createdAction;
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) MoveDetails(org.apache.nifi.action.details.MoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PreparedStatement(java.sql.PreparedStatement) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ActionDetails(org.apache.nifi.action.details.ActionDetails) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 7 with DataAccessException

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

the class StandardActionDAO method createConnectDetails.

private void createConnectDetails(int actionId, ConnectDetails connectionDetails) throws DataAccessException {
    PreparedStatement statement = null;
    try {
        // obtain a statement to insert to the processor action table
        statement = connection.prepareStatement(INSERT_CONNECT_DETAILS);
        statement.setInt(1, actionId);
        statement.setString(2, connectionDetails.getSourceId());
        statement.setString(3, StringUtils.left(connectionDetails.getSourceName(), 1000));
        statement.setString(4, StringUtils.left(connectionDetails.getSourceType().toString(), 1000));
        statement.setString(5, StringUtils.left(connectionDetails.getRelationship(), 1000));
        statement.setString(6, connectionDetails.getDestinationId());
        statement.setString(7, StringUtils.left(connectionDetails.getDestinationName(), 1000));
        statement.setString(8, StringUtils.left(connectionDetails.getDestinationType().toString(), 1000));
        // insert the action
        int updateCount = statement.executeUpdate();
        // ensure the operation completed successfully
        if (updateCount != 1) {
            throw new DataAccessException("Unable to insert connection details.");
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 8 with DataAccessException

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

the class StandardActionDAO method createRemoteProcessGroupDetails.

private void createRemoteProcessGroupDetails(int actionId, RemoteProcessGroupDetails remoteProcessGroupDetails) throws DataAccessException {
    PreparedStatement statement = null;
    try {
        // obtain a statement to insert to the processor action table
        statement = connection.prepareStatement(INSERT_REMOTE_PROCESS_GROUP_DETAILS);
        statement.setInt(1, actionId);
        statement.setString(2, StringUtils.left(remoteProcessGroupDetails.getUri(), 2500));
        // insert the action
        int updateCount = statement.executeUpdate();
        // ensure the operation completed successfully
        if (updateCount != 1) {
            throw new DataAccessException("Unable to insert remote prcoess group details.");
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 9 with DataAccessException

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

the class StandardActionDAO method createConfigureDetails.

private void createConfigureDetails(int actionId, ConfigureDetails configurationDetails) throws DataAccessException {
    PreparedStatement statement = null;
    try {
        // obtain a statement to insert to the processor action table
        statement = connection.prepareStatement(INSERT_CONFIGURE_DETAILS);
        statement.setInt(1, actionId);
        statement.setString(2, StringUtils.left(configurationDetails.getName(), 1000));
        statement.setString(3, StringUtils.left(configurationDetails.getValue(), 5000));
        statement.setString(4, StringUtils.left(configurationDetails.getPreviousValue(), 5000));
        // insert the action
        int updateCount = statement.executeUpdate();
        // ensure the operation completed successfully
        if (updateCount != 1) {
            throw new DataAccessException("Unable to insert configure details.");
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 10 with DataAccessException

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

the class StandardActionDAO method getExtensionDetails.

private ExtensionDetails getExtensionDetails(Integer actionId) throws DataAccessException {
    FlowChangeExtensionDetails extensionDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_EXTENSION_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            extensionDetails = new FlowChangeExtensionDetails();
            extensionDetails.setType(rs.getString("TYPE"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return extensionDetails;
}
Also used : SQLException(java.sql.SQLException) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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