Skip to content

Instantly share code, notes, and snippets.

@bisignam
Last active April 24, 2017 23:11
Show Gist options
  • Save bisignam/2410649e688bb683102b6a95f59d6105 to your computer and use it in GitHub Desktop.
Save bisignam/2410649e688bb683102b6a95f59d6105 to your computer and use it in GitHub Desktop.
public final static Constants {
public final static String COMPLEX_QUERY = "SELECT * FROM A_VERY_COMPLEX_QUERY";
}
@Repository
public class Repository1 {
public List<Item1> getItems() {
List<Item1> items = new ArrayList<>();
List<Map> rows = getJdbcTemplate().queryForList(Constants.COMPLEX_QUERY);
for (Map row : rows) {
Item1 item = new Item();
item.setX((String)(row.get("X")));
item.setY((String)row.get("Y"));
item.setZ((String)row.get("Z"));
items.add(item);
}
return items;
}
}
@Repository
public class Repository2 {
public List<Item2> getItems(final Integer param){
List<Item2> items = new ArrayList<>();
List<Map> rows = getJdbcTemplate().queryForList(Constants.COMPLEX_QUERY + " and param="+param);
for (Map row : rows) {
Item2 item = new Item2();
item.setA((String)(row.get("A")));
item.setB((String)row.get("B"));
item.setC((String)row.get("C"));
items.add(item);
}
return items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment