Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.utplsql.api.reporter.Reporter;

import java.io.PrintStream;
import java.sql.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -62,8 +65,6 @@ public void printAvailable(Connection conn, List<PrintStream> printStreams) thro
});
}

protected abstract PreparedStatement getLinesStatement( Connection conn ) throws SQLException;

protected abstract CallableStatement getLinesCursorStatement( Connection conn ) throws SQLException;

/**
Expand All @@ -74,11 +75,13 @@ public void printAvailable(Connection conn, List<PrintStream> printStreams) thro
*/
public void fetchAvailable(Connection conn, Consumer<String> onLineFetched) throws SQLException {

try (PreparedStatement pstmt = getLinesStatement(conn)) {
try (CallableStatement cstmt = getLinesCursorStatement(conn)) {
cstmt.execute();
cstmt.setFetchSize(1);

try (ResultSet resultSet = pstmt.executeQuery() ) {
try ( ResultSet resultSet = (ResultSet) cstmt.getObject(1)) {
while (resultSet.next())
onLineFetched.accept(resultSet.getString(1));
onLineFetched.accept(resultSet.getString("text"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/** Compatibility Output-Buffer for 3.0.0 - 3.0.4
Expand All @@ -18,13 +17,6 @@ class CompatibilityOutputBufferPre310 extends AbstractOutputBuffer {
super(reporter);
}

@Override
protected PreparedStatement getLinesStatement(Connection conn) throws SQLException {
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM table(ut_output_buffer.get_lines(?))");
pstmt.setString(1, getReporter().getId());
return pstmt;
}

@Override
protected CallableStatement getLinesCursorStatement(Connection conn) throws SQLException {
CallableStatement cstmt = conn.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OraclePreparedStatement;
import org.utplsql.api.reporter.Reporter;
import oracle.jdbc.OracleTypes;
import org.utplsql.api.reporter.Reporter;

import javax.xml.transform.Result;
import java.io.PrintStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

/**
* Fetches the lines produced by a reporter.
Expand All @@ -29,14 +25,6 @@ class DefaultOutputBuffer extends AbstractOutputBuffer {
super(reporter);
}

@Override
protected PreparedStatement getLinesStatement(Connection conn) throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
OraclePreparedStatement pstmt = (OraclePreparedStatement)oraConn.prepareStatement("select * from table(?.get_lines())");
pstmt.setORAData(1, getReporter());
return pstmt;
}

@Override
protected CallableStatement getLinesCursorStatement(Connection conn) throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/utplsql/api/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import oracle.jdbc.OracleTypes;
import oracle.sql.Datum;
import oracle.sql.ORAData;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.outputBuffer.OutputBuffer;

Expand Down Expand Up @@ -103,9 +101,7 @@ public String getId() {

public Datum toDatum(Connection c) throws SQLException
{
StructDescriptor sd =
StructDescriptor.createDescriptor(getTypeName(), c);
return new STRUCT(sd, c, getAttributes());
return (Datum)c.createStruct(getTypeName(), getAttributes());
}

public OutputBuffer getOutputBuffer() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/utplsql/api/reporter/ReporterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import oracle.sql.Datum;
import oracle.sql.ORAData;
import oracle.sql.ORADataFactory;
import oracle.sql.STRUCT;
import org.utplsql.api.compatibility.CompatibilityProxy;

import java.sql.SQLException;
import java.sql.Struct;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -117,9 +117,9 @@ public Map<String, String> getRegisteredReporterInfo() {
@Override
public ORAData create(Datum d, int sqlType) throws SQLException {
if (d == null) return null;
if ( d instanceof STRUCT) {
String sqlName = ((STRUCT)d).getDescriptor().getName();
return createReporter(sqlName, ((STRUCT)d).getAttributes());
if ( d instanceof Struct) {
String sqlName = ((Struct)d).getSQLTypeName();
return createReporter(sqlName, ((Struct)d).getAttributes());
}

return null;
Expand Down