[Major] RIP transactional mode
This commit is contained in:
parent
0d42defd2a
commit
f3ea159052
|
@ -56,9 +56,9 @@ public interface AuditTrail {
|
|||
|
||||
public void addAll(StrolchTransaction tx, List<Audit> audits);
|
||||
|
||||
public Audit update(StrolchTransaction tx, Audit audit);
|
||||
public void update(StrolchTransaction tx, Audit audit);
|
||||
|
||||
public List<Audit> updateAll(StrolchTransaction tx, List<Audit> audits);
|
||||
public void updateAll(StrolchTransaction tx, List<Audit> audits);
|
||||
|
||||
public void remove(StrolchTransaction tx, Audit audit);
|
||||
|
||||
|
|
|
@ -444,7 +444,7 @@ public interface ElementMap<T extends StrolchRootElement> {
|
|||
* <p>
|
||||
* <b>Note:</b> This method should only be used in the same transaction where the element was created to undo a
|
||||
* change in the same transaction. If there is a requirement to revert to a previous version, then the
|
||||
* {@link #revertToVersion(StrolchTransaction, StrolchRootElement)} method.
|
||||
* {@link #revertToVersion(StrolchTransaction, StrolchRootElement)} method should be used.
|
||||
* </p>
|
||||
*
|
||||
* @param tx
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -34,12 +34,12 @@ import li.strolch.utils.dbc.DBC;
|
|||
* This {@link AuditTrail} facade registers all actions performed i.e. it registers which {@link Audit Audits} are
|
||||
* retrieved, created, updated and deleted.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* In a single transaction an Audit may be created, updated and then deleted - this implementation does not "squash"
|
||||
* such actions, but registers them separately
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class AuditingAuditMapFacade implements AuditTrail {
|
||||
|
@ -163,17 +163,15 @@ public class AuditingAuditMapFacade implements AuditTrail {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Audit update(StrolchTransaction tx, Audit audit) {
|
||||
Audit replaced = this.auditTrail.update(tx, audit);
|
||||
public void update(StrolchTransaction tx, Audit audit) {
|
||||
this.auditTrail.update(tx, audit);
|
||||
this.updated.add(audit);
|
||||
return replaced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
List<Audit> replaced = this.auditTrail.updateAll(tx, audits);
|
||||
public void updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
this.auditTrail.updateAll(tx, audits);
|
||||
this.updated.addAll(audits);
|
||||
return replaced;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -198,6 +196,7 @@ public class AuditingAuditMapFacade implements AuditTrail {
|
|||
byType = byType + removed;
|
||||
this.deletedAllByType.put(type, byType);
|
||||
|
||||
this.deletedAll += removed;
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,16 +26,13 @@ import li.strolch.model.parameter.Parameter;
|
|||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryActivityDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryActivityQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class CachedActivityMap extends CachedElementMap<Activity> implements ActivityMap {
|
||||
|
||||
private ActivityDao cachedDao;
|
||||
|
||||
public CachedActivityMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
// the cached DAO should not have versioning enabled
|
||||
this.cachedDao = new InMemoryActivityDao(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +46,9 @@ public class CachedActivityMap extends CachedElementMap<Activity> implements Act
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActivityDao getCachedDao() {
|
||||
return this.cachedDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> query) {
|
||||
return getCachedDao().doQuery(query);
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> activityQuery) {
|
||||
InMemoryActivityQueryVisitor visitor = new InMemoryActivityQueryVisitor();
|
||||
InMemoryQuery<Activity, U> query = visitor.visit(activityQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,79 +17,30 @@ package li.strolch.agent.impl;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.audit.AuditQuery;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryAuditDao;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class CachedAuditTrail implements AuditTrail {
|
||||
public class CachedAuditTrail extends TransientAuditTrail {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CachedAuditTrail.class);
|
||||
|
||||
private AuditDao cachedDao;
|
||||
|
||||
public CachedAuditTrail() {
|
||||
this.cachedDao = new InMemoryAuditDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected AuditDao getCachedDao() {
|
||||
return this.cachedDao;
|
||||
}
|
||||
|
||||
protected AuditDao getDbDao(StrolchTransaction tx) {
|
||||
private AuditDao getDbDao(StrolchTransaction tx) {
|
||||
return tx.getPersistenceHandler().getAuditDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasAudit(StrolchTransaction tx, String type, Long id) {
|
||||
return getCachedDao().hasElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(StrolchTransaction tx, DateRange dateRange) {
|
||||
return getCachedDao().querySize(dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
return getCachedDao().querySize(type, dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getTypes(StrolchTransaction tx) {
|
||||
return getCachedDao().queryTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Audit getBy(StrolchTransaction tx, String type, Long id) {
|
||||
return getCachedDao().queryBy(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Audit> getAllElements(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
return getCachedDao().queryAll(type, dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(StrolchTransaction tx, Audit audit) {
|
||||
// first perform cached change
|
||||
getCachedDao().save(audit);
|
||||
super.add(tx, audit);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).save(audit);
|
||||
}
|
||||
|
@ -97,35 +48,31 @@ public class CachedAuditTrail implements AuditTrail {
|
|||
@Override
|
||||
public synchronized void addAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
// first perform cached change
|
||||
getCachedDao().saveAll(audits);
|
||||
super.addAll(tx, audits);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).saveAll(audits);
|
||||
}
|
||||
|
||||
// TODO for update we should return the updated elements, or remove the return value
|
||||
|
||||
@Override
|
||||
public synchronized Audit update(StrolchTransaction tx, Audit audit) {
|
||||
public synchronized void update(StrolchTransaction tx, Audit audit) {
|
||||
// first perform cached change
|
||||
getCachedDao().update(audit);
|
||||
super.update(tx, audit);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).update(audit);
|
||||
return audit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Audit> updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
public synchronized void updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
// first perform cached change
|
||||
getCachedDao().updateAll(audits);
|
||||
super.updateAll(tx, audits);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).updateAll(audits);
|
||||
return audits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(StrolchTransaction tx, Audit audit) {
|
||||
// first perform cached change
|
||||
getCachedDao().remove(audit);
|
||||
super.remove(tx, audit);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).remove(audit);
|
||||
}
|
||||
|
@ -133,15 +80,16 @@ public class CachedAuditTrail implements AuditTrail {
|
|||
@Override
|
||||
public synchronized void removeAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
// first perform cached change
|
||||
getCachedDao().removeAll(audits);
|
||||
super.removeAll(tx, audits);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).removeAll(audits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
|
||||
// first perform cached change
|
||||
long removed = getCachedDao().removeAll(type, dateRange);
|
||||
long removed = super.removeAll(tx, type, dateRange);
|
||||
|
||||
// last is to perform DB changes
|
||||
long daoRemoved = getDbDao(tx).removeAll(type, dateRange);
|
||||
|
|
|
@ -17,222 +17,33 @@ package li.strolch.agent.impl;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class CachedElementMap<T extends StrolchRootElement> implements ElementMap<T> {
|
||||
public abstract class CachedElementMap<T extends StrolchRootElement> extends TransientElementMap<T> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CachedElementMap.class);
|
||||
|
||||
private StrolchRealm realm;
|
||||
|
||||
public CachedElementMap(StrolchRealm realm) {
|
||||
super();
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
protected StrolchRealm getRealm() {
|
||||
return this.realm;
|
||||
}
|
||||
|
||||
protected abstract StrolchDao<T> getCachedDao();
|
||||
|
||||
protected abstract StrolchDao<T> getDbDao(StrolchTransaction tx);
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasType(StrolchTransaction tx, String type) {
|
||||
return getCachedDao().queryTypes().contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasElement(StrolchTransaction tx, String type, String id) {
|
||||
return getCachedDao().hasElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(StrolchTransaction tx) {
|
||||
return getCachedDao().querySize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(StrolchTransaction tx, String type) {
|
||||
return getCachedDao().querySize(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T getTemplate(StrolchTransaction tx, String type) {
|
||||
return getTemplate(tx, type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getTemplate(StrolchTransaction tx, String type, boolean assertExists) {
|
||||
T t = getCachedDao().queryBy(StrolchConstants.TEMPLATE, type);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The template with type {0} does not exist!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type));
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setId(StrolchAgent.getUniqueId());
|
||||
clone.setType(type);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T getBy(StrolchTransaction tx, String type, String id) {
|
||||
return getBy(tx, type, id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, boolean assertExists) throws StrolchException {
|
||||
T t = getCachedDao().queryBy(type, id);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id));
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
// TODO cloning has its issues, as queries don't return a clone!
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version) {
|
||||
return getBy(tx, type, id, version, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version, boolean assertExists)
|
||||
throws StrolchException {
|
||||
T t = getDbDao(tx).queryBy(type, id, version);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} and version {2} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, type, id, version);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
T t = getBy(tx, type, id, false);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists)
|
||||
throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
|
||||
String type = refP.getUom();
|
||||
List<String> ids = refP.getValue();
|
||||
|
||||
return ids.stream() //
|
||||
.map(id -> {
|
||||
T t = getBy(tx, type, id, false);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
|
||||
}
|
||||
return t;
|
||||
}) //
|
||||
.filter(Objects::nonNull) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getVersionsFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDbDao(tx).queryVersionsFor(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatestVersionFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDbDao(tx).queryLatestVersionFor(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> getAllElements(StrolchTransaction tx) {
|
||||
List<T> all = getCachedDao().queryAll();
|
||||
return all.stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> getElementsBy(StrolchTransaction tx, String type) {
|
||||
List<T> all = getCachedDao().queryAll(type);
|
||||
return all.stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getTypes(StrolchTransaction tx) {
|
||||
return getCachedDao().queryTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getAllKeys(StrolchTransaction tx) {
|
||||
return getCachedDao().queryKeySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getKeysBy(StrolchTransaction tx, String type) {
|
||||
return getCachedDao().queryKeySet(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method used when starting the container to cache the values. Not to be used anywhere else but from the
|
||||
* {@link CachedRealm}
|
||||
*
|
||||
* @param element
|
||||
* the element to insert
|
||||
*/
|
||||
synchronized void insert(T element) {
|
||||
getCachedDao().save(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(StrolchTransaction tx, T element) {
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
|
@ -243,7 +54,8 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
}
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().save(element);
|
||||
super.add(tx, element);
|
||||
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).save(element);
|
||||
}
|
||||
|
@ -260,75 +72,12 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
}
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().saveAll(elements);
|
||||
super.addAll(tx, elements);
|
||||
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).saveAll(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(StrolchTransaction tx, T element) {
|
||||
updateVersion(tx, element, false);
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().update(element);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).update(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T t : elements) {
|
||||
updateVersion(tx, t, false);
|
||||
}
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().updateAll(elements);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).updateAll(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(StrolchTransaction tx, T element) {
|
||||
updateVersion(tx, element, true);
|
||||
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().remove(element);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).update(element);
|
||||
|
||||
} else {
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().remove(element);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T t : elements) {
|
||||
updateVersion(tx, t, true);
|
||||
}
|
||||
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().removeAll(elements);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).updateAll(elements);
|
||||
|
||||
} else {
|
||||
|
||||
// first perform cached change
|
||||
getCachedDao().removeAll(elements);
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).removeAll(elements);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVersion(StrolchTransaction tx, T element, boolean deleted) {
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), deleted);
|
||||
|
@ -338,9 +87,67 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll(StrolchTransaction tx) {
|
||||
public synchronized void update(StrolchTransaction tx, T element) {
|
||||
updateVersion(tx, element, false);
|
||||
|
||||
// first perform cached change
|
||||
long removed = getCachedDao().removeAll();
|
||||
super.update(tx, element);
|
||||
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).update(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T t : elements) {
|
||||
updateVersion(tx, t, false);
|
||||
}
|
||||
|
||||
// first perform cached change
|
||||
super.updateAll(tx, elements);
|
||||
|
||||
// last is to perform DB changes
|
||||
getDbDao(tx).updateAll(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(StrolchTransaction tx, T element) {
|
||||
updateVersion(tx, element, true);
|
||||
|
||||
// first perform cached change
|
||||
super.remove(tx, element);
|
||||
|
||||
// last is to perform DB changes
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
getDbDao(tx).update(element);
|
||||
} else {
|
||||
getDbDao(tx).remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T t : elements) {
|
||||
updateVersion(tx, t, true);
|
||||
}
|
||||
|
||||
// first perform cached change
|
||||
super.removeAll(tx, elements);
|
||||
|
||||
// last is to perform DB changes
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
getDbDao(tx).updateAll(elements);
|
||||
} else {
|
||||
getDbDao(tx).removeAll(elements);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll(StrolchTransaction tx) {
|
||||
|
||||
// first perform cached change
|
||||
long removed = super.removeAll(tx);
|
||||
|
||||
// last is to perform DB changes
|
||||
long daoRemoved = getDbDao(tx).removeAll();
|
||||
|
||||
|
@ -354,8 +161,10 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
|
||||
@Override
|
||||
public synchronized long removeAllBy(StrolchTransaction tx, String type) {
|
||||
|
||||
// first perform cached change
|
||||
long removed = getCachedDao().removeAllBy(type);
|
||||
long removed = super.removeAllBy(tx, type);
|
||||
|
||||
// last is to perform DB changes
|
||||
long daoRemoved = getDbDao(tx).removeAllBy(type);
|
||||
|
||||
|
@ -367,6 +176,34 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version) {
|
||||
return getBy(tx, type, id, version, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version, boolean assertExists)
|
||||
throws StrolchException {
|
||||
T t = getDbDao(tx).queryBy(type, id, version);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} and version {2} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, type, id, version);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getVersionsFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDbDao(tx).queryVersionsFor(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatestVersionFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDbDao(tx).queryLatestVersionFor(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
return revertToVersion(tx, element.getType(), element.getId(), element.getVersion().getVersion());
|
||||
|
@ -374,9 +211,8 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, String type, String id, int version) throws StrolchException {
|
||||
if (!this.realm.isVersioningEnabled()) {
|
||||
if (!this.realm.isVersioningEnabled())
|
||||
throw new StrolchPersistenceException("Can not undo a version if versioning is not enabled!");
|
||||
}
|
||||
|
||||
// get the current and specified version
|
||||
T current = getBy(tx, type, id, true);
|
||||
|
@ -385,11 +221,10 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
// create the new version
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) versionT.getClone();
|
||||
clone.setVersion(current.getVersion().next(tx.getCertificate().getUsername(), false));
|
||||
clone.setVersion(current.getVersion());
|
||||
|
||||
// save the new version
|
||||
getCachedDao().update(clone);
|
||||
getDbDao(tx).update(clone);
|
||||
update(tx, clone);
|
||||
|
||||
// and return new version
|
||||
return clone;
|
||||
|
@ -397,9 +232,8 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
|
||||
@Override
|
||||
public void undoVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
if (!this.realm.isVersioningEnabled()) {
|
||||
if (!this.realm.isVersioningEnabled())
|
||||
throw new StrolchPersistenceException("Can not undo a version if versioning is not enabled!");
|
||||
}
|
||||
|
||||
String type = element.getType();
|
||||
String id = element.getId();
|
||||
|
@ -415,11 +249,11 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
}
|
||||
|
||||
if (elementVersion.isFirstVersion()) {
|
||||
getCachedDao().remove(element);
|
||||
super.remove(tx, element);
|
||||
getDbDao(tx).remove(element);
|
||||
} else {
|
||||
T previous = getBy(tx, type, id, elementVersion.getPreviousVersion(), true);
|
||||
getCachedDao().update(previous);
|
||||
super.update(tx, previous);
|
||||
getDbDao(tx).removeVersion(current);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,16 +26,13 @@ import li.strolch.model.parameter.Parameter;
|
|||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryOrderDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap {
|
||||
|
||||
private OrderDao cachedDao;
|
||||
|
||||
public CachedOrderMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
// the cached DAO should not have versioning enabled
|
||||
this.cachedDao = new InMemoryOrderDao(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +46,9 @@ public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap
|
|||
}
|
||||
|
||||
@Override
|
||||
protected OrderDao getCachedDao() {
|
||||
return this.cachedDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> query) {
|
||||
return getCachedDao().doQuery(query);
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> orderQuery) {
|
||||
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
|
||||
InMemoryQuery<Order, U> query = visitor.visit(orderQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class CachedRealm extends InternalStrolchRealm {
|
|||
if (isAuditTrailEnabled())
|
||||
this.auditTrail = new CachedAuditTrail();
|
||||
else
|
||||
this.auditTrail = new NoStrategyAuditTrail();
|
||||
this.auditTrail = new NoStrategyAuditTrail(getRealm());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,16 +26,13 @@ import li.strolch.model.parameter.Parameter;
|
|||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryResourceDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
|
||||
|
||||
public class CachedResourceMap extends CachedElementMap<Resource> implements ResourceMap {
|
||||
|
||||
private ResourceDao cachedDao;
|
||||
|
||||
public CachedResourceMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
// the cached DAO should not have versioning enabled
|
||||
this.cachedDao = new InMemoryResourceDao(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +46,9 @@ public class CachedResourceMap extends CachedElementMap<Resource> implements Res
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResourceDao getCachedDao() {
|
||||
return this.cachedDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> query) {
|
||||
return getCachedDao().doQuery(query);
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> resourceQuery) {
|
||||
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
|
||||
InMemoryQuery<Resource, U> query = visitor.visit(resourceQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,17 +54,6 @@ public enum DataStoreMode {
|
|||
public InternalStrolchRealm createRealm(String realm) {
|
||||
return new CachedRealm(realm);
|
||||
}
|
||||
}, //
|
||||
TRANSACTIONAL {
|
||||
@Override
|
||||
public boolean isTransient() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalStrolchRealm createRealm(String realm) {
|
||||
return new TransactionalRealm(realm);
|
||||
}
|
||||
}; //
|
||||
|
||||
public abstract InternalStrolchRealm createRealm(String realm);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,14 +17,8 @@ package li.strolch.agent.impl;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.agent.api.*;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryPersistence;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
|
@ -39,7 +33,6 @@ public class EmptyRealm extends InternalStrolchRealm {
|
|||
private OrderMap orderMap;
|
||||
private ActivityMap activityMap;
|
||||
private AuditTrail auditTrail;
|
||||
private PersistenceHandler persistenceHandler;
|
||||
|
||||
public EmptyRealm(String realm) {
|
||||
super(realm);
|
||||
|
@ -53,13 +46,13 @@ public class EmptyRealm extends InternalStrolchRealm {
|
|||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, String action) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, action);
|
||||
return new TransientTransaction(this.container, this, certificate, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
|
||||
return new TransientTransaction(this.container, this, certificate, clazz.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,15 +78,14 @@ public class EmptyRealm extends InternalStrolchRealm {
|
|||
@Override
|
||||
public void initialize(ComponentContainer container, ComponentConfiguration configuration) {
|
||||
super.initialize(container, configuration);
|
||||
this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled());
|
||||
this.resourceMap = new TransactionalResourceMap(this);
|
||||
this.orderMap = new TransactionalOrderMap(this);
|
||||
this.activityMap = new TransactionalActivityMap(this);
|
||||
this.resourceMap = new TransientResourceMap();
|
||||
this.orderMap = new TransientOrderMap();
|
||||
this.activityMap = new TransientActivityMap();
|
||||
|
||||
if (isAuditTrailEnabled())
|
||||
this.auditTrail = new TransactionalAuditTrail();
|
||||
this.auditTrail = new TransientAuditTrail();
|
||||
else
|
||||
this.auditTrail = new NoStrategyAuditTrail();
|
||||
this.auditTrail = new NoStrategyAuditTrail(getRealm());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,6 +56,7 @@ public abstract class InternalStrolchRealm implements StrolchRealm {
|
|||
private boolean versioningEnabled;
|
||||
private boolean updateObservers;
|
||||
private ObserverHandler observerHandler;
|
||||
protected ComponentContainer container;
|
||||
|
||||
public InternalStrolchRealm(String realm) {
|
||||
DBC.PRE.assertNotEmpty("RealmName may not be empty!", realm); //$NON-NLS-1$
|
||||
|
@ -84,6 +85,7 @@ public abstract class InternalStrolchRealm implements StrolchRealm {
|
|||
}
|
||||
|
||||
public void initialize(ComponentContainer container, ComponentConfiguration configuration) {
|
||||
this.container = container;
|
||||
|
||||
logger.info("Initializing Realm " + getRealm() + "...");
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -29,6 +29,12 @@ import li.strolch.utils.collections.DateRange;
|
|||
*/
|
||||
public class NoStrategyAuditTrail implements AuditTrail {
|
||||
|
||||
private String realm;
|
||||
|
||||
public NoStrategyAuditTrail(String realm) {
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
|
@ -75,13 +81,13 @@ public class NoStrategyAuditTrail implements AuditTrail {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Audit update(StrolchTransaction tx, Audit audit) {
|
||||
return null;
|
||||
public void update(StrolchTransaction tx, Audit audit) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
return null;
|
||||
public void updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,6 +107,6 @@ public class NoStrategyAuditTrail implements AuditTrail {
|
|||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query) {
|
||||
return null;
|
||||
throw new IllegalStateException("Audit trail is not enabled for realm " + this.realm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ACTIVITY_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class TransactionalActivityMap extends TransactionalElementMap<Activity> implements ActivityMap {
|
||||
|
||||
public TransactionalActivityMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ACTIVITY_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActivityDao getDao(StrolchTransaction tx) {
|
||||
return tx.getPersistenceHandler().getActivityDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> query) {
|
||||
return getDao(tx).doQuery(query);
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.audit.AuditQuery;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class TransactionalAuditTrail implements AuditTrail {
|
||||
|
||||
protected AuditDao getDao(StrolchTransaction tx) {
|
||||
return tx.getPersistenceHandler().getAuditDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAudit(StrolchTransaction tx, String type, Long id) {
|
||||
return getDao(tx).hasElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(StrolchTransaction tx, DateRange dateRange) {
|
||||
return getDao(tx).querySize(dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
return getDao(tx).querySize(type, dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTypes(StrolchTransaction tx) {
|
||||
return getDao(tx).queryTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Audit getBy(StrolchTransaction tx, String type, Long id) {
|
||||
return getDao(tx).queryBy(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> getAllElements(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
return getDao(tx).queryAll(type, dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(StrolchTransaction tx, Audit audit) {
|
||||
getDao(tx).save(audit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
getDao(tx).saveAll(audits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Audit update(StrolchTransaction tx, Audit audit) {
|
||||
getDao(tx).update(audit);
|
||||
return audit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
getDao(tx).updateAll(audits);
|
||||
return audits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(StrolchTransaction tx, Audit audit) {
|
||||
getDao(tx).remove(audit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
getDao(tx).removeAll(audits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long removeAll(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
return getDao(tx).removeAll(type, dateRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> query) {
|
||||
return getDao(tx).doQuery(query);
|
||||
}
|
||||
}
|
|
@ -1,399 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class TransactionalElementMap<T extends StrolchRootElement> implements ElementMap<T> {
|
||||
|
||||
private StrolchRealm realm;
|
||||
|
||||
public TransactionalElementMap(StrolchRealm realm) {
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
protected StrolchRealm getRealm() {
|
||||
return this.realm;
|
||||
}
|
||||
|
||||
protected abstract StrolchDao<T> getDao(StrolchTransaction tx);
|
||||
|
||||
@Override
|
||||
public boolean hasType(StrolchTransaction tx, String type) {
|
||||
return getDao(tx).queryTypes().contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasElement(StrolchTransaction tx, String type, String id) {
|
||||
return getDao(tx).hasElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(StrolchTransaction tx) {
|
||||
return getDao(tx).querySize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(StrolchTransaction tx, String type) {
|
||||
return getDao(tx).querySize(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getTemplate(StrolchTransaction tx, String type) {
|
||||
return getTemplate(tx, type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getTemplate(StrolchTransaction tx, String type, boolean assertExists) throws StrolchException {
|
||||
T t = getBy(tx, StrolchConstants.TEMPLATE, type);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The template for type {0} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, type);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setId(StrolchAgent.getUniqueId());
|
||||
clone.setType(type);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id) {
|
||||
return getBy(tx, type, id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, boolean assertExists) throws StrolchException {
|
||||
T t = getDao(tx).queryBy(type, id);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element for type {0} and id {1} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, type, id);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
if (!this.realm.getMode().isTransient())
|
||||
return t;
|
||||
|
||||
// TODO cloning has its issues, as queries don't return a clone!
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version) {
|
||||
return getBy(tx, type, id, version, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version, boolean assertExists)
|
||||
throws StrolchException {
|
||||
T t = getDao(tx).queryBy(type, id, version);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element for type {0} and id {1} and version {2} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, type, id, version);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
T t = getBy(tx, type, id);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, refP.getLocator(), id);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
if (!this.realm.getMode().isTransient())
|
||||
return t;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists)
|
||||
throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
|
||||
String type = refP.getUom();
|
||||
List<String> ids = refP.getValue();
|
||||
|
||||
return ids.stream().map(id -> {
|
||||
T t = getBy(tx, type, id);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, refP.getLocator(), id);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
return t;
|
||||
}).filter(Objects::nonNull).map(t -> {
|
||||
if (!this.realm.getMode().isTransient()) {
|
||||
return t;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getVersionsFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDao(tx).queryVersionsFor(type, id).stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatestVersionFor(StrolchTransaction tx, String type, String id) {
|
||||
return getDao(tx).queryLatestVersionFor(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getAllElements(StrolchTransaction tx) {
|
||||
List<T> all = getDao(tx).queryAll();
|
||||
|
||||
if (this.realm.getMode().isTransient())
|
||||
return all;
|
||||
|
||||
return all.stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getElementsBy(StrolchTransaction tx, String type) {
|
||||
List<T> all = getDao(tx).queryAll(type);
|
||||
|
||||
if (this.realm.getMode().isTransient())
|
||||
return all;
|
||||
|
||||
return all.stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTypes(StrolchTransaction tx) {
|
||||
return getDao(tx).queryTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllKeys(StrolchTransaction tx) {
|
||||
return getDao(tx).queryKeySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeysBy(StrolchTransaction tx, String type) {
|
||||
return getDao(tx).queryKeySet(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(StrolchTransaction tx, T element) {
|
||||
if (realm.isVersioningEnabled()) {
|
||||
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
||||
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
||||
} else {
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
}
|
||||
|
||||
getDao(tx).save(element);
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
if (realm.isVersioningEnabled()) {
|
||||
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
||||
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
||||
} else {
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
getDao(tx).saveAll(elements);
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(StrolchTransaction tx, T element) {
|
||||
if (realm.isVersioningEnabled())
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), false);
|
||||
else
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
|
||||
getDao(tx).update(element);
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
if (realm.isVersioningEnabled())
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), false);
|
||||
else
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
}
|
||||
|
||||
getDao(tx).updateAll(elements);
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(StrolchTransaction tx, T element) {
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), true);
|
||||
getDao(tx).update(element);
|
||||
} else {
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
getDao(tx).remove(element);
|
||||
}
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
if (realm.isVersioningEnabled())
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), true);
|
||||
else
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
}
|
||||
|
||||
if (this.realm.isVersioningEnabled()) {
|
||||
getDao(tx).updateAll(elements);
|
||||
} else {
|
||||
getDao(tx).removeAll(elements);
|
||||
}
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long removeAll(StrolchTransaction tx) {
|
||||
long removed = getDao(tx).removeAll();
|
||||
getDao(tx).flush();
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long removeAllBy(StrolchTransaction tx, String type) {
|
||||
long removed = getDao(tx).removeAllBy(type);
|
||||
getDao(tx).flush();
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
return revertToVersion(tx, element.getType(), element.getId(), element.getVersion().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, String type, String id, int version) throws StrolchException {
|
||||
if (!this.realm.isVersioningEnabled()) {
|
||||
throw new StrolchPersistenceException("Can not revert to a version if versioning is not enabled!");
|
||||
}
|
||||
|
||||
// get the current and specified version
|
||||
T current = getBy(tx, type, id, true);
|
||||
T versionT = getBy(tx, type, id, version, true);
|
||||
|
||||
// create the new version
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) versionT.getClone();
|
||||
clone.setVersion(current.getVersion().next(tx.getCertificate().getUsername(), false));
|
||||
|
||||
// save the new version
|
||||
getDao(tx).update(clone);
|
||||
getDao(tx).flush();
|
||||
|
||||
// and return new version
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
if (!this.realm.isVersioningEnabled()) {
|
||||
throw new StrolchPersistenceException("Can not undo a version if versioning is not enabled!");
|
||||
}
|
||||
|
||||
// make sure the given element is the latest version
|
||||
T current = getBy(tx, element.getType(), element.getId(), true);
|
||||
if (!current.getVersion().equals(element.getVersion())) {
|
||||
String msg = "Can not undo the version {0} as it is not the latest {1}!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getVersion(), current.getVersion());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
getDao(tx).removeVersion(current);
|
||||
getDao(tx).flush();
|
||||
}
|
||||
|
||||
protected abstract void assertIsRefParam(Parameter<?> refP);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ORDER_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class TransactionalOrderMap extends TransactionalElementMap<Order> implements OrderMap {
|
||||
|
||||
public TransactionalOrderMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ORDER_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OrderDao getDao(StrolchTransaction tx) {
|
||||
return tx.getPersistenceHandler().getOrderDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> query) {
|
||||
return getDao(tx).doQuery(query);
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class TransactionalRealm extends InternalStrolchRealm {
|
||||
|
||||
private ResourceMap resourceMap;
|
||||
private OrderMap orderMap;
|
||||
private ActivityMap activityMap;
|
||||
private AuditTrail auditTrail;
|
||||
private PersistenceHandler persistenceHandler;
|
||||
|
||||
public TransactionalRealm(String realm) {
|
||||
super(realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStoreMode getMode() {
|
||||
return DataStoreMode.TRANSACTIONAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, String action) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceMap getResourceMap() {
|
||||
return this.resourceMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderMap getOrderMap() {
|
||||
return this.orderMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityMap getActivityMap() {
|
||||
return this.activityMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditTrail getAuditTrail() {
|
||||
return this.auditTrail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ComponentContainer container, ComponentConfiguration configuration) {
|
||||
super.initialize(container, configuration);
|
||||
this.resourceMap = new TransactionalResourceMap(this);
|
||||
this.orderMap = new TransactionalOrderMap(this);
|
||||
this.activityMap = new TransactionalActivityMap(this);
|
||||
|
||||
if (isAuditTrailEnabled()) {
|
||||
this.auditTrail = new TransactionalAuditTrail();
|
||||
} else {
|
||||
this.auditTrail = new NoStrategyAuditTrail();
|
||||
}
|
||||
|
||||
this.persistenceHandler = container.getComponent(PersistenceHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(PrivilegeContext privilegeContext) {
|
||||
super.start(privilegeContext);
|
||||
|
||||
long start = System.nanoTime();
|
||||
int nrOfOrders = 0;
|
||||
int nrOfResources = 0;
|
||||
int nrOfActivities = 0;
|
||||
|
||||
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "strolch_boot")) {
|
||||
nrOfOrders = this.orderMap.getAllKeys(tx).size();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "strolch_boot")) {
|
||||
nrOfResources = this.resourceMap.getAllKeys(tx).size();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "strolch_boot")) {
|
||||
nrOfActivities = this.activityMap.getAllKeys(tx).size();
|
||||
}
|
||||
|
||||
long duration = System.nanoTime() - start;
|
||||
String durationS = StringHelper.formatNanoDuration(duration);
|
||||
logger.info(
|
||||
MessageFormat.format("Initialized Transactional Maps for realm {0} took {1}.", getRealm(), durationS)); //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format("There are {0} Orders", nrOfOrders)); //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format("There are {0} Resources", nrOfResources)); //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format("There are {0} Activities", nrOfActivities)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class TransactionalResourceMap extends TransactionalElementMap<Resource> implements ResourceMap {
|
||||
|
||||
public TransactionalResourceMap(StrolchRealm realm) {
|
||||
super(realm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_RESOURCE_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceDao getDao(StrolchTransaction tx) {
|
||||
return tx.getPersistenceHandler().getResourceDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> query) {
|
||||
return getDao(tx).doQuery(query);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ACTIVITY_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryActivityQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class TransientActivityMap extends TransientElementMap<Activity> implements ActivityMap {
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ACTIVITY_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ActivityQuery<U> activityQuery) {
|
||||
InMemoryActivityQueryVisitor visitor = new InMemoryActivityQueryVisitor();
|
||||
InMemoryQuery<Activity, U> query = visitor.visit(activityQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
|
@ -1,47 +1,31 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.audit.AuditQuery;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryAuditQuery;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryAuditQueryVisitor;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
import li.strolch.utils.collections.MapOfMaps;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryAuditDao implements AuditDao {
|
||||
public class TransientAuditTrail implements AuditTrail {
|
||||
|
||||
private MapOfMaps<String, Long, Audit> auditMap;
|
||||
|
||||
public InMemoryAuditDao() {
|
||||
public TransientAuditTrail() {
|
||||
this.auditMap = new MapOfMaps<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasElement(String type, Long id) {
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAudit(StrolchTransaction tx, String type, Long id) {
|
||||
Map<Long, Audit> byType = this.auditMap.getMap(type);
|
||||
if (byType == null)
|
||||
return false;
|
||||
|
@ -49,7 +33,7 @@ public class InMemoryAuditDao implements AuditDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(DateRange dateRange) {
|
||||
public long querySize(StrolchTransaction tx, DateRange dateRange) {
|
||||
long size = 0L;
|
||||
for (String type : this.auditMap.keySet()) {
|
||||
Map<Long, Audit> byType = this.auditMap.getMap(type);
|
||||
|
@ -63,7 +47,7 @@ public class InMemoryAuditDao implements AuditDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(String type, DateRange dateRange) {
|
||||
public long querySize(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
Map<Long, Audit> byType = this.auditMap.getMap(type);
|
||||
if (byType == null)
|
||||
return 0L;
|
||||
|
@ -77,17 +61,17 @@ public class InMemoryAuditDao implements AuditDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized Audit queryBy(String type, Long id) {
|
||||
return this.auditMap.getElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> queryTypes() {
|
||||
public Set<String> getTypes(StrolchTransaction tx) {
|
||||
return new HashSet<>(this.auditMap.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<Audit> queryAll(String type, DateRange dateRange) {
|
||||
public Audit getBy(StrolchTransaction tx, String type, Long id) {
|
||||
return this.auditMap.getElement(type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> getAllElements(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
List<Audit> audits = new ArrayList<>();
|
||||
Map<Long, Audit> byType = this.auditMap.getMap(type);
|
||||
if (byType == null)
|
||||
|
@ -101,44 +85,43 @@ public class InMemoryAuditDao implements AuditDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void save(Audit audit) {
|
||||
public void add(StrolchTransaction tx, Audit audit) {
|
||||
this.auditMap.addElement(audit.getElementType(), audit.getId(), audit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void saveAll(List<Audit> audits) {
|
||||
public void addAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
for (Audit audit : audits) {
|
||||
this.auditMap.addElement(audit.getElementType(), audit.getId(), audit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(Audit audit) {
|
||||
public void update(StrolchTransaction tx, Audit audit) {
|
||||
this.auditMap.addElement(audit.getElementType(), audit.getId(), audit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateAll(List<Audit> audits) {
|
||||
public void updateAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
for (Audit audit : audits) {
|
||||
this.auditMap.addElement(audit.getElementType(), audit.getId(), audit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(Audit audit) {
|
||||
public void remove(StrolchTransaction tx, Audit audit) {
|
||||
this.auditMap.removeElement(audit.getElementType(), audit.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll(List<Audit> audits) {
|
||||
public void removeAll(StrolchTransaction tx, List<Audit> audits) {
|
||||
for (Audit audit : audits) {
|
||||
this.auditMap.removeElement(audit.getElementType(), audit.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll(String type, DateRange dateRange) {
|
||||
|
||||
public long removeAll(StrolchTransaction tx, String type, DateRange dateRange) {
|
||||
Map<Long, Audit> byType = this.auditMap.getMap(type);
|
||||
if (byType == null)
|
||||
return 0L;
|
||||
|
@ -159,9 +142,9 @@ public class InMemoryAuditDao implements AuditDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(AuditQuery<U> auditQuery) {
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, AuditQuery<U> auditQuery) {
|
||||
InMemoryAuditQueryVisitor<U> visitor = new InMemoryAuditQueryVisitor<>();
|
||||
InMemoryAuditQuery<U> query = visitor.toInMemory(auditQuery);
|
||||
return query.doQuery(this);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,402 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class TransientElementMap<T extends StrolchRootElement> implements ElementMap<T> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TransientElementMap.class);
|
||||
|
||||
private Map<String, Map<String, T>> elementMap;
|
||||
|
||||
public TransientElementMap() {
|
||||
this.elementMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasType(StrolchTransaction tx, String type) {
|
||||
return this.elementMap.containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasElement(StrolchTransaction tx, String type, String id) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
return byType != null && byType.get(id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(StrolchTransaction tx) {
|
||||
return this.elementMap.entrySet().stream() //
|
||||
.map(e -> e.getValue().entrySet().size()) //
|
||||
.mapToInt(Integer::valueOf) //
|
||||
.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(StrolchTransaction tx, String type) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return 0;
|
||||
|
||||
return byType.entrySet().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T getTemplate(StrolchTransaction tx, String type) {
|
||||
return getTemplate(tx, type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getTemplate(StrolchTransaction tx, String type, boolean assertExists) {
|
||||
|
||||
T t = getBy(tx, StrolchConstants.TEMPLATE, type);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The template with type {0} does not exist!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type));
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setId(StrolchAgent.getUniqueId());
|
||||
clone.setType(type);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T getBy(StrolchTransaction tx, String type, String id) {
|
||||
return getBy(tx, type, id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, boolean assertExists) throws StrolchException {
|
||||
|
||||
T t = null;
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType != null) {
|
||||
t = byType.get(id);
|
||||
}
|
||||
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id));
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
// TODO cloning has its issues, as queries don't return a clone!
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
T t = getBy(tx, type, id, false);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists)
|
||||
throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
|
||||
String type = refP.getUom();
|
||||
List<String> ids = refP.getValue();
|
||||
|
||||
return ids.stream() //
|
||||
.map(id -> {
|
||||
T t = getBy(tx, type, id, false);
|
||||
if (assertExists && t == null) {
|
||||
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
|
||||
}
|
||||
return t;
|
||||
}) //
|
||||
.filter(Objects::nonNull) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> getAllElements(StrolchTransaction tx) {
|
||||
return this.elementMap.entrySet().stream() //
|
||||
.map(e -> e.getValue().entrySet().stream() //
|
||||
.map(Map.Entry::getValue)) //
|
||||
.flatMap(identity()) //
|
||||
.map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> getElementsBy(StrolchTransaction tx, String type) {
|
||||
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return new ArrayList<>(0);
|
||||
|
||||
return byType.entrySet().stream() //
|
||||
.map(Map.Entry::getValue) //
|
||||
.collect(Collectors.toList()).stream().map(t -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
T clone = (T) t.getClone();
|
||||
clone.setVersion(t.getVersion());
|
||||
return clone;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getTypes(StrolchTransaction tx) {
|
||||
return new HashSet<>(this.elementMap.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getAllKeys(StrolchTransaction tx) {
|
||||
return this.elementMap.entrySet().stream() //
|
||||
.map(e -> e.getValue().entrySet().stream() //
|
||||
.map(Map.Entry::getKey)) //
|
||||
.flatMap(identity()) //
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> getKeysBy(StrolchTransaction tx, String type) {
|
||||
Map<String, T> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return new HashSet<>(0);
|
||||
|
||||
return byType.entrySet().stream() //
|
||||
.map(Map.Entry::getKey) //
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method used when starting the container to cache the values. Not to be used anywhere else but from the
|
||||
* {@link CachedRealm}
|
||||
*
|
||||
* @param element
|
||||
* the element to insert
|
||||
*/
|
||||
synchronized void insert(T element) {
|
||||
|
||||
Map<String, T> byType = this.elementMap.computeIfAbsent(element.getType(), k -> new HashMap<>());
|
||||
|
||||
// assert no object already exists with this id
|
||||
if (byType.containsKey(element.getId())) {
|
||||
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
byType.put(element.getId(), element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(StrolchTransaction tx, T element) {
|
||||
|
||||
Map<String, T> byType = this.elementMap.computeIfAbsent(element.getType(), k -> new HashMap<>());
|
||||
|
||||
// assert no object already exists with this id
|
||||
if (byType.containsKey(element.getId())) {
|
||||
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
byType.put(element.getId(), element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
Map<String, T> byType = this.elementMap.computeIfAbsent(element.getType(), k -> new HashMap<>());
|
||||
|
||||
// assert no object already exists with this id
|
||||
if (byType.containsKey(element.getId())) {
|
||||
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
byType.put(element.getId(), element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(StrolchTransaction tx, T element) {
|
||||
Map<String, T> byType = this.elementMap.get(element.getType());
|
||||
if (byType == null) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
// assert no object already exists with this id
|
||||
if (!byType.containsKey(element.getId())) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
byType.put(element.getId(), element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
Map<String, T> byType = this.elementMap.get(element.getType());
|
||||
if (byType == null) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
// assert no object already exists with this id
|
||||
if (!byType.containsKey(element.getId())) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
byType.put(element.getId(), element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(StrolchTransaction tx, T element) {
|
||||
Map<String, T> byType = this.elementMap.get(element.getType());
|
||||
if (byType != null) {
|
||||
byType.remove(element.getId());
|
||||
|
||||
if (byType.isEmpty()) {
|
||||
this.elementMap.remove(element.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll(StrolchTransaction tx, List<T> elements) {
|
||||
for (T element : elements) {
|
||||
Map<String, T> byType = this.elementMap.get(element.getType());
|
||||
if (byType != null) {
|
||||
byType.remove(element.getId());
|
||||
|
||||
if (byType.isEmpty()) {
|
||||
this.elementMap.remove(element.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll(StrolchTransaction tx) {
|
||||
long removed = 0;
|
||||
Set<String> keySet = new HashSet<>(this.elementMap.keySet());
|
||||
for (String type : keySet) {
|
||||
Map<String, T> byType = this.elementMap.remove(type);
|
||||
removed += byType.size();
|
||||
byType.clear();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAllBy(StrolchTransaction tx, String type) {
|
||||
long removed = 0;
|
||||
Map<String, T> byType = this.elementMap.remove(type);
|
||||
if (byType != null) {
|
||||
removed = byType.size();
|
||||
byType.clear();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version) {
|
||||
return getBy(tx, type, id, version, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, String type, String id, int version, boolean assertExists)
|
||||
throws StrolchException {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getVersionsFor(StrolchTransaction tx, String type, String id) {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatestVersionFor(StrolchTransaction tx, String type, String id) {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
@Override
|
||||
public T revertToVersion(StrolchTransaction tx, String type, String id, int version) throws StrolchException {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoVersion(StrolchTransaction tx, T element) throws StrolchException {
|
||||
throw new IllegalStateException("Transient mode does not support versioning");
|
||||
}
|
||||
|
||||
protected abstract void assertIsRefParam(Parameter<?> refP);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ORDER_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class TransientOrderMap extends TransientElementMap<Order> implements OrderMap {
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ORDER_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, OrderQuery<U> orderQuery) {
|
||||
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
|
||||
InMemoryQuery<Order, U> query = visitor.visit(orderQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -18,16 +18,10 @@ package li.strolch.agent.impl;
|
|||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.agent.api.*;
|
||||
import li.strolch.model.ModelStatistics;
|
||||
import li.strolch.model.xml.XmlModelSaxFileReader;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryPersistence;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
@ -45,7 +39,6 @@ public class TransientRealm extends InternalStrolchRealm {
|
|||
private OrderMap orderMap;
|
||||
private ActivityMap activityMap;
|
||||
private AuditTrail auditTrail;
|
||||
private PersistenceHandler persistenceHandler;
|
||||
|
||||
private File modelFile;
|
||||
|
||||
|
@ -61,13 +54,13 @@ public class TransientRealm extends InternalStrolchRealm {
|
|||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, String action) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, action);
|
||||
return new TransientTransaction(this.container, this, certificate, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
|
||||
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
|
||||
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
|
||||
return new TransientTransaction(this.container, this, certificate, clazz.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,15 +96,14 @@ public class TransientRealm extends InternalStrolchRealm {
|
|||
|
||||
this.modelFile = configuration.getDataFile(key, null, configuration.getRuntimeConfiguration(), true);
|
||||
|
||||
this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled());
|
||||
this.resourceMap = new TransactionalResourceMap(this);
|
||||
this.orderMap = new TransactionalOrderMap(this);
|
||||
this.activityMap = new TransactionalActivityMap(this);
|
||||
this.resourceMap = new TransientResourceMap();
|
||||
this.orderMap = new TransientOrderMap();
|
||||
this.activityMap = new TransientActivityMap();
|
||||
|
||||
if (isAuditTrailEnabled())
|
||||
this.auditTrail = new TransactionalAuditTrail();
|
||||
this.auditTrail = new TransientAuditTrail();
|
||||
else
|
||||
this.auditTrail = new NoStrategyAuditTrail();
|
||||
this.auditTrail = new NoStrategyAuditTrail(getRealm());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,8 +127,9 @@ public class TransientRealm extends InternalStrolchRealm {
|
|||
}
|
||||
|
||||
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);
|
||||
logger.info(MessageFormat.format("Loaded XML Model file {0} for realm {1} took {2}.", this.modelFile.getName(), //$NON-NLS-1$
|
||||
getRealm(), durationS));
|
||||
logger.info(MessageFormat
|
||||
.format("Loaded XML Model file {0} for realm {1} took {2}.", this.modelFile.getName(), //$NON-NLS-1$
|
||||
getRealm(), durationS));
|
||||
logger.info(MessageFormat.format("Loaded {0} Orders", statistics.nrOfOrders)); //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format("Loaded {0} Resources", statistics.nrOfResources)); //$NON-NLS-1$
|
||||
logger.info(MessageFormat.format("Loaded {0} Activities", statistics.nrOfActivities)); //$NON-NLS-1$
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
|
||||
|
||||
public class TransientResourceMap extends TransientElementMap<Resource> implements ResourceMap {
|
||||
|
||||
@Override
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
ElementMapHelpers.assertIsRefParam(INTERPRETATION_RESOURCE_REF, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> resourceQuery) {
|
||||
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
|
||||
InMemoryQuery<Resource, U> query = visitor.visit(resourceQuery);
|
||||
return query.doQuery(tx, this);
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
|
@ -22,14 +22,11 @@ import li.strolch.persistence.api.PersistenceHandler;
|
|||
import li.strolch.persistence.api.TransactionState;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
|
||||
public class InMemoryTransaction extends AbstractTransaction {
|
||||
public class TransientTransaction extends AbstractTransaction {
|
||||
|
||||
private InMemoryPersistence persistenceHandler;
|
||||
|
||||
public InMemoryTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, String action,
|
||||
InMemoryPersistence persistenceHandler) {
|
||||
public TransientTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate,
|
||||
String action) {
|
||||
super(container, realm, certificate, action);
|
||||
this.persistenceHandler = persistenceHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +46,6 @@ public class InMemoryTransaction extends AbstractTransaction {
|
|||
|
||||
@Override
|
||||
public PersistenceHandler getPersistenceHandler() {
|
||||
return this.persistenceHandler;
|
||||
throw new IllegalStateException("No persistence handler for in-memory TX!");
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -94,10 +94,8 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
private String action;
|
||||
private Certificate certificate;
|
||||
|
||||
public AbstractTransaction(ComponentContainer container,
|
||||
StrolchRealm realm,
|
||||
Certificate certificate,
|
||||
String action) {
|
||||
public AbstractTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate,
|
||||
String action) {
|
||||
DBC.PRE.assertNotNull("container must be set!", container); //$NON-NLS-1$
|
||||
DBC.PRE.assertNotNull("realm must be set!", realm); //$NON-NLS-1$
|
||||
DBC.PRE.assertNotNull("certificate must be set!", certificate); //$NON-NLS-1$
|
||||
|
@ -524,10 +522,10 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
Order element = getElementFromFilter(Tags.ORDER, Order.locatorFor(StrolchConstants.TEMPLATE, type));
|
||||
if (element == null)
|
||||
element = getOrderMap().getTemplate(this, type, assertExists);
|
||||
|
||||
if(element != null)
|
||||
|
||||
if (element != null)
|
||||
element.setDate(new Date());
|
||||
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,192 +26,83 @@ import li.strolch.model.StrolchRootElement;
|
|||
* in Strolch are always referenced by a type and an ID. The type is a categorisation/grouping of the objects, while the
|
||||
* ID is a unique identifier of the object. The ID must be unique, even for multiple groups.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* The DAO must support versioning. i.e. if versioning is enabled, then if an object is updated or removed, the existing
|
||||
* version is not modified, but a new version is persisted so that rollbacks can be done
|
||||
* </p>
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* @param <T>
|
||||
* the object instance being queried from the underlying persistence layer
|
||||
* the object instance being queried from the underlying persistence layer
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface StrolchDao<T extends StrolchRootElement> {
|
||||
|
||||
/**
|
||||
* Queries the set of IDs for all elements, regardless of types from the underlying persistence layer.
|
||||
*
|
||||
* @return the set of IDs for all elements
|
||||
*/
|
||||
public Set<String> queryKeySet();
|
||||
|
||||
/**
|
||||
* Returns true if an element exists with the given type and id in the underlying persistence layer
|
||||
*
|
||||
* @param type
|
||||
* the type of elements
|
||||
* @param id
|
||||
* the id of the element to return
|
||||
*
|
||||
* @return true if an element exists with the given type and id
|
||||
*/
|
||||
public boolean hasElement(String type, String id);
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the underlying persistence layer, regardless of type
|
||||
*
|
||||
* @return the number of elements in the underlying persistence layer
|
||||
*/
|
||||
public long querySize();
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the underlying persistence layer for the given type
|
||||
*
|
||||
* @return the number of elements in the underlying persistence layer for the given type
|
||||
*/
|
||||
public long querySize(String type);
|
||||
|
||||
/**
|
||||
* Queries the set of IDs for the elements with the given type
|
||||
*
|
||||
* @return the set of IDs for the elements with the given type
|
||||
*/
|
||||
public Set<String> queryKeySet(String type);
|
||||
|
||||
/**
|
||||
* Queries the current list of types from the underlying persistence layer
|
||||
*
|
||||
*
|
||||
* @return the list of types
|
||||
*/
|
||||
public Set<String> queryTypes();
|
||||
|
||||
/**
|
||||
* Queries the latest version of the element with the given type and ID
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return the element with the given type and ID, or null if it does not exist
|
||||
*/
|
||||
public T queryBy(String type, String id);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Queries a specific version of the element with the given type and ID.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> If you want to query the latest version, then use the method with out the version parameter
|
||||
* </p>
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
* @param version
|
||||
* the version of the element to be returned
|
||||
*
|
||||
* @return the element with the given type and ID, or null if it does not exist
|
||||
*/
|
||||
public T queryBy(String type, String id, int version);
|
||||
|
||||
/**
|
||||
* Queries and returns all the versions of the element with the given type and ID
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return all the versions of the element with the given type and ID
|
||||
*/
|
||||
public List<T> queryVersionsFor(String type, String id);
|
||||
|
||||
/**
|
||||
* Queries and returns the latest version of the element with the given type and ID, -1 if no version available
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return the latest version of the element with the given type and ID, -1 if no version available
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public int queryLatestVersionFor(String type, String id);
|
||||
|
||||
/**
|
||||
* Queries and returns the number of versions for the element with the given type and ID
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return the number of versions for the element with the given type and ID
|
||||
*/
|
||||
public long queryVersionsSizeFor(String type, String id);
|
||||
|
||||
/**
|
||||
* Queries and returns all elements regardless of type
|
||||
*
|
||||
* @return all elements regardless of type
|
||||
*/
|
||||
public List<T> queryAll();
|
||||
public Set<String> queryTypes() throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Queries and returns all elements of the given type
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* the type of element to return
|
||||
*
|
||||
* the type of element to return
|
||||
*
|
||||
* @return all elements of the given type
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public List<T> queryAll(String type);
|
||||
public List<T> queryAll(String type) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Persists the given element. The element must not yet exist
|
||||
*
|
||||
*
|
||||
* @param element
|
||||
* the element to be persisted
|
||||
*
|
||||
* the element to be persisted
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if the element already exists
|
||||
* if the element already exists
|
||||
*/
|
||||
public void save(T element) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Persists the given list of elements. None of the elements may already exists
|
||||
*
|
||||
*
|
||||
* @param elements
|
||||
* the list of elements to be persisted
|
||||
*
|
||||
* the list of elements to be persisted
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if any of the elements already exist
|
||||
* if any of the elements already exist
|
||||
*/
|
||||
public void saveAll(List<T> elements) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Updates the given element. The element must already exist
|
||||
*
|
||||
*
|
||||
* @param element
|
||||
* the element to be updated
|
||||
*
|
||||
* the element to be updated
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if the element does not exist
|
||||
* if the element does not exist
|
||||
*/
|
||||
public void update(T element) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Updates the given list of elements. Each element must already exist
|
||||
*
|
||||
*
|
||||
* @param elements
|
||||
* the elements to be updated
|
||||
*
|
||||
* the elements to be updated
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if any of the elements do not exist
|
||||
* if any of the elements do not exist
|
||||
*/
|
||||
public void updateAll(List<T> elements) throws StrolchPersistenceException;
|
||||
|
||||
|
@ -219,17 +110,17 @@ public interface StrolchDao<T extends StrolchRootElement> {
|
|||
* <p>
|
||||
* Removes the given element from the underlying persistence layer
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> This method deletes the given object including its versions! Do not call this method if you want to
|
||||
* use versioning!
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param element
|
||||
* the element to be removed
|
||||
*
|
||||
* the element to be removed
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if the element does not exist
|
||||
* if the element does not exist
|
||||
*/
|
||||
public void remove(T element) throws StrolchPersistenceException;
|
||||
|
||||
|
@ -237,18 +128,17 @@ public interface StrolchDao<T extends StrolchRootElement> {
|
|||
* <p>
|
||||
* Removes the given elements from the underlying persistence layer
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> This method deletes the given objects including their versions! Do not call this method if you want
|
||||
* to use versioning!
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param elements
|
||||
* the elements to be removed
|
||||
*
|
||||
* the elements to be removed
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if any of the elements do not exist
|
||||
* if any of the elements do not exist
|
||||
*/
|
||||
public void removeAll(List<T> elements) throws StrolchPersistenceException;
|
||||
|
||||
|
@ -256,34 +146,116 @@ public interface StrolchDao<T extends StrolchRootElement> {
|
|||
* <p>
|
||||
* Removes all elements regardless of type from the underlying persistence layer
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> This method does not support versioning. This method completely removes all objects regardless of
|
||||
* type and their versions!
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return the number of elements removed
|
||||
*
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public long removeAll();
|
||||
public long removeAll() throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Removes all elements of the given type from the underlying persistence layer
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> This method does not support versioning. This method completely removes all objects of the given
|
||||
* type and their versions!
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* the type of element to remove
|
||||
*
|
||||
* the type of element to remove
|
||||
*
|
||||
* @return the number of elements removed
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public long removeAllBy(String type);
|
||||
public long removeAllBy(String type) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Queries a specific version of the element with the given type and ID.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> If you want to query the latest version, then use the method with out the version parameter
|
||||
* </p>
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
* @param version
|
||||
* the version of the element to be returned
|
||||
*
|
||||
* @return the element with the given type and ID, or null if it does not exist
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public T queryBy(String type, String id, int version) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Queries and returns all the versions of the element with the given type and ID
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return all the versions of the element with the given type and ID
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public List<T> queryVersionsFor(String type, String id) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Queries and returns the latest version of the element with the given type and ID, -1 if no version available
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return the latest version of the element with the given type and ID, -1 if no version available
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public int queryLatestVersionFor(String type, String id) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Queries and returns the number of versions for the element with the given type and ID
|
||||
*
|
||||
* @param type
|
||||
* the type of the element to be queried
|
||||
* @param id
|
||||
* the id of the element to be queried
|
||||
*
|
||||
* @return the number of versions for the element with the given type and ID
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public long queryVersionsSizeFor(String type, String id) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Queries and returns all elements regardless of type
|
||||
*
|
||||
* @return all elements regardless of type
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public List<T> queryAll() throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -291,21 +263,24 @@ public interface StrolchDao<T extends StrolchRootElement> {
|
|||
* latest version and thus always deletes the newest version. To delete multiple versions call this method multiple
|
||||
* times. To remove it completely, call the {@link #remove(StrolchRootElement)} method.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> This element given must be the current latest version!
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param element
|
||||
* the latest version of the element to be removed
|
||||
*
|
||||
* the latest version of the element to be removed
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if the element/version does not exist
|
||||
* if the element/version does not exist
|
||||
*/
|
||||
public void removeVersion(T element) throws StrolchPersistenceException;
|
||||
|
||||
/**
|
||||
* Causes the DAO to flush any actions which have not yet been sent to the underlying persistence layer
|
||||
*
|
||||
* @throws StrolchPersistenceException
|
||||
* if something goes wrong
|
||||
*/
|
||||
public void flush();
|
||||
public void flush() throws StrolchPersistenceException;
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryActivityQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class InMemoryActivityDao extends InMemoryDao<Activity> implements ActivityDao {
|
||||
|
||||
public InMemoryActivityDao(boolean versioningEnabled) {
|
||||
super(versioningEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(ActivityQuery<U> activityQuery) {
|
||||
InMemoryActivityQueryVisitor visitor = new InMemoryActivityQueryVisitor();
|
||||
InMemoryQuery<Activity, U> query = visitor.visit(activityQuery);
|
||||
return query.doQuery(this);
|
||||
}
|
||||
}
|
|
@ -1,331 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
|
||||
public class InMemoryDao<T extends StrolchRootElement> implements StrolchDao<T> {
|
||||
|
||||
private Map<String, Map<String, ArrayDeque<T>>> elementMap;
|
||||
private boolean versioningEnabled;
|
||||
|
||||
public InMemoryDao(boolean versioningEnabled) {
|
||||
this.versioningEnabled = versioningEnabled;
|
||||
this.elementMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean hasElement(String type, String id) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return false;
|
||||
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null)
|
||||
return false;
|
||||
|
||||
return !list.getLast().getVersion().isDeleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize() {
|
||||
return this.elementMap.entrySet().stream().map(e -> {
|
||||
return e.getValue().entrySet().stream().filter(f -> {
|
||||
return !f.getValue().getLast().getVersion().isDeleted();
|
||||
}).count();
|
||||
}).mapToInt(e -> e.intValue()).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long querySize(String type) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return 0;
|
||||
return byType.entrySet().stream().filter(e -> !e.getValue().getLast().getVersion().isDeleted()).count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> queryKeySet() {
|
||||
return this.elementMap.entrySet().stream() //
|
||||
.map(e -> {
|
||||
return e.getValue().entrySet().stream() //
|
||||
.filter(f -> !f.getValue().getLast().getVersion().isDeleted()) //
|
||||
.map(f -> f.getKey());
|
||||
}) //
|
||||
.flatMap(Function.identity()) //
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> queryKeySet(String type) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return new HashSet<>(0);
|
||||
|
||||
return byType.entrySet().stream() //
|
||||
.filter(e -> !e.getValue().getLast().getVersion().isDeleted()) //
|
||||
.map(e -> e.getKey()) //
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<String> queryTypes() {
|
||||
return new HashSet<>(this.elementMap.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T queryBy(String type, String id) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return null;
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null)
|
||||
return null;
|
||||
|
||||
T t = list.getLast();
|
||||
if (t.getVersion() != null && t.getVersion().isDeleted())
|
||||
return null;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized T queryBy(String type, String id, int version) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return null;
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null)
|
||||
return null;
|
||||
|
||||
for (T t : list) {
|
||||
if (t.getVersion().getVersion() == version)
|
||||
return t;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> queryVersionsFor(String type, String id) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return null;
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null)
|
||||
return new ArrayList<>(0);
|
||||
return new ArrayList<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryLatestVersionFor(String type, String id) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return -1;
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null || list.isEmpty())
|
||||
return -1;
|
||||
return list.stream().mapToInt(e -> e.getVersion().getVersion()).max().orElse(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long queryVersionsSizeFor(String type, String id) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return 0L;
|
||||
ArrayDeque<T> list = byType.get(id);
|
||||
if (list == null)
|
||||
return 0L;
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> queryAll() {
|
||||
return this.elementMap.entrySet().stream() //
|
||||
.map(e -> {
|
||||
return e.getValue().entrySet().stream() //
|
||||
.filter(f -> !f.getValue().getLast().getVersion().isDeleted()) //
|
||||
.map(f -> f.getValue().getLast());
|
||||
}) //
|
||||
.flatMap(Function.identity()) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> queryAll(String type) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(type);
|
||||
if (byType == null)
|
||||
return new ArrayList<>(0);
|
||||
|
||||
return byType.entrySet().stream() //
|
||||
.filter(e -> !e.getValue().getLast().getVersion().isDeleted()) //
|
||||
.map(e -> e.getValue().getLast()) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void save(T element) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(element.getType());
|
||||
if (byType == null) {
|
||||
byType = new HashMap<>();
|
||||
this.elementMap.put(element.getType(), byType);
|
||||
}
|
||||
|
||||
ArrayDeque<T> list = byType.get(element.getId());
|
||||
|
||||
// only allow add for existing id, if the existing one is "deleted"
|
||||
if (list != null && !list.getLast().getVersion().isDeleted()) {
|
||||
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayDeque<>(2);
|
||||
byType.put(element.getId(), list);
|
||||
}
|
||||
|
||||
list.addLast(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void saveAll(List<T> elements) {
|
||||
for (T element : elements) {
|
||||
save(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(T element) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(element.getType());
|
||||
if (byType == null) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
ArrayDeque<T> list = byType.get(element.getId());
|
||||
if (list == null) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
if (!this.versioningEnabled)
|
||||
list.clear();
|
||||
|
||||
list.addLast(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateAll(List<T> elements) {
|
||||
for (T element : elements) {
|
||||
update(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(T element) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(element.getType());
|
||||
if (byType != null) {
|
||||
byType.remove(element.getId());
|
||||
|
||||
if (byType.isEmpty()) {
|
||||
this.elementMap.remove(element.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll(List<T> elements) {
|
||||
for (T element : elements) {
|
||||
remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAll() {
|
||||
long removed = 0;
|
||||
|
||||
Set<String> keySet = new HashSet<>(this.elementMap.keySet());
|
||||
for (String type : keySet) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.remove(type);
|
||||
removed += byType.size();
|
||||
byType.clear();
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized long removeAllBy(String type) {
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.remove(type);
|
||||
if (byType == null)
|
||||
return 0;
|
||||
long removed = byType.size();
|
||||
byType.clear();
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeVersion(T element) throws StrolchPersistenceException {
|
||||
|
||||
Map<String, ArrayDeque<T>> byType = this.elementMap.get(element.getType());
|
||||
if (byType == null) {
|
||||
String msg = "The element does not yet exist with the type {0}!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
ArrayDeque<T> list = byType.get(element.getId());
|
||||
if (list == null) {
|
||||
String msg = "The element does not yet exist with the type {0} and id {1}!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, element.getType(), element.getId());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
T last = list.getLast();
|
||||
if (!last.getVersion().equals(element.getVersion())) {
|
||||
String msg = "The current version {0} is not the same as the version to remove {1}!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, last.getVersion(), element.getVersion());
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
list.removeLast();
|
||||
|
||||
if (list.isEmpty()) {
|
||||
byType.remove(element.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
|
||||
public class InMemoryOrderDao extends InMemoryDao<Order> implements OrderDao {
|
||||
|
||||
public InMemoryOrderDao(boolean versioningEnabled) {
|
||||
super(versioningEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(OrderQuery<U> orderQuery) {
|
||||
InMemoryOrderQueryVisitor visitor = new InMemoryOrderQueryVisitor();
|
||||
InMemoryQuery<Order, U> query = visitor.visit(orderQuery);
|
||||
return query.doQuery(this);
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
|
||||
public class InMemoryPersistence implements PersistenceHandler {
|
||||
|
||||
private boolean versioningEnabled;
|
||||
private Map<String, DaoCache> daoCache;
|
||||
private ComponentContainer container;
|
||||
|
||||
public InMemoryPersistence(ComponentContainer container, boolean versioningEnabled) {
|
||||
this.container = container;
|
||||
this.versioningEnabled = versioningEnabled;
|
||||
this.daoCache = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) {
|
||||
return new InMemoryTransaction(this.container, realm, certificate, action, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderDao getOrderDao(StrolchTransaction tx) {
|
||||
DaoCache daoCache = getDaoCache(tx);
|
||||
return daoCache.getOrderDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceDao getResourceDao(StrolchTransaction tx) {
|
||||
DaoCache daoCache = getDaoCache(tx);
|
||||
return daoCache.getResourceDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityDao getActivityDao(StrolchTransaction tx) {
|
||||
DaoCache daoCache = getDaoCache(tx);
|
||||
return daoCache.getActivityDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditDao getAuditDao(StrolchTransaction tx) {
|
||||
DaoCache daoCache = getDaoCache(tx);
|
||||
return daoCache.getAuditDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDbInitialization() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
private synchronized DaoCache getDaoCache(StrolchTransaction tx) {
|
||||
DaoCache daoCache = this.daoCache.get(tx.getRealmName());
|
||||
if (daoCache == null) {
|
||||
daoCache = new DaoCache(new InMemoryOrderDao(this.versioningEnabled),
|
||||
new InMemoryResourceDao(this.versioningEnabled), new InMemoryActivityDao(this.versioningEnabled),
|
||||
new InMemoryAuditDao());
|
||||
this.daoCache.put(tx.getRealmName(), daoCache);
|
||||
}
|
||||
return daoCache;
|
||||
}
|
||||
|
||||
private class DaoCache {
|
||||
private OrderDao orderDao;
|
||||
private ResourceDao resourceDao;
|
||||
private ActivityDao activityDao;
|
||||
private AuditDao auditDao;
|
||||
|
||||
public DaoCache(OrderDao orderDao, ResourceDao resourceDao, ActivityDao activityDao, AuditDao auditDao) {
|
||||
this.orderDao = orderDao;
|
||||
this.resourceDao = resourceDao;
|
||||
this.activityDao = activityDao;
|
||||
this.auditDao = auditDao;
|
||||
}
|
||||
|
||||
public OrderDao getOrderDao() {
|
||||
return this.orderDao;
|
||||
}
|
||||
|
||||
public ResourceDao getResourceDao() {
|
||||
return this.resourceDao;
|
||||
}
|
||||
|
||||
public AuditDao getAuditDao() {
|
||||
return this.auditDao;
|
||||
}
|
||||
|
||||
public ActivityDao getActivityDao() {
|
||||
return this.activityDao;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.inmemory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryQuery;
|
||||
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
|
||||
|
||||
public class InMemoryResourceDao extends InMemoryDao<Resource> implements ResourceDao {
|
||||
|
||||
public InMemoryResourceDao(boolean versioningEnabled) {
|
||||
super(versioningEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> List<U> doQuery(ResourceQuery<U> resourceQuery) {
|
||||
InMemoryResourceQueryVisitor visitor = new InMemoryResourceQueryVisitor();
|
||||
InMemoryQuery<Resource, U> query = visitor.visit(resourceQuery);
|
||||
return query.doQuery(this);
|
||||
}
|
||||
}
|
|
@ -17,13 +17,14 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface AuditNavigator {
|
||||
|
||||
public abstract List<Audit> navigate(AuditDao dao);
|
||||
public List<Audit> navigate(StrolchTransaction tx, AuditTrail auditTrail);
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,8 +17,9 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
|
@ -38,7 +39,7 @@ public class AuditTypeNavigator implements AuditNavigator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Audit> navigate(AuditDao dao) {
|
||||
return dao.queryAll(this.type, this.dateRange);
|
||||
public List<Audit> navigate(StrolchTransaction tx, AuditTrail auditTrail) {
|
||||
return auditTrail.getAllElements(tx, this.type, this.dateRange);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -18,14 +18,16 @@ package li.strolch.runtime.query.inmemory;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.AuditTrail;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.audit.AuditVisitor;
|
||||
import li.strolch.persistence.inmemory.InMemoryAuditDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
* @param <U>
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryAuditQuery<U> {
|
||||
|
||||
|
@ -45,10 +47,10 @@ public class InMemoryAuditQuery<U> {
|
|||
this.auditVisitor = auditVisitor;
|
||||
}
|
||||
|
||||
public List<U> doQuery(InMemoryAuditDao dao) {
|
||||
public List<U> doQuery(StrolchTransaction tx, AuditTrail auditTrail) {
|
||||
|
||||
List<U> result = new ArrayList<>();
|
||||
List<Audit> elements = this.navigator.navigate(dao);
|
||||
List<Audit> elements = this.navigator.navigate(tx, auditTrail);
|
||||
|
||||
elements.sort((a1, a2) -> a2.getDate().compareTo(a1.getDate()));
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,15 +15,12 @@
|
|||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
|
@ -36,10 +33,6 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
private StrolchElementVisitor<U> elementVisitor;
|
||||
private Comparator<T> comparator;
|
||||
|
||||
public InMemoryQuery() {
|
||||
// empty constructor
|
||||
}
|
||||
|
||||
public InMemoryQuery(Navigator<T> navigator, Selector<T> selector, StrolchElementVisitor<U> elementVisitor,
|
||||
Comparator<T> comparator) {
|
||||
this.navigator = navigator;
|
||||
|
@ -50,7 +43,7 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
|
||||
/**
|
||||
* @param navigator
|
||||
* the navigator to set
|
||||
* the navigator to set
|
||||
*/
|
||||
public void setNavigator(Navigator<T> navigator) {
|
||||
this.navigator = navigator;
|
||||
|
@ -58,7 +51,7 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
|
||||
/**
|
||||
* @param selector
|
||||
* the selector to set
|
||||
* the selector to set
|
||||
*/
|
||||
public void setSelector(Selector<T> selector) {
|
||||
this.selector = selector;
|
||||
|
@ -66,18 +59,18 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
|
||||
/**
|
||||
* @param elementVisitor
|
||||
* the elementVisitor to set
|
||||
* the elementVisitor to set
|
||||
*/
|
||||
public void setElementVisitor(StrolchElementVisitor<U> elementVisitor) {
|
||||
this.elementVisitor = elementVisitor;
|
||||
}
|
||||
|
||||
public List<U> doQuery(StrolchDao<T> dao) {
|
||||
public List<U> doQuery(StrolchTransaction tx, ElementMap<T> elementMap) {
|
||||
|
||||
if (this.selector == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<T> elements = this.navigator.navigate(dao);
|
||||
List<T> elements = this.navigator.navigate(tx, elementMap);
|
||||
if (this.comparator != null)
|
||||
elements.sort(this.comparator);
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,13 +17,14 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface Navigator<T extends StrolchRootElement> {
|
||||
|
||||
public List<T> navigate(StrolchDao<T> dao);
|
||||
public <U extends ElementMap<T>> List<T> navigate(StrolchTransaction tx, U elementMap);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,8 +17,9 @@ package li.strolch.runtime.query.inmemory;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -32,7 +33,7 @@ public abstract class StrolchTypeNavigator<T extends StrolchRootElement> impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<T> navigate(StrolchDao<T> dao) {
|
||||
return dao.queryAll(this.type);
|
||||
public <U extends ElementMap<T>> List<T> navigate(StrolchTransaction tx, U elementMap) {
|
||||
return elementMap.getElementsBy(tx, this.type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -41,7 +41,7 @@ import li.strolch.utils.helper.StringHelper;
|
|||
/**
|
||||
* Basically you should use the RuntimeMock class in the testbase project, but to mitigate circular dependencies, in
|
||||
* tests of the agent project we use this implementation
|
||||
*
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class RuntimeMock implements AutoCloseable {
|
||||
|
@ -110,12 +110,13 @@ public class RuntimeMock implements AutoCloseable {
|
|||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", this.srcPathF.getAbsolutePath(), //$NON-NLS-1$
|
||||
this.targetPathF.getAbsolutePath()));
|
||||
logger.info(
|
||||
MessageFormat.format("Mocking runtime from {0} to {1}", this.srcPathF.getAbsolutePath(), //$NON-NLS-1$
|
||||
this.targetPathF.getAbsolutePath()));
|
||||
|
||||
// setup the container
|
||||
this.agent = new StrolchBootstrapper(getAppVersion()).setupByCopyingRoot("dev", this.srcPathF,
|
||||
this.targetPathF);
|
||||
this.agent = new StrolchBootstrapper(getAppVersion())
|
||||
.setupByCopyingRoot("dev", this.srcPathF, this.targetPathF);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -160,7 +161,7 @@ public class RuntimeMock implements AutoCloseable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void run(StrolchRunnable runnable) {
|
||||
public void run(StrolchRunnable runnable) throws Exception {
|
||||
runnable.run(getAgent());
|
||||
}
|
||||
|
||||
|
@ -180,7 +181,7 @@ public class RuntimeMock implements AutoCloseable {
|
|||
}
|
||||
}
|
||||
|
||||
public static void runInStrolch(String targetPath, String srcPath, StrolchRunnable runnable) {
|
||||
public static void runInStrolch(String targetPath, String srcPath, StrolchRunnable runnable) throws Exception {
|
||||
try (RuntimeMock runtimeMock = new RuntimeMock(targetPath, srcPath)) {
|
||||
runtimeMock.mockRuntime();
|
||||
runtimeMock.startContainer();
|
||||
|
@ -201,6 +202,6 @@ public class RuntimeMock implements AutoCloseable {
|
|||
|
||||
public interface StrolchRunnable {
|
||||
|
||||
public void run(StrolchAgent agent);
|
||||
public void run(StrolchAgent agent) throws Exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,24 +15,15 @@
|
|||
*/
|
||||
package li.strolch.agent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static li.strolch.model.ModelGenerator.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.agent.api.*;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
@ -40,31 +31,28 @@ import li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest;
|
|||
import li.strolch.runtime.configuration.model.ServiceHandlerTest;
|
||||
import li.strolch.runtime.configuration.model.ServiceResultTest;
|
||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class ComponentContainerTest {
|
||||
|
||||
public static final String PATH_REALM_CONTAINER = "src/test/resources/realmtest";
|
||||
public static final String PATH_TRANSIENT_CONTAINER = "src/test/resources/transienttest";
|
||||
public static final String PATH_TRANSACTIONAL_CONTAINER = "src/test/resources/transactionaltest";
|
||||
public static final String PATH_CACHED_CONTAINER = "src/test/resources/cachedtest";
|
||||
public static final String PATH_EMPTY_CONTAINER = "src/test/resources/emptytest";
|
||||
public static final String PATH_MINIMAL_CONTAINER = "src/test/resources/minimaltest";
|
||||
public static final String PATH_VERSIONING_CONTAINER = "src/test/resources/versioningtest";
|
||||
|
||||
public static final String PATH_REALM_RUNTIME = "target/realmtest/";
|
||||
public static final String PATH_TRANSIENT_RUNTIME = "target/transienttest/";
|
||||
public static final String PATH_TRANSACTIONAL_RUNTIME = "target/transactionaltest/";
|
||||
public static final String PATH_CACHED_RUNTIME = "target/cachedtest/";
|
||||
public static final String PATH_EMPTY_RUNTIME = "target/emptytest/";
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(ComponentContainerTest.class);
|
||||
|
||||
@Test
|
||||
public void shouldStartEmptyContainer() {
|
||||
|
||||
public void shouldStartEmptyContainer() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, PATH_EMPTY_CONTAINER, agent -> testContainer(agent));
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, PATH_EMPTY_CONTAINER, ComponentContainerTest::testContainer);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
|
@ -72,10 +60,10 @@ public class ComponentContainerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartTransientContainer() {
|
||||
|
||||
public void shouldStartTransientContainer() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_TRANSIENT_RUNTIME, PATH_TRANSIENT_CONTAINER, agent -> testContainer(agent));
|
||||
RuntimeMock.runInStrolch(PATH_TRANSIENT_RUNTIME, PATH_TRANSIENT_CONTAINER,
|
||||
ComponentContainerTest::testContainer);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
|
@ -83,13 +71,9 @@ public class ComponentContainerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartTransactionalContainer() {
|
||||
|
||||
public void shouldStartRealmTestContainer() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_TRANSACTIONAL_RUNTIME, PATH_TRANSACTIONAL_CONTAINER, agent -> {
|
||||
testPersistenceContainer(agent);
|
||||
testElementMaps(agent);
|
||||
});
|
||||
RuntimeMock.runInStrolch(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER, ComponentContainerTest::testContainer);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
|
@ -97,33 +81,7 @@ public class ComponentContainerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartCachedContainer() {
|
||||
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_CACHED_RUNTIME, PATH_CACHED_CONTAINER, agent -> {
|
||||
testPersistenceContainer(agent);
|
||||
testElementMaps(agent);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartRealmTestContainer() {
|
||||
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER, agent -> testContainer(agent));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestRealms() {
|
||||
|
||||
public void shouldTestRealms() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER, agent -> {
|
||||
testContainer(agent);
|
||||
|
@ -136,8 +94,7 @@ public class ComponentContainerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldTestMinimal() {
|
||||
|
||||
public void shouldTestMinimal() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_REALM_RUNTIME, PATH_MINIMAL_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -181,20 +138,29 @@ public class ComponentContainerTest {
|
|||
|
||||
Certificate certificate = login(agent);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
ResourceDao resourceDao = tx.getPersistenceHandler().getResourceDao(tx);
|
||||
resourceDao.save(ModelGenerator.createResource("@testRes0", "Test Res", "Test"));
|
||||
Resource queriedRes = resourceDao.queryBy("Test", "@testRes0");
|
||||
tx.add(createResource("@testRes0", "Test Res", "Test"));
|
||||
Resource queriedRes = tx.getResourceBy("Test", "@testRes0");
|
||||
assertNotNull(queriedRes);
|
||||
assertEquals("@testRes0", queriedRes.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
OrderDao orderDao = tx.getPersistenceHandler().getOrderDao(tx);
|
||||
orderDao.save(ModelGenerator.createOrder("@testOrder0", "Test Order", "Test"));
|
||||
Order queriedOrder = orderDao.queryBy("Test", "@testOrder0");
|
||||
tx.add(createOrder("@testOrder0", "Test Order", "Test"));
|
||||
Order queriedOrder = tx.getOrderBy("Test", "@testOrder0");
|
||||
assertNotNull(queriedOrder);
|
||||
assertEquals("@testOrder0", queriedOrder.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
tx.add(createActivity("@testActivity0", "Test Activity", "Test", TimeOrdering.SERIES));
|
||||
Activity queriedActivity = tx.getActivityBy("Test", "@testActivity0");
|
||||
assertNotNull(queriedActivity);
|
||||
assertEquals("@testActivity0", queriedActivity.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
@ -206,19 +172,31 @@ public class ComponentContainerTest {
|
|||
Certificate certificate = login(agent);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@testRes1", "Test Res", "Test"));
|
||||
resourceMap.add(tx, createResource("@testRes1", "Test Res", "Test"));
|
||||
Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1");
|
||||
assertNotNull(queriedRes);
|
||||
assertEquals("@testRes1", queriedRes.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@testOrder1", "Test Order", "Test"));
|
||||
orderMap.add(tx, createOrder("@testOrder1", "Test Order", "Test"));
|
||||
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
|
||||
assertNotNull(queriedOrder);
|
||||
assertEquals("@testOrder1", queriedOrder.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
ActivityMap activityMap = tx.getActivityMap();
|
||||
activityMap.add(tx, createActivity("@testActivity0", "Test Activity", "Test", TimeOrdering.SERIES));
|
||||
Activity queriedActivity = activityMap.getBy(tx, "Test", "@testActivity0");
|
||||
assertNotNull(queriedActivity);
|
||||
assertEquals("@testActivity0", queriedActivity.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
@ -230,16 +208,23 @@ public class ComponentContainerTest {
|
|||
Certificate certificate = login(agent);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@testRes1", "Test Res", "Test"));
|
||||
resourceMap.add(tx, createResource("@testRes1", "Test Res", "Test"));
|
||||
Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1");
|
||||
assertNotNull(queriedRes);
|
||||
assertEquals("@testRes1", queriedRes.getId());
|
||||
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@testOrder1", "Test Order", "Test"));
|
||||
orderMap.add(tx, createOrder("@testOrder1", "Test Order", "Test"));
|
||||
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
|
||||
assertNotNull(queriedOrder);
|
||||
assertEquals("@testOrder1", queriedOrder.getId());
|
||||
|
||||
ActivityMap activityMap = tx.getActivityMap();
|
||||
activityMap.add(tx, createActivity("@testActivity0", "Test Activity", "Test", TimeOrdering.SERIES));
|
||||
Activity queriedActivity = activityMap.getBy(tx, "Test", "@testActivity0");
|
||||
assertNotNull(queriedActivity);
|
||||
assertEquals("@testActivity0", queriedActivity.getId());
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
|
@ -257,8 +242,17 @@ public class ComponentContainerTest {
|
|||
assertEquals("MyRealmOrder", myRealmOrder.getId());
|
||||
Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder");
|
||||
assertNull(otherRealmOrder);
|
||||
|
||||
ActivityMap activityMap = tx.getActivityMap();
|
||||
Activity myRealmAct = activityMap.getBy(tx, "TestType", "MyRealmAct");
|
||||
assertNotNull(myRealmAct);
|
||||
assertEquals("MyRealmAct", myRealmAct.getId());
|
||||
Activity otherRealmAct = activityMap.getBy(tx, "TestType", "OtherRealmAct");
|
||||
assertNull(otherRealmAct);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm("otherRealm").openTx(certificate, "test")) {
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
Resource otherRealmRes = resourceMap.getBy(tx, "TestType", "OtherRealmRes");
|
||||
|
@ -274,6 +268,15 @@ public class ComponentContainerTest {
|
|||
Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder");
|
||||
assertNull(myRealmOrder);
|
||||
tx.commitOnClose();
|
||||
|
||||
ActivityMap activityMap = tx.getActivityMap();
|
||||
Activity otherRealmAct = activityMap.getBy(tx, "TestType", "OtherRealmAct");
|
||||
assertNotNull(otherRealmAct);
|
||||
assertEquals("OtherRealmAct", otherRealmAct.getId());
|
||||
Activity myRealmAct = activityMap.getBy(tx, "TestType", "MyRealmAct");
|
||||
assertNull(myRealmAct);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -38,7 +38,7 @@ import li.strolch.agent.impl.DataStoreMode;
|
|||
public class RealmTest {
|
||||
|
||||
@Test
|
||||
public void shouldStartRealmTestContainer() {
|
||||
public void shouldStartRealmTestContainer() throws Exception {
|
||||
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER, agent -> {
|
||||
|
@ -46,17 +46,15 @@ public class RealmTest {
|
|||
|
||||
ComponentContainer container = agent.getContainer();
|
||||
Set<String> realmNames = container.getRealmNames();
|
||||
assertEquals(6, realmNames.size());
|
||||
assertEquals(4, realmNames.size());
|
||||
|
||||
Set<String> expectedRealmNames = new HashSet<>(Arrays.asList("defaultRealm", "myRealm", "otherRealm",
|
||||
"cachedRealm", "transactionalRealm", "emptyRealm"));
|
||||
Set<String> expectedRealmNames = new HashSet<>(
|
||||
Arrays.asList("defaultRealm", "myRealm", "otherRealm", "emptyRealm"));
|
||||
assertEquals(expectedRealmNames, realmNames);
|
||||
|
||||
assertEquals(DataStoreMode.TRANSIENT, container.getRealm("defaultRealm").getMode());
|
||||
assertEquals(DataStoreMode.TRANSIENT, container.getRealm("myRealm").getMode());
|
||||
assertEquals(DataStoreMode.TRANSIENT, container.getRealm("otherRealm").getMode());
|
||||
assertEquals(DataStoreMode.CACHED, container.getRealm("cachedRealm").getMode());
|
||||
assertEquals(DataStoreMode.TRANSACTIONAL, container.getRealm("transactionalRealm").getMode());
|
||||
assertEquals(DataStoreMode.EMPTY, container.getRealm("emptyRealm").getMode());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -37,7 +37,7 @@ public class PolicyHandlerTest {
|
|||
public static final String PATH_EMPTY_RUNTIME = "target/PolicyHandlerTest/"; //$NON-NLS-1$
|
||||
|
||||
@Test
|
||||
public void shouldInstantiatePolicies() {
|
||||
public void shouldInstantiatePolicies() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_TRANSIENT_CONTAINER, agent -> {
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class PolicyHandlerTest {
|
|||
|
||||
ComponentContainer container = agent.getContainer();
|
||||
Certificate certificate = container.getPrivilegeHandler().authenticate("test", "test".toCharArray());
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
||||
Resource res = tx.getResourceBy("TestType", "MyTestResource");
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -34,7 +34,7 @@ public class EnumHandlerTest {
|
|||
private static final String ENUM_HANDLER_TEST_RUNTIME = "target/EnumHandlerTest/";
|
||||
|
||||
@Test
|
||||
public void shouldFindByLocator() {
|
||||
public void shouldFindByLocator() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(ENUM_HANDLER_TEST_RUNTIME, ComponentContainerTest.PATH_TRANSIENT_CONTAINER, agent -> {
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,30 +15,27 @@
|
|||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import static li.strolch.agent.ComponentContainerTest.PATH_REALM_CONTAINER;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.audit.AccessType;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.audit.AuditQuery;
|
||||
import li.strolch.model.audit.AuditVisitor;
|
||||
import li.strolch.model.audit.NoStrategyAuditVisitor;
|
||||
import li.strolch.persistence.inmemory.InMemoryAuditDao;
|
||||
import li.strolch.model.audit.*;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -46,12 +43,16 @@ import org.junit.Test;
|
|||
@SuppressWarnings("nls")
|
||||
public class AuditQueryTest {
|
||||
|
||||
public static final String PATH_RUNTIME = "target/" + AuditQueryTest.class.getSimpleName();
|
||||
|
||||
private static Date past;
|
||||
private static Date earlier;
|
||||
private static Date current;
|
||||
private static Date later;
|
||||
private static Date future;
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AuditQueryTest.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws SQLException {
|
||||
|
||||
|
@ -69,112 +70,141 @@ public class AuditQueryTest {
|
|||
future = cal.getTime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryTypeAndDateRange() throws SQLException {
|
||||
|
||||
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
|
||||
|
||||
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(earlier, true).to(later,
|
||||
true));
|
||||
performQuery(query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true).to(current, true));
|
||||
performQuery(query, Arrays.asList(1L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true));
|
||||
performQuery(query, Arrays.asList(1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().to(current, true));
|
||||
performQuery(query, Arrays.asList(0L, 1L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.RESOURCE, new DateRange().from(past, true).to(future, true));
|
||||
performQuery(query, Arrays.<Long> asList());
|
||||
private static Certificate login(StrolchAgent agent) {
|
||||
PrivilegeHandler privilegeHandler = agent.getContainer().getPrivilegeHandler();
|
||||
return privilegeHandler.authenticate("test", "test".toCharArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryAudits() throws SQLException {
|
||||
public void shouldQueryTypeAndDateRange() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_RUNTIME, PATH_REALM_CONTAINER, agent -> {
|
||||
|
||||
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
|
||||
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
|
||||
|
||||
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future,
|
||||
true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ);
|
||||
performQuery(query, Arrays.asList(0L, 1L, 4L));
|
||||
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT,
|
||||
new DateRange().from(earlier, true).to(later, true));
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE);
|
||||
performQuery(query, Arrays.asList(0L, 4L));
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true).to(current, true));
|
||||
performQuery(agent, query, Arrays.asList(1L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
|
||||
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "create", "read");
|
||||
performQuery(query, Arrays.asList(0L, 1L, 4L));
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(current, true));
|
||||
performQuery(agent, query, Arrays.asList(1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
|
||||
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "read");
|
||||
performQuery(query, Arrays.asList(1L));
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().to(current, true));
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "crea");
|
||||
performQuery(query, Arrays.asList(0L, 4L));
|
||||
query = new AuditQuery<>(visitor, Tags.RESOURCE, new DateRange().from(past, true).to(future, true));
|
||||
performQuery(agent, query, Arrays.<Long>asList());
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_SENSITIVE, "crea");
|
||||
performQuery(query, Arrays.<Long> asList());
|
||||
});
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.EQUALS_CASE_INSENSITIVE, "create");
|
||||
performQuery(query, Arrays.asList(0L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier");
|
||||
performQuery(query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier", "later");
|
||||
performQuery(query, Arrays.asList(0L, 2L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
|
||||
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn");
|
||||
performQuery(query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
|
||||
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
|
||||
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
|
||||
performQuery(query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
|
||||
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
|
||||
performQuery(query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
|
||||
performQuery(query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Bar");
|
||||
performQuery(query, Arrays.asList());
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.limit(1).element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
|
||||
performQuery(query, Arrays.asList(2L));
|
||||
}
|
||||
|
||||
private void performQuery(AuditQuery<Audit> query, List<Long> expected) throws SQLException {
|
||||
|
||||
InMemoryAuditDao dao = new InMemoryAuditDao();
|
||||
dao.saveAll(getAudits());
|
||||
|
||||
List<Audit> result = dao.doQuery(query);
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (Audit audit : result) {
|
||||
ids.add(audit.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryAudits() throws Exception {
|
||||
try {
|
||||
RuntimeMock.runInStrolch(PATH_RUNTIME, PATH_REALM_CONTAINER, agent -> {
|
||||
|
||||
AuditVisitor<Audit> visitor = new NoStrategyAuditVisitor();
|
||||
|
||||
AuditQuery<Audit> query = new AuditQuery<>(visitor, Tags.AUDIT,
|
||||
new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ);
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE);
|
||||
performQuery(agent, query, Arrays.asList(0L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
|
||||
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "create", "read");
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.action().accessTypes(AccessType.CREATE, AccessType.READ)
|
||||
.actions(StringMatchMode.EQUALS_CASE_SENSITIVE, "read");
|
||||
performQuery(agent, query, Arrays.asList(1L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "crea");
|
||||
performQuery(agent, query, Arrays.asList(0L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.CONTAINS_CASE_SENSITIVE, "crea");
|
||||
performQuery(agent, query, Arrays.<Long>asList());
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementAccessed(StringMatchMode.EQUALS_CASE_INSENSITIVE, "create");
|
||||
performQuery(agent, query, Arrays.asList(0L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier");
|
||||
performQuery(agent, query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier", "later");
|
||||
performQuery(agent, query, Arrays.asList(0L, 2L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
|
||||
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn");
|
||||
performQuery(agent, query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().usernames(StringMatchMode.EQUALS_CASE_INSENSITIVE, "earlier")
|
||||
.firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
|
||||
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
|
||||
performQuery(agent, query, Arrays.asList(0L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.identity().firstnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "enn")
|
||||
.lastnames(StringMatchMode.CONTAINS_CASE_INSENSITIVE, "kennedy");
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
|
||||
performQuery(agent, query, Arrays.asList(0L, 1L, 2L, 3L, 4L));
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Bar");
|
||||
performQuery(agent, query, Arrays.asList());
|
||||
|
||||
query = new AuditQuery<>(visitor, Tags.AUDIT, new DateRange().from(past, true).to(future, true));
|
||||
query.limit(1).element().elementSubTypes(StringMatchMode.EQUALS_CASE_SENSITIVE, "Foo");
|
||||
performQuery(agent, query, Arrays.asList(2L));
|
||||
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void performQuery(StrolchAgent agent, AuditQuery<Audit> query, List<Long> expected) throws SQLException {
|
||||
|
||||
Certificate certificate = login(agent);
|
||||
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
||||
tx.setSuppressAudits(true);
|
||||
tx.getAuditTrail().addAll(tx, getAudits());
|
||||
|
||||
List<Audit> result = tx.doQuery(query);
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (Audit audit : result) {
|
||||
ids.add(audit.getId());
|
||||
}
|
||||
|
||||
assertEquals(new HashSet<>(expected), new HashSet<>(ids));
|
||||
}
|
||||
assertEquals(new HashSet<>(expected), new HashSet<>(ids));
|
||||
}
|
||||
|
||||
private static List<Audit> getAudits() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -57,7 +57,7 @@ public class FindByLocatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindByResource() {
|
||||
public void shouldFindByResource() throws Exception {
|
||||
runtimeMock.run(agent -> {
|
||||
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
@ -79,7 +79,8 @@ public class FindByLocatorTest {
|
|||
resStringParam);
|
||||
|
||||
// TimedState on Resource
|
||||
Locator locResIntegerState = Locator.valueOf("Resource/TestType/MyTestResource/TimedState/@integerState");
|
||||
Locator locResIntegerState = Locator
|
||||
.valueOf("Resource/TestType/MyTestResource/TimedState/@integerState");
|
||||
IntegerTimedState integerS = tx.findElement(locResIntegerState);
|
||||
assertNotNull("Should have found a IntegerTimedState with the locator " + locResIntegerState, integerS);
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class FindByLocatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindByOrder() {
|
||||
public void shouldFindByOrder() throws Exception {
|
||||
runtimeMock.run(agent -> {
|
||||
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
@ -113,7 +114,7 @@ public class FindByLocatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindByActivity() {
|
||||
public void shouldFindByActivity() throws Exception {
|
||||
runtimeMock.run(agent -> {
|
||||
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
@ -137,7 +138,7 @@ public class FindByLocatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindByAction() {
|
||||
public void shouldFindByAction() throws Exception {
|
||||
runtimeMock.run(agent -> {
|
||||
try (StrolchTransaction tx = agent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import static li.strolch.model.query.ParameterSelection.booleanSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.integerListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.longListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringSelection;
|
||||
import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER;
|
||||
import static li.strolch.model.query.ParameterSelection.*;
|
||||
import static li.strolch.utils.StringMatchMode.ci;
|
||||
import static li.strolch.utils.StringMatchMode.es;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -15,8 +10,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.State;
|
||||
|
@ -24,268 +19,281 @@ import li.strolch.model.Version;
|
|||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
import li.strolch.model.parameter.FloatListParameter;
|
||||
import li.strolch.model.parameter.FloatParameter;
|
||||
import li.strolch.model.parameter.IntegerListParameter;
|
||||
import li.strolch.model.parameter.LongListParameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.ActivityStateSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.persistence.inmemory.InMemoryActivityDao;
|
||||
import li.strolch.model.parameter.*;
|
||||
import li.strolch.model.query.*;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InMemoryActivityQueryTest {
|
||||
|
||||
protected InMemoryActivityDao daoInstance() {
|
||||
return new InMemoryActivityDao(false);
|
||||
public static final String PATH_RUNTIME = "target/" + InMemoryActivityQueryTest.class.getSimpleName();
|
||||
private static RuntimeMock runtimeMock;
|
||||
private static Certificate certificate;
|
||||
|
||||
private static Certificate login(StrolchAgent agent) {
|
||||
PrivilegeHandler privilegeHandler = agent.getContainer().getPrivilegeHandler();
|
||||
return privilegeHandler.authenticate("test", "test".toCharArray());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
runtimeMock = new RuntimeMock(PATH_RUNTIME, PATH_EMPTY_CONTAINER);
|
||||
runtimeMock.mockRuntime();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
certificate = login(runtimeMock.getAgent());
|
||||
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
getActivities().forEach(tx::add);
|
||||
tx.add(getBallActivity());
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private static StrolchTransaction openTx() {
|
||||
return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryById() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType1");
|
||||
activityQuery.with(new IdSelection("@1"));
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType1");
|
||||
activityQuery.with(new IdSelection("@1"));
|
||||
|
||||
List<Activity> result = dao.doQuery(activityQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
List<Activity> result = tx.doQuery(activityQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdOr() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType2");
|
||||
activityQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType2");
|
||||
activityQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
|
||||
List<Activity> result = dao.doQuery(activityQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
List<Activity> result = tx.doQuery(activityQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdAnd() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType2");
|
||||
activityQuery.and().with(new IdSelection("@3"), new NameSelection("Activity 3", es()));
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType2");
|
||||
activityQuery.and().with(new IdSelection("@3"), new NameSelection("Activity 3", es()));
|
||||
|
||||
List<Activity> result = dao.doQuery(activityQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
List<Activity> result = tx.doQuery(activityQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotQueryByIdAnd() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType1");
|
||||
activityQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
ActivityQuery<Activity> activityQuery = ActivityQuery.query("MyType1");
|
||||
activityQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
|
||||
List<Activity> result = dao.doQuery(activityQuery);
|
||||
assertEquals(0, result.size());
|
||||
List<Activity> result = tx.doQuery(activityQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByParameter() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true), floatSelection("parameters", "diameter", 22.0));
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true),
|
||||
floatSelection("parameters", "diameter", 22.0));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByListParameter() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery;
|
||||
List<Activity> result;
|
||||
ActivityQuery<Activity> ballQuery;
|
||||
List<Activity> result;
|
||||
|
||||
// string list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// string list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and()
|
||||
.with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// integer list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// integer list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// float list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// float list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// long list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// long list
|
||||
{
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter1() {
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter2() {
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter3() {
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByName() {
|
||||
|
||||
List<Activity> activities = getActivities();
|
||||
activities.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activities);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByState() {
|
||||
|
||||
List<Activity> activities = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activities);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("MyType1");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("MyType1");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
List<Activity> result = tx.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("MyType2");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ActivityQuery.query("MyType2");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
private Activity getBallActivity() {
|
||||
private static Activity getBallActivity() {
|
||||
Activity res1 = new Activity("childrensBall", "Ball 1", "Ball", TimeOrdering.SERIES);
|
||||
Version.setInitialVersionFor(res1, -1, "test");
|
||||
ParameterBag bag = new ParameterBag("parameters", "Ball Details", "Parameters");
|
||||
|
@ -302,7 +310,7 @@ public class InMemoryActivityQueryTest {
|
|||
return res1;
|
||||
}
|
||||
|
||||
private List<Activity> getActivities() {
|
||||
private static List<Activity> getActivities() {
|
||||
|
||||
Activity activity1 = ModelGenerator.createActivity("@1", "Activity 1", "MyType1", TimeOrdering.SERIES);
|
||||
((Action) activity1.getElement("action_" + activity1.getId())).setState(State.STOPPED);
|
||||
|
@ -322,18 +330,18 @@ public class InMemoryActivityQueryTest {
|
|||
Activity activity6 = ModelGenerator.createActivity("@6", "Activity 6", "MyType3", TimeOrdering.SERIES);
|
||||
((Action) activity6.getElement("action_" + activity6.getId())).setState(State.CLOSED);
|
||||
|
||||
List<Activity> activitys = new ArrayList<>();
|
||||
activitys.add(activity1);
|
||||
activitys.add(activity2);
|
||||
activitys.add(activity3);
|
||||
activitys.add(activity4);
|
||||
activitys.add(activity5);
|
||||
activitys.add(activity6);
|
||||
List<Activity> activities = new ArrayList<>();
|
||||
activities.add(activity1);
|
||||
activities.add(activity2);
|
||||
activities.add(activity3);
|
||||
activities.add(activity4);
|
||||
activities.add(activity5);
|
||||
activities.add(activity6);
|
||||
|
||||
for (Activity activity : activitys) {
|
||||
for (Activity activity : activities) {
|
||||
Version.setInitialVersionFor(activity, -1, "test");
|
||||
}
|
||||
|
||||
return activitys;
|
||||
return activities;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,13 +15,8 @@
|
|||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import static li.strolch.model.query.ParameterSelection.booleanSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.integerListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.longListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringSelection;
|
||||
import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER;
|
||||
import static li.strolch.model.query.ParameterSelection.*;
|
||||
import static li.strolch.utils.StringMatchMode.ci;
|
||||
import static li.strolch.utils.StringMatchMode.es;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -31,279 +26,288 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.*;
|
||||
import li.strolch.model.parameter.*;
|
||||
import li.strolch.model.query.*;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
import li.strolch.model.parameter.FloatListParameter;
|
||||
import li.strolch.model.parameter.FloatParameter;
|
||||
import li.strolch.model.parameter.IntegerListParameter;
|
||||
import li.strolch.model.parameter.LongListParameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.OrderStateSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.persistence.inmemory.InMemoryOrderDao;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class InMemoryOrderQueryTest {
|
||||
|
||||
protected InMemoryOrderDao daoInstance() {
|
||||
return new InMemoryOrderDao(false);
|
||||
public static final String PATH_RUNTIME = "target/" + InMemoryOrderQueryTest.class.getSimpleName();
|
||||
private static RuntimeMock runtimeMock;
|
||||
private static Certificate certificate;
|
||||
|
||||
private static Certificate login(StrolchAgent agent) {
|
||||
PrivilegeHandler privilegeHandler = agent.getContainer().getPrivilegeHandler();
|
||||
return privilegeHandler.authenticate("test", "test".toCharArray());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
runtimeMock = new RuntimeMock(PATH_RUNTIME, PATH_EMPTY_CONTAINER);
|
||||
runtimeMock.mockRuntime();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
certificate = login(runtimeMock.getAgent());
|
||||
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
getOrders().forEach(tx::add);
|
||||
tx.add(getBallOrder());
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private static StrolchTransaction openTx() {
|
||||
return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryById() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType1");
|
||||
orderQuery.with(new IdSelection("@1"));
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType1");
|
||||
orderQuery.with(new IdSelection("@1"));
|
||||
|
||||
List<Order> result = dao.doQuery(orderQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
List<Order> result = tx.doQuery(orderQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdOr() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType2");
|
||||
orderQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType2");
|
||||
orderQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
|
||||
List<Order> result = dao.doQuery(orderQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
List<Order> result = tx.doQuery(orderQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdAnd() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType2");
|
||||
orderQuery.and().with(new IdSelection("@3"), new NameSelection("Order 3", es()));
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType2");
|
||||
orderQuery.and().with(new IdSelection("@3"), new NameSelection("Order 3", es()));
|
||||
|
||||
List<Order> result = dao.doQuery(orderQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
List<Order> result = tx.doQuery(orderQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotQueryByIdAnd() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType1");
|
||||
orderQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
OrderQuery<Order> orderQuery = OrderQuery.query("MyType1");
|
||||
orderQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
|
||||
List<Order> result = dao.doQuery(orderQuery);
|
||||
assertEquals(0, result.size());
|
||||
List<Order> result = tx.doQuery(orderQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByParameter() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true), floatSelection("parameters", "diameter", 22.0));
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true),
|
||||
floatSelection("parameters", "diameter", 22.0));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByListParameter() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery;
|
||||
List<Order> result;
|
||||
OrderQuery<Order> ballQuery;
|
||||
List<Order> result;
|
||||
|
||||
// string list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// string list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and()
|
||||
.with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// integer list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// integer list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// float list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// float list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// long list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// long list
|
||||
{
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter1() {
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter2() {
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter3() {
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByName() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
orders.add(getBallOrder());
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByState() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("MyType1");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("MyType1");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
List<Order> result = tx.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("MyType2");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = OrderQuery.query("MyType2");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
private Order getBallOrder() {
|
||||
private static Order getBallOrder() {
|
||||
Order o1 = new Order("childrensBall", "Ball 1", "Ball");
|
||||
Version.setInitialVersionFor(o1, -1, "test");
|
||||
ParameterBag bag = new ParameterBag("parameters", "Ball Details", "Parameters");
|
||||
|
@ -320,7 +324,7 @@ public class InMemoryOrderQueryTest {
|
|||
return o1;
|
||||
}
|
||||
|
||||
private List<Order> getOrders() {
|
||||
private static List<Order> getOrders() {
|
||||
Order res1 = ModelGenerator.createOrder("@1", "Order 1", "MyType1", new Date(), State.STOPPED);
|
||||
Order res2 = ModelGenerator.createOrder("@2", "Order 2", "MyType1", new Date(), State.STOPPED);
|
||||
Order res3 = ModelGenerator.createOrder("@3", "Order 3", "MyType2", new Date(), State.STOPPED);
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.persistence.api.ActivityDao;
|
||||
import li.strolch.persistence.api.AuditDao;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.inmemory.InMemoryPersistence;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InMemoryPersistenceHandler extends StrolchComponent implements PersistenceHandler {
|
||||
|
||||
private InMemoryPersistence persistence;
|
||||
|
||||
/**
|
||||
* @param container
|
||||
* @param componentName
|
||||
*/
|
||||
public InMemoryPersistenceHandler(ComponentContainer container, String componentName) {
|
||||
super(container, componentName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ComponentConfiguration configuration) throws Exception {
|
||||
this.persistence = new InMemoryPersistence(getContainer(), false);
|
||||
super.initialize(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) {
|
||||
return this.persistence.openTx(realm, certificate, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderDao getOrderDao(StrolchTransaction tx) {
|
||||
return this.persistence.getOrderDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceDao getResourceDao(StrolchTransaction tx) {
|
||||
return this.persistence.getResourceDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityDao getActivityDao(StrolchTransaction tx) {
|
||||
return this.persistence.getActivityDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditDao getAuditDao(StrolchTransaction tx) {
|
||||
return this.persistence.getAuditDao(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDbInitialization() {
|
||||
// no-op
|
||||
}
|
||||
}
|
|
@ -1,12 +1,7 @@
|
|||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import static li.strolch.model.query.ParameterSelection.booleanSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.floatSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.integerListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.longListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringListSelection;
|
||||
import static li.strolch.model.query.ParameterSelection.stringSelection;
|
||||
import static li.strolch.agent.ComponentContainerTest.PATH_EMPTY_CONTAINER;
|
||||
import static li.strolch.model.query.ParameterSelection.*;
|
||||
import static li.strolch.utils.StringMatchMode.ci;
|
||||
import static li.strolch.utils.StringMatchMode.es;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -15,254 +10,274 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.api.StrolchAgent;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
import li.strolch.model.parameter.FloatListParameter;
|
||||
import li.strolch.model.parameter.FloatParameter;
|
||||
import li.strolch.model.parameter.IntegerListParameter;
|
||||
import li.strolch.model.parameter.LongListParameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.parameter.*;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.persistence.inmemory.InMemoryResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InMemoryResourceQueryTest {
|
||||
|
||||
protected InMemoryResourceDao daoInstance() {
|
||||
return new InMemoryResourceDao(false);
|
||||
public static final String PATH_RUNTIME = "target/" + InMemoryResourceQueryTest.class.getSimpleName();
|
||||
private static RuntimeMock runtimeMock;
|
||||
private static Certificate certificate;
|
||||
|
||||
private static Certificate login(StrolchAgent agent) {
|
||||
PrivilegeHandler privilegeHandler = agent.getContainer().getPrivilegeHandler();
|
||||
return privilegeHandler.authenticate("test", "test".toCharArray());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
runtimeMock = new RuntimeMock(PATH_RUNTIME, PATH_EMPTY_CONTAINER);
|
||||
runtimeMock.mockRuntime();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
certificate = login(runtimeMock.getAgent());
|
||||
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
getResources().forEach(tx::add);
|
||||
tx.add(getBallResource());
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private static StrolchTransaction openTx() {
|
||||
return runtimeMock.getAgent().getContainer().getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryById() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType1");
|
||||
resourceQuery.with(new IdSelection("@1"));
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType1");
|
||||
resourceQuery.with(new IdSelection("@1"));
|
||||
|
||||
List<Resource> result = dao.doQuery(resourceQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
List<Resource> result = tx.doQuery(resourceQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdOr() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType2");
|
||||
resourceQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType2");
|
||||
resourceQuery.or().with(new IdSelection("@3"), new IdSelection("@4"));
|
||||
|
||||
List<Resource> result = dao.doQuery(resourceQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
List<Resource> result = tx.doQuery(resourceQuery);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
assertEquals("@4", result.get(1).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByIdAnd() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType2");
|
||||
resourceQuery.and().with(new IdSelection("@3"), new NameSelection("Res 3", es()));
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType2");
|
||||
resourceQuery.and().with(new IdSelection("@3"), new NameSelection("Res 3", es()));
|
||||
|
||||
List<Resource> result = dao.doQuery(resourceQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
List<Resource> result = tx.doQuery(resourceQuery);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@3", result.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotQueryByIdAnd() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType1");
|
||||
resourceQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
ResourceQuery<Resource> resourceQuery = ResourceQuery.query("MyType1");
|
||||
resourceQuery.and().with(new IdSelection("@3"), new NameSelection("@4", es()));
|
||||
|
||||
List<Resource> result = dao.doQuery(resourceQuery);
|
||||
assertEquals(0, result.size());
|
||||
List<Resource> result = tx.doQuery(resourceQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByParameter() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true), floatSelection("parameters", "diameter", 22.0));
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(
|
||||
//
|
||||
stringSelection("parameters", "color", "red", es()),
|
||||
booleanSelection("parameters", "forChildren", true),
|
||||
floatSelection("parameters", "diameter", 22.0));
|
||||
|
||||
List<Resource> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Resource> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByListParameter() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> ballQuery;
|
||||
List<Resource> result;
|
||||
ResourceQuery<Resource> ballQuery;
|
||||
List<Resource> result;
|
||||
|
||||
// string list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// string list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a", "z")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and()
|
||||
.with(stringListSelection("parameters", "stringListValues", Arrays.asList("c", "b", "a")));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// integer list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// integer list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1, 5)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(integerListSelection("parameters", "intListValues", Arrays.asList(3, 2, 1)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// float list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// float list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0, 8.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(floatListSelection("parameters", "floatListValues", Arrays.asList(6.2, 5.1, 4.0)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
// long list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
// long list
|
||||
{
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L, 11L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with(longListSelection("parameters", "longListValues", Arrays.asList(10L, 9L, 8L)));
|
||||
result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter1() {
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
List<Resource> result = dao.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "color"));
|
||||
|
||||
List<Resource> result = tx.doQuery(ballQuery);
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter2() {
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
List<Resource> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Resource> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByNullParameter3() {
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
List<Resource> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.and().with( //
|
||||
ParameterSelection.nullSelection("parameters", "weight"));
|
||||
|
||||
List<Resource> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByName() {
|
||||
|
||||
List<Resource> resources = getResources();
|
||||
resources.add(getBallResource());
|
||||
InMemoryResourceDao dao = daoInstance();
|
||||
dao.saveAll(resources);
|
||||
try (StrolchTransaction tx = openTx()) {
|
||||
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
ResourceQuery<Resource> ballQuery = ResourceQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
|
||||
List<Resource> result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
List<Resource> result = tx.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
private Resource getBallResource() {
|
||||
private static Resource getBallResource() {
|
||||
Resource res1 = new Resource("childrensBall", "Ball 1", "Ball");
|
||||
Version.setInitialVersionFor(res1, -1, "test");
|
||||
ParameterBag bag = new ParameterBag("parameters", "Ball Details", "Parameters");
|
||||
|
@ -279,7 +294,7 @@ public class InMemoryResourceQueryTest {
|
|||
return res1;
|
||||
}
|
||||
|
||||
private List<Resource> getResources() {
|
||||
private static List<Resource> getResources() {
|
||||
Resource res1 = ModelGenerator.createResource("@1", "Res 1", "MyType1");
|
||||
Resource res2 = ModelGenerator.createResource("@2", "Res 2", "MyType1");
|
||||
Resource res3 = ModelGenerator.createResource("@3", "Res 3", "MyType2");
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,36 +15,30 @@
|
|||
*/
|
||||
package li.strolch.runtime.query.inmemory;
|
||||
|
||||
import static li.strolch.model.ModelGenerator.BAG_ID;
|
||||
import static li.strolch.model.ModelGenerator.PARAM_STRING_ID;
|
||||
import static li.strolch.model.ModelGenerator.createOrder;
|
||||
import static li.strolch.model.ModelGenerator.createResource;
|
||||
import static li.strolch.model.ModelGenerator.*;
|
||||
import static li.strolch.model.query.ParameterSelection.integerSelection;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.RuntimeMock;
|
||||
import li.strolch.agent.ComponentContainerTest;
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.model.parameter.IntegerParameter;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.query.Selection;
|
||||
import li.strolch.model.query.*;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class QueryTest {
|
||||
|
@ -56,7 +50,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceWithParamValue() {
|
||||
public void shouldQueryResourceWithParamValue() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -66,24 +60,24 @@ public class QueryTest {
|
|||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
IntegerParameter iP = new IntegerParameter("nbOfBooks", "Number of Books", 33);
|
||||
res1.addParameter(BAG_ID, iP);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.add(res1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
List<Selection> elementAndSelections = new ArrayList<>();
|
||||
elementAndSelections.add(new IdSelection("@1"));
|
||||
elementAndSelections.add(ParameterSelection.integerSelection(BAG_ID, "nbOfBooks", 33));
|
||||
elementAndSelections.add(integerSelection(BAG_ID, "nbOfBooks", 33));
|
||||
query.and().with(elementAndSelections);
|
||||
|
||||
InMemoryResourceQueryVisitor resourceQuery = new InMemoryResourceQueryVisitor();
|
||||
InMemoryQuery<Resource, Resource> inMemoryQuery = resourceQuery.visit(query);
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getResourceDao(tx));
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = inMemoryQuery.doQuery(tx, tx.getResourceMap());
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
|
@ -91,7 +85,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderWithParamValue() {
|
||||
public void shouldQueryOrderWithParamValue() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -101,24 +95,24 @@ public class QueryTest {
|
|||
Order o1 = createOrder("@1", "Test Order", "MyType");
|
||||
IntegerParameter iP = new IntegerParameter("nbOfBooks", "Number of Books", 33);
|
||||
o1.addParameter(BAG_ID, iP);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
tx.getOrderMap().add(tx, o1);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.add(o1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType");
|
||||
List<Selection> elementAndSelections = new ArrayList<>();
|
||||
elementAndSelections.add(new IdSelection("@1"));
|
||||
elementAndSelections.add(ParameterSelection.integerSelection(BAG_ID, "nbOfBooks", 33));
|
||||
elementAndSelections.add(integerSelection(BAG_ID, "nbOfBooks", 33));
|
||||
query.and().with(elementAndSelections);
|
||||
|
||||
InMemoryOrderQueryVisitor orderQuery = new InMemoryOrderQueryVisitor();
|
||||
InMemoryQuery<Order, Order> inMemoryQuery = orderQuery.visit(query);
|
||||
List<Order> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getOrderDao(tx));
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = inMemoryQuery.doQuery(tx, tx.getOrderMap());
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
|
@ -126,7 +120,42 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryContainsString() {
|
||||
public void shouldQueryActivityWithParamValue() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
||||
Certificate certificate = login(container);
|
||||
|
||||
Activity a1 = createActivity("@1", "Test Activity", "MyType", TimeOrdering.SERIES);
|
||||
IntegerParameter iP = new IntegerParameter("nbOfBooks", "Number of Books", 33);
|
||||
a1.addParameter(BAG_ID, iP);
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.add(a1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType");
|
||||
List<Selection> elementAndSelections = new ArrayList<>();
|
||||
elementAndSelections.add(new IdSelection("@1"));
|
||||
elementAndSelections.add(integerSelection(BAG_ID, "nbOfBooks", 33));
|
||||
query.and().with(elementAndSelections);
|
||||
|
||||
InMemoryActivityQueryVisitor orderQuery = new InMemoryActivityQueryVisitor();
|
||||
InMemoryQuery<Activity, Activity> inMemoryQuery = orderQuery.visit(query);
|
||||
List<Activity> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = inMemoryQuery.doQuery(tx, tx.getActivityMap());
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("@1", result.get(0).getId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryContainsString() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -134,18 +163,18 @@ public class QueryTest {
|
|||
Certificate certificate = login(container);
|
||||
|
||||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "olch",
|
||||
StringMatchMode.CONTAINS_CASE_SENSITIVE));
|
||||
query.and().with(ParameterSelection
|
||||
.stringSelection(BAG_ID, PARAM_STRING_ID, "olch", StringMatchMode.CONTAINS_CASE_SENSITIVE));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
|
@ -154,7 +183,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotQueryContainsString() {
|
||||
public void shouldNotQueryContainsString() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -162,18 +191,18 @@ public class QueryTest {
|
|||
Certificate certificate = login(container);
|
||||
|
||||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "str",
|
||||
StringMatchMode.CONTAINS_CASE_SENSITIVE));
|
||||
query.and().with(ParameterSelection
|
||||
.stringSelection(BAG_ID, PARAM_STRING_ID, "str", StringMatchMode.CONTAINS_CASE_SENSITIVE));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(0, result.size());
|
||||
|
@ -181,7 +210,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryCaseInsensitiveString() {
|
||||
public void shouldQueryCaseInsensitiveString() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -189,18 +218,18 @@ public class QueryTest {
|
|||
Certificate certificate = login(container);
|
||||
|
||||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
query.and().with(ParameterSelection
|
||||
.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch", StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
|
@ -209,7 +238,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotQueryCaseInsensitiveString() {
|
||||
public void shouldNotQueryCaseInsensitiveString() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -217,18 +246,18 @@ public class QueryTest {
|
|||
Certificate certificate = login(container);
|
||||
|
||||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
query.and().with(ParameterSelection
|
||||
.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(0, result.size());
|
||||
|
@ -236,7 +265,7 @@ public class QueryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryNot() {
|
||||
public void shouldQueryNot() throws Exception {
|
||||
|
||||
RuntimeMock.runInStrolch(PATH_EMPTY_RUNTIME, ComponentContainerTest.PATH_EMPTY_CONTAINER, agent -> {
|
||||
ComponentContainer container = agent.getContainer();
|
||||
|
@ -245,8 +274,8 @@ public class QueryTest {
|
|||
|
||||
Resource res1 = createResource("@1", "Test Resource", "MyType");
|
||||
Resource res2 = createResource("@2", "Test Resource", "MyType");
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
tx.getResourceMap().add(tx, res1);
|
||||
tx.getResourceMap().add(tx, res2);
|
||||
tx.commitOnClose();
|
||||
|
@ -256,8 +285,8 @@ public class QueryTest {
|
|||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.not(new IdSelection("@1"));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
|
@ -268,8 +297,8 @@ public class QueryTest {
|
|||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.not(new IdSelection("@2"));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
|
@ -280,8 +309,8 @@ public class QueryTest {
|
|||
ResourceQuery<Resource> query = ResourceQuery.query("MyType");
|
||||
query.not(new IdSelection("@1", "@2"));
|
||||
List<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate,
|
||||
"test")) {
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM)
|
||||
.openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
}
|
||||
assertEquals(0, result.size());
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Privilege>
|
||||
|
||||
<Container>
|
||||
|
||||
<Parameters>
|
||||
<!-- parameters for the container itself -->
|
||||
<Parameter name="autoPersistOnUserChangesData" value="true" />
|
||||
</Parameters>
|
||||
|
||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||
<Parameters>
|
||||
<!-- WARNING: If you change iterations or keyLength, then all passwords are invalid -->
|
||||
<!-- default algorithm is: PBKDF2WithHmacSHA512 -->
|
||||
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512" />
|
||||
<!-- default iterations: 200000 -->
|
||||
<Parameter name="hashIterations" value="10000" />
|
||||
<!-- default key length: 256 -->
|
||||
<Parameter name="hashKeyLength" value="256" />
|
||||
</Parameters>
|
||||
</EncryptionHandler>
|
||||
|
||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||
<Parameters>
|
||||
<Parameter name="usersXmlFile" value="PrivilegeUsers.xml" />
|
||||
<Parameter name="rolesXmlFile" value="PrivilegeRoles.xml" />
|
||||
</Parameters>
|
||||
</PersistenceHandler>
|
||||
|
||||
<UserChallengeHandler class="li.strolch.privilege.handler.ConsoleUserChallengeHandler">
|
||||
</UserChallengeHandler>
|
||||
|
||||
</Container>
|
||||
|
||||
<Policies>
|
||||
<Policy name="DefaultPrivilege" class="li.strolch.privilege.policy.DefaultPrivilege" />
|
||||
<Policy name="ModelPrivilege" class="li.strolch.runtime.privilege.ModelPrivilege" />
|
||||
<Policy name="RoleAccessPrivilege" class="li.strolch.privilege.policy.RoleAccessPrivilege" />
|
||||
<Policy name="UserAccessPrivilege" class="li.strolch.privilege.policy.UserAccessPrivilege" />
|
||||
</Policies>
|
||||
|
||||
</Privilege>
|
|
@ -1,91 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Roles>
|
||||
<Role name="agent">
|
||||
<Privilege name="li.strolch.privilege.handler.SystemAction" policy="DefaultPrivilege">
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemAction</Allow>
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemActionWithResult</Allow>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
<Role name="AppUser">
|
||||
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
</Roles>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Users>
|
||||
<User userId="1" username="agent">
|
||||
<State>SYSTEM</State>
|
||||
<Roles>
|
||||
<Role>agent</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
<User userId="2" username="test" password="fdd9d2def3475e1d5cc87107b87e14fd6adbca664c2874fc379a1e53931c0428" salt="74657374">
|
||||
<Firstname>Application</Firstname>
|
||||
<Lastname>Administrator</Lastname>
|
||||
<State>ENABLED</State>
|
||||
<Locale>en_GB</Locale>
|
||||
<Roles>
|
||||
<Role>AppUser</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
</Users>
|
|
@ -1,50 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchConfiguration>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchRuntimeTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<Properties>
|
||||
<dataStoreMode>CACHED</dataStoreMode>
|
||||
<dataStoreFile>StrolchModel.xml</dataStoreFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>ServiceHandler</name>
|
||||
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
|
||||
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
|
||||
<depends>RealmHandler</depends>
|
||||
<Properties>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PostInitializer</name>
|
||||
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
|
||||
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
|
||||
<depends>ServiceHandler</depends>
|
||||
<Properties>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.runtime.query.inmemory.InMemoryPersistenceHandler</impl>
|
||||
</Component>
|
||||
</env>
|
||||
</StrolchConfiguration>
|
|
@ -16,27 +16,20 @@
|
|||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.runtime.query.inmemory.InMemoryPersistenceHandler</impl>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<realms>defaultRealm, myRealm, otherRealm, cachedRealm, transactionalRealm, emptyRealm</realms>
|
||||
<realms>defaultRealm, myRealm, otherRealm, emptyRealm</realms>
|
||||
<dataStoreMode>TRANSIENT</dataStoreMode>
|
||||
<dataStoreFile>DefaultRealm.xml</dataStoreFile>
|
||||
<enableAuditTrail>true</enableAuditTrail>
|
||||
<dataStoreMode.myRealm>TRANSIENT</dataStoreMode.myRealm>
|
||||
<dataStoreFile.myRealm>MyRealm.xml</dataStoreFile.myRealm>
|
||||
<dataStoreMode.otherRealm>TRANSIENT</dataStoreMode.otherRealm>
|
||||
<dataStoreFile.otherRealm>OtherRealm.xml</dataStoreFile.otherRealm>
|
||||
<dataStoreMode.transactionalRealm>TRANSACTIONAL</dataStoreMode.transactionalRealm>
|
||||
<dataStoreMode.cachedRealm>CACHED</dataStoreMode.cachedRealm>
|
||||
<dataStoreMode.emptyRealm>EMPTY</dataStoreMode.emptyRealm>
|
||||
</Properties>
|
||||
</Component>
|
||||
|
|
|
@ -22,4 +22,25 @@
|
|||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
<Activity Id="MyRealmAct" Name="Test Name" Type="TestType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer" />
|
||||
</Action>
|
||||
<Activity Id="child_activity" Name="Child Activity" Type="childType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="Planned" Type="Use" />
|
||||
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use" />
|
||||
</Activity>
|
||||
</Activity>
|
||||
</StrolchModel>
|
||||
|
|
|
@ -22,4 +22,25 @@
|
|||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
<Activity Id="OtherRealmAct" Name="Test Name" Type="TestType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer" />
|
||||
</Action>
|
||||
<Activity Id="child_activity" Name="Child Activity" Type="childType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="Planned" Type="Use" />
|
||||
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use" />
|
||||
</Activity>
|
||||
</Activity>
|
||||
</StrolchModel>
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Privilege>
|
||||
|
||||
<Container>
|
||||
|
||||
<Parameters>
|
||||
<!-- parameters for the container itself -->
|
||||
<Parameter name="autoPersistOnUserChangesData" value="true" />
|
||||
</Parameters>
|
||||
|
||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||
<Parameters>
|
||||
<!-- WARNING: If you change iterations or keyLength, then all passwords are invalid -->
|
||||
<!-- default algorithm is: PBKDF2WithHmacSHA512 -->
|
||||
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512" />
|
||||
<!-- default iterations: 200000 -->
|
||||
<Parameter name="hashIterations" value="10000" />
|
||||
<!-- default key length: 256 -->
|
||||
<Parameter name="hashKeyLength" value="256" />
|
||||
</Parameters>
|
||||
</EncryptionHandler>
|
||||
|
||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||
<Parameters>
|
||||
<Parameter name="usersXmlFile" value="PrivilegeUsers.xml" />
|
||||
<Parameter name="rolesXmlFile" value="PrivilegeRoles.xml" />
|
||||
</Parameters>
|
||||
</PersistenceHandler>
|
||||
|
||||
<UserChallengeHandler class="li.strolch.privilege.handler.ConsoleUserChallengeHandler">
|
||||
</UserChallengeHandler>
|
||||
|
||||
</Container>
|
||||
|
||||
<Policies>
|
||||
<Policy name="DefaultPrivilege" class="li.strolch.privilege.policy.DefaultPrivilege" />
|
||||
<Policy name="ModelPrivilege" class="li.strolch.runtime.privilege.ModelPrivilege" />
|
||||
<Policy name="RoleAccessPrivilege" class="li.strolch.privilege.policy.RoleAccessPrivilege" />
|
||||
<Policy name="UserAccessPrivilege" class="li.strolch.privilege.policy.UserAccessPrivilege" />
|
||||
</Policies>
|
||||
|
||||
</Privilege>
|
|
@ -1,92 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Roles>
|
||||
<Role name="agent">
|
||||
<Privilege name="li.strolch.privilege.handler.SystemAction" policy="DefaultPrivilege">
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemAction</Allow>
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemActionWithResult</Allow>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
|
||||
<Role name="AppUser">
|
||||
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
</Roles>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Users>
|
||||
<User userId="1" username="agent">
|
||||
<State>SYSTEM</State>
|
||||
<Roles>
|
||||
<Role>agent</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
<User userId="2" username="test" password="fdd9d2def3475e1d5cc87107b87e14fd6adbca664c2874fc379a1e53931c0428" salt="74657374">
|
||||
<Firstname>Application</Firstname>
|
||||
<Lastname>Administrator</Lastname>
|
||||
<State>ENABLED</State>
|
||||
<Locale>en_GB</Locale>
|
||||
<Roles>
|
||||
<Role>AppUser</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
</Users>
|
|
@ -1,51 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchConfiguration>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchRuntimeTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<dataStoreMode>TRANSACTIONAL</dataStoreMode>
|
||||
<dataStoreFile>StrolchModel.xml</dataStoreFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>ServiceHandler</name>
|
||||
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
|
||||
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
|
||||
<depends>RealmHandler</depends>
|
||||
<Properties>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PostInitializer</name>
|
||||
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
|
||||
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
|
||||
<depends>ServiceHandler</depends>
|
||||
<Properties>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.runtime.query.inmemory.InMemoryPersistenceHandler</impl>
|
||||
</Component>
|
||||
</env>
|
||||
</StrolchConfiguration>
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<StrolchModel>
|
||||
<Order Id="MyTestOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
</StrolchModel>
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<StrolchModel>
|
||||
<Resource Id="MyTestResource" Name="Test Name" Type="TestType">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
</StrolchModel>
|
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchModel>
|
||||
<Resource Id="TestType" Name="TestType Template" Type="Template">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Order Id="Template" Name="MyTestOrder Template" Type="MyTestOrder">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
|
||||
<IncludeFile file="Resources.xml" />
|
||||
<IncludeFile file="Orders.xml" />
|
||||
|
||||
</StrolchModel>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchModel>
|
||||
|
||||
<Activity Id="activity_1" Name="Activity" Type="ActivityType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer" />
|
||||
</Action>
|
||||
<Activity Id="child_activity" Name="Child Activity" Type="childType" TimeOrdering="Series">
|
||||
<Policies>
|
||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation" />
|
||||
</Policies>
|
||||
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="Planned" Type="Use" />
|
||||
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use" />
|
||||
</Activity>
|
||||
</Activity>
|
||||
|
||||
</StrolchModel>
|
|
@ -25,5 +25,6 @@
|
|||
|
||||
<IncludeFile file="Resources.xml" />
|
||||
<IncludeFile file="Orders.xml" />
|
||||
<IncludeFile file="Activities.xml" />
|
||||
|
||||
</StrolchModel>
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -52,103 +52,6 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
|
||||
protected abstract T parseFromXml(String id, String type, SQLXML xml);
|
||||
|
||||
@Override
|
||||
public boolean hasElement(String type, String id) {
|
||||
String sql = "select count(*) from " + getTableName() + " where type = ? and id = ? and latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, type);
|
||||
statement.setString(2, id);
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
result.next();
|
||||
long numberOfElements = result.getLong(1);
|
||||
if (numberOfElements == 0)
|
||||
return false;
|
||||
if (numberOfElements == 1)
|
||||
return true;
|
||||
|
||||
String msg = MessageFormat.format("Non unique number of elements with type {0} and id {1}", type, id);
|
||||
throw new StrolchPersistenceException(msg);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query size due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize() {
|
||||
String sql = "select count(*) from " + getTableName() + " where latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
result.next();
|
||||
return result.getLong(1);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query size due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long querySize(String type) {
|
||||
String sql = "select count(*) from " + getTableName() + " where type = ? and latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, type);
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
result.next();
|
||||
return result.getLong(1);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query size due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryKeySet() {
|
||||
|
||||
Set<String> keySet = new HashSet<>();
|
||||
|
||||
String sql = "select id from " + getTableName() + " where latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
while (result.next()) {
|
||||
keySet.add(result.getString("id"));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query key set due to: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryKeySet(String type) {
|
||||
Set<String> keySet = new HashSet<>();
|
||||
|
||||
String sql = "select id from " + getTableName() + " where type = ? and latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, type);
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
while (result.next()) {
|
||||
keySet.add(result.getString("id"));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query key set due to: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> queryTypes() {
|
||||
Set<String> keySet = new HashSet<>();
|
||||
|
@ -169,40 +72,6 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
return keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T queryBy(String type, String id) {
|
||||
|
||||
String sql = "select id, name, type, version, created_by, created_at, deleted, asxml from " + getTableName()
|
||||
+ " where type = ? and id = ? and latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, type);
|
||||
statement.setString(2, id);
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
if (!result.next()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SQLXML sqlxml = result.getSQLXML("asxml");
|
||||
T t = parseFromXml(id, type, sqlxml);
|
||||
|
||||
int v = result.getInt(4);
|
||||
String createdBy = result.getString(5);
|
||||
Date createdAt = result.getDate(6);
|
||||
boolean deleted = result.getBoolean(7);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, deleted);
|
||||
t.setVersion(version);
|
||||
|
||||
if (result.next())
|
||||
throw new StrolchPersistenceException("Non unique result for query: " + sql);
|
||||
return t;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query types due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T queryBy(String type, String id, int versionNr) {
|
||||
|
||||
|
@ -476,6 +345,35 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
});
|
||||
}
|
||||
|
||||
private long querySize() {
|
||||
String sql = "select count(*) from " + getTableName() + " where latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
result.next();
|
||||
return result.getLong(1);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query size due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private long querySize(String type) {
|
||||
String sql = "select count(*) from " + getTableName() + " where type = ? and latest = true";
|
||||
try (PreparedStatement statement = tx().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, type);
|
||||
|
||||
try (ResultSet result = statement.executeQuery()) {
|
||||
result.next();
|
||||
return result.getLong(1);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new StrolchPersistenceException("Failed to query size due to: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
*/
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -86,10 +86,10 @@ public class RealmTest extends AbstractModelTest {
|
|||
|
||||
{
|
||||
StrolchRealm firstRealm = runtimeMock.getRealm(FIRST);
|
||||
assertEquals(DataStoreMode.TRANSACTIONAL, firstRealm.getMode());
|
||||
assertEquals(DataStoreMode.CACHED, firstRealm.getMode());
|
||||
Resource expectedRes1 = ModelGenerator.createResource(expectedId1, "Bla bla", type); //$NON-NLS-1$
|
||||
try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) {
|
||||
tx.getResourceMap().add(tx, expectedRes1);
|
||||
tx.add(expectedRes1);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
|
@ -101,10 +101,10 @@ public class RealmTest extends AbstractModelTest {
|
|||
|
||||
{
|
||||
StrolchRealm secondRealm = runtimeMock.getRealm(SECOND);
|
||||
assertEquals(DataStoreMode.TRANSACTIONAL, secondRealm.getMode());
|
||||
assertEquals(DataStoreMode.CACHED, secondRealm.getMode());
|
||||
Resource expectedRes2 = ModelGenerator.createResource(expectedId2, "Bla bla", type); //$NON-NLS-1$
|
||||
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
|
||||
tx.getResourceMap().add(tx, expectedRes2);
|
||||
tx.add(expectedRes2);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import li.strolch.testbase.runtime.AbstractModelTest;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class TransactionalDaoTest extends AbstractModelTest {
|
||||
|
||||
public static final String RUNTIME_PATH = "target/transactionalStrolchRuntime/"; //$NON-NLS-1$
|
||||
public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$
|
||||
public static final String CONFIG_SRC = "src/test/resources/transactionalruntime"; //$NON-NLS-1$
|
||||
|
||||
protected static RuntimeMock runtimeMock;
|
||||
|
||||
@Override
|
||||
protected RuntimeMock getRuntimeMock() {
|
||||
return runtimeMock;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import li.strolch.testbase.runtime.AbstractModelTest;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class TransactionalVersioningDaoTest extends AbstractModelTest {
|
||||
|
||||
public static final String RUNTIME_PATH = "target/transactionalStrolchRuntime/"; //$NON-NLS-1$
|
||||
public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$
|
||||
public static final String CONFIG_SRC = "src/test/resources/transactionalruntimeVersioning"; //$NON-NLS-1$
|
||||
|
||||
protected static RuntimeMock runtimeMock;
|
||||
|
||||
@Override
|
||||
protected RuntimeMock getRuntimeMock() {
|
||||
return runtimeMock;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
}
|
|
@ -1,53 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchConfiguration>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchPersistenceTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<realms>defaultRealm, first, second</realms>
|
||||
<dataStoreMode>EMPTY</dataStoreMode>
|
||||
<dataStoreMode.first>TRANSACTIONAL</dataStoreMode.first>
|
||||
<dataStoreMode.second>TRANSACTIONAL</dataStoreMode.second>
|
||||
<enableAuditTrail.first>true</enableAuditTrail.first>
|
||||
<enableAuditTrail.second>true</enableAuditTrail.second>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
|
||||
<Properties>
|
||||
<allowSchemaCreation>true</allowSchemaCreation>
|
||||
<allowSchemaDrop>true</allowSchemaDrop>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchPersistenceTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<realms>defaultRealm, first, second</realms>
|
||||
<dataStoreMode>EMPTY</dataStoreMode>
|
||||
<dataStoreMode.first>CACHED</dataStoreMode.first>
|
||||
<dataStoreFile.first>StrolchModel.xml</dataStoreFile.first>
|
||||
<enableAuditTrail.first>true</enableAuditTrail.first>
|
||||
<dataStoreMode.second>CACHED</dataStoreMode.second>
|
||||
<dataStoreFile.second>StrolchModel.xml</dataStoreFile.second>
|
||||
<enableAuditTrail.second>true</enableAuditTrail.second>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
|
||||
<Properties>
|
||||
<allowSchemaCreation>true</allowSchemaCreation>
|
||||
<allowSchemaDrop>true</allowSchemaDrop>
|
||||
|
||||
<db.url.first>jdbc:postgresql://localhost/testdb1</db.url.first>
|
||||
<db.username.first>testuser1</db.username.first>
|
||||
<db.password.first>test</db.password.first>
|
||||
<db.pool.maximumPoolSize.first>1</db.pool.maximumPoolSize.first>
|
||||
<db.url.first>jdbc:postgresql://localhost/testdb1</db.url.first>
|
||||
<db.username.first>testuser1</db.username.first>
|
||||
<db.password.first>test</db.password.first>
|
||||
<db.pool.maximumPoolSize.first>1</db.pool.maximumPoolSize.first>
|
||||
|
||||
<db.url.second>jdbc:postgresql://localhost/testdb2</db.url.second>
|
||||
<db.username.second>testuser2</db.username.second>
|
||||
<db.password.second>test</db.password.second>
|
||||
<db.pool.maximumPoolSize.second>1</db.pool.maximumPoolSize.second>
|
||||
</Properties>
|
||||
</Component>
|
||||
</env>
|
||||
<db.url.second>jdbc:postgresql://localhost/testdb2</db.url.second>
|
||||
<db.username.second>testuser2</db.username.second>
|
||||
<db.password.second>test</db.password.second>
|
||||
<db.pool.maximumPoolSize.second>1</db.pool.maximumPoolSize.second>
|
||||
</Properties>
|
||||
</Component>
|
||||
</env>
|
||||
</StrolchConfiguration>
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Privilege>
|
||||
|
||||
<Container>
|
||||
|
||||
<Parameters>
|
||||
<!-- parameters for the container itself -->
|
||||
<Parameter name="autoPersistOnUserChangesData" value="true" />
|
||||
</Parameters>
|
||||
|
||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||
<Parameters>
|
||||
<!-- WARNING: If you change iterations or keyLength, then all passwords are invalid -->
|
||||
<!-- default algorithm is: PBKDF2WithHmacSHA512 -->
|
||||
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512" />
|
||||
<!-- default iterations: 200000 -->
|
||||
<Parameter name="hashIterations" value="10000" />
|
||||
<!-- default key length: 256 -->
|
||||
<Parameter name="hashKeyLength" value="256" />
|
||||
</Parameters>
|
||||
</EncryptionHandler>
|
||||
|
||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||
<Parameters>
|
||||
<Parameter name="usersXmlFile" value="PrivilegeUsers.xml" />
|
||||
<Parameter name="rolesXmlFile" value="PrivilegeRoles.xml" />
|
||||
</Parameters>
|
||||
</PersistenceHandler>
|
||||
|
||||
<UserChallengeHandler class="li.strolch.privilege.handler.ConsoleUserChallengeHandler">
|
||||
</UserChallengeHandler>
|
||||
|
||||
</Container>
|
||||
|
||||
<Policies>
|
||||
<Policy name="DefaultPrivilege" class="li.strolch.privilege.policy.DefaultPrivilege" />
|
||||
<Policy name="ModelPrivilege" class="li.strolch.runtime.privilege.ModelPrivilege" />
|
||||
<Policy name="RoleAccessPrivilege" class="li.strolch.privilege.policy.RoleAccessPrivilege" />
|
||||
<Policy name="UserAccessPrivilege" class="li.strolch.privilege.policy.UserAccessPrivilege" />
|
||||
</Policies>
|
||||
|
||||
</Privilege>
|
|
@ -1,93 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Roles>
|
||||
<Role name="agent">
|
||||
<Privilege name="li.strolch.privilege.handler.SystemAction" policy="DefaultPrivilege">
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemAction</Allow>
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemActionWithResult</Allow>
|
||||
<Allow>li.strolch.persistence.postgresql.PostgreSqlSchemaInitializer</Allow>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
|
||||
<Role name="AppUser">
|
||||
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
</Roles>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Users>
|
||||
<User userId="1" username="agent">
|
||||
<State>SYSTEM</State>
|
||||
<Roles>
|
||||
<Role>agent</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
<User userId="2" username="test" password="fdd9d2def3475e1d5cc87107b87e14fd6adbca664c2874fc379a1e53931c0428" salt="74657374">
|
||||
<Firstname>Application</Firstname>
|
||||
<Lastname>Administrator</Lastname>
|
||||
<State>ENABLED</State>
|
||||
<Locale>en_GB</Locale>
|
||||
<Roles>
|
||||
<Role>AppUser</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
</Users>
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchConfiguration>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchPersistenceTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<dataStoreMode>TRANSACTIONAL</dataStoreMode>
|
||||
<enableAuditTrail>true</enableAuditTrail>
|
||||
<enableObserverUpdates>true</enableObserverUpdates>
|
||||
<dataStoreFile>StrolchModel.xml</dataStoreFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
|
||||
<Properties>
|
||||
<allowDataInitOnSchemaCreate>true</allowDataInitOnSchemaCreate>
|
||||
<allowSchemaCreation>true</allowSchemaCreation>
|
||||
<allowSchemaDrop>true</allowSchemaDrop>
|
||||
<db.url>jdbc:postgresql://localhost/testdb</db.url>
|
||||
<db.username>testuser</db.username>
|
||||
<db.password>test</db.password>
|
||||
<db.pool.maximumPoolSize>1</db.pool.maximumPoolSize>
|
||||
</Properties>
|
||||
</Component>
|
||||
</env>
|
||||
</StrolchConfiguration>
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<StrolchModel>
|
||||
<Resource Id="MyRealmRes" Name="Test Name" Type="TestType">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Order Id="MyRealmOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
</StrolchModel>
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Privilege>
|
||||
|
||||
<Container>
|
||||
|
||||
<Parameters>
|
||||
<!-- parameters for the container itself -->
|
||||
<Parameter name="autoPersistOnUserChangesData" value="true" />
|
||||
</Parameters>
|
||||
|
||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||
<Parameters>
|
||||
<!-- WARNING: If you change iterations or keyLength, then all passwords are invalid -->
|
||||
<!-- default algorithm is: PBKDF2WithHmacSHA512 -->
|
||||
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512" />
|
||||
<!-- default iterations: 200000 -->
|
||||
<Parameter name="hashIterations" value="10000" />
|
||||
<!-- default key length: 256 -->
|
||||
<Parameter name="hashKeyLength" value="256" />
|
||||
</Parameters>
|
||||
</EncryptionHandler>
|
||||
|
||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||
<Parameters>
|
||||
<Parameter name="usersXmlFile" value="PrivilegeUsers.xml" />
|
||||
<Parameter name="rolesXmlFile" value="PrivilegeRoles.xml" />
|
||||
</Parameters>
|
||||
</PersistenceHandler>
|
||||
|
||||
<UserChallengeHandler class="li.strolch.privilege.handler.ConsoleUserChallengeHandler">
|
||||
</UserChallengeHandler>
|
||||
|
||||
</Container>
|
||||
|
||||
<Policies>
|
||||
<Policy name="DefaultPrivilege" class="li.strolch.privilege.policy.DefaultPrivilege" />
|
||||
<Policy name="ModelPrivilege" class="li.strolch.runtime.privilege.ModelPrivilege" />
|
||||
<Policy name="RoleAccessPrivilege" class="li.strolch.privilege.policy.RoleAccessPrivilege" />
|
||||
<Policy name="UserAccessPrivilege" class="li.strolch.privilege.policy.UserAccessPrivilege" />
|
||||
</Policies>
|
||||
|
||||
</Privilege>
|
|
@ -1,92 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Roles>
|
||||
<Role name="agent">
|
||||
<Privilege name="li.strolch.privilege.handler.SystemAction" policy="DefaultPrivilege">
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemAction</Allow>
|
||||
<Allow>li.strolch.runtime.privilege.StrolchSystemActionWithResult</Allow>
|
||||
<Allow>li.strolch.persistence.postgresql.PostgreSqlSchemaInitializer</Allow>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
<Role name="AppUser">
|
||||
<Privilege name="li.strolch.service.api.Service" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="li.strolch.model.query.StrolchQuery" policy="DefaultPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
|
||||
<Privilege name="GetResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="GetActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="AddActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="UpdateActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveResource" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveOrder" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
<Privilege name="RemoveActivity" policy="ModelPrivilege">
|
||||
<AllAllowed>true</AllAllowed>
|
||||
</Privilege>
|
||||
</Role>
|
||||
</Roles>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Users>
|
||||
<User userId="1" username="agent">
|
||||
<State>SYSTEM</State>
|
||||
<Roles>
|
||||
<Role>agent</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
<User userId="2" username="test" password="fdd9d2def3475e1d5cc87107b87e14fd6adbca664c2874fc379a1e53931c0428" salt="74657374">
|
||||
<Firstname>Application</Firstname>
|
||||
<Lastname>Administrator</Lastname>
|
||||
<State>ENABLED</State>
|
||||
<Locale>en_GB</Locale>
|
||||
<Roles>
|
||||
<Role>AppUser</Role>
|
||||
</Roles>
|
||||
</User>
|
||||
</Users>
|
|
@ -1,47 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StrolchConfiguration>
|
||||
<env id="dev">
|
||||
<Runtime>
|
||||
<applicationName>StrolchPersistenceTest</applicationName>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
</Runtime>
|
||||
<Component>
|
||||
<name>PrivilegeHandler</name>
|
||||
<api>li.strolch.runtime.privilege.PrivilegeHandler</api>
|
||||
<impl>li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler</impl>
|
||||
<Properties>
|
||||
<privilegeConfigFile>PrivilegeConfig.xml</privilegeConfigFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>RealmHandler</name>
|
||||
<api>li.strolch.agent.api.RealmHandler</api>
|
||||
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
||||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<dataStoreMode>TRANSACTIONAL</dataStoreMode>
|
||||
<enableAuditTrail>true</enableAuditTrail>
|
||||
<enableObserverUpdates>true</enableObserverUpdates>
|
||||
<enableVersioning>true</enableVersioning>
|
||||
<dataStoreFile>StrolchModel.xml</dataStoreFile>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component>
|
||||
<name>PersistenceHandler</name>
|
||||
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
||||
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
|
||||
<Properties>
|
||||
<allowDataInitOnSchemaCreate>true</allowDataInitOnSchemaCreate>
|
||||
<allowSchemaCreation>true</allowSchemaCreation>
|
||||
<allowSchemaDrop>true</allowSchemaDrop>
|
||||
<db.url>jdbc:postgresql://localhost/testdb</db.url>
|
||||
<db.username>testuser</db.username>
|
||||
<db.password>test</db.password>
|
||||
<db.pool.maximumPoolSize>1</db.pool.maximumPoolSize>
|
||||
</Properties>
|
||||
</Component>
|
||||
</env>
|
||||
</StrolchConfiguration>
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<StrolchModel>
|
||||
<Resource Id="MyRealmRes" Name="Test Name" Type="TestType">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
<Order Id="MyRealmOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED">
|
||||
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
||||
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
|
||||
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />
|
||||
<Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" />
|
||||
<Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" />
|
||||
<Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" />
|
||||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
</StrolchModel>
|
|
@ -15,23 +15,13 @@
|
|||
*/
|
||||
package li.strolch.command;
|
||||
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.CONFIG_SRC;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_CACHED;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSACTIONAL;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSIENT;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.RUNTIME_PATH;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.dropSchema;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.importFromXml;
|
||||
import static li.strolch.service.test.AbstractRealmServiceTest.*;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -39,6 +29,9 @@ import li.strolch.privilege.model.Certificate;
|
|||
import li.strolch.service.api.Command;
|
||||
import li.strolch.service.api.ServiceHandler;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -57,7 +50,6 @@ public abstract class AbstractRealmCommandTest {
|
|||
public void beforeClass() throws Exception {
|
||||
|
||||
dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test");
|
||||
dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test");
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
|
@ -67,7 +59,6 @@ public abstract class AbstractRealmCommandTest {
|
|||
|
||||
certificate = runtimeMock.getPrivilegeHandler().authenticate(getUsername(), getUsername().toCharArray());
|
||||
importFromXml(REALM_CACHED, certificate, getServiceHandler());
|
||||
importFromXml(REALM_TRANSACTIONAL, certificate, getServiceHandler());
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -131,12 +122,6 @@ public abstract class AbstractRealmCommandTest {
|
|||
doCommand(REALM_CACHED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoCommandTransactional() {
|
||||
doCommandAsFail(REALM_TRANSACTIONAL);
|
||||
doCommand(REALM_TRANSACTIONAL);
|
||||
}
|
||||
|
||||
private class FailCommandFacade extends Command {
|
||||
|
||||
private Command command;
|
||||
|
|
|
@ -52,7 +52,6 @@ public abstract class AbstractRealmServiceTest {
|
|||
|
||||
public static final String REALM_CACHED = "svcCached";
|
||||
public static final String REALM_CACHED_AUDITS_VERSIONING = "svcCachedAuditsVersioning";
|
||||
public static final String REALM_TRANSACTIONAL = "svcTransactional";
|
||||
public static final String REALM_TRANSIENT = "svcTransient";
|
||||
public static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$
|
||||
public static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$
|
||||
|
@ -70,7 +69,6 @@ public abstract class AbstractRealmServiceTest {
|
|||
public void before() throws Exception {
|
||||
|
||||
dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test");
|
||||
dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test");
|
||||
dropSchema("jdbc:postgresql://localhost/cacheduserauditsversioningdb", "cacheduserauditsversioning", "test");
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
|
@ -81,7 +79,6 @@ public abstract class AbstractRealmServiceTest {
|
|||
|
||||
this.certificate = runtimeMock.getPrivilegeHandler().authenticate(getUsername(), getUsername().toCharArray());
|
||||
importFromXml(REALM_CACHED, this.certificate, getServiceHandler());
|
||||
importFromXml(REALM_TRANSACTIONAL, this.certificate, getServiceHandler());
|
||||
importFromXml(REALM_CACHED_AUDITS_VERSIONING, this.certificate, getServiceHandler());
|
||||
}
|
||||
|
||||
|
@ -166,23 +163,11 @@ public abstract class AbstractRealmServiceTest {
|
|||
runTransient(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||
runCached(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||
runCachedWithAuditsAndVersioning(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||
runTransactional(constructor.newInstance(), expectedServiceResultType, arg, before, validator, after);
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Failed to instantiate class " + svcClass.getName() + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected <T extends ServiceArgument, U extends ServiceResult> void runTransactional(Service<T, U> svc,
|
||||
Class<?> expectedServiceResultType, T arg) {
|
||||
runTransactional(svc, expectedServiceResultType, arg, null, null, null);
|
||||
}
|
||||
|
||||
protected <T extends ServiceArgument, U extends ServiceResult> void runTransactional(Service<T, U> svc,
|
||||
Class<?> expectedServiceResultType, T arg, Runner before, Runner validator, Runner after) {
|
||||
doService(REALM_TRANSACTIONAL, ServiceResultState.SUCCESS, expectedServiceResultType, svc, arg, before,
|
||||
validator, after);
|
||||
}
|
||||
|
||||
protected <T extends ServiceArgument, U extends ServiceResult> void runCached(Service<T, U> svc,
|
||||
Class<?> expectedServiceResultType, T arg) {
|
||||
runCached(svc, expectedServiceResultType, arg, null, null, null);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<depends>PrivilegeHandler</depends>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<Properties>
|
||||
<realms>defaultRealm, svcTransient, svcCached, svcCachedAuditsVersioning, svcTransactional</realms>
|
||||
<realms>defaultRealm, svcTransient, svcCached, svcCachedAuditsVersioning</realms>
|
||||
|
||||
<dataStoreMode>EMPTY</dataStoreMode>
|
||||
|
||||
|
@ -41,9 +41,6 @@
|
|||
<enableAuditTrail.svcCachedAuditsVersioning>true</enableAuditTrail.svcCachedAuditsVersioning>
|
||||
<enableVersioning.svcCachedAuditsVersioning>true</enableVersioning.svcCachedAuditsVersioning>
|
||||
|
||||
<tryLockTimeUnit.svcTransactional>SECONDS</tryLockTimeUnit.svcTransactional>
|
||||
<tryLockTime.svcTransactional>1</tryLockTime.svcTransactional>
|
||||
<dataStoreMode.svcTransactional>TRANSACTIONAL</dataStoreMode.svcTransactional>
|
||||
</Properties>
|
||||
</Component>
|
||||
|
||||
|
@ -65,11 +62,6 @@
|
|||
<db.password.svcCachedAuditsVersioning>test</db.password.svcCachedAuditsVersioning>
|
||||
<db.pool.maximumPoolSize.svcCachedAuditsVersioning>1</db.pool.maximumPoolSize.svcCachedAuditsVersioning>
|
||||
|
||||
<db.url.svcTransactional>jdbc:postgresql://localhost/transactionaluserdb</db.url.svcTransactional>
|
||||
<db.username.svcTransactional>transactionaluser</db.username.svcTransactional>
|
||||
<db.password.svcTransactional>test</db.password.svcTransactional>
|
||||
<db.pool.maximumPoolSize.svcTransactional>1</db.pool.maximumPoolSize.svcTransactional>
|
||||
|
||||
</Properties>
|
||||
</Component>
|
||||
|
||||
|
|
Loading…
Reference in New Issue