Hello there,
I was going around 3.0M1, gone on the quick starts to see how it is ;-)
I have been a bit disappointed by the "Main.java" code snippet :
QueryChain chain = new QueryChain();
chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
"table",
"PAINTING")));
chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
"table",
"ARTIST")));
chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
"table",
"GALLERY")));
context.performGenericQuery(chain);
Its a lot of cut-and-paste, compared to the comment "we need to run the
same query three times with different sets of parameters". Wouldn't the
best code for this statement be :
QueryChain chain = new QueryChain();
for (String tableName : new String[] {
"PAINTING", "ARTIST", "GALLERY"}) {
chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
"table", tableName)));
}
context.performGenericQuery(chain);
Then we could even show people how easy it is to build good APIs with
Cayenne ;-) :
public static void emptyTables(String... tables) {
QueryChain chain = new QueryChain();
for (String tableName : tables) {
chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
"table", tableName)));
}
context.performGenericQuery(chain);
}
And in the "main" method :
emptyTables("PAINTING", "ARTIST", "GALLERY");
I may go to far for a quick start, but worth to post on the mailing list
anyway ;-)
-- Mikaël Cluseau <mc.isi.n..mail.com> ISI.NC
This archive was generated by hypermail 2.0.0 : Fri Oct 26 2007 - 18:54:09 EDT