I translated this report in my GWT project in models "PersonTO" and
"UserTO".
The code UserTO is as follows:
package com.google.gwt.client.to;
import java.io.Serializable;
public class UserTO implements Serializable {
private int id;
private String username;
private String password;
private PersonTO personTO;
public UserTO() {
}
public UserTO(int id, String username, String password, PersonTO
person ) {
this.id = id;
this.username = username;
this.password = password;
this.personTO = person;
}
public PersonTO getPersonTO() {
return personTO;
}
public void setPerson(PersonTO person) {
this.personTO = person;
}
....
and other getter/setter methods
...
The database queries are made within the class UserDAO, but I do not
know how to invoke the constructor UserTO properly:
package com.google.gwt.server.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.google.gwt.client.exceptions.DBException;
import com.google.gwt.client.to.PersonTO;
import com.google.gwt.client.to.UserTO;
public class UserDAO extends BaseDAO {
private static String findUserFromCfSQL = "SELECT
id,username,password,person_id FROM users WHERE person_id = (SELECT id
FROM persons WHERE cod_fiscale = ?)";
public UserTO getUserFromCF(String cod_fiscale) throws DBException {
Connection conn = null;
PreparedStatement prepStat = null;
ResultSet rs = null;
UserTO user = null;
try {
conn = this.getConnection();
prepStat = conn.prepareStatement(findUserFromCfSQL);
prepStat.setString(1, cod_fiscale);
rs = prepStat.executeQuery();
************** user = new UserTO(rs.getInt(1), rs.getString(2),
rs.getString(3), (PersonTO)rs.getObject(4)); ***********
return user;
} catch (SQLException ex) {
ex.printStackTrace();
throw new DBException();
} finally {
try {
prepStat.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
throw new DBException();
}
}
}
}
(PersonTO)rs.getObject(4)) Of course it is wrong, because in
ResultSet at index 4 there is an object of type Integer, but I do not
know whether it is right to call for a service that returns the object
PersonDAO to pass it through to the constructor new UserTO(...)
Someone would know this dilemma?
What do you think?