CAY-1873 | Add DataDomain cache configuration into DI

Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/a4cba4e0
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/a4cba4e0
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/a4cba4e0

Branch: refs/heads/master
Commit: a4cba4e0c12e7f77de6b3454e3940444cdd1f64f
Parents: 9c32b76
Author: Savva Kolbachev <s.kolbac...@gmail.com>
Authored: Mon Jun 29 11:11:41 2015 +0300
Committer: Nikita Timofeev <stari...@gmail.com>
Committed: Fri Mar 10 15:54:44 2017 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/access/DataDomain.java   |  48 ++++----
 .../cayenne/access/DataRowStoreFactory.java     |  38 ++++++
 .../access/DefaultDataRowStoreFactory.java      |  47 ++++++++
 .../apache/cayenne/configuration/Constants.java |   8 ++
 .../server/DataContextFactory.java              |  18 ++-
 .../configuration/server/ServerModule.java      |  33 ++++-
 .../cayenne/access/DataRowStoreFactoryIT.java   | 119 +++++++++++++++++++
 .../server/DataContextFactoryTest.java          |   7 ++
 8 files changed, 283 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomain.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomain.java 
b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomain.java
index 9bc0129..73e0c02 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomain.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomain.java
@@ -92,6 +92,12 @@ public class DataDomain implements QueryEngine, DataChannel {
        protected TransactionManager transactionManager;
 
        /**
+     * @since 4.0
+     */
+    @Inject
+    protected DataRowStoreFactory dataRowStoreFactory;
+
+    /**
         * @since 3.1
         */
        protected int maxIdQualifierSize;
@@ -137,7 +143,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Creates new DataDomain.
-        * 
+        *
         * @param name
         *            DataDomain name. Domain can be located using its name in 
the
         *            Configuration object.
@@ -168,7 +174,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Checks that Domain is not stopped. Throws DomainStoppedException
         * otherwise.
-        * 
+        *
         * @since 3.0
         */
        protected void checkStopped() throws DomainStoppedException {
@@ -204,7 +210,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Reinitializes domain state with a new set of properties.
-        * 
+        *
         * @since 1.1
         * @deprecated since 4.0 properties are processed by the DI provider.
         */
@@ -228,7 +234,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Returns EventManager used by this DataDomain.
-        * 
+        *
         * @since 1.2
         */
        public EventManager getEventManager() {
@@ -237,7 +243,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Sets EventManager used by this DataDomain.
-        * 
+        *
         * @since 1.2
         */
        public void setEventManager(EventManager eventManager) {
@@ -282,7 +288,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Returns whether child DataContexts default behavior is to perform 
object
         * validation before commit is executed.
-        * 
+        *
         * @since 1.1
         */
        public boolean isValidatingObjectsOnCommit() {
@@ -292,7 +298,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Sets the property defining whether child DataContexts should perform
         * object validation before commit is executed.
-        * 
+        *
         * @since 1.1
         */
        public void setValidatingObjectsOnCommit(boolean flag) {
@@ -325,7 +331,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
         */
        synchronized DataRowStore nonNullSharedSnapshotCache() {
                if (sharedSnapshotCache == null) {
-                       this.sharedSnapshotCache = new DataRowStore(name, 
properties, eventManager);
+                       this.sharedSnapshotCache = 
dataRowStoreFactory.createDataRowStore(name);
                }
 
                return sharedSnapshotCache;
@@ -365,7 +371,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Removes named DataMap from this DataDomain and any underlying 
DataNodes
         * that include it.
-        * 
+        *
         * @since 3.1
         */
        public void removeDataMap(String mapName) {
@@ -441,7 +447,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Returns registered DataNode whose name matches <code>name</code>
         * parameter.
-        * 
+        *
         * @since 3.1
         */
        public DataNode getDataNode(String nodeName) {
@@ -451,7 +457,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Returns a DataNode that should handle queries for all entities in a
         * DataMap.
-        * 
+        *
         * @since 1.1
         */
        public DataNode lookupDataNode(DataMap map) {
@@ -493,7 +499,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * Sets EntityResolver. If not set explicitly, DataDomain creates a 
default
         * EntityResolver internally on demand.
-        * 
+        *
         * @since 1.1
         */
        public void setEntityResolver(EntityResolver entityResolver) {
@@ -541,7 +547,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Runs query returning generic QueryResponse.
-        * 
+        *
         * @since 1.2
         */
        @Override
@@ -574,7 +580,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Only handles commit-type synchronization, ignoring any other type.
-        * 
+        *
         * @since 1.2
         */
        @Override
@@ -636,7 +642,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Returns shared {@link QueryCache} used by this DataDomain.
-        * 
+        *
         * @since 3.0
         */
        public QueryCache getQueryCache() {
@@ -666,7 +672,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
         * Filter ordering note: filters are applied in reverse order of their
         * occurrence in the filter list. I.e. the last filter in the list 
called
         * first in the chain.
-        * 
+        *
         * @since 3.1
         */
        public List<DataChannelFilter> getFilters() {
@@ -677,7 +683,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
         * Adds a new filter, immediately calling its 'init' method. Since 4.0 
this
         * method also registers passed filter as an event listener, if any of 
its
         * methods have event annotations.
-        * 
+        *
         * @since 3.1
         */
        public void addFilter(DataChannelFilter filter) {
@@ -688,7 +694,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
 
        /**
         * Removes a filter from the filter chain.
-        * 
+        *
         * @since 3.1
         */
        public void removeFilter(DataChannelFilter filter) {
@@ -699,7 +705,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
         * Adds a listener, mapping its methods to events based on annotations. 
This
         * is a shortcut for
         * 'getEntityResolver().getCallbackRegistry().addListener(listener)'.
-        * 
+        *
         * @since 4.0
         */
        public void addListener(Object listener) {
@@ -756,7 +762,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
        /**
         * An optional DataNode that is used for DataMaps that are not linked 
to a
         * DataNode explicitly.
-        * 
+        *
         * @since 3.1
         */
        public DataNode getDefaultNode() {
@@ -780,7 +786,7 @@ public class DataDomain implements QueryEngine, DataChannel 
{
         * changed either by calling {@link #setMaxIdQualifierSize(int)} or 
changing
         * the value for property
         * {@link Constants#SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY}.
-        * 
+        *
         * @since 3.1
         */
        public int getMaxIdQualifierSize() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/access/DataRowStoreFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/DataRowStoreFactory.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/DataRowStoreFactory.java
new file mode 100644
index 0000000..7939468
--- /dev/null
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/DataRowStoreFactory.java
@@ -0,0 +1,38 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.cayenne.access;
+
+/**
+ * A factory for creating {@link DataRowStore}
+ *
+ * @since 4.0
+ */
+public interface DataRowStoreFactory {
+
+    /**
+     * Create new {@link DataRowStore} object.
+     *
+     * @since 4.0
+     * @param name DataRowStore name. Used to identify this DataRowStore in 
events, etc.
+     *             Can't be null.
+     */
+    DataRowStore createDataRowStore(String name);
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/access/DefaultDataRowStoreFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/DefaultDataRowStoreFactory.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/DefaultDataRowStoreFactory.java
new file mode 100644
index 0000000..f6f67fc
--- /dev/null
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/DefaultDataRowStoreFactory.java
@@ -0,0 +1,47 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.cayenne.access;
+
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.di.DIRuntimeException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.event.EventManager;
+
+import java.util.Map;
+
+/**
+ * A default implementation of {@link DataRowStoreFactory}
+ *
+ * @since 4.0
+ */
+public class DefaultDataRowStoreFactory implements DataRowStoreFactory {
+
+    @Inject
+    protected EventManager eventManager;
+
+    @Inject(Constants.DATA_ROW_STORE_PROPERTIES_MAP)
+    Map<String, String> properties;
+
+    @Override
+    public DataRowStore createDataRowStore(String name) throws 
DIRuntimeException {
+        return new DataRowStore(name, properties, eventManager);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
index 7844d6e..18c42cd 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
@@ -264,4 +264,12 @@ public interface Constants {
     @Deprecated
     public static final String ROP_CONTEXT_LIFECYCLE_EVENTS_PROPERTY = 
"cayenne.rop.context_lifecycle_events";
 
+    /**
+     * A DI container key for the Map&lt;String, String&gt; storing
+     * {@link org.apache.cayenne.access.DataRowStore} properties
+     *
+     * @since 4.0
+     */
+    public static final String DATA_ROW_STORE_PROPERTIES_MAP = 
"cayenne.server.data_row_store";
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
index b6b51a1..f5cca8b 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
@@ -23,13 +23,13 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataRowStore;
+import org.apache.cayenne.access.DataRowStoreFactory;
 import org.apache.cayenne.access.ObjectStore;
 import org.apache.cayenne.cache.NestedQueryCache;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.configuration.ObjectStoreFactory;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.tx.TransactionFactory;
 
@@ -45,7 +45,7 @@ public class DataContextFactory implements 
ObjectContextFactory {
     protected EventManager eventManager;
 
     @Inject
-    protected Injector injector;
+    protected DataRowStoreFactory dataRowStoreFactory;
     
     @Inject
     protected ObjectStoreFactory objectStoreFactory;
@@ -80,11 +80,9 @@ public class DataContextFactory implements 
ObjectContextFactory {
 
         // for new dataRowStores use the same name for all stores
         // it makes it easier to track the event subject
-        DataRowStore snapshotCache = (dataDomain.isSharedCacheEnabled()) ? 
dataDomain
-                .getSharedSnapshotCache() : new DataRowStore(
-                dataDomain.getName(),
-                dataDomain.getProperties(),
-                eventManager);
+        DataRowStore snapshotCache = (dataDomain.isSharedCacheEnabled())
+                ? dataDomain.getSharedSnapshotCache()
+                : dataRowStoreFactory.createDataRowStore(dataDomain.getName());
 
         DataContext context = newInstance(
                 parent, objectStoreFactory.createObjectStore(snapshotCache));
@@ -112,9 +110,9 @@ public class DataContextFactory implements 
ObjectContextFactory {
 
         // for new dataRowStores use the same name for all stores
         // it makes it easier to track the event subject
-        DataRowStore snapshotCache = (parent.isSharedCacheEnabled()) ? parent
-                .getSharedSnapshotCache() : new DataRowStore(parent.getName(), 
parent
-                .getProperties(), eventManager);
+        DataRowStore snapshotCache = (parent.isSharedCacheEnabled())
+                ? parent.getSharedSnapshotCache()
+                : dataRowStoreFactory.createDataRowStore(parent.getName());
 
         DataContext context = newInstance(
                 parent, objectStoreFactory.createObjectStore(snapshotCache));

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
index e8314c0..2f8590d 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
@@ -21,6 +21,8 @@ package org.apache.cayenne.configuration.server;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.DataChannelFilter;
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataRowStoreFactory;
+import org.apache.cayenne.access.DefaultDataRowStoreFactory;
 import org.apache.cayenne.access.DefaultObjectMapRetainStrategy;
 import org.apache.cayenne.access.ObjectMapRetainStrategy;
 import org.apache.cayenne.access.dbsync.DefaultSchemaUpdateStrategyFactory;
@@ -32,7 +34,24 @@ import 
org.apache.cayenne.access.translator.batch.BatchTranslatorFactory;
 import 
org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory;
 import 
org.apache.cayenne.access.translator.select.DefaultSelectTranslatorFactory;
 import org.apache.cayenne.access.translator.select.SelectTranslatorFactory;
-import org.apache.cayenne.access.types.*;
+import org.apache.cayenne.access.types.BigDecimalType;
+import org.apache.cayenne.access.types.BigIntegerType;
+import org.apache.cayenne.access.types.BooleanType;
+import org.apache.cayenne.access.types.ByteArrayType;
+import org.apache.cayenne.access.types.ByteType;
+import org.apache.cayenne.access.types.CalendarType;
+import org.apache.cayenne.access.types.CharType;
+import org.apache.cayenne.access.types.DateType;
+import org.apache.cayenne.access.types.DoubleType;
+import org.apache.cayenne.access.types.FloatType;
+import org.apache.cayenne.access.types.IntegerType;
+import org.apache.cayenne.access.types.LongType;
+import org.apache.cayenne.access.types.ShortType;
+import org.apache.cayenne.access.types.TimeType;
+import org.apache.cayenne.access.types.TimestampType;
+import org.apache.cayenne.access.types.UUIDType;
+import org.apache.cayenne.access.types.UtilDateType;
+import org.apache.cayenne.access.types.VoidType;
 import org.apache.cayenne.ashwood.AshwoodEntitySorter;
 import org.apache.cayenne.cache.MapQueryCacheProvider;
 import org.apache.cayenne.cache.QueryCache;
@@ -64,7 +83,12 @@ import org.apache.cayenne.dba.postgres.PostgresSniffer;
 import org.apache.cayenne.dba.sqlite.SQLiteSniffer;
 import org.apache.cayenne.dba.sqlserver.SQLServerSniffer;
 import org.apache.cayenne.dba.sybase.SybaseSniffer;
-import org.apache.cayenne.di.*;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.ClassLoaderManager;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.ListBuilder;
+import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
 import org.apache.cayenne.di.spi.DefaultClassLoaderManager;
 import org.apache.cayenne.event.DefaultEventManager;
@@ -268,8 +292,9 @@ public class ServerModule implements Module {
 
         binder.bind(QueryCache.class).toProvider(MapQueryCacheProvider.class);
 
-        // a service to provide the main stack DataDomain
-        binder.bind(DataDomain.class).toProvider(DataDomainProvider.class);
+               
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+        binder.bindMap(Constants.DATA_ROW_STORE_PROPERTIES_MAP);// a service 
to provide the main stack DataDomain
+               
binder.bind(DataDomain.class).toProvider(DataDomainProvider.class);
 
         binder.bind(DataNodeFactory.class).to(DefaultDataNodeFactory.class);
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/test/java/org/apache/cayenne/access/DataRowStoreFactoryIT.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/access/DataRowStoreFactoryIT.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/access/DataRowStoreFactoryIT.java
new file mode 100644
index 0000000..743368c
--- /dev/null
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/access/DataRowStoreFactoryIT.java
@@ -0,0 +1,119 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.cayenne.access;
+
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.DefaultRuntimeProperties;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.log.CommonsJdbcEventLogger;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.tx.DefaultTransactionFactory;
+import org.apache.cayenne.tx.DefaultTransactionManager;
+import org.apache.cayenne.tx.TransactionFactory;
+import org.apache.cayenne.tx.TransactionManager;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
+public class DataRowStoreFactoryIT extends ServerCase {
+
+    @Test
+    public void testGetDataRowStore() throws Exception {
+        ServerRuntime runtime = 
getUnitTestInjector().getInstance(ServerRuntime.class);
+        DataRowStore dataStore = 
runtime.getInjector().getInstance(DataRowStoreFactory.class)
+                .createDataRowStore("test");
+
+        assertNotNull(dataStore);
+    }
+
+    @Test
+    public void testGetDataRowStoreWithParameters() {
+        final DataDomain DOMAIN = new DataDomain("test");
+        final EventManager EVENT_MANAGER = new DefaultEventManager();
+        final int CACHE_SIZE = 500;
+        final int EXPIRATION_PROPERTY = 60 * 60 * 24;
+
+        Module testModule = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+                binder.bindMap(Constants.DATA_ROW_STORE_PROPERTIES_MAP)
+                        .put(DataRowStore.SNAPSHOT_CACHE_SIZE_PROPERTY, 
String.valueOf(CACHE_SIZE))
+                        .put(DataRowStore.SNAPSHOT_EXPIRATION_PROPERTY, 
String.valueOf(EXPIRATION_PROPERTY));
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(testModule);
+        DataRowStore dataStore = 
injector.getInstance(DataRowStoreFactory.class)
+                .createDataRowStore("test");
+
+        assertNotNull(dataStore);
+        assertEquals(dataStore.maximumSize(), CACHE_SIZE);
+    }
+
+    @Test
+    public void testGetDataRowStoreWithBridge() {
+        final DataDomain DOMAIN = new DataDomain("test");
+        final EventManager EVENT_MANAGER = new DefaultEventManager();
+
+        Module testModule = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+                binder.bindMap(Constants.DATA_ROW_STORE_PROPERTIES_MAP);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(testModule);
+        DataRowStore dataStore = 
injector.getInstance(DataRowStoreFactory.class)
+                .createDataRowStore("test");
+
+        dataStore.stopListeners();
+        dataStore.startListeners();
+        dataStore.shutdown();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a4cba4e0/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
index cdb7e6b..0304a2e 100644
--- 
a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
@@ -20,10 +20,13 @@ package org.apache.cayenne.configuration.server;
 
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataRowStoreFactory;
+import org.apache.cayenne.access.DefaultDataRowStoreFactory;
 import org.apache.cayenne.access.DefaultObjectMapRetainStrategy;
 import org.apache.cayenne.access.ObjectMapRetainStrategy;
 import org.apache.cayenne.cache.MapQueryCache;
 import org.apache.cayenne.cache.QueryCache;
+import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.DefaultObjectStoreFactory;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.ObjectStoreFactory;
@@ -74,6 +77,8 @@ public class DataContextFactoryTest {
                 
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
                 
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
                 
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+                binder.bindMap(Constants.DATA_ROW_STORE_PROPERTIES_MAP);
             }
         };
 
@@ -111,6 +116,8 @@ public class DataContextFactoryTest {
                 
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
                 
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
                 
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
+                binder.bindMap(Constants.DATA_ROW_STORE_PROPERTIES_MAP);
             }
         };
 

Reply via email to