@Override public void execute(final Connection connection) throws SQLException { procedure.execute(connection); } });
@Override public void execute(final T stateReceiver) throws E { procedure.execute(stateReceiver); } };
@Override public void actionPerformed(final ActionEvent e) { this.closeStrategy.execute(this.contentPane); } }
@Override public void execute(final T stateReceiver) throws E { procedure.execute(stateReceiver); } };
@Override public void close() throws SQLException { this.closeProcedure.execute(this); }
public void forAllDo(final IProcedure<L, RuntimeException> procedure) { final Collection<L> cloneList; synchronized (this) { cloneList = new ArrayList<>(this.listeners); } for (final L listener : cloneList) { procedure.execute(listener); } }
public void forAllDoLastListenerFirst(final IProcedure<L, RuntimeException> procedure) { final List<L> cloneList; synchronized (this) { cloneList = new ArrayList<>(this.listeners); } Collections.reverse(cloneList); for (final L listener : cloneList) { procedure.execute(listener); } }
@Override public void close() throws IOException { check(); this.isClosed = true; IOException exception = JsonObjectUtilities.close(() -> closer.execute(this.parser), null); exception = JsonObjectUtilities.close(this.iterator, exception); exception = JsonObjectUtilities.close(this.parser, exception); if (exception != null) { throw exception; } }
private void initialize() throws IOException { this.parser = new JsonFactory().createParser(new InputStreamReader(inputStream, "utf-8")); //$NON-NLS-1$ initializer.execute(this.parser); this.iterator = new ObjectMapper().readerFor(clazz).readValues(this.parser); } };
public static void execute( final IDatabaseConnector connector, final IJdbcConnectionDescription connectionDescription, final IProcedure<Connection, SQLException> procedure) throws SQLException { try (Connection connection = connector.connectWritable(connectionDescription);) { procedure.execute(connection); } }
@Override public void close() throws IOException { check(); this.isClosed = true; IOException exception = JsonObjectUtilities.close(() -> closer.execute(this.generator), null); exception = JsonObjectUtilities.close(this.writer, exception); exception = JsonObjectUtilities.close(this.generator, exception); if (exception != null) { throw exception; } }
public static int count( final PreparedStatement statement, final IProcedure<PreparedStatement, SQLException> prepareProcedure) throws SQLException { prepareProcedure.execute(statement); if (statement.execute()) { try (final ResultSet resultSet = statement.getResultSet()) { if (resultSet.next()) { final Object object = resultSet.getObject(1); if (!(object instanceof Number)) { return 0; } final Number number = (Number) object; return number.intValue(); } } } return 0; }
public static boolean execute( final Connection connection, final String statementString, final IProcedure<PreparedStatement, SQLException> prepareProcedure, final IProcedure<ResultSet, SQLException> resultProcedure) throws SQLException { logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$ try (PreparedStatement statement = connection.prepareStatement(statementString)) { prepareProcedure.execute(statement); if (statement.execute()) { try (final ResultSet resultSet = statement.getResultSet()) { resultProcedure.execute(resultSet); return true; } } return statement.getUpdateCount() > 0; } catch (final SQLException exception) { throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$ } }
@SuppressWarnings("resource") public static <T> ResultSet resultSet( final Connection connection, final String statementString, final IProcedure<PreparedStatement, SQLException> prepareProcedure) throws SQLException { try { logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$ final PreparedStatement statement = connection.prepareStatement(statementString); prepareProcedure.execute(statement); if (statement.execute()) { return statement.getResultSet(); } return null; } catch (final SQLException exception) { throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$ } }
public static void add( final PreparedStatement statement, final IProcedure<PreparedStatement, SQLException> prepareProcedure) throws SQLException { try { prepareProcedure.execute(statement); statement.addBatch(); } catch (final SQLException exception) { throw exception; } }
private void initialize() throws IOException { this.generator = new JsonFactory().createGenerator(outputStream).configure(Feature.AUTO_CLOSE_TARGET, false); initializer.execute(this.generator); this.writer = new ObjectMapper() .writerFor(clazz) .with(SerializationFeature.FLUSH_AFTER_WRITE_VALUE) .writeValuesAsArray(this.generator); } };
public static List<Object> update( final Connection connection, final String statementString, final IProcedure<PreparedStatement, SQLException> prepareProcedure) throws SQLException { logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$ try (PreparedStatement statement = connection.prepareStatement(statementString, Statement.RETURN_GENERATED_KEYS)) { try { prepareProcedure.execute(statement); final int numberOfChangedRows = statement.executeUpdate(); if (numberOfChangedRows == 0) { return new ArrayList<>(); } final ArrayList<Object> keys = new ArrayList<>(); try (ResultSet generatedKeys = statement.getGeneratedKeys()) { while (generatedKeys.next()) { final Object key = generatedKeys.getObject(1); logger.log(ILevel.DEBUG, " key: " + toDebugString(key)); //$NON-NLS-1$ keys.add(key); } } return keys; } catch (final SQLException exception) { throw exception; } } catch (final SQLException exception) { throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$ } }
public static List<Object> update( final Connection connection, final String statementString, final String[] returnColumns, final IProcedure<PreparedStatement, SQLException> prepareProcedure) throws SQLException { logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$ try (PreparedStatement statement = connection.prepareStatement(statementString, returnColumns)) { prepareProcedure.execute(statement); final int numberOfChangedRows = statement.executeUpdate(); if (numberOfChangedRows == 0) { return new ArrayList<>(); } final ArrayList<Object> keys = new ArrayList<>(); try (ResultSet generatedKeys = statement.getGeneratedKeys()) { while (generatedKeys.next()) { final Object key = generatedKeys.getObject(1); logger.log(ILevel.DEBUG, " key: " + toDebugString(key)); //$NON-NLS-1$ keys.add(key); } } return keys; } catch (final SQLException exception) { throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$ } }
public static boolean call( final Connection connection, final String statementString, final IProcedure<PreparedStatement, SQLException> prepareProcedure, final IProcedure<ResultSet, SQLException> resultProcedure) throws SQLException { logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$ try (CallableStatement statement = connection.prepareCall(statementString)) { prepareProcedure.execute(statement); if (statement.execute()) { try (final ResultSet resultSet = statement.getResultSet()) { resultProcedure.execute(resultSet); return true; } } return statement.getUpdateCount() > 0; } catch (final SQLException exception) { throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$ } }