diff --git a/fda-query-service/services/src/main/java/at/tuwien/service/QueryService.java b/fda-query-service/services/src/main/java/at/tuwien/service/QueryService.java index c4b9d668e01780646f3bee4a69bc4660ba89b94e..01dcce99577c08fe80a154212c9c91559ba25c4a 100644 --- a/fda-query-service/services/src/main/java/at/tuwien/service/QueryService.java +++ b/fda-query-service/services/src/main/java/at/tuwien/service/QueryService.java @@ -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); diff --git a/fda-table-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java b/fda-table-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java index 30ef83fc31c2a67a3e43a20376987919eb512041..51cb27ded905ef4ca0b5563234f5a9c884f5d2d4 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java +++ b/fda-table-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java @@ -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); diff --git a/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java b/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java index 0a20f485e714c58340ab4fa7828b5d53ccabad9e..1ffdb34c545a4c5bfac7a87c4128bf921da2398f 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java +++ b/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java @@ -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) { - stringBuilder.append(" LIMIT ") - .append(size) - .append(" OFFSET ") - .append(page * size) - .append(";"); - } + stringBuilder.append(" FOR SYSTEM_TIME AS OF TIMESTAMP'") + .append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna"))) + .append("'"); + 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 { } } + }