[Bugfix] fixed bug where InMemory realms were not separated

InMemoryPersistenceHandler did not keep separate DAOs for each realm, so
that the realms were not separated in memory
This commit is contained in:
Robert von Burg 2014-02-13 22:20:56 +01:00
parent 8767f8c953
commit e4d5f9623f
31 changed files with 328 additions and 110 deletions

View File

@ -19,6 +19,8 @@ import java.util.Set;
import li.strolch.agent.impl.DataStoreMode;
import li.strolch.agent.impl.StrolchRealm;
import li.strolch.exception.StrolchException;
import li.strolch.runtime.StrolchConstants;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -34,13 +36,22 @@ public interface ComponentContainer {
public abstract boolean hasComponent(Class<?> clazz);
public abstract <T> T getComponent(Class<T> clazz);
public abstract Set<Class<?>> getComponentTypes();
public abstract Set<String> getRealmNames();
public abstract StrolchRealm getDefaultRealm();
/**
* Returns the {@link StrolchRealm} with the given name. To get the default realm, use the constante
* {@link StrolchConstants#DEFAULT_REALM}.
*
* @param realm
* the name of the {@link StrolchRealm} to return
* @return the {@link StrolchRealm} with the given name
*
* @throws StrolchException
* if the {@link StrolchRealm} does not exist with the given name
*/
public abstract StrolchRealm getRealm(String realm);
}

View File

@ -18,15 +18,31 @@ package li.strolch.agent.api;
import java.util.Set;
import li.strolch.agent.impl.StrolchRealm;
import li.strolch.exception.StrolchException;
import li.strolch.runtime.StrolchConstants;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ElementMapHandler {
/**
* Returns the names of the configured {@link StrolchRealm StrolchRealms}
*
* @return the set of names of the configured {@link StrolchRealm StrolchRealms}
*/
public Set<String> getRealmNames();
public StrolchRealm getDefaultRealm();
/**
* Returns the {@link StrolchRealm} with the given name. To get the default realm, use the constante
* {@link StrolchConstants#DEFAULT_REALM}.
*
* @param realm
* the name of the {@link StrolchRealm} to return
* @return the {@link StrolchRealm} with the given name
*
* @throws StrolchException
* if the {@link StrolchRealm} does not exist with the given name
*/
public StrolchRealm getRealm(String realm);
}

View File

