You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/11/24 12:33:00 UTC
[incubator-plc4x] branch develop updated: [plc4j-opm] fixed issue
with detached entity.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 90b7f10 [plc4j-opm] fixed issue with detached entity.
90b7f10 is described below
commit 90b7f109307389b8c052e13ad1c199c859393928
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 13:24:59 2018 +0100
[plc4j-opm] fixed issue with detached entity.
---
.../java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java | 12 ++++++++++++
.../java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java | 11 ++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
index 1a8953b..346e07e 100644
--- a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
+++ b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
@@ -158,6 +158,18 @@ public class PlcEntityInterceptor {
@FieldValue(PlcEntityManager.ALIAS_REGISTRY) AliasRegistry registry,
@FieldValue(PlcEntityManager.LAST_FETCHED) Map<String, Instant> lastFetched,
@Argument(0) Object argument) throws OPMException {
+ LOGGER.trace("Invoked method {} on connected PlcEntity {}", method.getName(), method.getDeclaringClass().getName());
+
+ // If "detached" (i.e. _driverManager is null) simply forward the call
+ if (driverManager == null) {
+ LOGGER.trace("Entity not connected, simply fowarding call");
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ throw new OPMException("Exception during forwarding call", e);
+ }
+ }
+
if (method.getName().startsWith("set")) {
if (method.getParameterCount() != 1) {
throw new OPMException("Only setter with one arguments are supported");
diff --git a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
index 91a6f9e..940719b 100644
--- a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
+++ b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
@@ -178,13 +178,18 @@ public class PlcEntityManagerTest implements WithAssertions {
AliasEntity connected = entityManager.write(AliasEntity.class, "mock:test", object);
connected.setAliasedField("changed2");
connected.getAliasedField();
+ verify(mockDevice, times(0)).read(eq("real_field"));
+ verify(mockDevice, times(1)).write(eq("real_field"), any());
+ AliasEntity merge = entityManager.merge(AliasEntity.class, "mock:test", connected);
+ merge.setAliasedField("changed2");
+ merge.getAliasedField();
// Assert that "field" was queried
verify(mockDevice, times(1)).read(eq("real_field"));
- verify(mockDevice, times(2)).write(eq("real_field"), any());
+ verify(mockDevice, times(3)).write(eq("real_field"), any());
- entityManager.disconnect(connected);
- assertThat(connected.getAliasedField()).isEqualTo("value");
+ entityManager.disconnect(merge);
+ assertThat(merge.getAliasedField()).isEqualTo("value");
}
@Test