From a198989a76cb8078ebc0f8cc5493991467391c6b Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Tue, 7 Nov 2017 23:01:43 -0500 Subject: [PATCH] Cleanup. --- .../net/helenus/core/cache/CacheUtil.java | 23 ++++++++++++------- .../operation/AbstractOptionalOperation.java | 2 +- .../operation/AbstractStreamOperation.java | 2 +- .../core/operation/SelectOperation.java | 20 ++++++++-------- .../helenus/mapping/HelenusMappingEntity.java | 5 ++-- .../java/net/helenus/mapping/MappingUtil.java | 9 ++++++++ .../core/unitofwork/UnitOfWorkTest.java | 3 ++- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/helenus/core/cache/CacheUtil.java b/src/main/java/net/helenus/core/cache/CacheUtil.java index 1efafa2..78ae064 100644 --- a/src/main/java/net/helenus/core/cache/CacheUtil.java +++ b/src/main/java/net/helenus/core/cache/CacheUtil.java @@ -51,20 +51,27 @@ public class CacheUtil { }) .collect(Collectors.toList())); // TODO(gburd): rework so as to not generate the combinations at all rather than filter + facets = facets.stream() + .filter(f -> !f.fixed()) + .filter(f -> !f.alone() || !f.combined()) + .collect(Collectors.toList()); for (Facet facet : facets) { - if (facet.fixed()) continue; - if (facet.alone() && facet.combined() && true) continue; combinations = combinations .stream() .filter(combo -> { - for (String c : combo) { - // When used alone, this facet is not distinct so don't use it as a key. - if (facet.alone() == false && c.equals(facet.name())) { + // When used alone, this facet is not distinct so don't use it as a key. + if (combo.length == 1) { + if (!facet.alone() && combo[0].startsWith(facet.name() + "==")) { return false; } - // Don't use this facet in combination with others to create keys. - if (facet.combined() == false && c.split("==")[0].equals(facet.name())) { - return false; + } else { + if (!facet.combined()) { + for (String c : combo) { + // Don't use this facet in combination with others to create keys. + if (c.startsWith(facet.name() + "==")) { + return false; + } + } } } return true; diff --git a/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java b/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java index c013d20..def7fff 100644 --- a/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java +++ b/src/main/java/net/helenus/core/operation/AbstractOptionalOperation.java @@ -91,7 +91,7 @@ public abstract class AbstractOptionalOperation extends AbstractFilterStreamOperation extends AbstractFilterStreamOperation this.props.add(p)); this.isCacheable = entity.isCacheable(); - this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class); + this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class); } public SelectOperation( @@ -112,7 +112,7 @@ public final class SelectOperation extends AbstractFilterStreamOperation this.props.add(p)); this.isCacheable = entity.isCacheable(); - this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class); + this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class); } public SelectOperation(AbstractSessionOperations sessionOperations, Function rowMapper, @@ -125,7 +125,7 @@ public final class SelectOperation extends AbstractFilterStreamOperation extends AbstractFilterStreamOperation clazz, Class iface) { + Class[] interfaces = clazz.getInterfaces(); + for (Class i : interfaces) { + if (i == iface) + return true; + } + return false; + } + private static void rethrow(Throwable cause) throws CloneNotSupportedException { if (cause instanceof RuntimeException) { throw (RuntimeException) cause; diff --git a/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java b/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java index 7048950..8f24484 100644 --- a/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java +++ b/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java @@ -381,8 +381,9 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest { uow.commit(); committedAt = uow.committedAt(); } + // 'c' is distinct, but not on it's own so this should miss cache w4 = session.select(Widget.class) - .where(widget::id, eq(key)) + .where(widget::c, eq(w3.c())) .single() .sync() .orElse(null);