It’s been a while since I have last ranted about annotations and the increasing Annotatiomania™ in the JEE ecosystem. I haven’t been exposed to much JEE either, until yesterday, when I was confronted with an awesome talk by
Adam Bien at
ch-open, where I’ve also held a talk about
jOOQ. JEE 7 ships with lots of goodies.
But then, I saw this!
Let me treat you to a introductory example of how to use a stored procedure through JPA 2.1, which our friends from EclipseLink have had the courtesy to share with us:
@NamedStoredProcedureQuery(
name="ReadUsingMultipleResultSetMappings",
procedureName="Read_Multiple_Result_Sets",
resultSetMappings={
"EmployeeResultSetMapping",
"AddressResultSetMapping",
"ProjectResultSetMapping",
"EmployeeConstructorResultSetMapping"
}
)
@SqlResultSetMappings({
@SqlResultSetMapping(
name = "EmployeeResultSetMapping",
entities = {
@EntityResult(entityClass=Employee.class)
}
),
@SqlResultSetMapping(
name="EmployeeConstructorResultSetMapping",
classes = {
@ConstructorResult(
targetClass = EmployeeDetails.class,
columns = {
@ColumnResult(
name="EMP_ID",
type=Integer.class
),
@ColumnResult(
name="F_NAME",
type=String.class
),
@ColumnResult(
name="L_NAME",
type=String.class
),
@ColumnResult(
name="R_COUNT",
type=Integer.class
)
}
)
}
)
})
public Employee(){
....
}
Obviously, Eclipse Copernicus (or what’s Kepler’s successor?) will ship with an Enterprise-licensed source code formatter built by Nobel Prize mathematicians to actually display the above. With that license, you also get a 50% discount coupon on the latest 67″ Samsung flat screen for an Enterprise coding experience. Awesome!
Also, whenever I hear “ReadUsingMultipleResultSetMappings”, I immediately think
J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource, too. Some powerful permutation mathematics and random natural language processing is thus involved.
Not just did
JPAnnotatiomania™ 2.1 treat us with stored procedure support, named fetch graphs are now also part of the game. Do note that with only a few lines of code, we will finally be safe from writing tedious SQL! Behold:
@NamedEntityGraph(
name="ExecutiveProjects"
attributeNodes={
@NamedAttributeNode("address"),
@NamedAttributeNode(
value="projects",
subgraph="projects"
)
},
subgraphs={
@NamedSubgraph(
name="projects",
attributeNodes={
@NamedAttributeNode("properties")
}
),
@NamedSubgraph(
name="projects",
type=LargeProject.class,
attributeNodes={
@NamedAttributeNode("executive")
}
)
}
)
Another 5000$ spent on formatting licenses to format the above.
Conclusion
No longer shall effective developers be paid by the lines of code, but they should be paid by the lines of @-signs they write. And I’m surely looking forward to Adam Bien’s next talk, about JEE 7 Best Practices!
Like this:
Like Loading...
Published by lukaseder
I made jOOQ
View all posts by lukaseder
Yes, and it doesn’t at all resemble in verboseness or readability the equivalent in XML configuration that so many on the annotations bandwagon love to hate.
… or that of the same code written in JDBC