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
No related branches found
No related tags found
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 { ...@@ -36,6 +36,7 @@ public class QueryService extends JdbcConnector {
this.databaseRepository = databaseRepository; this.databaseRepository = databaseRepository;
} }
@Deprecated
@Transactional @Transactional
public List<Query> findAll(Long databaseId) throws DatabaseNotFoundException { public List<Query> findAll(Long databaseId) throws DatabaseNotFoundException {
final Database database = findDatabase(databaseId); final Database database = findDatabase(databaseId);
......
...@@ -20,6 +20,7 @@ public interface QueryMapper { ...@@ -20,6 +20,7 @@ public interface QueryMapper {
for (Record record : data) { for (Record record : data) {
final Map<String, Object> map = new HashMap<>(); final Map<String, Object> map = new HashMap<>();
for (Field<?> column : record.fields()) { for (Field<?> column : record.fields()) {
System.out.println("Columnname: "+column);
map.put(column.getName(), record.get(column.getName())); map.put(column.getName(), record.get(column.getName()));
} }
result.add(map); result.add(map);
......
...@@ -248,14 +248,16 @@ public class MariaDataService extends JdbcConnector implements DataService { ...@@ -248,14 +248,16 @@ public class MariaDataService extends JdbcConnector implements DataService {
@Override @Override
@Transactional @Transactional
public QueryResultDto selectAll(@NonNull Long databaseId, @NonNull Long tableId, Instant timestamp, public QueryResultDto selectAll(@NonNull Long databaseId, @NonNull Long tableId, Instant timestamp,
Long page, Long size) throws TableNotFoundException, @NonNull Long page, @NonNull Long size) throws TableNotFoundException,
DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException, TableMalformedException {
TableMalformedException { if(timestamp == null) {
if (page != null && page < 0) { timestamp = Instant.now();
throw new TableMalformedException("page cannot be lower than zero"); }
if (page < 0) {
throw new TableMalformedException("Page number cannot be lower than 0");
} }
if (size != null && (size <= 0 || page == null)) { if (size <= 0) {
throw new TableMalformedException("size cannot be lower than zero or page is null"); throw new TableMalformedException("Page number cannot be lower or equal to 0");
} }
final Table table = findById(databaseId, tableId); final Table table = findById(databaseId, tableId);
try { try {
...@@ -266,18 +268,16 @@ public class MariaDataService extends JdbcConnector implements DataService { ...@@ -266,18 +268,16 @@ public class MariaDataService extends JdbcConnector implements DataService {
StringBuilder stringBuilder = new StringBuilder() StringBuilder stringBuilder = new StringBuilder()
.append("SELECT * FROM ") .append("SELECT * FROM ")
.append(table.getInternalName()); .append(table.getInternalName());
if (timestamp != null) {
stringBuilder.append(" FOR SYSTEM_TIME AS OF TIMESTAMP'") stringBuilder.append(" FOR SYSTEM_TIME AS OF TIMESTAMP'")
.append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna"))) .append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")))
.append("'"); .append("'");
} page = Math.abs(page);
if (page != null && size != null) { size = Math.abs(size);
stringBuilder.append(" LIMIT ") stringBuilder.append(" LIMIT ")
.append(size) .append(size)
.append(" OFFSET ") .append(" OFFSET ")
.append(page * size) .append(page * size)
.append(";"); .append(";");
}
return queryMapper.recordListToQueryResultDto(context.fetch(stringBuilder.toString())); return queryMapper.recordListToQueryResultDto(context.fetch(stringBuilder.toString()));
} else { } else {
log.debug("Not MariaDB, can only provide legacy pagination"); log.debug("Not MariaDB, can only provide legacy pagination");
...@@ -291,4 +291,5 @@ public class MariaDataService extends JdbcConnector implements DataService { ...@@ -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