You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2016/12/11 17:59:59 UTC
[05/10] cayenne git commit: CAY-2166 Auto-loading of Cayenne modules
CAY-2166 Auto-loading of Cayenne modules
* auto-loading of Java8Module
* renamed CayenneJava8Module to Java8Module
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/c0c1c5af
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/c0c1c5af
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/c0c1c5af
Branch: refs/heads/master
Commit: c0c1c5af79ad04df192da2b3232c6b0c384ef01f
Parents: 0fbc622
Author: Andrus Adamchik <an...@objectstyle.com>
Authored: Sun Dec 11 17:05:33 2016 +0300
Committer: Andrus Adamchik <an...@objectstyle.com>
Committed: Sun Dec 11 19:54:42 2016 +0300
----------------------------------------------------------------------
cayenne-java8/pom.xml | 22 ++++++++++
.../cayenne/java8/CayenneJava8Module.java | 42 -------------------
.../org/apache/cayenne/java8/Java8Module.java | 40 ++++++++++++++++++
.../cayenne/java8/Java8ModuleProvider.java | 43 ++++++++++++++++++++
.../org.apache.cayenne.di.spi.ModuleProvider | 1 +
.../cayenne/java8/Java8ModuleProviderTest.java | 30 ++++++++++++++
.../org/apache/cayenne/java8/RuntimeBase.java | 5 +--
.../cayenne/rop/protostuff/RuntimeBase.java | 12 +++---
.../apache/cayenne/tutorial/Http2Client.java | 4 +-
.../cayenne/tutorial/Http2ROPServlet.java | 11 ++---
10 files changed, 152 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/pom.xml
----------------------------------------------------------------------
diff --git a/cayenne-java8/pom.xml b/cayenne-java8/pom.xml
index 978601a..525f1b3 100644
--- a/cayenne-java8/pom.xml
+++ b/cayenne-java8/pom.xml
@@ -46,6 +46,28 @@
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-server</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/main/java/org/apache/cayenne/java8/CayenneJava8Module.java
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/main/java/org/apache/cayenne/java8/CayenneJava8Module.java b/cayenne-java8/src/main/java/org/apache/cayenne/java8/CayenneJava8Module.java
deleted file mode 100644
index 251718e..0000000
--- a/cayenne-java8/src/main/java/org/apache/cayenne/java8/CayenneJava8Module.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*****************************************************************
- * 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.java8;
-
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.java8.access.types.LocalDateTimeType;
-import org.apache.cayenne.java8.access.types.LocalDateType;
-import org.apache.cayenne.java8.access.types.LocalTimeType;
-
-public class CayenneJava8Module implements Module {
-
- public CayenneJava8Module() {
- }
-
- @Override
- public void configure(Binder binder) {
- ServerModule.contributeDefaultTypes(binder)
- .add(new LocalDateType())
- .add(new LocalTimeType())
- .add(new LocalDateTimeType());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8Module.java
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8Module.java b/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8Module.java
new file mode 100644
index 0000000..2de3749
--- /dev/null
+++ b/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8Module.java
@@ -0,0 +1,40 @@
+/*
+ * 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.java8;
+
+import org.apache.cayenne.configuration.server.ServerModule;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.java8.access.types.LocalDateTimeType;
+import org.apache.cayenne.java8.access.types.LocalDateType;
+import org.apache.cayenne.java8.access.types.LocalTimeType;
+
+/**
+ * @since 4.0
+ */
+public class Java8Module implements Module {
+
+ @Override
+ public void configure(Binder binder) {
+ ServerModule.contributeDefaultTypes(binder)
+ .add(new LocalDateType())
+ .add(new LocalTimeType())
+ .add(new LocalDateTimeType());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8ModuleProvider.java
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8ModuleProvider.java b/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8ModuleProvider.java
new file mode 100644
index 0000000..243dc73
--- /dev/null
+++ b/cayenne-java8/src/main/java/org/apache/cayenne/java8/Java8ModuleProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.java8;
+
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.di.spi.ModuleProvider;
+
+/**
+ * @since 4.0
+ */
+public class Java8ModuleProvider implements ModuleProvider {
+
+ @Override
+ public Module module() {
+ return new Java8Module();
+ }
+
+ @Override
+ public Class<? extends Module> moduleType() {
+ return Java8Module.class;
+ }
+
+ @Override
+ public Class<? extends Module>[] overrides() {
+ return new Class[0];
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider b/cayenne-java8/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider
new file mode 100644
index 0000000..d24953f
--- /dev/null
+++ b/cayenne-java8/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider
@@ -0,0 +1 @@
+org.apache.cayenne.java8.Java8ModuleProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/test/java/org/apache/cayenne/java8/Java8ModuleProviderTest.java
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/test/java/org/apache/cayenne/java8/Java8ModuleProviderTest.java b/cayenne-java8/src/test/java/org/apache/cayenne/java8/Java8ModuleProviderTest.java
new file mode 100644
index 0000000..4c4df57
--- /dev/null
+++ b/cayenne-java8/src/test/java/org/apache/cayenne/java8/Java8ModuleProviderTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.java8;
+
+import org.apache.cayenne.unit.util.ModuleProviderChecker;
+import org.junit.Test;
+
+public class Java8ModuleProviderTest {
+
+ @Test
+ public void testProviderPresent() {
+ ModuleProviderChecker.testProviderPresent(Java8ModuleProvider.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-java8/src/test/java/org/apache/cayenne/java8/RuntimeBase.java
----------------------------------------------------------------------
diff --git a/cayenne-java8/src/test/java/org/apache/cayenne/java8/RuntimeBase.java b/cayenne-java8/src/test/java/org/apache/cayenne/java8/RuntimeBase.java
index f150818..8b75880 100644
--- a/cayenne-java8/src/test/java/org/apache/cayenne/java8/RuntimeBase.java
+++ b/cayenne-java8/src/test/java/org/apache/cayenne/java8/RuntimeBase.java
@@ -20,7 +20,6 @@
package org.apache.cayenne.java8;
import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Module;
import org.junit.Before;
public class RuntimeBase {
@@ -29,8 +28,6 @@ public class RuntimeBase {
@Before
public void setUpRuntime() throws Exception {
- Module java8Module = new CayenneJava8Module();
- this.runtime = new ServerRuntime("cayenne-java8.xml", java8Module);
+ this.runtime = ServerRuntime.builder().addConfig("cayenne-java8.xml").build();
}
-
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
index 91bd033..3867862 100644
--- a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
@@ -26,7 +26,7 @@ import org.apache.cayenne.configuration.rop.client.ClientRuntime;
import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.di.Module;
-import org.apache.cayenne.java8.CayenneJava8Module;
+import org.apache.cayenne.java8.Java8Module;
import org.apache.cayenne.remote.ClientConnection;
import org.apache.cayenne.remote.service.ProtostuffLocalConnectionProvider;
import org.junit.Before;
@@ -42,9 +42,11 @@ public class RuntimeBase extends ProtostuffProperties {
@Before
public void setUpRuntimes() throws Exception {
- this.serverRuntime = new ServerRuntime("cayenne-protostuff.xml",
- new ProtostuffModule(),
- new CayenneJava8Module());
+ this.serverRuntime = ServerRuntime
+ .builder()
+ .addConfig("cayenne-protostuff.xml")
+ .addModule(new ProtostuffModule())
+ .build();
Map<String, String> properties = new HashMap<>();
properties.put(ClientConstants.ROP_CHANNEL_EVENTS_PROPERTY, Boolean.TRUE.toString());
@@ -56,7 +58,7 @@ public class RuntimeBase extends ProtostuffProperties {
serverRuntime.getInjector(),
properties,
new ProtostuffModule(),
- new CayenneJava8Module(),
+ new Java8Module(),
module);
this.context = clientRuntime.newContext();
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/tutorials/tutorial-rop-client-http2/src/main/java/org/apache/cayenne/tutorial/Http2Client.java
----------------------------------------------------------------------
diff --git a/tutorials/tutorial-rop-client-http2/src/main/java/org/apache/cayenne/tutorial/Http2Client.java b/tutorials/tutorial-rop-client-http2/src/main/java/org/apache/cayenne/tutorial/Http2Client.java
index 6fb819d..33f7d93 100644
--- a/tutorials/tutorial-rop-client-http2/src/main/java/org/apache/cayenne/tutorial/Http2Client.java
+++ b/tutorials/tutorial-rop-client-http2/src/main/java/org/apache/cayenne/tutorial/Http2Client.java
@@ -24,7 +24,7 @@ import org.apache.cayenne.configuration.rop.client.ClientConstants;
import org.apache.cayenne.configuration.rop.client.ClientJettyHttp2Module;
import org.apache.cayenne.configuration.rop.client.ClientRuntime;
import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
-import org.apache.cayenne.java8.CayenneJava8Module;
+import org.apache.cayenne.java8.Java8Module;
import org.apache.cayenne.query.ObjectSelect;
import org.apache.cayenne.rop.JettyHttp2ClientConnectionProvider;
import org.apache.cayenne.rop.http.JettyHttpROPConnector;
@@ -69,7 +69,7 @@ public class Http2Client {
ClientRuntime runtime = new ClientRuntime(properties,
new ClientJettyHttp2Module(),
new ProtostuffModule(),
- new CayenneJava8Module());
+ new Java8Module());
ObjectContext context = runtime.newContext();
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c0c1c5af/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
----------------------------------------------------------------------
diff --git a/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java b/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
index 1ae9865..4c4b4df 100644
--- a/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
+++ b/tutorials/tutorial-rop-server-http2/src/main/java/org/apache/cayenne/tutorial/Http2ROPServlet.java
@@ -25,7 +25,6 @@ import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.configuration.web.WebConfiguration;
import org.apache.cayenne.configuration.web.WebUtil;
import org.apache.cayenne.di.Module;
-import org.apache.cayenne.java8.CayenneJava8Module;
import org.apache.cayenne.remote.RemoteService;
import org.apache.cayenne.rop.ROPSerializationService;
import org.apache.cayenne.rop.ROPServlet;
@@ -51,11 +50,13 @@ public class Http2ROPServlet extends ROPServlet {
Collection<Module> modules = configAdapter.createModules(
new ROPServerModule(eventBridgeParameters),
- new ProtostuffModule(),
- new CayenneJava8Module());
+ new ProtostuffModule());
- ServerRuntime runtime = new ServerRuntime(configurationLocation, modules
- .toArray(new Module[modules.size()]));
+ ServerRuntime runtime = ServerRuntime
+ .builder()
+ .addConfig(configurationLocation)
+ .addModules(modules)
+ .build();
this.remoteService = runtime.getInjector().getInstance(RemoteService.class);
this.serializationService = runtime.getInjector().getInstance(ROPSerializationService.class);