21 Mart 2012 Çarşamba

Generating jax-ws classes of an endpoint with wsgen

An example jax-ws end point class:

package com.sample;

@WebService(serviceName = "sampleEndPoint")
public class SampleEndPoint {
    @WebMethod
    public boolean sampleWebMethod(@WebParam(name = "parameter") int parameter){
        return true;
    }
}
After the compilation of this class, we may want to generate request and response classes of this service. wsgen command is used for this purpose:
wsgen -keep -verbose -cp . com.sample.SampleEndPoint 

After the generation is done, we have two Java classes. One is for request and the other is for the response.
Request class is:
@XmlRootElement(name = "sampleWebMethod", namespace = "http://sample.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sampleWebMethod", namespace = "http://sample.com/")
public class Trigger {

    @XmlElement(name = "parameter", namespace = "")
    private int parameter;

    public int getParameter() {
        return this.parameter;
    }

    public void setParameter(int parameter) {
        this.parameter= parameter;
    }
}
and the response class is:
@XmlRootElement(name = "sampleWebMethodResponse", namespace = "http://sample.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sampleWebMethodResponse", namespace = "http://sample.com/")
public class SampleWebMethodResponse {

    @XmlElement(name = "return", namespace = "")
    private boolean _return;

    public boolean isReturn() {
        return this._return;
    }

    public void setReturn(boolean _return) {
        this._return = _return;
    }

}

Spring JdbcTemplate get inserted id

Getting the primary key after insertion is done with Spring JdbcTemplate:

        
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemplate().update(new PreparedStatementCreator() {
     public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"id of the corresponding table"});
          return ps;
     }
}, keyHolder);
int insertedId = keyHolder.getKey().intValue();
where insertSql is the query for insertion. The name of the id field is given while preparing the statement. Then after the insertion, the inserted id can be taken GeneratedKeyHolder's key value.