diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index 0b0447e22..7ff89af30 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -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 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 diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchDao.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchDao.java index 28a445645..a1bcd9319 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchDao.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchDao.java @@ -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 */ -public interface StrolchDao { +public interface StrolchDao { public Set queryKeySet(); diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index 2e61afc80..87a085499 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -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); + /** *

* Performs the given {@link OrderQuery} and each returned {@link Order} is passed through the {@link OrderVisitor} diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java index 64967426c..c220d619a 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java @@ -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 implements StrolchDao { +public class InMemoryDao implements StrolchDao { private Map> elementMap; diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryVisitor.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryVisitor.java index 244d0b844..6c3f982d8 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryVisitor.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryActivityQueryVisitor.java @@ -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 */ -public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor implements - ActivityQueryVisitor { +public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor implements ActivityQueryVisitor { public InMemoryActivityQueryVisitor() { super(); } @Override - protected InMemoryQueryVisitor newInstance() { + protected InMemoryQueryVisitor newInstance() { return new InMemoryActivityQueryVisitor(); } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryVisitor.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryVisitor.java index 6c9c1f388..9b5b9c31e 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryVisitor.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryOrderQueryVisitor.java @@ -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 */ -public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor implements OrderQueryVisitor { +public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor implements OrderQueryVisitor { public InMemoryOrderQueryVisitor() { super(); } @Override - protected InMemoryQueryVisitor newInstance() { + protected InMemoryQueryVisitor newInstance() { return new InMemoryOrderQueryVisitor(); } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQuery.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQuery.java index a2788ce2f..875247759 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQuery.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQuery.java @@ -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 */ -public class InMemoryQuery { +public class InMemoryQuery { private Navigator navigator; private Selector selector; diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQueryVisitor.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQueryVisitor.java index bc8de2ab7..4723243b5 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQueryVisitor.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryQueryVisitor.java @@ -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 */ -public abstract class InMemoryQueryVisitor> +public abstract class InMemoryQueryVisitor implements StrolchRootElementSelectionVisitor, ParameterSelectionVisitor, StrolchQueryOrderingVisitor { - private Comparator comparator; private Navigator navigator; + private Comparator comparator; private List> selectors; private boolean any; @@ -94,7 +93,7 @@ public abstract class InMemoryQueryVisitor newInstance(); + protected abstract InMemoryQueryVisitor 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 query = newInstance(); + InMemoryQueryVisitor query = newInstance(); List selections = andSelection.getSelections(); for (Selection selection : selections) { selection.accept(query); @@ -127,7 +126,7 @@ public abstract class InMemoryQueryVisitor query = newInstance(); + InMemoryQueryVisitor query = newInstance(); List selections = orSelection.getSelections(); for (Selection selection : selections) { selection.accept(query); @@ -139,7 +138,7 @@ public abstract class InMemoryQueryVisitor query = newInstance(); + InMemoryQueryVisitor query = newInstance(); List selections = notSelection.getSelections(); for (Selection selection : selections) { selection.accept(query); @@ -261,19 +260,19 @@ public abstract class InMemoryQueryVisitor visit(OrderById ordering) { + public InMemoryQueryVisitor visit(OrderById ordering) { this.comparator = new InMemoryStrolchQueryOrderingVisitor().visit(ordering).getComparator(); return this; } @Override - public InMemoryQueryVisitor visit(OrderByName ordering) { + public InMemoryQueryVisitor visit(OrderByName ordering) { this.comparator = new InMemoryStrolchQueryOrderingVisitor().visit(ordering).getComparator(); return this; } @Override - public InMemoryQueryVisitor visit(OrderByParameter ordering) { + public InMemoryQueryVisitor visit(OrderByParameter ordering) { this.comparator = new InMemoryStrolchQueryOrderingVisitor().visit(ordering).getComparator(); return this; } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java index fd5989d52..2cba7fb3d 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java @@ -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 */ -public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor implements - ResourceQueryVisitor { +public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor + implements ResourceQueryVisitor { public InMemoryResourceQueryVisitor() { super(); } @Override - protected InMemoryQueryVisitor newInstance() { + protected InMemoryQueryVisitor newInstance() { return new InMemoryResourceQueryVisitor(); } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryStrolchQueryOrderingVisitor.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryStrolchQueryOrderingVisitor.java index 81cc5dcb7..6be3c5c89 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryStrolchQueryOrderingVisitor.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/InMemoryStrolchQueryOrderingVisitor.java @@ -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 */ -public class InMemoryStrolchQueryOrderingVisitor implements - StrolchQueryOrderingVisitor { +public class InMemoryStrolchQueryOrderingVisitor implements StrolchQueryOrderingVisitor { private Comparator comparator; diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/Navigator.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/Navigator.java index d3183475a..a2efbf860 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/Navigator.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/Navigator.java @@ -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 */ -public interface Navigator { +public interface Navigator { public List navigate(StrolchDao dao); } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterBagSelector.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterBagSelector.java index bd72511d4..fb0321472 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterBagSelector.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterBagSelector.java @@ -15,12 +15,12 @@ */ package li.strolch.runtime.query.inmemory; -import li.strolch.model.GroupedParameterizedElement; +import li.strolch.model.StrolchRootElement; /** * @author Robert von Burg */ -public class ParameterBagSelector implements Selector { +public class ParameterBagSelector implements Selector { protected String bagKey; @@ -33,7 +33,7 @@ public class ParameterBagSelector impleme return element.hasParameterBag(this.bagKey); } - public static class NullParameterBagSelector extends ParameterBagSelector { + public static class NullParameterBagSelector extends ParameterBagSelector { public NullParameterBagSelector(String bagKey) { super(bagKey); diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterSelector.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterSelector.java index ef1459ee6..1a9903c64 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterSelector.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/ParameterSelector.java @@ -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 */ -public abstract class ParameterSelector implements Selector { +public abstract class ParameterSelector implements Selector { protected String bagKey; protected String paramKey; @@ -46,79 +46,79 @@ public abstract class ParameterSelector i } @Override - public abstract boolean select(GroupedParameterizedElement element); + public abstract boolean select(ParameterBagContainer element); - public static StringParameterSelector stringSelector(String bagKey, + public static StringParameterSelector stringSelector(String bagKey, String paramKey, String value, StringMatchMode matchMode) { return new StringParameterSelector<>(bagKey, paramKey, value, matchMode); } - public static IntegerParameterSelector integerSelector(String bagKey, + public static IntegerParameterSelector integerSelector(String bagKey, String paramKey, int value) { return new IntegerParameterSelector<>(bagKey, paramKey, value); } - public static BooleanParameterSelector booleanSelector(String bagKey, + public static BooleanParameterSelector booleanSelector(String bagKey, String paramKey, boolean value) { return new BooleanParameterSelector<>(bagKey, paramKey, value); } - public static FloatParameterSelector floatSelector(String bagKey, + public static FloatParameterSelector floatSelector(String bagKey, String paramKey, double value) { return new FloatParameterSelector<>(bagKey, paramKey, value); } - public static LongParameterSelector longSelector(String bagKey, + public static LongParameterSelector longSelector(String bagKey, String paramKey, long value) { return new LongParameterSelector<>(bagKey, paramKey, value); } - public static DateParameterSelector dateSelector(String bagKey, + public static DateParameterSelector dateSelector(String bagKey, String paramKey, Date value) { return new DateParameterSelector<>(bagKey, paramKey, value); } - public static DurationParameterSelector durationSelector(String bagKey, + public static DurationParameterSelector durationSelector(String bagKey, String paramKey, Long value) { return new DurationParameterSelector<>(bagKey, paramKey, value); } - public static DateRangeParameterSelector dateRangeSelector(String bagKey, + public static DateRangeParameterSelector dateRangeSelector(String bagKey, String paramKey, DateRange dateRange) { return new DateRangeParameterSelector<>(bagKey, paramKey, dateRange); } - public static StringListParameterSelector stringListSelector( - String bagKey, String paramKey, List value) { + public static StringListParameterSelector stringListSelector(String bagKey, + String paramKey, List value) { return new StringListParameterSelector<>(bagKey, paramKey, value); } - public static IntegerListParameterSelector integerListSelector( - String bagKey, String paramKey, List value) { + public static IntegerListParameterSelector integerListSelector(String bagKey, + String paramKey, List value) { return new IntegerListParameterSelector<>(bagKey, paramKey, value); } - public static FloatListParameterSelector floatListSelector(String bagKey, + public static FloatListParameterSelector floatListSelector(String bagKey, String paramKey, List value) { return new FloatListParameterSelector<>(bagKey, paramKey, value); } - public static LongListParameterSelector longListSelector(String bagKey, + public static LongListParameterSelector longListSelector(String bagKey, String paramKey, List value) { return new LongListParameterSelector<>(bagKey, paramKey, value); } - public static NullParameterSelector nullSelector(String bagKey, + public static NullParameterSelector nullSelector(String bagKey, String paramKey) { return new NullParameterSelector<>(bagKey, paramKey); } - public static AnyTypeParameterSelector anyTypeSelection(String bagKey, + public static AnyTypeParameterSelector anyTypeSelection(String bagKey, String paramKey, String value, StringMatchMode matchMode) { return new AnyTypeParameterSelector<>(bagKey, paramKey, value, matchMode); } - public static class AnyTypeParameterSelector extends ParameterSelector { + public static class AnyTypeParameterSelector extends ParameterSelector { private StringMatchMode matchMode; private String value; @@ -130,7 +130,7 @@ public abstract class ParameterSelector 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 i } } - public static class NullParameterSelector extends ParameterSelector { + public static class NullParameterSelector extends ParameterSelector { 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 i } } - public static class StringParameterSelector extends ParameterSelector { + public static class StringParameterSelector extends ParameterSelector { private StringMatchMode matchMode; private String value; @@ -180,7 +180,7 @@ public abstract class ParameterSelector 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 i } } - public static class IntegerParameterSelector extends ParameterSelector { + public static class IntegerParameterSelector extends ParameterSelector { private Integer value; @@ -206,7 +206,7 @@ public abstract class ParameterSelector 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 i } } - public static class BooleanParameterSelector extends ParameterSelector { + public static class BooleanParameterSelector extends ParameterSelector { private Boolean value; @@ -229,7 +229,7 @@ public abstract class ParameterSelector 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 i } } - public static class FloatParameterSelector extends ParameterSelector { + public static class FloatParameterSelector extends ParameterSelector { private Double value; @@ -252,7 +252,7 @@ public abstract class ParameterSelector 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 i } } - public static class LongParameterSelector extends ParameterSelector { + public static class LongParameterSelector extends ParameterSelector { private Long value; @@ -275,7 +275,7 @@ public abstract class ParameterSelector 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 i } } - public static class DateParameterSelector extends ParameterSelector { + public static class DateParameterSelector extends ParameterSelector { private Date value; @@ -298,7 +298,7 @@ public abstract class ParameterSelector 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 i } } - public static class DateRangeParameterSelector extends ParameterSelector { + public static class DateRangeParameterSelector extends ParameterSelector { private DateRange dateRange; @@ -321,7 +321,7 @@ public abstract class ParameterSelector 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 i } } - public static class DurationParameterSelector extends ParameterSelector { + public static class DurationParameterSelector extends ParameterSelector { private Long value; @@ -346,7 +346,7 @@ public abstract class ParameterSelector 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 i } } - public static abstract class AbstractListParameterSelector + public static abstract class AbstractListParameterSelector extends ParameterSelector { private List value; @@ -370,7 +370,7 @@ public abstract class ParameterSelector 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 i } } - public static class StringListParameterSelector + public static class StringListParameterSelector extends AbstractListParameterSelector { public StringListParameterSelector(String bagKey, String paramKey, List value) { @@ -391,7 +391,7 @@ public abstract class ParameterSelector i } } - public static class IntegerListParameterSelector + public static class IntegerListParameterSelector extends AbstractListParameterSelector { public IntegerListParameterSelector(String bagKey, String paramKey, List value) { @@ -399,7 +399,7 @@ public abstract class ParameterSelector i } } - public static class FloatListParameterSelector + public static class FloatListParameterSelector extends AbstractListParameterSelector { public FloatListParameterSelector(String bagKey, String paramKey, List value) { @@ -407,7 +407,7 @@ public abstract class ParameterSelector i } } - public static class LongListParameterSelector + public static class LongListParameterSelector extends AbstractListParameterSelector { public LongListParameterSelector(String bagKey, String paramKey, List value) { diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/StrolchTypeNavigator.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/StrolchTypeNavigator.java index 6a6db9fd0..5a954d51a 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/StrolchTypeNavigator.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/inmemory/StrolchTypeNavigator.java @@ -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 */ -public abstract class StrolchTypeNavigator implements Navigator { +public abstract class StrolchTypeNavigator implements Navigator { private String type; diff --git a/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 4b88df156..379742f05 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -30,7 +30,7 @@ import li.strolch.utils.helper.StringHelper; /** * @author Robert von Burg */ -public abstract class GroupedParameterizedElement extends AbstractStrolchElement { +public abstract class GroupedParameterizedElement extends AbstractStrolchElement implements ParameterBagContainer { private static final long serialVersionUID = 0L; diff --git a/li.strolch.model/src/main/java/li/strolch/model/Order.java b/li.strolch.model/src/main/java/li/strolch/model/Order.java index 07fddcb6e..e20b00d4f 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Order.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Order.java @@ -33,11 +33,11 @@ import li.strolch.utils.iso8601.ISO8601FormatFactory; * * @author Robert von Burg */ -public class Order extends GroupedParameterizedElement - implements StrolchRootElement, Comparable, PolicyContainer { +public class Order extends GroupedParameterizedElement implements StrolchRootElement, Comparable { 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; diff --git a/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java b/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java new file mode 100644 index 000000000..5de7cbde1 --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java @@ -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 + */ +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 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 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 Parameter 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 getParameterBagKeySet(); +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java b/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java index caf1db62c..dbdfa4bae 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java +++ b/li.strolch.model/src/main/java/li/strolch/model/PolicyContainer.java @@ -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 + */ 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); } diff --git a/li.strolch.model/src/main/java/li/strolch/model/Resource.java b/li.strolch.model/src/main/java/li/strolch/model/Resource.java index 356c93543..b682856e8 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Resource.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Resource.java @@ -33,11 +33,11 @@ import li.strolch.model.visitor.StrolchRootElementVisitor; /** * @author Robert von Burg */ -public class Resource extends GroupedParameterizedElement - implements StrolchRootElement, Comparable, PolicyContainer { +public class Resource extends GroupedParameterizedElement implements StrolchRootElement, Comparable { private static final long serialVersionUID = 0L; + protected Version version; protected Map>> 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) { diff --git a/li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java index 5f06e7180..4f8901146 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/StrolchElement.java @@ -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 diff --git a/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java index 7b99b045d..890940791 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java @@ -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 */ -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(); + + /** + *

+ * Sets the version of this object. + *

+ * + *

+ * Note: If the version is set, then the new version must have the {@link Version#getVersion()} be an + * increment to the current version! + *

+ * + * @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 accept(StrolchRootElementVisitor visitor); } diff --git a/li.strolch.model/src/main/java/li/strolch/model/Version.java b/li.strolch.model/src/main/java/li/strolch/model/Version.java new file mode 100644 index 000000000..5c3eca43f --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/Version.java @@ -0,0 +1,164 @@ +package li.strolch.model; + +import java.text.MessageFormat; +import java.util.Date; + +import li.strolch.utils.dbc.DBC; + +/** + *

+ * 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. + *

+ * + *

+ * 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. + *

+ * + *

+ * A version has a flag delete which, if true, designates that this version was removed + *

+ * + * @author Robert von Burg + */ +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(); + } +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java index d4118c4eb..dd512c0ad 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java +++ b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java @@ -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 */ public class Activity extends GroupedParameterizedElement - implements IActivityElement, StrolchRootElement, Comparable, PolicyContainer { + implements IActivityElement, StrolchRootElement, Comparable { private static final long serialVersionUID = 1L; + private Version version; protected Activity parent; protected Map 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 diff --git a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByIdComparator.java b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByIdComparator.java index 03633df2c..4454a5a36 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByIdComparator.java +++ b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByIdComparator.java @@ -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 */ -public class ByIdComparator implements Comparator { +public class ByIdComparator implements Comparator { private boolean ascending; diff --git a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByNameComparator.java b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByNameComparator.java index fccf768be..e3b6bdb0e 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByNameComparator.java +++ b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByNameComparator.java @@ -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 */ -public class ByNameComparator implements Comparator { +public class ByNameComparator implements Comparator { private boolean ascending; diff --git a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByParamComparator.java b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByParamComparator.java index 175eced36..0ad95363f 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByParamComparator.java +++ b/li.strolch.model/src/main/java/li/strolch/model/query/ordering/ByParamComparator.java @@ -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 */ -public class ByParamComparator implements Comparator { +public class ByParamComparator implements Comparator { private String bagKey; private String paramKey; @@ -29,13 +29,13 @@ public class ByParamComparator 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); } diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlOrderDao.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlOrderDao.java index c76a2975c..fffcae303 100644 --- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlOrderDao.java +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlOrderDao.java @@ -45,7 +45,7 @@ import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.StrolchPersistenceException; @SuppressWarnings("nls") -public class PostgreSqlOrderDao extends PostgresqlDao implements OrderDao { +public class PostgreSqlOrderDao extends PostgresqlXmlDao implements OrderDao { public static final String ORDERS = "orders"; @@ -70,16 +70,16 @@ public class PostgreSqlOrderDao extends PostgresqlDao 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); } diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlDao.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlDao.java index 344beb203..d3f3121f8 100644 --- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlDao.java +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlDao.java @@ -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 implements StrolchDao { +public abstract class PostgresqlDao implements StrolchDao { protected PostgreSqlStrolchTransaction tx; protected List commands; diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlXmlDao.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlXmlDao.java new file mode 100644 index 000000000..c6557f40c --- /dev/null +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgresqlXmlDao.java @@ -0,0 +1,14 @@ +package li.strolch.persistence.postgresql; + +import java.sql.SQLXML; + +import li.strolch.model.StrolchRootElement; + +public abstract class PostgresqlXmlDao extends PostgresqlDao { + + public PostgresqlXmlDao(PostgreSqlStrolchTransaction tx) { + super(tx); + } + + protected abstract T parseFromXml(String id, String type, SQLXML xml); +} diff --git a/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java index 711f83545..030613383 100644 --- a/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java +++ b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java @@ -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 implements StrolchDao { +public abstract class AbstractDao implements StrolchDao { + private XmlStrolchTransaction strolchTx; protected PersistenceTransaction tx; protected AbstractDao(StrolchTransaction tx) { - XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx; + this.strolchTx = (XmlStrolchTransaction) tx; this.tx = strolchTx.getTx(); }