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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations