Skip to content
Snippets Groups Projects
Verified Commit 20189e43 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: fixing cql's updated filter

parent fa7f69e9
No related branches found
No related tags found
2 merge requests!41REL: update changelog, bump version of pom.xml, update DEPENDENCIES,!39fixing cql's updated filter
Pipeline #14981 passed
......@@ -26,6 +26,8 @@ import org.caosdb.server.database.BackendTransaction;
import org.caosdb.server.database.backend.interfaces.InsertTransactionHistoryImpl;
import org.caosdb.server.database.exceptions.TransactionException;
import org.caosdb.server.entity.EntityInterface;
import org.caosdb.server.entity.InsertEntity;
import org.caosdb.server.entity.UpdateEntity;
import org.caosdb.server.entity.container.TransactionContainer;
import org.caosdb.server.utils.EntityStatus;
......@@ -60,7 +62,8 @@ public class InsertTransactionHistory extends BackendTransaction {
for (final EntityInterface e : this.container) {
if (e.getEntityStatus() == EntityStatus.DELETED
|| e.getEntityStatus() == EntityStatus.VALID) {
|| (e instanceof UpdateEntity && e.getEntityStatus() == EntityStatus.QUALIFIED)
|| (e instanceof InsertEntity && e.getEntityStatus() == EntityStatus.VALID)) {
t.execute(
e.getClass().getSimpleName().replace("Entity", ""),
......
......@@ -101,6 +101,9 @@ public class RetrieveFullEntityTransaction extends BackendTransaction {
* @param selections
*/
public void retrieveFullEntity(EntityInterface e, List<Selection> selections) {
if (!needMoreThanId(selections)) {
return;
}
execute(new RetrieveSparseEntity(e));
if (e.getEntityStatus() == EntityStatus.VALID) {
......@@ -108,8 +111,17 @@ public class RetrieveFullEntityTransaction extends BackendTransaction {
if (e.getRole() == Role.QueryTemplate) {
execute(new RetrieveQueryTemplateDefinition(e));
}
if (needParents(selections)) {
execute(new RetrieveParents(e));
} else {
// do nothing
}
if (needProperties(selections)) {
execute(new RetrieveProperties(e));
} else {
// do nothing
}
// recursion! retrieveSubEntities calls retrieveFull sometimes, but with reduced selectors.
if (selections != null && !selections.isEmpty()) {
......@@ -118,6 +130,39 @@ public class RetrieveFullEntityTransaction extends BackendTransaction {
}
}
private boolean needMoreThanId(List<Selection> selections) {
if (selections == null || selections.isEmpty()) {
return true;
} else if (selections.size() == 1 && selections.get(0).isId()) {
return false;
}
return true;
}
private boolean needProperties(List<Selection> selections) {
if (selections == null || selections.isEmpty()) {
return true;
}
for (Selection s : selections) {
if (s.isProperty()) {
return true;
}
}
return false;
}
private boolean needParents(List<Selection> selections) {
if (selections == null || selections.isEmpty()) {
return true;
}
for (Selection s : selections) {
if (s.isParent()) {
return true;
}
}
return false;
}
/**
* Recursively resolve the reference values of the list of reference property `p` (but only the
* selected sub-properties).
......
......@@ -32,12 +32,15 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
......@@ -74,6 +77,10 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac
public static class Selection {
private final String selector;
private Selection subselection = null;
static final Set<String> MAGIC_NON_PROPERTIES =
new HashSet<>(
Arrays.asList(
new String[] {"value", "parent", "id", "name", "description", "datatype"}));
public Selection setSubSelection(final Selection sub) {
if (this.subselection != null) {
......@@ -111,6 +118,18 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac
ret.setAttribute("name", toString());
return ret;
}
public boolean isParent() {
return this.selector.equalsIgnoreCase("parent");
}
public boolean isProperty() {
return !MAGIC_NON_PROPERTIES.contains(this.selector.toLowerCase());
}
public boolean isId() {
return this.selector.equalsIgnoreCase("id");
}
}
public enum Role {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment