[New] Added doQuery() methods to DAOs and hooked up InMemory querying
This commit is contained in:
parent
986492854b
commit
a514ceec99
|
@ -1,9 +1,19 @@
|
||||||
package li.strolch.persistence.inmemory;
|
package li.strolch.persistence.inmemory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.query.OrderQuery;
|
||||||
import li.strolch.persistence.api.OrderDao;
|
import li.strolch.persistence.api.OrderDao;
|
||||||
|
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
|
||||||
|
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||||
|
|
||||||
public class InMemoryOrderDao extends InMemoryDao<Order> implements OrderDao {
|
public class InMemoryOrderDao extends InMemoryDao<Order> implements OrderDao {
|
||||||
|
|
||||||
// marker class
|
@Override
|
||||||
|
public List<Order> doQuery(OrderQuery orderQuery) {
|
||||||
|
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
|
||||||
|
InMemoryQuery<Order> query = visitor.visit(orderQuery);
|
||||||
|
return query.doQuery(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
package li.strolch.persistence.inmemory;
|
package li.strolch.persistence.inmemory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.query.ResourceQuery;
|
||||||
import li.strolch.persistence.api.ResourceDao;
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
|
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||||
|
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
|
||||||
|
|
||||||
public class InMemoryResourceDao extends InMemoryDao<Resource> implements ResourceDao {
|
public class InMemoryResourceDao extends InMemoryDao<Resource> implements ResourceDao {
|
||||||
|
|
||||||
// marker class
|
@Override
|
||||||
|
public List<Resource> doQuery(ResourceQuery resourceQuery) {
|
||||||
|
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
|
||||||
|
InMemoryQuery<Resource> query = visitor.visit(resourceQuery);
|
||||||
|
return query.doQuery(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.agent.api;
|
package li.strolch.runtime.agent.api;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ComponentContainer {
|
public interface ComponentContainer {
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,8 @@ import li.strolch.model.Order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface OrderMap extends ElementMap<Order> {
|
public interface OrderMap extends ElementMap<Order> {
|
||||||
|
|
||||||
//
|
// marker interface
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,8 @@ import li.strolch.model.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ResourceMap extends ElementMap<Resource> {
|
public interface ResourceMap extends ElementMap<Resource> {
|
||||||
|
|
||||||
//
|
// marker interface
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.model.query.StrolchQuery;
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.StrolchDao;
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
@ -14,7 +15,8 @@ import li.strolch.runtime.agent.api.ElementMap;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class TransactionalElementMap<T extends StrolchElement> implements ElementMap<T> {
|
public abstract class TransactionalElementMap<T extends StrolchElement, U extends StrolchQuery<?>> implements
|
||||||
|
ElementMap<T> {
|
||||||
|
|
||||||
private PersistenceHandler persistenceHandler;
|
private PersistenceHandler persistenceHandler;
|
||||||
private String realm;
|
private String realm;
|
||||||
|
@ -28,6 +30,10 @@ public abstract class TransactionalElementMap<T extends StrolchElement> implemen
|
||||||
return this.realm;
|
return this.realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PersistenceHandler getPersistenceHandler() {
|
||||||
|
return this.persistenceHandler;
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract StrolchDao<T> getDao(StrolchTransaction tx);
|
protected abstract StrolchDao<T> getDao(StrolchTransaction tx);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package li.strolch.runtime.agent.impl;
|
package li.strolch.runtime.agent.impl;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.query.OrderQuery;
|
||||||
import li.strolch.persistence.api.OrderDao;
|
import li.strolch.persistence.api.OrderDao;
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.OrderMap;
|
import li.strolch.runtime.agent.api.OrderMap;
|
||||||
|
|
||||||
public class TransactionalOrderMap extends TransactionalElementMap<Order> implements OrderMap {
|
public class TransactionalOrderMap extends TransactionalElementMap<Order, OrderQuery> implements OrderMap {
|
||||||
|
|
||||||
public TransactionalOrderMap(String realm, PersistenceHandler persistenceHandler) {
|
public TransactionalOrderMap(String realm, PersistenceHandler persistenceHandler) {
|
||||||
super(realm, persistenceHandler);
|
super(realm, persistenceHandler);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package li.strolch.runtime.agent.impl;
|
package li.strolch.runtime.agent.impl;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.query.ResourceQuery;
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.ResourceDao;
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.agent.api.ResourceMap;
|
import li.strolch.runtime.agent.api.ResourceMap;
|
||||||
|
|
||||||
public class TransactionalResourceMap extends TransactionalElementMap<Resource> implements ResourceMap {
|
public class TransactionalResourceMap extends TransactionalElementMap<Resource, ResourceQuery> implements ResourceMap {
|
||||||
|
|
||||||
public TransactionalResourceMap(String realm, PersistenceHandler persistenceHandler) {
|
public TransactionalResourceMap(String realm, PersistenceHandler persistenceHandler) {
|
||||||
super(realm, persistenceHandler);
|
super(realm, persistenceHandler);
|
||||||
|
|
|
@ -18,21 +18,15 @@ package li.strolch.runtime.query.inmemory;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class ListNavigator<T extends StrolchElement> implements Navigator<T> {
|
public class AnyNavigator<T extends StrolchElement> implements Navigator<T> {
|
||||||
|
|
||||||
private List<T> input;
|
|
||||||
|
|
||||||
public ListNavigator(List<T> input) {
|
|
||||||
this.input = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> navigate(StrolchTransaction tx) {
|
public List<T> navigate(StrolchDao<T> dao) {
|
||||||
return this.input;
|
return dao.queryAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,20 +21,20 @@ import li.strolch.model.query.OrderQuery;
|
||||||
import li.strolch.model.query.OrderQueryVisitor;
|
import li.strolch.model.query.OrderQueryVisitor;
|
||||||
import li.strolch.model.query.StateSelection;
|
import li.strolch.model.query.StateSelection;
|
||||||
import li.strolch.model.query.StrolchTypeNavigation;
|
import li.strolch.model.query.StrolchTypeNavigation;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
import li.strolch.persistence.api.OrderDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order> implements OrderQueryVisitor {
|
public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order, OrderDao> implements OrderQueryVisitor {
|
||||||
|
|
||||||
public InMemoryOrderQueryVisitor(ComponentContainer container) {
|
public InMemoryOrderQueryVisitor() {
|
||||||
super(container);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InMemoryQueryVisitor<Order> newInstance() {
|
protected InMemoryQueryVisitor<Order, OrderDao> newInstance() {
|
||||||
return new InMemoryOrderQueryVisitor(this.container);
|
return new InMemoryOrderQueryVisitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InMemoryQuery<Order> visit(OrderQuery orderQuery) {
|
public InMemoryQuery<Order> visit(OrderQuery orderQuery) {
|
||||||
|
@ -50,7 +50,7 @@ public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order> imple
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(StrolchTypeNavigation navigation) {
|
public void visit(StrolchTypeNavigation navigation) {
|
||||||
this.navigator = new OrderTypeNavigator(navigation.getType(), this.container);
|
this.navigator = new OrderTypeNavigator(navigation.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -51,9 +51,9 @@ public class InMemoryQuery<T extends StrolchElement> {
|
||||||
this.selectors.add(selector);
|
this.selectors.add(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> doQuery(StrolchTransaction tx) {
|
public List<T> doQuery(StrolchDao<T> dao) {
|
||||||
|
|
||||||
List<T> elements = this.navigator.navigate(tx);
|
List<T> elements = this.navigator.navigate(dao);
|
||||||
Iterator<T> iter = elements.iterator();
|
Iterator<T> iter = elements.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
T element = iter.next();
|
T element = iter.next();
|
||||||
|
@ -66,6 +66,7 @@ public class InMemoryQuery<T extends StrolchElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAccepted(T element) {
|
private boolean isAccepted(T element) {
|
||||||
|
|
||||||
for (Selector<T> selector : this.selectors) {
|
for (Selector<T> selector : this.selectors) {
|
||||||
if (!selector.select(element))
|
if (!selector.select(element))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -24,9 +24,6 @@ import li.strolch.model.query.BooleanSelection;
|
||||||
import li.strolch.model.query.IdSelection;
|
import li.strolch.model.query.IdSelection;
|
||||||
import li.strolch.model.query.NameSelection;
|
import li.strolch.model.query.NameSelection;
|
||||||
import li.strolch.model.query.OrSelection;
|
import li.strolch.model.query.OrSelection;
|
||||||
import li.strolch.model.query.ParameterSelectionVisitor;
|
|
||||||
import li.strolch.model.query.Selection;
|
|
||||||
import li.strolch.model.query.StrolchElementSelectionVisitor;
|
|
||||||
import li.strolch.model.query.ParameterSelection.BooleanParameterSelection;
|
import li.strolch.model.query.ParameterSelection.BooleanParameterSelection;
|
||||||
import li.strolch.model.query.ParameterSelection.DateParameterSelection;
|
import li.strolch.model.query.ParameterSelection.DateParameterSelection;
|
||||||
import li.strolch.model.query.ParameterSelection.FloatParameterSelection;
|
import li.strolch.model.query.ParameterSelection.FloatParameterSelection;
|
||||||
|
@ -34,20 +31,21 @@ import li.strolch.model.query.ParameterSelection.IntegerParameterSelection;
|
||||||
import li.strolch.model.query.ParameterSelection.LongParameterSelection;
|
import li.strolch.model.query.ParameterSelection.LongParameterSelection;
|
||||||
import li.strolch.model.query.ParameterSelection.StringListParameterSelection;
|
import li.strolch.model.query.ParameterSelection.StringListParameterSelection;
|
||||||
import li.strolch.model.query.ParameterSelection.StringParameterSelection;
|
import li.strolch.model.query.ParameterSelection.StringParameterSelection;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
import li.strolch.model.query.ParameterSelectionVisitor;
|
||||||
|
import li.strolch.model.query.Selection;
|
||||||
|
import li.strolch.model.query.StrolchElementSelectionVisitor;
|
||||||
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement> implements
|
public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement, S extends StrolchDao<?>> implements
|
||||||
StrolchElementSelectionVisitor, ParameterSelectionVisitor {
|
StrolchElementSelectionVisitor, ParameterSelectionVisitor {
|
||||||
|
|
||||||
protected ComponentContainer container;
|
|
||||||
protected Navigator<T> navigator;
|
protected Navigator<T> navigator;
|
||||||
protected List<Selector<T>> selectors;
|
protected List<Selector<T>> selectors;
|
||||||
|
|
||||||
public InMemoryQueryVisitor(ComponentContainer container) {
|
public InMemoryQueryVisitor() {
|
||||||
this.container = container;
|
|
||||||
this.selectors = new ArrayList<>();
|
this.selectors = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,11 +62,11 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
||||||
*
|
*
|
||||||
* @return a new instance of this concrete type
|
* @return a new instance of this concrete type
|
||||||
*/
|
*/
|
||||||
protected abstract InMemoryQueryVisitor<T> newInstance();
|
protected abstract InMemoryQueryVisitor<T, S> newInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends Selection> void visitAnd(AndSelection<U> andSelection) {
|
public <U extends Selection> void visitAnd(AndSelection<U> andSelection) {
|
||||||
InMemoryQueryVisitor<T> query = newInstance();
|
InMemoryQueryVisitor<T, S> query = newInstance();
|
||||||
List<U> selections = andSelection.getSelections();
|
List<U> selections = andSelection.getSelections();
|
||||||
for (U selection : selections) {
|
for (U selection : selections) {
|
||||||
selection.accept(query);
|
selection.accept(query);
|
||||||
|
@ -79,7 +77,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends Selection> void visitOr(OrSelection<U> orSelection) {
|
public <U extends Selection> void visitOr(OrSelection<U> orSelection) {
|
||||||
InMemoryQueryVisitor<T> query = newInstance();
|
InMemoryQueryVisitor<T, S> query = newInstance();
|
||||||
List<U> selections = orSelection.getSelections();
|
List<U> selections = orSelection.getSelections();
|
||||||
for (U selection : selections) {
|
for (U selection : selections) {
|
||||||
selection.accept(query);
|
selection.accept(query);
|
||||||
|
|
|
@ -15,34 +15,25 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.query.inmemory;
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.query.ResourceQuery;
|
import li.strolch.model.query.ResourceQuery;
|
||||||
import li.strolch.model.query.ResourceQueryVisitor;
|
import li.strolch.model.query.ResourceQueryVisitor;
|
||||||
import li.strolch.model.query.StrolchTypeNavigation;
|
import li.strolch.model.query.StrolchTypeNavigation;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource> implements ResourceQueryVisitor {
|
public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource, ResourceDao> implements
|
||||||
|
ResourceQueryVisitor {
|
||||||
|
|
||||||
private ComponentContainer container;
|
public InMemoryResourceQueryVisitor() {
|
||||||
|
super();
|
||||||
private Navigator<Resource> navigator;
|
|
||||||
private List<Selector<Resource>> selectors;
|
|
||||||
|
|
||||||
public InMemoryResourceQueryVisitor(ComponentContainer container) {
|
|
||||||
super(container);
|
|
||||||
this.container = container;
|
|
||||||
this.selectors = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InMemoryQueryVisitor<Resource> newInstance() {
|
protected InMemoryQueryVisitor<Resource, ResourceDao> newInstance() {
|
||||||
return new InMemoryResourceQueryVisitor(this.container);
|
return new InMemoryResourceQueryVisitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InMemoryQuery<Resource> visit(ResourceQuery resourceQuery) {
|
public InMemoryQuery<Resource> visit(ResourceQuery resourceQuery) {
|
||||||
|
@ -58,6 +49,6 @@ public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(StrolchTypeNavigation navigation) {
|
public void visit(StrolchTypeNavigation navigation) {
|
||||||
this.navigator = new ResourceTypeNavigator(navigation.getType(), this.container);
|
this.navigator = new ResourceTypeNavigator(navigation.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ package li.strolch.runtime.query.inmemory;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public interface Navigator<T extends StrolchElement> {
|
public interface Navigator<T extends StrolchElement> {
|
||||||
|
|
||||||
public List<T> navigate(StrolchTransaction tx);
|
public List<T> navigate(StrolchDao<T> dao);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,26 +16,16 @@
|
||||||
package li.strolch.runtime.query.inmemory;
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
|
||||||
import li.strolch.runtime.agent.api.ElementMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class OrderTypeNavigator extends StrolchTypeNavigator<Order> {
|
public class OrderTypeNavigator extends StrolchTypeNavigator<Order> {
|
||||||
|
|
||||||
private ComponentContainer container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public OrderTypeNavigator(String type, ComponentContainer container) {
|
public OrderTypeNavigator(String type) {
|
||||||
super(type);
|
super(type);
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ElementMap<Order> getElementMap() {
|
|
||||||
return this.container.getOrderMap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,26 +16,16 @@
|
||||||
package li.strolch.runtime.query.inmemory;
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
|
||||||
import li.strolch.runtime.agent.api.ElementMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class ResourceTypeNavigator extends StrolchTypeNavigator<Resource> {
|
public class ResourceTypeNavigator extends StrolchTypeNavigator<Resource> {
|
||||||
|
|
||||||
private ComponentContainer container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public ResourceTypeNavigator(String type, ComponentContainer container) {
|
public ResourceTypeNavigator(String type) {
|
||||||
super(type);
|
super(type);
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ElementMap<Resource> getElementMap() {
|
|
||||||
return this.container.getResourceMap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ package li.strolch.runtime.query.inmemory;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.StrolchElement;
|
import li.strolch.model.StrolchElement;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
import li.strolch.runtime.agent.api.ElementMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -33,9 +32,7 @@ public abstract class StrolchTypeNavigator<T extends StrolchElement> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> navigate(StrolchTransaction tx) {
|
public List<T> navigate(StrolchDao<T> dao) {
|
||||||
return getElementMap().getElementsBy(tx, this.type);
|
return dao.queryAll(this.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ElementMap<T> getElementMap();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,13 @@ import li.strolch.model.State;
|
||||||
import li.strolch.model.parameter.BooleanParameter;
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
import li.strolch.model.parameter.StringParameter;
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
import li.strolch.persistence.inmemory.InMemoryOrderDao;
|
||||||
|
import li.strolch.persistence.inmemory.InMemoryResourceDao;
|
||||||
import li.strolch.runtime.query.inmemory.AndSelector;
|
import li.strolch.runtime.query.inmemory.AndSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.AnyNavigator;
|
||||||
import li.strolch.runtime.query.inmemory.BooleanSelector;
|
import li.strolch.runtime.query.inmemory.BooleanSelector;
|
||||||
import li.strolch.runtime.query.inmemory.IdSelector;
|
import li.strolch.runtime.query.inmemory.IdSelector;
|
||||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||||
import li.strolch.runtime.query.inmemory.ListNavigator;
|
|
||||||
import li.strolch.runtime.query.inmemory.NameSelector;
|
import li.strolch.runtime.query.inmemory.NameSelector;
|
||||||
import li.strolch.runtime.query.inmemory.OrSelector;
|
import li.strolch.runtime.query.inmemory.OrSelector;
|
||||||
import li.strolch.runtime.query.inmemory.ParameterSelector;
|
import li.strolch.runtime.query.inmemory.ParameterSelector;
|
||||||
|
@ -52,12 +54,14 @@ public class InMemoryQueryTest {
|
||||||
public void shouldQueryOrderById() {
|
public void shouldQueryOrderById() {
|
||||||
|
|
||||||
List<Order> orders = getOrders();
|
List<Order> orders = getOrders();
|
||||||
|
InMemoryOrderDao dao = new InMemoryOrderDao();
|
||||||
|
dao.saveAll(orders);
|
||||||
|
|
||||||
InMemoryQuery<Order> orderQuery = new InMemoryQuery<>();
|
InMemoryQuery<Order> orderQuery = new InMemoryQuery<>();
|
||||||
orderQuery.setNavigator(new ListNavigator<>(orders));
|
orderQuery.setNavigator(new AnyNavigator<Order>());
|
||||||
orderQuery.addSelector(new IdSelector<Order>("@1"));
|
orderQuery.addSelector(new IdSelector<Order>("@1"));
|
||||||
|
|
||||||
List<Order> result = orderQuery.doQuery(null);
|
List<Order> result = orderQuery.doQuery(dao);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("@1", result.get(0).getId());
|
assertEquals("@1", result.get(0).getId());
|
||||||
}
|
}
|
||||||
|
@ -66,12 +70,14 @@ public class InMemoryQueryTest {
|
||||||
public void shouldQueryResourceById() {
|
public void shouldQueryResourceById() {
|
||||||
|
|
||||||
List<Resource> resources = getResources();
|
List<Resource> resources = getResources();
|
||||||
|
InMemoryResourceDao dao = new InMemoryResourceDao();
|
||||||
|
dao.saveAll(resources);
|
||||||
|
|
||||||
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
||||||
resourceQuery.setNavigator(new ListNavigator<>(resources));
|
resourceQuery.setNavigator(new AnyNavigator<Resource>());
|
||||||
resourceQuery.addSelector(new IdSelector<Resource>("@1"));
|
resourceQuery.addSelector(new IdSelector<Resource>("@1"));
|
||||||
|
|
||||||
List<Resource> result = resourceQuery.doQuery(null);
|
List<Resource> result = resourceQuery.doQuery(dao);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("@1", result.get(0).getId());
|
assertEquals("@1", result.get(0).getId());
|
||||||
}
|
}
|
||||||
|
@ -80,14 +86,16 @@ public class InMemoryQueryTest {
|
||||||
public void shouldQueryResourceByIdOr() {
|
public void shouldQueryResourceByIdOr() {
|
||||||
|
|
||||||
List<Resource> resources = getResources();
|
List<Resource> resources = getResources();
|
||||||
|
InMemoryResourceDao dao = new InMemoryResourceDao();
|
||||||
|
dao.saveAll(resources);
|
||||||
|
|
||||||
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
||||||
resourceQuery.setNavigator(new ListNavigator<>(resources));
|
resourceQuery.setNavigator(new AnyNavigator<Resource>());
|
||||||
BooleanSelector<Resource> andSelector = new OrSelector<>(new IdSelector<Resource>("@3"),
|
BooleanSelector<Resource> andSelector = new OrSelector<>(new IdSelector<Resource>("@3"),
|
||||||
new IdSelector<Resource>("@4"));
|
new IdSelector<Resource>("@4"));
|
||||||
resourceQuery.addSelector(andSelector);
|
resourceQuery.addSelector(andSelector);
|
||||||
|
|
||||||
List<Resource> result = resourceQuery.doQuery(null);
|
List<Resource> result = resourceQuery.doQuery(dao);
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals("@3", result.get(0).getId());
|
assertEquals("@3", result.get(0).getId());
|
||||||
assertEquals("@4", result.get(1).getId());
|
assertEquals("@4", result.get(1).getId());
|
||||||
|
@ -97,16 +105,18 @@ public class InMemoryQueryTest {
|
||||||
public void shouldQueryResourceByIdAnd() {
|
public void shouldQueryResourceByIdAnd() {
|
||||||
|
|
||||||
List<Resource> resources = getResources();
|
List<Resource> resources = getResources();
|
||||||
|
InMemoryResourceDao dao = new InMemoryResourceDao();
|
||||||
|
dao.saveAll(resources);
|
||||||
|
|
||||||
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
||||||
resourceQuery.setNavigator(new ListNavigator<>(resources));
|
resourceQuery.setNavigator(new AnyNavigator<Resource>());
|
||||||
List<Selector<Resource>> andSelectors = new ArrayList<>();
|
List<Selector<Resource>> andSelectors = new ArrayList<>();
|
||||||
andSelectors.add(new IdSelector<Resource>("@3"));
|
andSelectors.add(new IdSelector<Resource>("@3"));
|
||||||
andSelectors.add(new NameSelector<Resource>("Res 3"));
|
andSelectors.add(new NameSelector<Resource>("Res 3"));
|
||||||
BooleanSelector<Resource> andSelector = new AndSelector<Resource>(andSelectors);
|
BooleanSelector<Resource> andSelector = new AndSelector<Resource>(andSelectors);
|
||||||
resourceQuery.addSelector(andSelector);
|
resourceQuery.addSelector(andSelector);
|
||||||
|
|
||||||
List<Resource> result = resourceQuery.doQuery(null);
|
List<Resource> result = resourceQuery.doQuery(dao);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("@3", result.get(0).getId());
|
assertEquals("@3", result.get(0).getId());
|
||||||
}
|
}
|
||||||
|
@ -115,16 +125,18 @@ public class InMemoryQueryTest {
|
||||||
public void shouldNotQueryResourceByIdAnd() {
|
public void shouldNotQueryResourceByIdAnd() {
|
||||||
|
|
||||||
List<Resource> resources = getResources();
|
List<Resource> resources = getResources();
|
||||||
|
InMemoryResourceDao dao = new InMemoryResourceDao();
|
||||||
|
dao.saveAll(resources);
|
||||||
|
|
||||||
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
InMemoryQuery<Resource> resourceQuery = new InMemoryQuery<>();
|
||||||
resourceQuery.setNavigator(new ListNavigator<>(resources));
|
resourceQuery.setNavigator(new AnyNavigator<Resource>());
|
||||||
List<Selector<Resource>> andSelectors = new ArrayList<>();
|
List<Selector<Resource>> andSelectors = new ArrayList<>();
|
||||||
andSelectors.add(new IdSelector<Resource>("@3"));
|
andSelectors.add(new IdSelector<Resource>("@3"));
|
||||||
andSelectors.add(new NameSelector<Resource>("Res 4"));
|
andSelectors.add(new NameSelector<Resource>("Res 4"));
|
||||||
BooleanSelector<Resource> andSelector = new AndSelector<Resource>(andSelectors);
|
BooleanSelector<Resource> andSelector = new AndSelector<Resource>(andSelectors);
|
||||||
resourceQuery.addSelector(andSelector);
|
resourceQuery.addSelector(andSelector);
|
||||||
|
|
||||||
List<Resource> result = resourceQuery.doQuery(null);
|
List<Resource> result = resourceQuery.doQuery(dao);
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,14 +145,16 @@ public class InMemoryQueryTest {
|
||||||
|
|
||||||
List<Resource> resources = getResources();
|
List<Resource> resources = getResources();
|
||||||
resources.add(getBallResource());
|
resources.add(getBallResource());
|
||||||
|
InMemoryResourceDao dao = new InMemoryResourceDao();
|
||||||
|
dao.saveAll(resources);
|
||||||
|
|
||||||
InMemoryQuery<Resource> ballQuery = new InMemoryQuery<>();
|
InMemoryQuery<Resource> ballQuery = new InMemoryQuery<>();
|
||||||
ballQuery.setNavigator(new ListNavigator<>(resources));
|
ballQuery.setNavigator(new AnyNavigator<Resource>());
|
||||||
ballQuery.addSelector(ParameterSelector.<Resource> stringSelector("parameters", "color", "red"));
|
ballQuery.addSelector(ParameterSelector.<Resource> stringSelector("parameters", "color", "red"));
|
||||||
ballQuery.addSelector(ParameterSelector.<Resource> booleanSelector("parameters", "forChildren", true));
|
ballQuery.addSelector(ParameterSelector.<Resource> booleanSelector("parameters", "forChildren", true));
|
||||||
ballQuery.addSelector(ParameterSelector.<Resource> floatSelector("parameters", "diameter", 22.0));
|
ballQuery.addSelector(ParameterSelector.<Resource> floatSelector("parameters", "diameter", 22.0));
|
||||||
|
|
||||||
List<Resource> result = ballQuery.doQuery(null);
|
List<Resource> result = ballQuery.doQuery(dao);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,11 @@ public class QueryTest {
|
||||||
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
|
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
|
||||||
query.addSelection(andSelection);
|
query.addSelection(andSelection);
|
||||||
|
|
||||||
InMemoryResourceQueryVisitor resourceQuery = new InMemoryResourceQueryVisitor(agent.getContainer());
|
InMemoryResourceQueryVisitor resourceQuery = new InMemoryResourceQueryVisitor();
|
||||||
InMemoryQuery<Resource> inMemoryQuery = resourceQuery.visit(query);
|
InMemoryQuery<Resource> inMemoryQuery = resourceQuery.visit(query);
|
||||||
List<Resource> result;
|
List<Resource> result;
|
||||||
try (StrolchTransaction tx = resourceMap.openTx()) {
|
try (StrolchTransaction tx = resourceMap.openTx()) {
|
||||||
result = inMemoryQuery.doQuery(tx);
|
result = inMemoryQuery.doQuery(tx.getResourceDao());
|
||||||
}
|
}
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("@1", result.get(0).getId());
|
assertEquals("@1", result.get(0).getId());
|
||||||
|
@ -103,11 +103,11 @@ public class QueryTest {
|
||||||
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType"));
|
OrderQuery query = new OrderQuery(new StrolchTypeNavigation("MyType"));
|
||||||
query.addSelection(andSelection);
|
query.addSelection(andSelection);
|
||||||
|
|
||||||
InMemoryOrderQueryVisitor orderQuery = new InMemoryOrderQueryVisitor(agent.getContainer());
|
InMemoryOrderQueryVisitor orderQuery = new InMemoryOrderQueryVisitor();
|
||||||
InMemoryQuery<Order> inMemoryQuery = orderQuery.visit(query);
|
InMemoryQuery<Order> inMemoryQuery = orderQuery.visit(query);
|
||||||
List<Order> result;
|
List<Order> result;
|
||||||
try (StrolchTransaction tx = orderMap.openTx()) {
|
try (StrolchTransaction tx = orderMap.openTx()) {
|
||||||
result = inMemoryQuery.doQuery(tx);
|
result = inMemoryQuery.doQuery(tx.getOrderDao());
|
||||||
}
|
}
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals("@1", result.get(0).getId());
|
assertEquals("@1", result.get(0).getId());
|
||||||
|
|
Loading…
Reference in New Issue