@ -20,12 +20,11 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import ch.eitchnet.utils.dbc.DBC;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.ElementMapHandler;
import li.strolch.agent.api.StrolchComponent;
import li.strolch.exception.StrolchException;
import li.strolch.runtime.StrolchConstants;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -48,12 +47,7 @@ public abstract class AbstractElementMapHandler extends StrolchComponent impleme
}
@Override
public StrolchRealm getDefaultRealm() {
return getRealm(StrolchConstants.DEFAULT_REALM);
}
@Override
public StrolchRealm getRealm(String realm) {
public StrolchRealm getRealm(String realm) throws StrolchException {
DBC.PRE.assertNotEmpty("Realm name must be set!", realm);
StrolchRealm strolchRealm = this.realms.get(realm);
if (strolchRealm == null) {

View File

@ -27,7 +27,7 @@ import li.strolch.agent.api.ComponentState;
import li.strolch.agent.api.ElementMapHandler;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.agent.api.StrolchComponent;
import li.strolch.runtime.StrolchConstants;
import li.strolch.exception.StrolchException;
import li.strolch.runtime.configuration.ComponentConfiguration;
import li.strolch.runtime.configuration.StrolchConfiguration;
import li.strolch.runtime.configuration.StrolchConfigurationException;
@ -97,12 +97,7 @@ public class ComponentContainerImpl implements ComponentContainer {
}
@Override
public StrolchRealm getDefaultRealm() {
return getRealm(StrolchConstants.DEFAULT_REALM);
}
@Override
public StrolchRealm getRealm(String realm) {
public StrolchRealm getRealm(String realm) throws StrolchException {
return getComponent(ElementMapHandler.class).getRealm(realm);
}
@ -130,8 +125,8 @@ public class ComponentContainerImpl implements ComponentContainer {
@SuppressWarnings("unchecked")
Class<StrolchComponent> strolchComponentClass = (Class<StrolchComponent>) implClass;
Constructor<StrolchComponent> constructor = strolchComponentClass.getConstructor(
ComponentContainer.class, String.class);
Constructor<StrolchComponent> constructor = strolchComponentClass.getConstructor(ComponentContainer.class,
String.class);
StrolchComponent strolchComponent = constructor.newInstance(this, componentName);
componentMap.put(apiClass, strolchComponent);

View File

@ -45,6 +45,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
protected static final Logger logger = LoggerFactory.getLogger(InMemoryTransaction.class);
private StrolchRealm realm;
@Override
public String getRealmName() {
return this.realm.getRealm();
}
/**
* @param realm
*/

View File

@ -31,6 +31,8 @@ import li.strolch.model.query.ResourceQuery;
public interface StrolchTransaction extends AutoCloseable {
public String getRealmName();
public void setCloseStrategy(TransactionCloseStrategy closeStrategy);
public void autoCloseableCommit();

View File

@ -1,5 +1,8 @@
package li.strolch.persistence.inmemory;
import java.util.HashMap;
import java.util.Map;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchComponent;
import li.strolch.agent.impl.StrolchRealm;
@ -7,11 +10,11 @@ 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.runtime.configuration.ComponentConfiguration;
public class InMemoryPersistenceHandler extends StrolchComponent implements PersistenceHandler {
private OrderDao orderDao;
private ResourceDao resourceDao;
private Map<String, DaoCache> daoCache;
public InMemoryPersistenceHandler(ComponentContainer container, String componentName) {
super(container, componentName);
@ -22,17 +25,48 @@ public class InMemoryPersistenceHandler extends StrolchComponent implements Pers
return new InMemoryTransaction(realm, this);
}
@Override
public void initialize(ComponentConfiguration configuration) {
super.initialize(configuration);
this.daoCache = new HashMap<>();
}
@Override
public OrderDao getOrderDao(StrolchTransaction tx) {
if (this.orderDao == null)
this.orderDao = new InMemoryOrderDao();
return this.orderDao;
DaoCache daoCache = getDaoCache(tx);
return daoCache.getOrderDao();
}
@Override
public ResourceDao getResourceDao(StrolchTransaction tx) {
if (this.resourceDao == null)
this.resourceDao = new InMemoryResourceDao();
return this.resourceDao;
DaoCache daoCache = getDaoCache(tx);
return daoCache.getResourceDao();
}
private synchronized DaoCache getDaoCache(StrolchTransaction tx) {
DaoCache daoCache = this.daoCache.get(tx.getRealmName());
if (daoCache == null) {
daoCache = new DaoCache(new InMemoryOrderDao(), new InMemoryResourceDao());
this.daoCache.put(tx.getRealmName(), daoCache);
}
return daoCache;
}
private class DaoCache {
private OrderDao orderDao;
private ResourceDao resourceDao;
public DaoCache(OrderDao orderDao, ResourceDao resourceDao) {
this.orderDao = orderDao;
this.resourceDao = resourceDao;
}
public OrderDao getOrderDao() {
return this.orderDao;
}
public ResourceDao getResourceDao() {
return this.resourceDao;
}
}
}

View File

@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component;
package li.strolch.agent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.text.MessageFormat;
@ -31,10 +32,11 @@ import li.strolch.model.Resource;
import li.strolch.persistence.api.OrderDao;
import li.strolch.persistence.api.ResourceDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
import li.strolch.runtime.configuration.RuntimeConfiguration;
import li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest;
import li.strolch.runtime.test.component.model.ServiceHandlerTest;
import li.strolch.runtime.test.component.model.ServiceResultTest;
import li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest;
import li.strolch.runtime.configuration.model.ServiceHandlerTest;
import li.strolch.runtime.configuration.model.ServiceResultTest;
import org.junit.Test;
import org.slf4j.Logger;
@ -57,7 +59,8 @@ public class ComponentContainerTest {
public static final String PATH_CACHED_RUNTIME = "target/cachedtest/";
public static final String PATH_EMPTY_RUNTIME = "target/emptytest/";
private static final Logger logger = LoggerFactory.getLogger(ComponentContainerTest.class);
public static final Logger logger = LoggerFactory.getLogger(ComponentContainerTest.class);
private static final String TARGET = "target"; //$NON-NLS-1$
@Test
@ -127,7 +130,21 @@ public class ComponentContainerTest {
}
}
private static void testContainer(StrolchAgent agent) {
@Test
public void shouldTestRealms() {
try {
StrolchAgent agent = startContainer(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER);
testContainer(agent);
testRealms(agent);
destroyContainer(agent);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
public static void testContainer(StrolchAgent agent) {
ComponentContainer container = agent.getContainer();
@ -142,7 +159,7 @@ public class ComponentContainerTest {
assertEquals("@testRes", resource.getId());
}
private static void testPersistenceContainer(StrolchAgent agent) {
public static void testPersistenceContainer(StrolchAgent agent) {
ComponentContainer container = agent.getContainer();
@ -150,7 +167,7 @@ public class ComponentContainerTest {
ServiceResultTest result = serviceHandler.doService();
assertEquals(1, result.getResult());
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
ResourceDao resourceDao = tx.getPersistenceHandler().getResourceDao(tx);
resourceDao.save(ModelGenerator.createResource("@testRes0", "Test Res", "Test"));
Resource queriedRes = resourceDao.queryBy("Test", "@testRes0");
@ -158,7 +175,7 @@ public class ComponentContainerTest {
assertEquals("@testRes0", queriedRes.getId());
}
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
OrderDao orderDao = tx.getPersistenceHandler().getOrderDao(tx);
orderDao.save(ModelGenerator.createOrder("@testOrder0", "Test Order", "Test"));
Order queriedOrder = orderDao.queryBy("Test", "@testOrder0");
@ -167,11 +184,11 @@ public class ComponentContainerTest {
}
}
private static void testElementMaps(StrolchAgent agent) {
public static void testElementMaps(StrolchAgent agent) {
ComponentContainer container = agent.getContainer();
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
resourceMap.add(tx, ModelGenerator.createResource("@testRes1", "Test Res", "Test"));
Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1");
@ -179,7 +196,7 @@ public class ComponentContainerTest {
assertEquals("@testRes1", queriedRes.getId());
}
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
OrderMap orderMap = tx.getOrderMap();
orderMap.add(tx, ModelGenerator.createOrder("@testOrder1", "Test Order", "Test"));
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
@ -188,6 +205,56 @@ public class ComponentContainerTest {
}
}
public static void testRealms(StrolchAgent agent) {
ComponentContainer container = agent.getContainer();
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
resourceMap.add(tx, ModelGenerator.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"));
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
assertNotNull(queriedOrder);
assertEquals("@testOrder1", queriedOrder.getId());
}
try (StrolchTransaction tx = container.getRealm("myRealm").openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
Resource myRealmRes = resourceMap.getBy(tx, "TestType", "MyRealmRes");
assertNotNull(myRealmRes);
assertEquals("MyRealmRes", myRealmRes.getId());
Resource otherRealmRes = resourceMap.getBy(tx, "TestType", "OtherRealmRes");
assertNull(otherRealmRes);
OrderMap orderMap = tx.getOrderMap();
Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder");
assertNotNull(myRealmOrder);
assertEquals("MyRealmOrder", myRealmOrder.getId());
Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder");
assertNull(otherRealmOrder);
}
try (StrolchTransaction tx = container.getRealm("otherRealm").openTx()) {
ResourceMap resourceMap = tx.getResourceMap();
Resource otherRealmRes = resourceMap.getBy(tx, "TestType", "OtherRealmRes");
assertNotNull(otherRealmRes);
assertEquals("OtherRealmRes", otherRealmRes.getId());
Resource myRealmRes = resourceMap.getBy(tx, "TestType", "MyRealmRes");
assertNull(myRealmRes);
OrderMap orderMap = tx.getOrderMap();
Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder");
assertNotNull(otherRealmOrder);
assertEquals("OtherRealmOrder", otherRealmOrder.getId());
Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder");
assertNull(myRealmOrder);
}
}
public static StrolchAgent startContainer(String rootPath, String configSrc) {
File rootPathF = new File(rootPath);
File configSrcF = new File(configSrc);

View File

@ -0,0 +1,43 @@
/*
* 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;
import li.strolch.agent.api.StrolchAgent;
import static li.strolch.agent.ComponentContainerTest.*;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RealmTest {
@Test
public void shouldStartRealmTestContainer() {
try {
StrolchAgent agent = startContainer(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER);
testContainer(agent);
destroyContainer(agent);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component;
package li.strolch.runtime.configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -87,8 +87,8 @@ public class ConfigurationParserTest {
// <Component>
// <name>ResourceGeneratorHandler</name>
// <api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
// <impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
// <api>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest</api>
// <impl>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl</impl>
// <Properties>
// <verbose>true</verbose>
// </Properties>
@ -97,9 +97,9 @@ public class ConfigurationParserTest {
.getComponentConfiguration("ResourceGeneratorHandler");
assertNotNull("Should have created a ResourceGeneratorHandler Configuration", persistenceHandlerConfiguration);
assertEquals("ResourceGeneratorHandler", persistenceHandlerConfiguration.getName());
assertEquals("li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest",
assertEquals("li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest",
persistenceHandlerConfiguration.getApi());
assertEquals("li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl",
assertEquals("li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl",
persistenceHandlerConfiguration.getImpl());
assertEquals(1, persistenceHandlerConfiguration.getPropertyKeys().size());
assertEquals(true, persistenceHandlerConfiguration.getBoolean("verbose", null));

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component;
package li.strolch.runtime.configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
public interface PostInitializerTest {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchComponent;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
import li.strolch.model.Resource;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchComponent;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
public interface ServiceHandlerTest {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchComponent;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.component.model;
package li.strolch.runtime.configuration.model;
public class ServiceResultTest {

View File

@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.query.enums;
package li.strolch.runtime.query.enums;
import static org.junit.Assert.assertEquals;
import java.util.Locale;
import li.strolch.agent.ComponentContainerTest;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.runtime.query.enums.EnumHandler;
import li.strolch.runtime.query.enums.StrolchEnum;
import li.strolch.runtime.test.component.ComponentContainerTest;
import org.junit.Test;

View File

@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.query.inmemory;
package li.strolch.runtime.query.inmemory;
import static org.junit.Assert.assertNotNull;
import li.strolch.agent.ComponentContainerTest;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.model.Locator;
@ -24,7 +25,7 @@ import li.strolch.model.Resource;
import li.strolch.model.parameter.FloatParameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.test.component.ComponentContainerTest;
import li.strolch.runtime.StrolchConstants;
import org.junit.Test;
@ -43,7 +44,7 @@ public class FindByLocatorTest {
ComponentContainerTest.PATH_TRANSIENT_CONTAINER);
ComponentContainer container = agent.getContainer();
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
Locator locResStringParam = Locator.valueOf("Resource/TestType/MyTestResource/@bag01/@param5");
StringParameter resStringParam = tx.findElement(locResStringParam);
assertNotNull("Should have found a StringParameter with the locator " + locResStringParam, resStringParam);

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.query.inmemory;
package li.strolch.runtime.query.inmemory;
import static org.junit.Assert.assertEquals;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.runtime.test.query.inmemory;
package li.strolch.runtime.query.inmemory;
import static li.strolch.model.ModelGenerator.BAG_ID;
import static li.strolch.model.ModelGenerator.PARAM_STRING_ID;
@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.ComponentContainerTest;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchAgent;
import li.strolch.model.Order;
@ -36,10 +37,7 @@ import li.strolch.model.query.ResourceQuery;
import li.strolch.model.query.Selection;
import li.strolch.model.query.StrolchTypeNavigation;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.query.inmemory.InMemoryOrderQueryVisitor;
import li.strolch.runtime.query.inmemory.InMemoryQuery;
import li.strolch.runtime.query.inmemory.InMemoryResourceQueryVisitor;
import li.strolch.runtime.test.component.ComponentContainerTest;
import li.strolch.runtime.StrolchConstants;
import org.junit.Test;
@ -62,7 +60,7 @@ 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.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
}
@ -75,7 +73,7 @@ public class QueryTest {
InMemoryResourceQueryVisitor resourceQuery = new InMemoryResourceQueryVisitor();
InMemoryQuery<Resource> inMemoryQuery = resourceQuery.visit(query);
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getResourceDao(tx));
}
assertEquals(1, result.size());
@ -92,7 +90,7 @@ 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.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getOrderMap().add(tx, o1);
}
@ -105,7 +103,7 @@ public class QueryTest {
InMemoryOrderQueryVisitor orderQuery = new InMemoryOrderQueryVisitor();
InMemoryQuery<Order> inMemoryQuery = orderQuery.visit(query);
List<Order> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getOrderDao(tx));
}
assertEquals(1, result.size());
@ -120,14 +118,14 @@ public class QueryTest {
ComponentContainer container = agent.getContainer();
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
}
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "olch").contains(true));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(1, result.size());
@ -142,14 +140,14 @@ public class QueryTest {
ComponentContainer container = agent.getContainer();
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
}
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "str").contains(true));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(0, result.size());
@ -163,14 +161,14 @@ public class QueryTest {
ComponentContainer container = agent.getContainer();
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
}
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch").caseInsensitive(true));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(1, result.size());
@ -185,14 +183,14 @@ public class QueryTest {
ComponentContainer container = agent.getContainer();
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
}
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.and().with(ParameterSelection.stringSelection(BAG_ID, PARAM_STRING_ID, "strolch"));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(0, result.size());
@ -207,7 +205,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType");
Resource res2 = createResource("@2", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
tx.getResourceMap().add(tx, res1);
tx.getResourceMap().add(tx, res2);
}
@ -216,7 +214,7 @@ public class QueryTest {
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.not(new IdSelection("@1"));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(1, result.size());
@ -227,7 +225,7 @@ public class QueryTest {
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.not(new IdSelection("@2"));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(1, result.size());
@ -238,7 +236,7 @@ public class QueryTest {
ResourceQuery query = new ResourceQuery(new StrolchTypeNavigation("MyType"));
query.not(new IdSelection("@1", "@2"));
List<Resource> result;
try (StrolchTransaction tx = container.getDefaultRealm().openTx()) {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
result = tx.doQuery(query);
}
assertEquals(0, result.size());

View File

@ -10,16 +10,16 @@
</Runtime>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.component.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ServiceHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
<depends>PersistenceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>PostInitializer</name>
<api>li.strolch.runtime.test.component.model.PostInitializerTest</api>
<impl>li.strolch.runtime.test.component.model.PostInitializerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
<depends>ServiceHandler</depends>
<Properties>
</Properties>

View File

@ -26,8 +26,8 @@
</Component>
<Component>
<name>ResourceGeneratorHandler</name>
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl</impl>
<depends>PersistenceHandler</depends>
<depends>ServiceHandler</depends>
<Properties>

View File

@ -9,15 +9,15 @@
</Runtime>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.component.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ServiceHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
<Properties>
</Properties>
</Component>
<Component>
<name>ResourceGeneratorHandler</name>
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl</impl>
<Properties>
<verbose>true</verbose>
</Properties>

View File

@ -4,31 +4,33 @@
<applicationName>StrolchRuntimeTest</applicationName>
<Properties>
<dataStoreMode>TRANSIENT</dataStoreMode>
<realms>myRealm</realms>
<dataStoreFile.myRealm>StrolchModel.xml</dataStoreFile.myRealm>
<realms>defaultRealm, myRealm, otherRealm</realms>
<dataStoreFile>DefaultRealm.xml</dataStoreFile>
<dataStoreFile.myRealm>MyRealm.xml</dataStoreFile.myRealm>
<dataStoreFile.otherRealm>OtherRealm.xml</dataStoreFile.otherRealm>
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.component.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ServiceHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
<depends>PersistenceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>PostInitializer</name>
<api>li.strolch.runtime.test.component.model.PostInitializerTest</api>
<impl>li.strolch.runtime.test.component.model.PostInitializerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
<depends>ServiceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>ResourceGeneratorHandler</name>
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl</impl>
<Properties>
<verbose>true</verbose>
</Properties>

View File

@ -0,0 +1,25 @@
<?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>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<StrolchModel>
<Resource Id="OtherRealmRes" 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="OtherRealmOrder" 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>

View File

@ -10,16 +10,16 @@
</Runtime>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.component.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ServiceHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
<depends>PersistenceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>PostInitializer</name>
<api>li.strolch.runtime.test.component.model.PostInitializerTest</api>
<impl>li.strolch.runtime.test.component.model.PostInitializerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
<depends>ServiceHandler</depends>
<Properties>
</Properties>

View File

@ -10,24 +10,24 @@
</Runtime>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.component.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ServiceHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ServiceHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ServiceHandlerTestImpl</impl>
<depends>PersistenceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>PostInitializer</name>
<api>li.strolch.runtime.test.component.model.PostInitializerTest</api>
<impl>li.strolch.runtime.test.component.model.PostInitializerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.PostInitializerTest</api>
<impl>li.strolch.runtime.configuration.model.PostInitializerTestImpl</impl>
<depends>ServiceHandler</depends>
<Properties>
</Properties>
</Component>
<Component>
<name>ResourceGeneratorHandler</name>
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
<api>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTest</api>
<impl>li.strolch.runtime.configuration.model.ResourceGeneratorHandlerTestImpl</impl>
<Properties>
<verbose>true</verbose>
</Properties>