org.apache.solr.client.solrj.io.stream

## Class JDBCStream

- java.lang.Object
- - org.apache.solr.client.solrj.io.stream.TupleStream
  - - org.apache.solr.client.solrj.io.stream.JDBCStream

All Implemented Interfaces:
  Closeable, Serializable, AutoCloseable, Expressible, MapSerializable, MapWriter

    public class JDBCStream
    extends TupleStream
    implements Expressible

Connects to a datasource using a registered JDBC driver and execute a query. The results of that query will be returned as tuples. An EOF tuple will indicate that all have been read. Supported Datatypes for most types vary by JDBC driver based on the specific java type as reported by `ResultSetMetaData.getColumnClassName(int)`. The exception are `Types.DATE`, `Types.TIME` or `Types.TIMESTAMP` which are determined by the JDBC type.

Java or JDBC Type | Tuple Type | Notes
--- | --- | ---
Boolean | Boolean |
String | String |
Short, Integer, Long | Long |
Float, Double | Double |
`Clob` and subclasses | String | Clobs up to length 231-1 are supported.
Other subclasses of `Number` | Long, Double | Tuple Type based on `BigDecimal.scale()`.
JDBC `Types.DATE` | String | yyyy-MM-dd, calls `Date.toString()`
JDBC `Types.TIME` | String | hh:mm:ss, calls `Time.toString()`
JDBC `Types.TIMESTAMP` | String | See `DateTimeFormatter.ISO_INSTANT`

See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`static interface` `JDBCStream.ResultSetValueSelector`

### Nested classes/interfaces inherited from class org.apache.solr.client.solrj.io.stream.TupleStream

`TupleStream.IgnoreException`

### Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter

`MapWriter.EntryWriter`

### Field Summary

Fields
`protected ResultSet` `resultSet`
`protected String` `sep`
`protected StreamContext` `streamContext`

### Constructor Summary

Constructors
Constructor and Description
`JDBCStream(StreamExpression expression, StreamFactory factory)`
`JDBCStream(String connectionUrl, String sqlQuery, StreamComparator definedSort)`
`JDBCStream(String connectionUrl, String sqlQuery, StreamComparator definedSort, Properties connectionProperties, String driverClassName)`

### Method Summary

All Methods Instance Methods Concrete Methods
`List<TupleStream>` `children()`
`void` `close()` Closes the JDBCStream
`protected JDBCStream.ResultSetValueSelector` `determineValueSelector(int columnIdx, ResultSetMetaData metadata)`
`StreamComparator` `getStreamSort()`
`void` `open()` Opens the JDBCStream
`Tuple` `read()`
`void` `setStreamContext(StreamContext context)`
`Explanation` `toExplanation(StreamFactory factory)` Returns an explanation about the stream object
`StreamExpressionParameter` `toExpression(StreamFactory factory)`

### Methods inherited from class org.apache.solr.client.solrj.io.stream.TupleStream

`getCost, getShards, getSlices, getStreamNodeId, writeMap`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.solr.common.MapWriter

`toMap`

### Field Detail

#### resultSet

    protected ResultSet resultSet

#### streamContext

    protected transient StreamContext streamContext

#### sep

    protected String sep

### Constructor Detail

#### JDBCStream

    public JDBCStream(String connectionUrl,
                      String sqlQuery,
                      StreamComparator definedSort)
               throws IOException

Throws:
  `IOException`

#### JDBCStream

    public JDBCStream(String connectionUrl,
                      String sqlQuery,
                      StreamComparator definedSort,
                      Properties connectionProperties,
                      String driverClassName)
               throws IOException

Throws:
  `IOException`

#### JDBCStream

    public JDBCStream(StreamExpression expression,
                      StreamFactory factory)
               throws IOException

Throws:
  `IOException`

### Method Detail

#### setStreamContext

    public void setStreamContext(StreamContext context)

Specified by:
  `setStreamContext` in class `TupleStream`

#### open

    public void open()
              throws IOException

Opens the JDBCStream

Specified by:
  `open` in class `TupleStream`
Throws:
  `IOException`

#### determineValueSelector

    protected JDBCStream.ResultSetValueSelector determineValueSelector(int columnIdx,
                                                                       ResultSetMetaData metadata)
                                                                throws SQLException

Throws:
  `SQLException`

#### close

    public void close()
               throws IOException

Closes the JDBCStream

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in class `TupleStream`
Throws:
  `IOException`

#### read

    public Tuple read()
               throws IOException

Specified by:
  `read` in class `TupleStream`
Throws:
  `IOException`

#### toExpression

    public StreamExpressionParameter toExpression(StreamFactory factory)
                                           throws IOException

Specified by:
  `toExpression` in interface `Expressible`
Throws:
  `IOException`

#### toExplanation

    public Explanation toExplanation(StreamFactory factory)
                              throws IOException

Description copied from interface: `Expressible`
Returns an explanation about the stream object

Specified by:
  `toExplanation` in interface `Expressible`
Specified by:
  `toExplanation` in class `TupleStream`
Parameters:
  `factory` - Stream factory for this, contains information about the function name
Returns:
  Explanation about this stream object containing explanations of any child stream objects
Throws:
  `IOException` - throw on any error

#### children

    public List<TupleStream> children()

Specified by:
  `children` in class `TupleStream`

#### getStreamSort

    public StreamComparator getStreamSort()

Specified by:
  `getStreamSort` in class `TupleStream`