[Devel] Query engine transparent to the underlying implementation
Currently querying in memory works, now we need the visitor pattern to abstract away the details of the in memory querying mechanism and allow other querying mechanisms
This commit is contained in:
parent
925a25657a
commit
9bea101c9d
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AndSelection extends BooleanSelection {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param selections
|
||||||
|
*/
|
||||||
|
public AndSelection(List<Selection<QueryVisitor>> selections) {
|
||||||
|
super(selections);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AndSelection(Selection<QueryVisitor> leftHandSide, Selection<QueryVisitor> rightHandSide) {
|
||||||
|
super(leftHandSide, rightHandSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(QueryVisitor visitor) {
|
||||||
|
visitor.visitAnd(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BooleanSelection implements Selection<QueryVisitor> {
|
||||||
|
|
||||||
|
protected List<Selection<QueryVisitor>> selections;
|
||||||
|
|
||||||
|
public BooleanSelection(Selection<QueryVisitor> leftHandSide, Selection<QueryVisitor> rightHandSide) {
|
||||||
|
this.selections = new ArrayList<>();
|
||||||
|
this.selections.add(leftHandSide);
|
||||||
|
this.selections.add(rightHandSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanSelection(List<Selection<QueryVisitor>> selections) {
|
||||||
|
this.selections = selections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Selection<QueryVisitor>> getSelections() {
|
||||||
|
return this.selections;
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,37 +19,33 @@
|
||||||
* along with XXX. If not, see
|
* along with XXX. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.query.inmemory;
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
import li.strolch.runtime.component.ComponentContainer;
|
|
||||||
import li.strolch.runtime.query.ResourceQuery;
|
|
||||||
import li.strolch.runtime.query.ResourceQueryVisitor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InMemoryResourceQueryVisitor implements ResourceQueryVisitor {
|
public class ElementQuery implements Query<StrolchElementVisitor> {
|
||||||
|
|
||||||
private ArrayList<Resource> result;
|
private Navigation<QueryVisitor> navigation;
|
||||||
|
private List<Selection<QueryVisitor>> selections;
|
||||||
|
|
||||||
public List<Resource> performQuery(ComponentContainer container, ResourceQuery query) {
|
public ElementQuery(Navigation<QueryVisitor> navigation) {
|
||||||
this.result = new ArrayList<>();
|
this.selections = new ArrayList<>();
|
||||||
|
|
||||||
query.accept(this);
|
|
||||||
|
|
||||||
return this.result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ResourceQuery resourceQuery) {
|
public void visit(StrolchElementVisitor queryVisitor) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
this.navigation.accept(queryVisitor);
|
||||||
|
|
||||||
|
for (Selection<QueryVisitor> selection : this.selections) {
|
||||||
|
selection.accept(queryVisitor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class IdSelection implements Selection<StrolchElementVisitor> {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public IdSelection(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StrolchElementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NameSelection implements Selection<StrolchElementVisitor> {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public NameSelection(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StrolchElementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,9 +25,7 @@ package li.strolch.runtime.query;
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ByElementSelection {
|
public interface Navigation<T extends QueryVisitor> {
|
||||||
|
|
||||||
private String id;
|
public void accept(T visitor);
|
||||||
private String name;
|
|
||||||
private String type;
|
|
||||||
}
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class OrSelection extends BooleanSelection {
|
||||||
|
|
||||||
|
public OrSelection(List<Selection<QueryVisitor>> selections) {
|
||||||
|
super(selections);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrSelection(Selection<QueryVisitor> leftHandSide, Selection<QueryVisitor> rightHandSide) {
|
||||||
|
super(leftHandSide, rightHandSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(QueryVisitor visitor) {
|
||||||
|
visitor.visitOr(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class OrderTypeNavigation extends StrolchTypeNavigation<StrolchElementVisitor> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
OrderTypeNavigation(String type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StrolchElementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface Query<T extends QueryVisitor> {
|
||||||
|
|
||||||
|
public void visit(T queryVisitor);
|
||||||
|
}
|
|
@ -21,22 +21,14 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.query;
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ResourceQuery {
|
public interface QueryVisitor {
|
||||||
|
|
||||||
|
public void visitAnd(AndSelection andSelection);
|
||||||
|
|
||||||
private String byType;
|
public void visitOr(OrSelection orSelection);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void accept(ResourceQueryVisitor visitor) {
|
|
||||||
visitor.visit(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResourceTypeNavigation extends StrolchTypeNavigation<StrolchElementVisitor>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
ResourceTypeNavigation(String type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StrolchElementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ package li.strolch.runtime.query;
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface ResourceQueryVisitor {
|
public interface Selection<T extends QueryVisitor> {
|
||||||
|
|
||||||
public void visit(ResourceQuery query);
|
public void accept(T visitor);
|
||||||
}
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StrolchElementSelection {
|
||||||
|
|
||||||
|
private List<Selection<StrolchElementVisitor>> selections;
|
||||||
|
|
||||||
|
public StrolchElementSelection() {
|
||||||
|
this.selections = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSelection(Selection<StrolchElementVisitor> selection) {
|
||||||
|
this.selections.add(selection);
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,18 +21,17 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.query;
|
package li.strolch.runtime.query;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TypeSelection {
|
public abstract class StrolchTypeNavigation<T extends StrolchElementVisitor> implements Navigation<T> {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/**
|
StrolchTypeNavigation(String type) {
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
public TypeSelection(String type) {
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.runtime.query.AndSelection;
|
||||||
|
import li.strolch.runtime.query.BooleanSelection;
|
||||||
|
import li.strolch.runtime.query.OrSelection;
|
||||||
|
import li.strolch.runtime.query.QueryVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BooleanVisitor<T extends StrolchElement> implements QueryVisitor {
|
||||||
|
|
||||||
|
private List<Selector<T>> selectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param selectors
|
||||||
|
*/
|
||||||
|
public BooleanVisitor(List<Selector<T>> selectors) {
|
||||||
|
this.selectors = selectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param selection
|
||||||
|
*/
|
||||||
|
public void visit(BooleanSelection selection) {
|
||||||
|
selection.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitAnd(AndSelection selection) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitOr(OrSelection selection) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.runtime.component.ComponentContainer;
|
||||||
|
import li.strolch.runtime.query.AndSelection;
|
||||||
|
import li.strolch.runtime.query.ElementQuery;
|
||||||
|
import li.strolch.runtime.query.IdSelection;
|
||||||
|
import li.strolch.runtime.query.NameSelection;
|
||||||
|
import li.strolch.runtime.query.OrSelection;
|
||||||
|
import li.strolch.runtime.query.OrderTypeNavigation;
|
||||||
|
import li.strolch.runtime.query.QueryVisitor;
|
||||||
|
import li.strolch.runtime.query.ResourceTypeNavigation;
|
||||||
|
import li.strolch.runtime.query.Selection;
|
||||||
|
import li.strolch.runtime.query.visitor.StrolchElementVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class InMemoryQueryVisitor<T extends StrolchElement> implements StrolchElementVisitor {
|
||||||
|
|
||||||
|
private Navigator<T> navigator;
|
||||||
|
private List<Selector<T>> selectors;
|
||||||
|
private ComponentContainer container;
|
||||||
|
|
||||||
|
public InMemoryQueryVisitor(ComponentContainer container) {
|
||||||
|
this.container = container;
|
||||||
|
this.selectors = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the navigator
|
||||||
|
*/
|
||||||
|
public Navigator<T> getNavigator() {
|
||||||
|
return this.navigator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the selectors
|
||||||
|
*/
|
||||||
|
public List<Selector<T>> getSelectors() {
|
||||||
|
return this.selectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visit(ElementQuery query) {
|
||||||
|
query.visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitAnd(AndSelection andSelection) {
|
||||||
|
InMemoryQueryVisitor<T> visitor = new InMemoryQueryVisitor<>(this.container);
|
||||||
|
List<Selection<QueryVisitor>> selections = andSelection.getSelections();
|
||||||
|
for (Selection<QueryVisitor> selection : selections) {
|
||||||
|
selection.accept(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
AndSelector<T> andSelector = new AndSelector<>(visitor.getSelectors());
|
||||||
|
this.selectors.add(andSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitOr(OrSelection orSelection) {
|
||||||
|
InMemoryQueryVisitor<T> visitor = new InMemoryQueryVisitor<>(this.container);
|
||||||
|
List<Selection<QueryVisitor>> selections = orSelection.getSelections();
|
||||||
|
for (Selection<QueryVisitor> selection : selections) {
|
||||||
|
selection.accept(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
OrSelector<T> andSelector = new OrSelector<>(visitor.getSelectors());
|
||||||
|
this.selectors.add(andSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(IdSelection selection) {
|
||||||
|
this.selectors.add(new IdSelector<T>(selection.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(NameSelection selection) {
|
||||||
|
this.selectors.add(new NameSelector<T>(selection.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void visit(OrderTypeNavigation navigation) {
|
||||||
|
this.navigator = (Navigator<T>) new OrderTypeNavigator(navigation.getType(), this.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void visit(ResourceTypeNavigation navigation) {
|
||||||
|
// XXX not good... class should be parameterized, but then there is no sense in ResourceType... but then one would need the ElementMap passed in...
|
||||||
|
this.navigator = (Navigator<T>) new ResourceTypeNavigator(navigation.getType(), this.container);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,6 @@ import li.strolch.runtime.component.ComponentContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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> {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query.inmemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StrolchTypeNavigationVisitor {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.runtime.query.visitor;
|
||||||
|
|
||||||
|
import li.strolch.runtime.query.IdSelection;
|
||||||
|
import li.strolch.runtime.query.NameSelection;
|
||||||
|
import li.strolch.runtime.query.OrderTypeNavigation;
|
||||||
|
import li.strolch.runtime.query.QueryVisitor;
|
||||||
|
import li.strolch.runtime.query.ResourceTypeNavigation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface StrolchElementVisitor extends QueryVisitor {
|
||||||
|
|
||||||
|
public void visit(IdSelection selection);
|
||||||
|
|
||||||
|
public void visit(NameSelection selection);
|
||||||
|
|
||||||
|
public void visit(OrderTypeNavigation navigation);
|
||||||
|
|
||||||
|
public void visit(ResourceTypeNavigation navigation);
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -8,9 +8,6 @@ import java.io.File;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.runtime.agent.StrolchAgent;
|
import li.strolch.runtime.agent.StrolchAgent;
|
||||||
import li.strolch.runtime.component.ComponentContainer;
|
import li.strolch.runtime.component.ComponentContainer;
|
||||||
import li.strolch.runtime.test.PersistenceHandlerTest;
|
|
||||||
import li.strolch.runtime.test.ServiceHandlerTest;
|
|
||||||
import li.strolch.runtime.test.ServiceResultTest;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.runtime.component.ComponentContainer;
|
import li.strolch.runtime.component.ComponentContainer;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
public interface PostInitializerTest {
|
public interface PostInitializerTest {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import li.strolch.runtime.component.ComponentContainer;
|
import li.strolch.runtime.component.ComponentContainer;
|
||||||
import li.strolch.runtime.component.StrolchComponent;
|
import li.strolch.runtime.component.StrolchComponent;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
public interface ServiceHandlerTest {
|
public interface ServiceHandlerTest {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import li.strolch.runtime.component.ComponentContainer;
|
import li.strolch.runtime.component.ComponentContainer;
|
||||||
import li.strolch.runtime.component.StrolchComponent;
|
import li.strolch.runtime.component.StrolchComponent;
|
|
@ -1,4 +1,4 @@
|
||||||
package li.strolch.runtime.test;
|
package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
public class ServiceResultTest {
|
public class ServiceResultTest {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* along with li.strolch.model. If not, see
|
* along with li.strolch.model. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime;
|
package li.strolch.runtime.test.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
|
@ -19,7 +19,7 @@
|
||||||
* along with XXX. If not, see
|
* along with XXX. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime;
|
package li.strolch.runtime.test.query;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -35,11 +35,7 @@ public class QueryTest {
|
||||||
@Ignore
|
@Ignore
|
||||||
public void shouldQueryResourceWithParamValue() {
|
public void shouldQueryResourceWithParamValue() {
|
||||||
|
|
||||||
// ResourceQuery resQuery = new ResourceQuery();
|
|
||||||
// resQuery.with(new TypeMatcher("MyType"));
|
|
||||||
// resQuery.with(new ParameterBagMatcher("Bla").with(ParameterMatcher.stringValue("color", "red")));
|
|
||||||
//
|
//
|
||||||
// List<Resource> result = resQuery.doQuery();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
* along with XXX. If not, see
|
* along with XXX. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package li.strolch.runtime.query.inmemory;
|
package li.strolch.runtime.test.query.inmemory;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -35,7 +35,17 @@ 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.runtime.ModelBuilder;
|
import li.strolch.runtime.query.inmemory.AndSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.BooleanSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.IdSelector;
|
||||||
|
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.OrSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.ParameterSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.ParameterizedElementSelector;
|
||||||
|
import li.strolch.runtime.query.inmemory.Selector;
|
||||||
|
import li.strolch.runtime.test.query.ModelBuilder;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
Loading…
Reference in New Issue