[Major] Refactored object hierarchy and added version to objects
- New ParameterBagContainer interface for GroupedParameterizedElement - StrolchRootElement extends ParameterBagContainer - StrolchRootElement is now required in Queries, not StrolchElement - New Version object on StrolchRootElement
This commit is contained in:
parent
47df6b20c7
commit
0703103d3b
|
@ -49,6 +49,7 @@ import li.strolch.model.Resource;
|
|||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.audit.AccessType;
|
||||
import li.strolch.model.audit.Audit;
|
||||
|
@ -85,6 +86,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
private boolean suppressUpdates;
|
||||
private boolean suppressAudits;
|
||||
private boolean suppressDoNothingLogging;
|
||||
private boolean versioningEnabled;
|
||||
private TransactionResult txResult;
|
||||
|
||||
private List<Command> commands;
|
||||
|
@ -209,6 +211,16 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return this.suppressAudits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVersioningEnabled(boolean versioningEnabled) {
|
||||
this.versioningEnabled = versioningEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVersioningEnabled() {
|
||||
return this.versioningEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressDoNothingLogging() {
|
||||
return suppressDoNothingLogging;
|
||||
|
@ -904,6 +916,15 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return audit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVersionFor(StrolchRootElement element, boolean deleted) {
|
||||
if (this.versioningEnabled) {
|
||||
int v = element.getVersion() == null ? 0 : element.getVersion().getVersion() + 1;
|
||||
Version version = new Version(element.getLocator(), v, this.certificate.getUsername(), deleted);
|
||||
element.setVersion(version);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link Command#validate()} on all registered command. This is done before we perform any commands and thus
|
||||
* no rollback needs be done due to invalid input for a command
|
||||
|
|
|
@ -18,12 +18,12 @@ package li.strolch.persistence.api;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface StrolchDao<T extends StrolchElement> {
|
||||
public interface StrolchDao<T extends StrolchRootElement> {
|
||||
|
||||
public Set<String> queryKeySet();
|
||||
|
||||
|
|
|
@ -279,6 +279,19 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*/
|
||||
public boolean isSuppressAudits();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param versioningEnabled
|
||||
*/
|
||||
public void setVersioningEnabled(boolean versioningEnabled);
|
||||
|
||||
/**
|
||||
* Returns true if versioning of objects is enabled
|
||||
*
|
||||
* @return true if versioning of objects is enabled
|
||||
*/
|
||||
public boolean isVersioningEnabled();
|
||||
|
||||
/**
|
||||
* If the given argument is true, then logging of a {@link TransactionCloseStrategy#DO_NOTHING} will be suppressed
|
||||
*
|
||||
|
@ -363,6 +376,21 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*/
|
||||
public Audit auditFrom(AccessType accessType, StrolchRootElement element);
|
||||
|
||||
/**
|
||||
* Creates a new version for the given element. If the element has no version yet, then the result will be version
|
||||
* 0, otherwise the version will be an increment to the current version
|
||||
*
|
||||
* @param element
|
||||
* the element for which to create a new version
|
||||
* @param deleted
|
||||
* if true, then the version will be marked as deleted, i.e. this object was removed from the element
|
||||
* maps
|
||||
*
|
||||
* @return the new version, which is either an increment of the existing version on the element, or it will be
|
||||
* version 0
|
||||
*/
|
||||
public void updateVersionFor(StrolchRootElement element, boolean deleted);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Performs the given {@link OrderQuery} and each returned {@link Order} is passed through the {@link OrderVisitor}
|
||||
|
|
|
@ -23,11 +23,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
|
||||
public class InMemoryDao<T extends StrolchElement> implements StrolchDao<T> {
|
||||
public class InMemoryDao<T extends StrolchRootElement> implements StrolchDao<T> {
|
||||
|
||||
private Map<String, Map<String, T>> elementMap;
|
||||
|
||||
|
|
|
@ -22,21 +22,19 @@ import li.strolch.model.activity.Activity;
|
|||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.ActivityQueryVisitor;
|
||||
import li.strolch.model.query.StrolchTypeNavigation;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor<Activity, ActivityDao> implements
|
||||
ActivityQueryVisitor {
|
||||
public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor<Activity> implements ActivityQueryVisitor {
|
||||
|
||||
public InMemoryActivityQueryVisitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InMemoryQueryVisitor<Activity, ActivityDao> newInstance() {
|
||||
protected InMemoryQueryVisitor<Activity> newInstance() {
|
||||
return new InMemoryActivityQueryVisitor();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,20 +24,19 @@ import li.strolch.model.query.OrderQuery;
|
|||
import li.strolch.model.query.OrderQueryVisitor;
|
||||
import li.strolch.model.query.StateSelection;
|
||||
import li.strolch.model.query.StrolchTypeNavigation;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order, OrderDao> implements OrderQueryVisitor {
|
||||
public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order> implements OrderQueryVisitor {
|
||||
|
||||
public InMemoryOrderQueryVisitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InMemoryQueryVisitor<Order, OrderDao> newInstance() {
|
||||
protected InMemoryQueryVisitor<Order> newInstance() {
|
||||
return new InMemoryOrderQueryVisitor();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Comparator;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -29,7 +29,7 @@ import li.strolch.utils.dbc.DBC;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryQuery<T extends StrolchElement, U> {
|
||||
public class InMemoryQuery<T extends StrolchRootElement, U> {
|
||||
|
||||
private Navigator<T> navigator;
|
||||
private Selector<T> selector;
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.query.AndSelection;
|
||||
import li.strolch.model.query.BooleanSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
|
@ -50,7 +50,6 @@ import li.strolch.model.query.ordering.OrderById;
|
|||
import li.strolch.model.query.ordering.OrderByName;
|
||||
import li.strolch.model.query.ordering.OrderByParameter;
|
||||
import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.runtime.query.inmemory.ParameterBagSelector.NullParameterBagSelector;
|
||||
import li.strolch.runtime.query.inmemory.ParameterSelector.StringParameterSelector;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -58,11 +57,11 @@ import li.strolch.utils.dbc.DBC;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement, S extends StrolchDao<?>>
|
||||
public abstract class InMemoryQueryVisitor<T extends StrolchRootElement>
|
||||
implements StrolchRootElementSelectionVisitor, ParameterSelectionVisitor, StrolchQueryOrderingVisitor {
|
||||
|
||||
private Comparator<T> comparator;
|
||||
private Navigator<T> navigator;
|
||||
private Comparator<T> comparator;
|
||||
private List<Selector<T>> selectors;
|
||||
private boolean any;
|
||||
|
||||
|
@ -94,7 +93,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
|||
*
|
||||
* @return a new instance of this concrete type
|
||||
*/
|
||||
protected abstract InMemoryQueryVisitor<T, S> newInstance();
|
||||
protected abstract InMemoryQueryVisitor<T> newInstance();
|
||||
|
||||
private void assertNotAny() {
|
||||
DBC.INTERIM.assertFalse("Not allowed to use further Selections with Any!", this.any); //$NON-NLS-1$
|
||||
|
@ -115,7 +114,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
|||
@Override
|
||||
public void visitAnd(AndSelection andSelection) {
|
||||
assertNotAny();
|
||||
InMemoryQueryVisitor<T, S> query = newInstance();
|
||||
InMemoryQueryVisitor<T> query = newInstance();
|
||||
List<Selection> selections = andSelection.getSelections();
|
||||
for (Selection selection : selections) {
|
||||
selection.accept(query);
|
||||
|
@ -127,7 +126,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
|||
@Override
|
||||
public void visitOr(OrSelection orSelection) {
|
||||
assertNotAny();
|
||||
InMemoryQueryVisitor<T, S> query = newInstance();
|
||||
InMemoryQueryVisitor<T> query = newInstance();
|
||||
List<Selection> selections = orSelection.getSelections();
|
||||
for (Selection selection : selections) {
|
||||
selection.accept(query);
|
||||
|
@ -139,7 +138,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
|||
@Override
|
||||
public void visitNot(NotSelection notSelection) {
|
||||
assertNotAny();
|
||||
InMemoryQueryVisitor<T, S> query = newInstance();
|
||||
InMemoryQueryVisitor<T> query = newInstance();
|
||||
List<Selection> selections = notSelection.getSelections();
|
||||
for (Selection selection : selections) {
|
||||
selection.accept(query);
|
||||
|
@ -261,19 +260,19 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
|
|||
}
|
||||
|
||||
@Override
|
||||
public InMemoryQueryVisitor<T, S> visit(OrderById ordering) {
|
||||
public InMemoryQueryVisitor<T> visit(OrderById ordering) {
|
||||
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InMemoryQueryVisitor<T, S> visit(OrderByName ordering) {
|
||||
public InMemoryQueryVisitor<T> visit(OrderByName ordering) {
|
||||
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InMemoryQueryVisitor<T, S> visit(OrderByParameter ordering) {
|
||||
public InMemoryQueryVisitor<T> visit(OrderByParameter ordering) {
|
||||
this.comparator = new InMemoryStrolchQueryOrderingVisitor<T>().visit(ordering).getComparator();
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -22,21 +22,20 @@ import li.strolch.model.ResourceVisitor;
|
|||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.query.ResourceQueryVisitor;
|
||||
import li.strolch.model.query.StrolchTypeNavigation;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource, ResourceDao> implements
|
||||
ResourceQueryVisitor {
|
||||
public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource>
|
||||
implements ResourceQueryVisitor {
|
||||
|
||||
public InMemoryResourceQueryVisitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InMemoryQueryVisitor<Resource, ResourceDao> newInstance() {
|
||||
protected InMemoryQueryVisitor<Resource> newInstance() {
|
||||
return new InMemoryResourceQueryVisitor();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.query.ordering.ByIdComparator;
|
||||
import li.strolch.model.query.ordering.ByNameComparator;
|
||||
import li.strolch.model.query.ordering.ByParamComparator;
|
||||
|
@ -29,8 +29,7 @@ import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryStrolchQueryOrderingVisitor<T extends GroupedParameterizedElement> implements
|
||||
StrolchQueryOrderingVisitor {
|
||||
public class InMemoryStrolchQueryOrderingVisitor<T extends StrolchRootElement> implements StrolchQueryOrderingVisitor {
|
||||
|
||||
private Comparator<T> comparator;
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface Navigator<T extends StrolchElement> {
|
||||
public interface Navigator<T extends StrolchRootElement> {
|
||||
|
||||
public List<T> navigate(StrolchDao<T> dao);
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ParameterBagSelector<T extends GroupedParameterizedElement> implements Selector<T> {
|
||||
public class ParameterBagSelector<T extends StrolchRootElement> implements Selector<T> {
|
||||
|
||||
protected String bagKey;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ParameterBagSelector<T extends GroupedParameterizedElement> impleme
|
|||
return element.hasParameterBag(this.bagKey);
|
||||
}
|
||||
|
||||
public static class NullParameterBagSelector<T extends GroupedParameterizedElement> extends ParameterBagSelector<T> {
|
||||
public static class NullParameterBagSelector<T extends StrolchRootElement> extends ParameterBagSelector<T> {
|
||||
|
||||
public NullParameterBagSelector(String bagKey) {
|
||||
super(bagKey);
|
||||
|
|
|
@ -18,8 +18,8 @@ package li.strolch.runtime.query.inmemory;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.ParameterBagContainer;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
import li.strolch.model.parameter.DateParameter;
|
||||
import li.strolch.model.parameter.DurationParameter;
|
||||
|
@ -35,7 +35,7 @@ import li.strolch.utils.collections.DateRange;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class ParameterSelector<T extends GroupedParameterizedElement> implements Selector<T> {
|
||||
public abstract class ParameterSelector<T extends ParameterBagContainer> implements Selector<T> {
|
||||
|
||||
protected String bagKey;
|
||||
protected String paramKey;
|
||||
|
@ -46,79 +46,79 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean select(GroupedParameterizedElement element);
|
||||
public abstract boolean select(ParameterBagContainer element);
|
||||
|
||||
public static <T extends GroupedParameterizedElement> StringParameterSelector<T> stringSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> StringParameterSelector<T> stringSelector(String bagKey,
|
||||
String paramKey, String value, StringMatchMode matchMode) {
|
||||
return new StringParameterSelector<>(bagKey, paramKey, value, matchMode);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> IntegerParameterSelector<T> integerSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> IntegerParameterSelector<T> integerSelector(String bagKey,
|
||||
String paramKey, int value) {
|
||||
return new IntegerParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> BooleanParameterSelector<T> booleanSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> BooleanParameterSelector<T> booleanSelector(String bagKey,
|
||||
String paramKey, boolean value) {
|
||||
return new BooleanParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> FloatParameterSelector<T> floatSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> FloatParameterSelector<T> floatSelector(String bagKey,
|
||||
String paramKey, double value) {
|
||||
return new FloatParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> LongParameterSelector<T> longSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> LongParameterSelector<T> longSelector(String bagKey,
|
||||
String paramKey, long value) {
|
||||
return new LongParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> DateParameterSelector<T> dateSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> DateParameterSelector<T> dateSelector(String bagKey,
|
||||
String paramKey, Date value) {
|
||||
return new DateParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> DurationParameterSelector<T> durationSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> DurationParameterSelector<T> durationSelector(String bagKey,
|
||||
String paramKey, Long value) {
|
||||
return new DurationParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> DateRangeParameterSelector<T> dateRangeSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> DateRangeParameterSelector<T> dateRangeSelector(String bagKey,
|
||||
String paramKey, DateRange dateRange) {
|
||||
return new DateRangeParameterSelector<>(bagKey, paramKey, dateRange);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> StringListParameterSelector<T> stringListSelector(
|
||||
String bagKey, String paramKey, List<String> value) {
|
||||
public static <T extends ParameterBagContainer> StringListParameterSelector<T> stringListSelector(String bagKey,
|
||||
String paramKey, List<String> value) {
|
||||
return new StringListParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> IntegerListParameterSelector<T> integerListSelector(
|
||||
String bagKey, String paramKey, List<Integer> value) {
|
||||
public static <T extends ParameterBagContainer> IntegerListParameterSelector<T> integerListSelector(String bagKey,
|
||||
String paramKey, List<Integer> value) {
|
||||
return new IntegerListParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> FloatListParameterSelector<T> floatListSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> FloatListParameterSelector<T> floatListSelector(String bagKey,
|
||||
String paramKey, List<Double> value) {
|
||||
return new FloatListParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> LongListParameterSelector<T> longListSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> LongListParameterSelector<T> longListSelector(String bagKey,
|
||||
String paramKey, List<Long> value) {
|
||||
return new LongListParameterSelector<>(bagKey, paramKey, value);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> NullParameterSelector<T> nullSelector(String bagKey,
|
||||
public static <T extends ParameterBagContainer> NullParameterSelector<T> nullSelector(String bagKey,
|
||||
String paramKey) {
|
||||
return new NullParameterSelector<>(bagKey, paramKey);
|
||||
}
|
||||
|
||||
public static <T extends GroupedParameterizedElement> AnyTypeParameterSelector<T> anyTypeSelection(String bagKey,
|
||||
public static <T extends ParameterBagContainer> AnyTypeParameterSelector<T> anyTypeSelection(String bagKey,
|
||||
String paramKey, String value, StringMatchMode matchMode) {
|
||||
return new AnyTypeParameterSelector<>(bagKey, paramKey, value, matchMode);
|
||||
}
|
||||
|
||||
public static class AnyTypeParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class AnyTypeParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private StringMatchMode matchMode;
|
||||
private String value;
|
||||
|
@ -130,7 +130,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
|
||||
ParameterBag bag = element.getParameterBag(this.bagKey);
|
||||
if (bag == null) {
|
||||
|
@ -146,14 +146,14 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class NullParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class NullParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
public NullParameterSelector(String bagKey, String key) {
|
||||
super(bagKey, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
|
||||
ParameterBag bag = element.getParameterBag(this.bagKey);
|
||||
if (bag == null) {
|
||||
|
@ -164,7 +164,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class StringParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class StringParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private StringMatchMode matchMode;
|
||||
private String value;
|
||||
|
@ -180,7 +180,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
@ -196,7 +196,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class IntegerParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class IntegerParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Integer value;
|
||||
|
||||
|
@ -206,7 +206,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -219,7 +219,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class BooleanParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class BooleanParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Boolean value;
|
||||
|
||||
|
@ -229,7 +229,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -242,7 +242,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class FloatParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class FloatParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Double value;
|
||||
|
||||
|
@ -252,7 +252,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -265,7 +265,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class LongParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class LongParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Long value;
|
||||
|
||||
|
@ -275,7 +275,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -288,7 +288,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class DateParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class DateParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Date value;
|
||||
|
||||
|
@ -298,7 +298,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -311,7 +311,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class DateRangeParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class DateRangeParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private DateRange dateRange;
|
||||
|
||||
|
@ -321,7 +321,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -336,7 +336,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class DurationParameterSelector<T extends GroupedParameterizedElement> extends ParameterSelector<T> {
|
||||
public static class DurationParameterSelector<T extends ParameterBagContainer> extends ParameterSelector<T> {
|
||||
|
||||
private Long value;
|
||||
|
||||
|
@ -346,7 +346,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -359,7 +359,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static abstract class AbstractListParameterSelector<U, T extends GroupedParameterizedElement>
|
||||
public static abstract class AbstractListParameterSelector<U, T extends ParameterBagContainer>
|
||||
extends ParameterSelector<T> {
|
||||
|
||||
private List<U> value;
|
||||
|
@ -370,7 +370,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean select(GroupedParameterizedElement element) {
|
||||
public boolean select(ParameterBagContainer element) {
|
||||
if (!element.hasParameterBag(this.bagKey))
|
||||
return false;
|
||||
|
||||
|
@ -383,7 +383,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class StringListParameterSelector<T extends GroupedParameterizedElement>
|
||||
public static class StringListParameterSelector<T extends ParameterBagContainer>
|
||||
extends AbstractListParameterSelector<String, T> {
|
||||
|
||||
public StringListParameterSelector(String bagKey, String paramKey, List<String> value) {
|
||||
|
@ -391,7 +391,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class IntegerListParameterSelector<T extends GroupedParameterizedElement>
|
||||
public static class IntegerListParameterSelector<T extends ParameterBagContainer>
|
||||
extends AbstractListParameterSelector<Integer, T> {
|
||||
|
||||
public IntegerListParameterSelector(String bagKey, String paramKey, List<Integer> value) {
|
||||
|
@ -399,7 +399,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class FloatListParameterSelector<T extends GroupedParameterizedElement>
|
||||
public static class FloatListParameterSelector<T extends ParameterBagContainer>
|
||||
extends AbstractListParameterSelector<Double, T> {
|
||||
|
||||
public FloatListParameterSelector(String bagKey, String paramKey, List<Double> value) {
|
||||
|
@ -407,7 +407,7 @@ public abstract class ParameterSelector<T extends GroupedParameterizedElement> i
|
|||
}
|
||||
}
|
||||
|
||||
public static class LongListParameterSelector<T extends GroupedParameterizedElement>
|
||||
public static class LongListParameterSelector<T extends ParameterBagContainer>
|
||||
extends AbstractListParameterSelector<Long, T> {
|
||||
|
||||
public LongListParameterSelector(String bagKey, String paramKey, List<Long> value) {
|
||||
|
|
|
@ -17,13 +17,13 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class StrolchTypeNavigator<T extends StrolchElement> implements Navigator<T> {
|
||||
public abstract class StrolchTypeNavigator<T extends StrolchRootElement> implements Navigator<T> {
|
||||
|
||||
private String type;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import li.strolch.utils.helper.StringHelper;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class GroupedParameterizedElement extends AbstractStrolchElement {
|
||||
public abstract class GroupedParameterizedElement extends AbstractStrolchElement implements ParameterBagContainer {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
|||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class Order extends GroupedParameterizedElement
|
||||
implements StrolchRootElement, Comparable<Order>, PolicyContainer {
|
||||
public class Order extends GroupedParameterizedElement implements StrolchRootElement, Comparable<Order> {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
protected Version version;
|
||||
protected Date date;
|
||||
protected State state;
|
||||
protected PolicyDefs policyDefs;
|
||||
|
@ -79,6 +79,18 @@ public class Order extends GroupedParameterizedElement
|
|||
setDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVersion(Version version) throws IllegalArgumentException, IllegalStateException {
|
||||
if (this.version != null)
|
||||
this.version.validateIsNext(version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
@ -96,7 +108,7 @@ public class Order extends GroupedParameterizedElement
|
|||
}
|
||||
|
||||
@Override
|
||||
public PolicyDefs getPolicyDefs() {
|
||||
public PolicyDefs getPolicyDefs() throws StrolchPolicyException {
|
||||
if (this.policyDefs == null)
|
||||
throw new StrolchPolicyException(getLocator() + " has no Policies defined!");
|
||||
return this.policyDefs;
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
package li.strolch.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.exception.StrolchModelException;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
|
||||
/**
|
||||
* A {@link ParameterBagContainer} has a map of {@link ParameterBag ParameterBags} where the key is the id of the
|
||||
* parameter bag. This allows to group {@link Parameter Parameters} in strolch objects
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface ParameterBagContainer extends StrolchElement {
|
||||
|
||||
/**
|
||||
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
|
||||
* the {@link Parameter} or the {@link ParameterBag} does not exist
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
|
||||
* @param paramKey
|
||||
* the key of the {@link Parameter} which is to be returned
|
||||
*
|
||||
* @return the found {@link Parameter} or null if it was not found
|
||||
*/
|
||||
public <T extends Parameter<?>> T getParameter(String bagKey, String paramKey);
|
||||
|
||||
/**
|
||||
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
|
||||
* the {@link Parameter} or the {@link ParameterBag} does not exist
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
|
||||
* @param paramKey
|
||||
* the key of the {@link Parameter} which is to be returned
|
||||
* @param assertExists
|
||||
* if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown
|
||||
*
|
||||
* @return the found {@link Parameter} or null if it was not found
|
||||
*/
|
||||
public <T extends Parameter<?>> T getParameter(String bagKey, String paramKey, boolean assertExists);
|
||||
|
||||
/**
|
||||
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} to which the {@link Parameter} should be added
|
||||
* @param parameter
|
||||
* the {@link Parameter} to be added to the {@link ParameterBag}
|
||||
*
|
||||
* @throws StrolchException
|
||||
* if the {@link ParameterBag} does not exist
|
||||
*/
|
||||
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException;
|
||||
|
||||
/**
|
||||
* Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
|
||||
* @param paramKey
|
||||
* the key of the {@link Parameter} which is to be removed
|
||||
*
|
||||
* @return the removed {@link Parameter} or null if it did not exist
|
||||
*/
|
||||
public <T> Parameter<T> removeParameter(String bagKey, String paramKey);
|
||||
|
||||
/**
|
||||
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
|
||||
*
|
||||
* @param key
|
||||
* the key of the {@link ParameterBag} to return
|
||||
*
|
||||
* @return the {@link ParameterBag} with the given key, or null if it does not exist
|
||||
*/
|
||||
public ParameterBag getParameterBag(String key);
|
||||
|
||||
/**
|
||||
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
|
||||
*
|
||||
* @param bag
|
||||
* the {@link ParameterBag} to add
|
||||
*/
|
||||
public void addParameterBag(ParameterBag bag);
|
||||
|
||||
/**
|
||||
* Removes the {@link ParameterBag} with the given key
|
||||
*
|
||||
* @param key
|
||||
* the key of the {@link ParameterBag} to remove
|
||||
*
|
||||
* @return the removed {@link ParameterBag}, or null if it does not exist
|
||||
*/
|
||||
public ParameterBag removeParameterBag(String key);
|
||||
|
||||
/**
|
||||
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
||||
*
|
||||
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
|
||||
*/
|
||||
public boolean hasParameterBags();
|
||||
|
||||
/**
|
||||
* Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} which is to be checked for existence
|
||||
* @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}.
|
||||
*/
|
||||
public boolean hasParameterBag(String bagKey);
|
||||
|
||||
/**
|
||||
* Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
|
||||
* bagKey
|
||||
*
|
||||
* @param bagKey
|
||||
* the key of the {@link ParameterBag} on which to find the {@link Parameter}
|
||||
* @param paramKey
|
||||
* the key of the {@link Parameter} to be found
|
||||
*
|
||||
* @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
|
||||
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not
|
||||
* exist on the {@link ParameterBag}
|
||||
*/
|
||||
public boolean hasParameter(String bagKey, String paramKey);
|
||||
|
||||
/**
|
||||
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
||||
*
|
||||
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
|
||||
*/
|
||||
public Set<String> getParameterBagKeySet();
|
||||
}
|
|
@ -1,12 +1,36 @@
|
|||
package li.strolch.model;
|
||||
|
||||
import li.strolch.exception.StrolchPolicyException;
|
||||
import li.strolch.model.policy.PolicyDefs;
|
||||
|
||||
/**
|
||||
* A {@link PolicyContainer} has a reference to {@link PolicyDefs} on which Policy configurations are stored for the
|
||||
* given object
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface PolicyContainer {
|
||||
|
||||
public PolicyDefs getPolicyDefs();
|
||||
/**
|
||||
* Returns the reference to the {@link PolicyDefs}
|
||||
*
|
||||
* @return the reference to the {@link PolicyDefs}
|
||||
*
|
||||
* @throws StrolchPolicyException
|
||||
* if no {@link PolicyDefs} are available
|
||||
*/
|
||||
public PolicyDefs getPolicyDefs() throws StrolchPolicyException;
|
||||
|
||||
/**
|
||||
* @return true if this container has {@link PolicyDefs}, false if not
|
||||
*/
|
||||
public boolean hasPolicyDefs();
|
||||
|
||||
/**
|
||||
* Set the reference to the {@link PolicyDefs}
|
||||
*
|
||||
* @param policyDefs
|
||||
* the {@link PolicyDefs} to set
|
||||
*/
|
||||
public void setPolicyDefs(PolicyDefs policyDefs);
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ import li.strolch.model.visitor.StrolchRootElementVisitor;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class Resource extends GroupedParameterizedElement
|
||||
implements StrolchRootElement, Comparable<Resource>, PolicyContainer {
|
||||
public class Resource extends GroupedParameterizedElement implements StrolchRootElement, Comparable<Resource> {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
protected Version version;
|
||||
protected Map<String, StrolchTimedState<IValue<?>>> timedStateMap;
|
||||
protected PolicyDefs policyDefs;
|
||||
|
||||
|
@ -59,6 +59,18 @@ public class Resource extends GroupedParameterizedElement
|
|||
super(id, name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVersion(Version version) throws IllegalArgumentException, IllegalStateException {
|
||||
if (this.version != null)
|
||||
this.version.validateIsNext(version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
|
||||
if (this.timedStateMap == null) {
|
||||
|
|
|
@ -30,7 +30,7 @@ public interface StrolchElement extends Serializable {
|
|||
public Locator getLocator();
|
||||
|
||||
/**
|
||||
* Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
|
||||
* Set the semi unique id of this {@link StrolchElement}. This value should be unique for all concrete
|
||||
* implementations of this interface
|
||||
*
|
||||
* @param id
|
||||
|
@ -38,7 +38,7 @@ public interface StrolchElement extends Serializable {
|
|||
public void setId(String id);
|
||||
|
||||
/**
|
||||
* Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
|
||||
* Returns the semi unique id of this {@link StrolchElement}. This value should be unique for all concrete
|
||||
* implementations of this interface
|
||||
*
|
||||
* @return
|
||||
|
|
|
@ -19,11 +19,46 @@ import li.strolch.model.visitor.StrolchRootElementVisitor;
|
|||
|
||||
/**
|
||||
* Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
|
||||
* Resources} and {@link Order Orders}
|
||||
* Resources} and {@link Order Orders}. Every root element has a version, so that versions can be kept of an object
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface StrolchRootElement extends StrolchElement {
|
||||
public interface StrolchRootElement extends StrolchElement, PolicyContainer, ParameterBagContainer {
|
||||
|
||||
/**
|
||||
* Returns the current version of this object, or null if no version is set
|
||||
*
|
||||
* @return the current version of this object, or null if no version is set
|
||||
*/
|
||||
public Version getVersion();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the version of this object.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> If the version is set, then the new version must have the {@link Version#getVersion()} be an
|
||||
* increment to the current version!
|
||||
* </p>
|
||||
*
|
||||
* @param version
|
||||
* the version to set
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the given version's locator is not equal to the current version's locator
|
||||
* @throws IllegalStateException
|
||||
* if the given version is not the next version (an increment)
|
||||
*/
|
||||
public void setVersion(Version version) throws IllegalArgumentException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* Visitor pattern accept method. Takes a {@link StrolchRootElementVisitor} to visit this element
|
||||
*
|
||||
* @param visitor
|
||||
* the visitor
|
||||
*
|
||||
* @return the result of the visitation
|
||||
*/
|
||||
public <T> T accept(StrolchRootElementVisitor<T> visitor);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
package li.strolch.model;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Defines the version of a {@link StrolchRootElement}. The version of an object allows to store the history of changes
|
||||
* as an absolute change, not differential.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Versions have an integer value, which is incremented for each further version. Thus to retrieve the previous version,
|
||||
* decrement the objects current version. To find the next version increment the version.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A version has a flag <code>delete</code> which, if true, designates that this version was removed
|
||||
* </p>
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class Version {
|
||||
|
||||
private final Locator locator;
|
||||
private final int version;
|
||||
private final String createdBy;
|
||||
private final Date createdAt;
|
||||
private final boolean deleted;
|
||||
|
||||
/**
|
||||
* Creates a new version instance with the given values. The creation date is now.
|
||||
*
|
||||
* @param version
|
||||
* the integer version which must be > 0 and should be incremented for each new version of an object
|
||||
* @param createdBy
|
||||
* the username of the creator of this object
|
||||
*/
|
||||
public Version(Locator locator, int version, String createdBy, boolean deleted) {
|
||||
DBC.PRE.assertTrue("Version must by > 0", version > 0);
|
||||
DBC.PRE.assertNotNull("locator must be set!", locator);
|
||||
DBC.PRE.assertNotNull("createdBy must be set!", createdBy);
|
||||
this.locator = locator;
|
||||
this.version = version;
|
||||
this.createdBy = createdBy;
|
||||
this.createdAt = new Date();
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public Locator getLocator() {
|
||||
return this.locator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer version, which is > 0
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public int getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version incremented
|
||||
*
|
||||
* @return the current version incremented
|
||||
*/
|
||||
public int getNextVersion() {
|
||||
return this.version + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this version == 0
|
||||
*
|
||||
* @return true if this version == 0
|
||||
*/
|
||||
public boolean isFirstVersion() {
|
||||
return this.version == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version decremented
|
||||
*
|
||||
* @return the current version decremented
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if this version is already the first version
|
||||
*/
|
||||
public int getPreviousVersion() throws IllegalStateException {
|
||||
if (this.version == 0)
|
||||
throw new IllegalStateException(
|
||||
"This is the first version, no previous version available for " + this.locator);
|
||||
return this.version - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the creator
|
||||
*
|
||||
* @return the username of the creator
|
||||
*/
|
||||
public String getCreatedBy() {
|
||||
return this.createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date when this version was created
|
||||
*
|
||||
* @return the date when this version was created
|
||||
*/
|
||||
public Date getCreatedAt() {
|
||||
return this.createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this version was deleted, otherwise false
|
||||
*
|
||||
* @return true if this version was deleted, otherwise false
|
||||
*/
|
||||
public boolean isDeleted() {
|
||||
return this.deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the given argument is an increment to this version
|
||||
*
|
||||
* @param other
|
||||
* the other version to check
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the given argument's locator is not equal to this version's locator
|
||||
* @throws IllegalStateException
|
||||
* if the given argument is not the next version
|
||||
*/
|
||||
public void validateIsNext(Version other) throws IllegalArgumentException, IllegalStateException {
|
||||
if (!this.locator.equals(other.locator)) {
|
||||
String msg = "Other version {0} is not for same object: {1}";
|
||||
throw new IllegalArgumentException(MessageFormat.format(msg, other, this.version));
|
||||
}
|
||||
|
||||
if (other.version != this.version + 1) {
|
||||
String msg = "Other version: {0} is not an increment to this version: {1}";
|
||||
throw new IllegalArgumentException(MessageFormat.format(msg, other, this.version));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Version [version=");
|
||||
builder.append(this.version);
|
||||
builder.append(", locator=");
|
||||
builder.append(this.locator);
|
||||
builder.append(", createdBy=");
|
||||
builder.append(this.createdBy);
|
||||
builder.append(", createdAt=");
|
||||
builder.append(this.createdAt);
|
||||
builder.append(", deleted=");
|
||||
builder.append(this.deleted);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -26,11 +26,11 @@ import li.strolch.exception.StrolchPolicyException;
|
|||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import li.strolch.model.PolicyContainer;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -42,10 +42,11 @@ import li.strolch.utils.dbc.DBC;
|
|||
* @author Martin Smock <martin.smock@bluewin.ch>
|
||||
*/
|
||||
public class Activity extends GroupedParameterizedElement
|
||||
implements IActivityElement, StrolchRootElement, Comparable<Activity>, PolicyContainer {
|
||||
implements IActivityElement, StrolchRootElement, Comparable<Activity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Version version;
|
||||
protected Activity parent;
|
||||
protected Map<String, IActivityElement> elements;
|
||||
protected PolicyDefs policyDefs;
|
||||
|
@ -57,10 +58,31 @@ public class Activity extends GroupedParameterizedElement
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param type
|
||||
*/
|
||||
public Activity(String id, String name, String type) {
|
||||
super(id, name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVersion(Version version) throws IllegalArgumentException, IllegalStateException {
|
||||
if (!this.isRootElement())
|
||||
throw new IllegalStateException("Can't set the version on non root of " + getLocator());
|
||||
if (this.version != null)
|
||||
this.version.validateIsNext(version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private void initElements() {
|
||||
if (this.elements == null) {
|
||||
// use a LinkedHashMap since we will iterate elements in the order added and lookup elements by ID
|
||||
|
|
|
@ -5,12 +5,12 @@ package li.strolch.model.query.ordering;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ByIdComparator<T extends GroupedParameterizedElement> implements Comparator<T> {
|
||||
public class ByIdComparator<T extends StrolchRootElement> implements Comparator<T> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ package li.strolch.model.query.ordering;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ByNameComparator<T extends GroupedParameterizedElement> implements Comparator<T> {
|
||||
public class ByNameComparator<T extends StrolchRootElement> implements Comparator<T> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ package li.strolch.model.query.ordering;
|
|||
import java.util.Comparator;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ByParamComparator<T extends GroupedParameterizedElement> implements Comparator<T> {
|
||||
public class ByParamComparator<T extends StrolchRootElement> implements Comparator<T> {
|
||||
|
||||
private String bagKey;
|
||||
private String paramKey;
|
||||
|
@ -29,13 +29,13 @@ public class ByParamComparator<T extends GroupedParameterizedElement> implements
|
|||
|
||||
Parameter<?> param1 = o1.getParameter(bagKey, paramKey);
|
||||
if (param1 == null)
|
||||
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey
|
||||
+ " does not exist on " + o1.getLocator());
|
||||
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey + " does not exist on "
|
||||
+ o1.getLocator());
|
||||
|
||||
Parameter<?> param2 = o2.getParameter(bagKey, paramKey);
|
||||
if (param2 == null)
|
||||
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey
|
||||
+ " does not exist on " + o2.getLocator());
|
||||
throw new StrolchException("Sorting parameter bag=" + bagKey + ", param=" + paramKey + " does not exist on "
|
||||
+ o2.getLocator());
|
||||
|
||||
return this.ascending ? param1.compareTo(param2) : param2.compareTo(param1);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ import li.strolch.persistence.api.OrderDao;
|
|||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao {
|
||||
public class PostgreSqlOrderDao extends PostgresqlXmlDao<Order> implements OrderDao {
|
||||
|
||||
public static final String ORDERS = "orders";
|
||||
|
||||
|
@ -70,16 +70,16 @@ public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao
|
|||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
parser.parse(binaryStream, new XmlModelSaxReader(listener));
|
||||
} catch (SQLException | IOException | SAXException | ParserConfigurationException e) {
|
||||
throw new StrolchPersistenceException(MessageFormat.format(
|
||||
"Failed to extract Order from sqlxml value for {0} / {1}", id, type), e);
|
||||
throw new StrolchPersistenceException(
|
||||
MessageFormat.format("Failed to extract Order from sqlxml value for {0} / {1}", id, type), e);
|
||||
}
|
||||
|
||||
if (listener.getOrders().size() == 0)
|
||||
throw new StrolchPersistenceException(MessageFormat.format(
|
||||
"No Orders parsed from sqlxml value for {0} / {1}", id, type));
|
||||
throw new StrolchPersistenceException(
|
||||
MessageFormat.format("No Orders parsed from sqlxml value for {0} / {1}", id, type));
|
||||
if (listener.getOrders().size() > 1)
|
||||
throw new StrolchPersistenceException(MessageFormat.format(
|
||||
"Multiple Orders parsed from sqlxml value for {0} / {1}", id, type));
|
||||
throw new StrolchPersistenceException(
|
||||
MessageFormat.format("Multiple Orders parsed from sqlxml value for {0} / {1}", id, type));
|
||||
|
||||
return listener.getOrders().get(0);
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.TransactionResult;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public abstract class PostgresqlDao<T extends StrolchElement> implements StrolchDao<T> {
|
||||
public abstract class PostgresqlDao<T extends StrolchRootElement> implements StrolchDao<T> {
|
||||
|
||||
protected PostgreSqlStrolchTransaction tx;
|
||||
protected List<DaoCommand> commands;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package li.strolch.persistence.postgresql;
|
||||
|
||||
import java.sql.SQLXML;
|
||||
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
|
||||
public abstract class PostgresqlXmlDao<T extends StrolchRootElement> extends PostgresqlDao<T> {
|
||||
|
||||
public PostgresqlXmlDao(PostgreSqlStrolchTransaction tx) {
|
||||
super(tx);
|
||||
}
|
||||
|
||||
protected abstract T parseFromXml(String id, String type, SQLXML xml);
|
||||
}
|
|
@ -20,7 +20,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.xmlpers.api.PersistenceTransaction;
|
||||
|
@ -28,12 +28,13 @@ import li.strolch.xmlpers.objref.IdOfSubTypeRef;
|
|||
import li.strolch.xmlpers.objref.SubTypeRef;
|
||||
import li.strolch.xmlpers.objref.TypeRef;
|
||||
|
||||
public abstract class AbstractDao<T extends StrolchElement> implements StrolchDao<T> {
|
||||
public abstract class AbstractDao<T extends StrolchRootElement> implements StrolchDao<T> {
|
||||
|
||||
private XmlStrolchTransaction strolchTx;
|
||||
protected PersistenceTransaction tx;
|
||||
|
||||
protected AbstractDao(StrolchTransaction tx) {
|
||||
XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx;
|
||||
this.strolchTx = (XmlStrolchTransaction) tx;
|
||||
this.tx = strolchTx.getTx();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue