Skip to content
Snippets Groups Projects
Commit d5f3ed71 authored by Martin Weise's avatar Martin Weise
Browse files

Merge branch 'dev' into 95-refactor-fix-all-todos-and-fixmes-in-the-backend-config

parents 92b83529 ebd9d8a1
Branches
Tags
4 merge requests!81New stable release,!43Merge dev to master,!33Draft: merge dev to master,!30Resolve "Refactor: fix all TODOs and FIXMEs in the backend"
......@@ -36,6 +36,7 @@ public class QueryService extends JdbcConnector {
this.databaseRepository = databaseRepository;
}
@Deprecated
@Transactional
public List<Query> findAll(Long databaseId) throws DatabaseNotFoundException {
final Database database = findDatabase(databaseId);
......
......@@ -20,6 +20,7 @@ public interface QueryMapper {
for (Record record : data) {
final Map<String, Object> map = new HashMap<>();
for (Field<?> column : record.fields()) {
System.out.println("Columnname: "+column);
map.put(column.getName(), record.get(column.getName()));
}
result.add(map);
......
......@@ -248,14 +248,16 @@ public class MariaDataService extends JdbcConnector implements DataService {
@Override
@Transactional
public QueryResultDto selectAll(@NonNull Long databaseId, @NonNull Long tableId, Instant timestamp,
Long page, Long size) throws TableNotFoundException,
DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException,
TableMalformedException {
if (page != null && page < 0) {
throw new TableMalformedException("page cannot be lower than zero");
@NonNull Long page, @NonNull Long size) throws TableNotFoundException,
DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException, TableMalformedException {
if(timestamp == null) {
timestamp = Instant.now();
}
if (page < 0) {
throw new TableMalformedException("Page number cannot be lower than 0");
}
if (size != null && (size <= 0 || page == null)) {
throw new TableMalformedException("size cannot be lower than zero or page is null");
if (size <= 0) {
throw new TableMalformedException("Page number cannot be lower or equal to 0");
}
final Table table = findById(databaseId, tableId);
try {
......@@ -266,18 +268,16 @@ public class MariaDataService extends JdbcConnector implements DataService {
StringBuilder stringBuilder = new StringBuilder()
.append("SELECT * FROM ")
.append(table.getInternalName());
if (timestamp != null) {
stringBuilder.append(" FOR SYSTEM_TIME AS OF TIMESTAMP'")
.append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")))
.append("'");
}
if (page != null && size != null) {
page = Math.abs(page);
size = Math.abs(size);
stringBuilder.append(" LIMIT ")
.append(size)
.append(" OFFSET ")
.append(page * size)
.append(";");
}
return queryMapper.recordListToQueryResultDto(context.fetch(stringBuilder.toString()));
} else {
log.debug("Not MariaDB, can only provide legacy pagination");
......@@ -291,4 +291,5 @@ public class MariaDataService extends JdbcConnector implements DataService {
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment