Fixed bugs:
- typo on one page - show archive only when public or to moderators Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -91,6 +91,7 @@ public class Database {
|
||||
*/
|
||||
public class Request{
|
||||
|
||||
private String groupBy = null;
|
||||
private final StringBuilder sql; // buffer the sql to be built
|
||||
private final HashMap<String, List<Object>> where = new HashMap<>(); // buffer condition statements for select
|
||||
private final HashMap<String,Object> values = new HashMap<>(); // buffer values for insert/update statements
|
||||
@@ -128,33 +129,14 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
private void applyGrouping(){
|
||||
if (groupBy != null && !groupBy.isBlank()) sql.append(" GROUP BY ").append(groupBy.trim());
|
||||
}
|
||||
|
||||
private void applySorting(){
|
||||
if (!sortFields.isEmpty()) sql.append(" ORDER BY ").append(String.join(", ",sortFields));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Request clone() {
|
||||
Request clone = new Request(new StringBuilder(sql));
|
||||
clone.where.putAll(where);
|
||||
clone.values.putAll(values);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* finalize sql, save sql and arguments as compiled request
|
||||
* @return
|
||||
*/
|
||||
public CompiledRequest compile(Object ...additionalArgs){
|
||||
var args = new ArrayList<>();
|
||||
applyValues(args);
|
||||
applyConditions(args);
|
||||
applySorting();
|
||||
if (additionalArgs != null) {
|
||||
for (Object arg : additionalArgs) args.add(arg);
|
||||
}
|
||||
return new CompiledRequest(sql.toString(),args);
|
||||
}
|
||||
|
||||
/**
|
||||
* apply values (for insert or update statements)
|
||||
* @param args
|
||||
@@ -188,6 +170,38 @@ public class Database {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Request clone() {
|
||||
Request clone = new Request(new StringBuilder(sql));
|
||||
clone.where.putAll(where);
|
||||
clone.values.putAll(values);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* finalize sql, save sql and arguments as compiled request
|
||||
* @return
|
||||
*/
|
||||
public CompiledRequest compile(Object ...additionalArgs){
|
||||
var args = new ArrayList<>();
|
||||
applyValues(args);
|
||||
applyConditions(args);
|
||||
applyGrouping();
|
||||
applySorting();
|
||||
if (additionalArgs != null) {
|
||||
for (Object arg : additionalArgs) args.add(arg);
|
||||
}
|
||||
return new CompiledRequest(sql.toString(),args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Request groupBy(String column) {
|
||||
groupBy = column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void run() throws SQLException {
|
||||
compile().run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user