Announcement Announcement Module
Collapse
No announcement yet.
JDBCCursorItemReader - read multiple rows as one object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDBCCursorItemReader - read multiple rows as one object

    Hi,

    I`m using JdbcCursorItemReader to read database.

    How can I read multiple rows with one cursor call? This resultset (say about 5 rows) should be mapped to one object with mapper.

  • #2
    Here is an example for this.

    Database contains 30 rows. 3 specified rows (columX, columnY, columnZ etc) must be mapped to one object


    Code:
    DATABASE 
    -------------------------------------
    COLUMN_X | COLUMN_Y | COLUMN_z | id |
    VALUE      NULL      NULL          
    NULL       value     NULL          
    NULL       NULL      value
    Code:
    // object to be mapped from 3 rows.
    public void MyObject{
    private int colum_X
    private int column_Y
    private int column_Z
    
    }

    So for each read call, cursor should read three columns to ResultSet object. After this, Mapper class maps this to MyObject. So, 10 objects should be created from 30 rows.

    So, how can I read multiple rows?

    Comment


    • #3
      Hmm..it seems that this can be done with fetchsize. Have to test that..I could maybe iterate resultset on mapper fetchsize times.

      Doesn`t anyone have any comments on this?

      Comment


      • #4
        Resolved this by myself.

        ResultSet iteration in mapper was not good choice, because it mixed up the cursor position in reader.

        Instead, I created a NullObject for my model (using the NULL object pattern) and created semi-statefull rowmapper, that returns NullObject to writer in case that all attributes had not been set my model entity.

        RowMapper also had the model entity as instance variable for keeping the state. A new entity was created in case of that all attributes had been set. In DAO level I just skipped NullObject entities from writing.

        Comment

        Working...
        X