1 2 Previous Next 18 Replies Latest reply on Oct 11, 2016 12:07 PM by cfang Go to original post
      • 15. Re: ItemProcessor
        richardmoore

        If I leave out the processor everything works, even on the linux server. Is there something as far as the CDI setup that I can try for the processor?

        • 16. Re: ItemProcessor
          cfang

          anything special about item processor class?  Does it have a subclass that is also declared as CDI bean?  I notice it has a super class, is the super class also a CDI bean?

          • 17. Re: ItemProcessor
            richardmoore

            Here are the classes -

             

            package com.awginc.batch.system.jdbc.batchlet;

             

             

            import java.sql.Connection;

            import java.sql.ResultSet;

            import java.sql.ResultSetMetaData;

            import java.sql.SQLException;

            import java.util.logging.Logger;

             

             

            import javax.batch.api.BatchProperty;

            import javax.batch.api.chunk.ItemProcessor;

            import javax.inject.Inject;

            import javax.naming.Context;

            import javax.naming.InitialContext;

            import javax.naming.NamingException;

            import javax.sql.DataSource;

             

             

            public abstract class JdbcItemProcessor implements ItemProcessor {

             

             

              @Inject

              @BatchProperty(name = "dataSourceLookup")

              private String dataSourceLookup;

             

              protected Connection getConnection() throws SQLException, NamingException {

              return this.getDataSource().getConnection();

              }

             

              protected DataSource getDataSource() throws NamingException {

              if (this.dataSourceLookup == null) {

              throw new RuntimeException("Missing required batch property - dataSourceLookup");

              }

              Context ctxt = new InitialContext();

              DataSource ds = (DataSource) ctxt.lookup(dataSourceLookup);

              return ds;

              }

             

              protected void display(ResultSet rs) throws SQLException {

              log.info("Row = " + rs.getRow());

             

              ResultSetMetaData rsdm = rs.getMetaData();

              for (int idx = 1; idx <= rsdm.getColumnCount(); idx++) {

              log.info(rsdm.getTableName(idx) + "." + rsdm.getColumnName(idx) + " = '" + rs.getObject(rsdm.getColumnName(idx)) + "'");

              }

              }

             

              protected final Logger log = Logger.getLogger(this.getClass().getSimpleName());

            }

             

             

             

             

             

             

             

             

            package com.awginc.jberet.examples;

             

             

            import java.sql.Connection;

            import java.sql.PreparedStatement;

            import java.sql.ResultSet;

            import java.sql.SQLException;

            import java.util.Map;

             

             

            import javax.annotation.PostConstruct;

            import javax.annotation.PreDestroy;

             

             

            import com.awginc.batch.system.jdbc.batchlet.JdbcItemProcessor;

             

             

            public class JberetAdhocTestCase3ItemProcessor extends JdbcItemProcessor {

             

             

              @PostConstruct

                private void postConstruct() {

              log.info("Creating database resources.");

              try {

              this.connection = this.getConnection();

              this.stmt = this.connection.prepareStatement("select * from db2pdba.aim_fclty where dw_fclty_ltr2_cd = ?");

              } catch (Exception e) {

              throw new RuntimeException(e);

              }

              }

             

              @PreDestroy

                private void preDestroy() {

              log.info("Closing database resources.");

              if (this.stmt != null) {

              try {

              this.stmt.close();

              } catch (SQLException e) {

              log.warning(e.getMessage());

              }

              }

              if (this.connection != null) {

              try {

              this.connection.close();

              } catch (SQLException e) {

              log.warning(e.getMessage());

              }

              }

              }

             

              @Override

              public Object processItem(Object item) throws Exception {

              @SuppressWarnings("unchecked")

              Map<Object, Object> map = (Map<Object, Object>) item;

              map.put("FCLTY_NM", map.get("FCLTY_NM").toString().trim());

              log.info(map.toString());

             

             

              ResultSet rs = null;

              try {

              this.stmt.clearParameters();

              this.stmt.setString(1, map.get("DW_FCLTY_LTR2_CD").toString());

              rs = stmt.executeQuery();

              while (rs.next()) {

              this.display(rs);

              }

              } catch (SQLException e) {

              throw e;

              } finally {

              if (rs != null) {

              rs.close();

              }

              }

             

             

              return map;

              }

             

              private Connection connection;

              private PreparedStatement stmt;

            }

            • 18. Re: ItemProcessor
              cfang

              public class JberetAdhocTestCase3ItemProcessor extends JdbcItemProcessor {

               

              should have a @Named in order to be discovered by Weld:  Can you try it?

               

              @Named

              public class JberetAdhocTestCase3ItemProcessor extends JdbcItemProcessor {

              1 2 Previous Next