Announcement Announcement Module
Collapse
No announcement yet.
configuration help: pool problems create deadlocks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    I haven't read this book, nor have I used this technique before, but it must be a pretty common problem.
    the book is good, i learnt from there how to work with JR

    If you are leaving ResultSets open, who is supposed to clean them up. JRResultSetDataSource doesn't have a close method.
    yes, i am agree

    Is this a recommended example from the book, or is it simply this implementation that's causing the problems?
    is the unique example in all the book about integration spring/JR , my implementation is almost the same that the book for all my classes that works with JR


    now if some good member can share a link or code using JdbcTemplate.queryForList(String sql) or
    ColumnMapRowMapper like was suggested by our friend Jörg
    i really appreciate

    thanks for advanced

    Comment


    • #32
      The reference manual has the examples you should need.
      http://www.springframework.org/docs/...c-JdbcTemplate
      Last edited by karldmoore; Aug 29th, 2007, 12:17 PM.

      Comment


      • #33
        The reference manual has the examples you should need.
        if is for one object could be, but if is more not, i cant see an exmaple

        Code:
        Querying and populating a single domain object.
        
        Actor actor = (Actor) this.jdbcTemplate.queryForObject(
            "select first_name, surname from t_actor where id = ?",
            new Object[]{new Long(1212)},
            new RowMapper() {
        
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    Actor actor = new Actor();
                    actor.setFirstName(rs.getString("first_name"));
                    actor.setSurname(rs.getString("surname"));
                    return actor;
                }
            });
        but for my case
        Code:
        String query = " SELECT * FROM CabeceraAlmacen c, 
                                DetalleAlmacen d, 
                                Articulo a, 
                                Medida m  WHERE "
        well i am lost, i dunno have idea how to resolve this

        can you help me?

        regards

        Comment


        • #34
          I think the next example is the one you want. If you are using Spring 2.0 and Java 5 you might also want to have a look at this thread.
          Code:
          Collection actors = this.jdbcTemplate.query(
              "select first_name, surname from t_actor",
              new RowMapper() {
          
                  public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                      Actor actor = new Actor();
                      actor.setFirstName(rs.getString("first_name"));
                      actor.setSurname(rs.getString("surname"));
                      return actor;
                  }
              });
          http://blog.interface21.com/main/200...-in-spring-20/
          Last edited by karldmoore; Aug 29th, 2007, 12:17 PM.

          Comment


          • #35
            i think we are confused

            about of my previous post
            Code:
            Actor actor = (Actor) this.jdbcTemplate.queryForObject(
                "select first_name, surname from t_actor where id = ?",
            ok it retuns one row to be assigned to one object, ok

            about yours
            Code:
            Collection actors = this.jdbcTemplate.query(
                "select first_name, surname from t_actor",
                new RowMapper() {
            yes thanks, i see that it returns more rows (of the same object) , so here the Collection

            but see pls that each query use from t_actor like one entity
            and
            the object is filled for one Object/Entity
            Code:
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                        Actor actor = new Actor(); // can return 10 rows of the same object
                        actor.setFirstName(rs.getString("first_name"));
                        actor.setSurname(rs.getString("surname"));
                        return actor;
                    }

            in the mime really 4
            Code:
            String query = " SELECT * FROM CabeceraAlmacen c, 
                                    DetalleAlmacen d, 
                                    Articulo a, 
                                    Medida m  WHERE "
            and really each table is an object/entity (used by Hibernate too)
            so how represent this to

            Code:
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                      //Actor actor = new Actor(); // not anymore
                       ?????? // how??? if each table of the query represents an object, so i have 4
            i hope you see now my point

            regards

            Comment


            • #36
              You need to return some structure to contain the four objects. You could use a wrapper object that contains the four objects or you could put them in a Collection. The idea is that you are building the rows that make up the report. The easier this structure is the easier it is going to be to render your report.
              Last edited by karldmoore; Aug 29th, 2007, 12:16 PM.

              Comment


              • #37
                Code:
                You need to return some structure to contain the four objects.
                ok, it seems

                Code:
                You could use a wrapper object that contains the four objects or you could put them in a Collection.
                i am confuse and i need orientation here

                Code:
                String query = " SELECT * FROM CabeceraAlmacen c, 
                                        DetalleAlmacen d, 
                                        Articulo a, 
                                        Medida m  WHERE "
                it consists or should return this, a header and its details
                so the header should return once and many times the details,

                how should i manage this in the wrap class??
                Collection and One Class???

                and in others reports i work with the feature of JR groups in the details
                so the wrap class
                what behaviour would show in the JR ?

                thanks for advanced

                Comment


                • #38
                  working now with your suggestions friends

                  hello guys

                  i changed JR working with ResultSet now with the BeanCollections,
                  maybe this can help to other members

                  first, if you remember my sql merge 4 tables or Entites,

                  in the jrxml
                  you should see something like this
                  Code:
                          <field name="idnumero" class="java.lang.String"/>
                  	<field name="serie" class="java.lang.String"/>
                  	<field name="tipo" class="java.lang.String"/>
                  	<field name="idEmpresa" class="java.lang.String"/>
                  	<field name="documento" class="java.lang.String"/>
                  	<field name="fecha" class="java.sql.Date"/>
                  	<field name="tipoVenta" class="java.lang.String"/>
                  	<field name="valorventa" class="java.math.BigDecimal"/>
                  	<field name="igv" class="java.math.BigDecimal"/>
                  	<field name="adicionigv" class="java.math.BigDecimal"/>
                  	<field name="totalNeto" class="java.math.BigDecimal"/>
                  	<field name="idProveedor" class="java.lang.String"/>
                  	<field name="motivoDevolucion" class="java.lang.String"/>
                  	<field name="idCabeceraCompra" class="java.lang.String"/>
                  	<field name="idCabeceraIngresoInsumos" class="java.lang.String"/>
                  	<field name="idDetalleAlmacen" class="java.lang.String"/>
                  	<field name="idArticulo" class="java.lang.String"/>
                  	<field name="cantidad" class="java.math.BigDecimal"/>
                  	<field name="preciounitario" class="java.math.BigDecimal"/>
                  	<field name="subtotal" class="java.math.BigDecimal"/>
                  	<field name="idLineaCategoria" class="java.lang.String"/>
                  	<field name="idMedida" class="java.lang.String"/>
                  	<field name="descripcion" class="java.lang.String"/>
                  	<field name="stockinicial" class="java.math.BigDecimal"/>
                  	<field name="stockactual" class="java.math.BigDecimal"/>
                  	<field name="preciototal" class="java.math.BigDecimal"/>
                  	<field name="nombre" class="java.lang.String"/>
                  now simple create a pojo that represents each variable
                  Code:
                  import java.sql.Date;
                  import java.math.BigDecimal;
                  public class WrapCabeceraDetalleSalidaAlmacenArticuloMedida {
                  
                  	private String idnumero;
                  	private String serie;
                  	private String tipo; 
                  	private String idEmpresa;
                  	private String documento;
                  	private Date fecha;
                  	private String tipoVenta;
                  	private BigDecimal valorventa;
                  	private BigDecimal igv;
                  	private BigDecimal adicionigv;
                  	private BigDecimal totalNeto;
                  	private String idProveedor;
                  	private String motivoDevolucion;
                  	private String idCabeceraCompra;
                  	private String idCabeceraIngresoInsumos;
                  	private String idDetalleAlmacen;
                  	private String idArticulo;
                  	private BigDecimal cantidad;
                  	private BigDecimal preciounitario;
                  	private BigDecimal subtotal;
                  	private String idLineaCategoria;
                  	private String idMedida;
                  	private String descripcion;
                  	private BigDecimal stockinicial;
                  	private BigDecimal stockactual;
                  	private BigDecimal preciototal;
                  	private String nombre;
                  
                          //accesor methods
                  now for the controller to that fills the JR
                  Code:
                   String query = " SELECT * FROM CabeceraAlmacen c, DetalleAlmacen d, Articulo a, Medida m  WHERE " +
                                        " c.idnumero=d.idnumero AND c.serie=d.serie AND " +
                                        " d.idArticulo=a.idArticulo AND a.idMedida=m.idMedida AND " +
                                        " c.serie='SAL' AND c.idnumero=?";
                  	    	
                  Collection mycollecion = this.jdbcTemplate.query(
                               query ,
                               new Object[]{almacenPK.getIdnumero()},
                               new RowMapper() {
                                 	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {	    					WrapCabeceraDetalleSalidaAlmacenArticuloMedida a =     						new WrapCabeceraDetalleSalidaAlmacenArticuloMedida();	    				
                                          //fill all set methods for each variable .....
                  	   		a.setIdnumero(rs.getString("idnumero"));
                  	    	        //.......
                  	    		return a;
                  	    		}
                  	      });        	    	
                  JRBeanCollectionDataSource jRBeanCollectionDataSource = new JRBeanCollectionDataSource(mycollecion);
                  context.getRequestScope().put("datasource", jRBeanCollectionDataSource);
                  now in the code i dont open nothing and of course close nothing (like the ResultSet object)

                  Karl and to other members, if i am forgeting something, pls let me know

                  i am transforming all my JR to this way

                  i hope that this resolve of this hell of the resources

                  BTW, exists a way that with log4j see the status of the pool???

                  regards

                  Comment


                  • #39
                    Originally posted by dr_pompeii View Post
                    i changed JR working with ResultSet now with the BeanCollections
                    Congratulations!

                    Originally posted by dr_pompeii View Post
                    now in the code i dont open nothing and of course close nothing (like the ResultSet object)
                    JdbcTemplate is doing this for you.

                    Jörg

                    Comment


                    • #40
                      What we now need to know is................. did that solve the problems you were having? I'm very much hoping that this is a yes .
                      Last edited by karldmoore; Aug 29th, 2007, 12:16 PM.

                      Comment


                      • #41
                        Congratulations!
                        thanks

                        Code:
                        JdbcTemplate is doing this for you.
                        good, happy of this

                        What we now need to know is................. did that solve the problems you were having?
                        i dont know yet, i dont finish yet to convert all JR classes with ResultSet to BeanCollections

                        Code:
                        I'm very much hoping that this is a yes .
                        so am i

                        regards guys

                        about of this
                        exists a way that with log4j see the status of the pool?
                        is possible this?

                        Comment


                        • #42
                          Originally posted by dr_pompeii View Post
                          exists a way that with log4j see the status of the pool?
                          It's not a matter of log4j, but of the pool API.

                          Jörg

                          Comment

                          Working...
                          X