Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active November 15, 2025 22:44
Show Gist options
  • Select an option

  • Save mcsee/e8e9c14ecc8a9782c9af326f30cbdd61 to your computer and use it in GitHub Desktop.

Select an option

Save mcsee/e8e9c14ecc8a9782c9af326f30cbdd61 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public class QueryBuilder {
public String buildEmployeeQuery() {
String sql = "SELECT emp.employee_id, " +
"emp.first_name, emp.last_name, " +
" dept.department_name, " +
"emp.salary " +
"FROM employees emp " +
"JOIN departments dept ON " +
"emp.department_id = " +
"dept.department_id " +
"WHERE emp.salary > ? " +
" AND dept.location = ? " +
"ORDER BY emp.salary DESC";
return sql;
}
public String buildJsonPayload(String name, int age) {
String json = "{\n" +
" \"name\": \"" + name + "\",\n" +
" \"age\": " + age + ",\n" +
" \"address\": {\n" +
" \"street\": " +
"\"123 Main St\",\n" +
" \"city\": \"New York\"\n" +
" }\n" +
"}";
return json;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment