|
From: Thomas R. <tri...@tr...> - 2003-05-04 17:39:38
|
Isabelle,
I think you have a good start, but I have a few suggestions. Why not
start with the high level interfaces first, and then dig deeper into the
framework when we need to explain the more intricate features in more
detail. I would start with the ManualExtractionSqlQuery and SqlUpdate
classes.
Speaking of the ManualExtractionSqlQuery -- is there any chance that we
could rename this class to maybe MappingSqlQuery or something similar?
The current name makes it sound like there is a lot of manual work
involved in extracting some data from the database. In reality, it is
an elegant way of mapping your row data to Java classes, and I think the
name should reflect this. If we also renamed the extract() to mapRow(),
then that would in my mind make everything much clearer. Any thoughts
on this?
Here is an exmple of what the Query would look like:
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.interface21.jdbc.object.MappingSqlQuery;
import com.interface21.jdbc.core.SqlParameter;
/**
* @author trisberg
*/
public class SpringEmployeeQuery extends MappingSqlQuery {
public SpringEmployeeQuery(DataSource ds) {
super(ds, "select EMPNO, ENAME, HIREDATE from EMP where EMPNO = ?");
declareParameter(new SqlParameter(java.sql.Types.NUMERIC));
compile();
}
protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
Employee emp = new Employee();
emp.setEmployeeId(rs.getInt("EMPNO"));
emp.setName(rs.getString("ENAME"));
emp.setHireDate(rs.getDate("HIREDATE"));
return emp;
}
}
Usage looks the same as before:
int employeeId = 7788;
SpringEmployeeQuery seq = new SpringEmployeeQuery(ds);
java.util.List empList = seq.execute(employeeId);
if (empList.iterator().hasNext()) {
Employee emp = (Employee) empList.iterator().next();
System.out.println(emp.getEmployeeId() + " " +
emp.getName() + " " +
emp.getHireDate().toString());
}
One additional thought. We currently require an explicit .compile() on
all queries and update statements. Could we not compile the sql behind
the scenes instead of throwing an exception. That would be more user
friendly and I can't see any disadvantage to this. What do you think?
Thomas
> Hi everyone,
>
> I've put the first part of the tutorial on the download section of my
website (www.meta-logix.com). I still need to incorporate the UML
diagrams, so it's a work in progress.
>
> Isabelle
>
> --
> Isabelle Muszynski
> Software Engineer
> Zandweellaan 4
> 2660 Antwerpen
> Belgium
> Tel. 32-(0)3-830 18 54
> Mobile: 32-(0)485 49 50 89
> Email: isa...@me...
> Website: www.meta-logix.com
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
--
Thomas Risberg
tri...@tr...
|