Search |
||
Meta protocol mix in JDBC 4.0Posted by forax on August 2, 2006 at 2:18 AM PDT
While reading the JDBC 4.0 spec, i found a meta protocol mix in the way the spec specifies how to create an empty DataSet using the newly introduced query interface mecanism. But before let me introduce the context : JDBC 4JDBC 4.0 introduces a new way to map a class to a result of a JDBC Query automagically. It's not a real O/R Mapper like hibernate or the one describes by the EJB3 spec because by example inheritance or relationship between tables are not managed. It's just a toy O/R Mapper that ease the repetitive task of manually copying data from a ResultSet to object fields.
By example, the class below describes a table of authors and
the inner-interface Author.Query describes queries that
can be applied on this table.
public class Author {
private int id;
private String firstname;
private String lastname;
public Author() {
// used by JDBC mapper
}
public int getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public static final String DDL=
"create table author(\n" +
" id INTEGER NOT NULL\n"+
" PRIMARY KEY GENERATED ALWAYS AS IDENTITY\n"+
" (START WITH 1, INCREMENT BY 1),\n" +
" firstname VARCHAR(128) NOT NULL UNIQUE,\n"+
" lastname VARCHAR(128) NOT NULL UNIQUE"+
")";
public interface Query extends BaseQuery {
@Select(sql="SELECT * FROM author")
DataSet
To specify a query, the spec introduces two annotations
@Select (SELECT)or @Update (UPDATE, ALTER, DELETE etc)
but no annotation for operations like CREATE or DROP.
Connection con=... Author.Query query=con.createQueryObject(Author.Query.class); DatatSet [I've updated the following section, Rémi]
Now, the spec introduces a way
to create an empty DataSet automatically without using
a query SELECT (section 19.4.2.6).
What is a meta protocol ?
What if a method named "create" is tagged by an annotation
@Select ?
oups, there is a meta protocol mix.
»
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|