|
3 | 3 | import oracle.jdbc.OracleTypes; |
4 | 4 |
|
5 | 5 | import java.sql.CallableStatement; |
| 6 | +import java.sql.PreparedStatement; |
6 | 7 | import java.sql.ResultSet; |
7 | 8 | import java.sql.SQLException; |
8 | 9 | import java.util.ArrayList; |
|
11 | 12 | /** |
12 | 13 | * Created by Vinicius on 13/04/2017. |
13 | 14 | */ |
14 | | -public final class OutputBuffer { |
| 15 | +public class OutputBuffer { |
15 | 16 |
|
16 | | - private OutputBuffer() {} |
| 17 | + private String reporterId; |
17 | 18 |
|
18 | | - public static List<String> getAllLines(String reporterId) throws SQLException { |
| 19 | + public OutputBuffer(String reporterId) { |
| 20 | + this.reporterId = reporterId; |
| 21 | + } |
| 22 | + |
| 23 | + public String getReporterId() { |
| 24 | + return reporterId; |
| 25 | + } |
| 26 | + |
| 27 | + public void setReporterId(String reporterId) { |
| 28 | + this.reporterId = reporterId; |
| 29 | + } |
| 30 | + |
| 31 | + public List<String> getLines() throws SQLException { |
| 32 | + PreparedStatement preparedStatement = null; |
| 33 | + ResultSet resultSet = null; |
| 34 | + try { |
| 35 | + preparedStatement = UTPLSQL.getConnection() |
| 36 | + .prepareStatement("SELECT * FROM TABLE(ut_output_buffer.get_lines(?, 1))"); |
| 37 | + |
| 38 | + preparedStatement.setString(1, getReporterId()); |
| 39 | + resultSet = preparedStatement.executeQuery(); |
| 40 | + |
| 41 | + List<String> outputLines = new ArrayList<>(); |
| 42 | + while (resultSet.next()) { |
| 43 | + outputLines.add(resultSet.getString(1)); |
| 44 | + } |
| 45 | + return outputLines; |
| 46 | + } finally { |
| 47 | + if (resultSet != null) |
| 48 | + resultSet.close(); |
| 49 | + if (preparedStatement != null) |
| 50 | + preparedStatement.close(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public List<String> getAllLines() throws SQLException { |
19 | 55 | CallableStatement callableStatement = null; |
20 | 56 | ResultSet resultSet = null; |
21 | 57 | try { |
22 | 58 | callableStatement = UTPLSQL.getConnection() |
23 | 59 | .prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;"); |
24 | 60 |
|
25 | 61 | callableStatement.registerOutParameter(1, OracleTypes.CURSOR); |
26 | | - callableStatement.setString(2, reporterId); |
| 62 | + callableStatement.setString(2, getReporterId()); |
27 | 63 | callableStatement.execute(); |
28 | 64 |
|
29 | 65 | resultSet = (ResultSet) callableStatement.getObject(1); |
|
0 commit comments