diff --git a/core/pom.xml b/core/pom.xml index e863fc7a4..2093eb79e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -120,6 +120,12 @@ ${jpa-streamer.version} + + com.speedment.jpastreamer + termopmodifier-standard + ${jpa-streamer.version} + + com.speedment.jpastreamer announcer diff --git a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java index 5b22c946f..89fd62e88 100644 --- a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java +++ b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java @@ -95,11 +95,19 @@ public boolean process(Set annotations, RoundEnvironment return false; } - roundEnv.getElementsAnnotatedWith(Entity.class).stream() + Set entities = roundEnv.getElementsAnnotatedWith(Entity.class); + + if (entities.isEmpty()) { + System.out.format("[JPAStreamer Field Generator Processor] Found no classes annotated with jakarta.persistence.Entity.\n"); + return true; + } + + entities.stream() .filter(ae -> ae.getKind() == ElementKind.CLASS) .forEach(ae -> { try { final String entityName = ae.asType().toString(); + System.out.format("[JPAStreamer Field Generator Processor] Generating class for: %s\n", entityName); final String shortEntityName = shortName(entityName); final String prefix = processingEnv.getOptions().getOrDefault("jpaStreamerPrefix", ""); diff --git a/provider/renderer-standard/pom.xml b/provider/renderer-standard/pom.xml index 960b463a4..af991d233 100644 --- a/provider/renderer-standard/pom.xml +++ b/provider/renderer-standard/pom.xml @@ -60,22 +60,22 @@ com.speedment.jpastreamer interopoptimizer - + com.speedment.jpastreamer rootfactory + + com.speedment.jpastreamer + termopmodifier + + jakarta.persistence jakarta.persistence-api ${jakarta.version} - - com.speedment.jpastreamer - termopoptimizer - - diff --git a/provider/renderer-standard/src/main/java/com/speedment/jpastreamer/renderer/standard/internal/StandardRenderer.java b/provider/renderer-standard/src/main/java/com/speedment/jpastreamer/renderer/standard/internal/StandardRenderer.java index e0a0eca28..8d8ca7c3c 100644 --- a/provider/renderer-standard/src/main/java/com/speedment/jpastreamer/renderer/standard/internal/StandardRenderer.java +++ b/provider/renderer-standard/src/main/java/com/speedment/jpastreamer/renderer/standard/internal/StandardRenderer.java @@ -29,7 +29,7 @@ import com.speedment.jpastreamer.rootfactory.RootFactory; import com.speedment.jpastreamer.streamconfiguration.StreamConfiguration; -import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizerFactory; +import com.speedment.jpastreamer.termopmodifier.TerminalOperationModifierFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.TypedQuery; @@ -49,7 +49,7 @@ final class StandardRenderer implements Renderer { private final CriteriaFactory criteriaFactory; private final IntermediateOperationOptimizerFactory intermediateOperationOptimizerFactory; - private final TerminalOperationOptimizerFactory terminalOperationOptimizerFactory; + private final TerminalOperationModifierFactory terminalOperationModifierFactory; private final MergerFactory mergerFactory; @@ -61,7 +61,7 @@ final class StandardRenderer implements Renderer { this.entityManager = requireNonNull(entityManagerSupplier).get(); this.criteriaFactory = RootFactory.getOrThrow(CriteriaFactory.class, ServiceLoader::load); this.intermediateOperationOptimizerFactory = RootFactory.getOrThrow(IntermediateOperationOptimizerFactory.class, ServiceLoader::load); - this.terminalOperationOptimizerFactory = RootFactory.getOrThrow(TerminalOperationOptimizerFactory.class, ServiceLoader::load); + this.terminalOperationModifierFactory = RootFactory.getOrThrow(TerminalOperationModifierFactory.class, ServiceLoader::load); this.mergerFactory = RootFactory.getOrThrow(MergerFactory.class, ServiceLoader::load); } @@ -69,13 +69,14 @@ final class StandardRenderer implements Renderer { this.entityManager = entityManager; this.criteriaFactory = RootFactory.getOrThrow(CriteriaFactory.class, ServiceLoader::load); this.intermediateOperationOptimizerFactory = RootFactory.getOrThrow(IntermediateOperationOptimizerFactory.class, ServiceLoader::load); - this.terminalOperationOptimizerFactory = RootFactory.getOrThrow(TerminalOperationOptimizerFactory.class, ServiceLoader::load); + this.terminalOperationModifierFactory = RootFactory.getOrThrow(TerminalOperationModifierFactory.class, ServiceLoader::load); this.mergerFactory = RootFactory.getOrThrow(MergerFactory.class, ServiceLoader::load); } @Override @SuppressWarnings("unchecked") public > RenderResult render(final Pipeline pipeline, final StreamConfiguration streamConfiguration) { + modifyPipeline(pipeline); optimizePipeline(pipeline); final Class entityClass = pipeline.root(); @@ -182,9 +183,12 @@ private > S replay(final Stream stream, fina return decorated; */ } - + + private void modifyPipeline(final Pipeline pipeline) { + terminalOperationModifierFactory.get().modify(pipeline); + } + private void optimizePipeline(final Pipeline pipeline) { - terminalOperationOptimizerFactory.get().optimize(pipeline); intermediateOperationOptimizerFactory.stream().forEach(intermediateOperationOptimizer -> intermediateOperationOptimizer.optimize(pipeline)); } diff --git a/provider/renderer-standard/src/main/java9/module-info.java b/provider/renderer-standard/src/main/java9/module-info.java index a1d8ef152..faa7c8791 100644 --- a/provider/renderer-standard/src/main/java9/module-info.java +++ b/provider/renderer-standard/src/main/java9/module-info.java @@ -19,7 +19,7 @@ requires jpastreamer.criteria; requires jpastreamer.merger; requires jpastreamer.interopoptimizer; - requires jpastreamer.termopoptimizer; + requires jpastreamer.termopmodifier; exports com.speedment.jpastreamer.renderer.standard; // Todo: Enable this diff --git a/provider/termopmodifier-standard/pom.xml b/provider/termopmodifier-standard/pom.xml index 87cc52ba3..c9f74aebf 100644 --- a/provider/termopmodifier-standard/pom.xml +++ b/provider/termopmodifier-standard/pom.xml @@ -35,10 +35,28 @@ + com.speedment.jpastreamer termopmodifier + + + com.speedment.jpastreamer + rootfactory + + + + com.speedment.jpastreamer + pipeline-standard + test + + + + com.speedment.jpastreamer + field + + diff --git a/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/InternalTerminalOperatorModifierFactory.java b/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/InternalTerminalOperatorModifierFactory.java index 6d29e34cc..c5a664602 100644 --- a/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/InternalTerminalOperatorModifierFactory.java +++ b/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/InternalTerminalOperatorModifierFactory.java @@ -23,4 +23,5 @@ public final class InternalTerminalOperatorModifierFactory implements TerminalOp public TerminalOperationModifier get() { return singleton; } + } diff --git a/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperatorModifier.java b/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperatorModifier.java index b63981c78..49b979ee1 100644 --- a/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperatorModifier.java +++ b/provider/termopmodifier-standard/src/main/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperatorModifier.java @@ -12,16 +12,93 @@ */ package com.speedment.jpastreamer.termopmodifier.standard.internal; +import com.speedment.jpastreamer.field.predicate.SpeedmentPredicate; import com.speedment.jpastreamer.pipeline.Pipeline; +import com.speedment.jpastreamer.pipeline.intermediate.IntermediateOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationType; +import com.speedment.jpastreamer.rootfactory.RootFactory; +import com.speedment.jpastreamer.termopmodifier.TerminalOperationModifier; + +import java.util.Optional; +import java.util.ServiceLoader; import static java.util.Objects.requireNonNull; -final class StandardTerminalOperatorModifier implements com.speedment.jpastreamer.termopmodifier.TerminalOperationModifier { +final class StandardTerminalOperatorModifier implements TerminalOperationModifier { + + private final IntermediateOperationFactory intermediateOperationFactory; + private final TerminalOperationFactory terminalOperationFactory; + StandardTerminalOperatorModifier() { + this.intermediateOperationFactory = RootFactory.getOrThrow(IntermediateOperationFactory.class, ServiceLoader::load); + this.terminalOperationFactory = RootFactory.getOrThrow(TerminalOperationFactory.class, ServiceLoader::load); + } + @Override public Pipeline modify(Pipeline pipeline) { requireNonNull(pipeline); - // For now, just return whatever we get. + + final TerminalOperationType terminalOperationType = pipeline.terminatingOperation().type(); + + switch (terminalOperationType) { + case ANY_MATCH: + return modifyAnyMatch(pipeline); + case NONE_MATCH: + return modifyNoneMatch(pipeline); + case FIND_FIRST: + return modifyFindFirst(pipeline); + case FIND_ANY: + return modifyFindAny(pipeline); + default: + return pipeline; + } + } + + private Pipeline modifyAnyMatch(Pipeline pipeline) { + this.getPredicate(pipeline.terminatingOperation()).ifPresent(speedmentPredicate -> { + pipeline.intermediateOperations().add(intermediateOperationFactory.createFilter(speedmentPredicate)); + pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); + pipeline.terminatingOperation(terminalOperationFactory.createAnyMatch(p -> true)); + }); return pipeline; } + + private Pipeline modifyNoneMatch(Pipeline pipeline) { + this.getPredicate(pipeline.terminatingOperation()).ifPresent(speedmentPredicate -> { + pipeline.intermediateOperations().add(intermediateOperationFactory.createFilter(speedmentPredicate)); + pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); + // NoneMatch() - If the stream is empty then true is returned and the predicate is not evaluated. + // If the expression is evaluated => There is a match and the expression is always false. + pipeline.terminatingOperation(terminalOperationFactory.createNoneMatch(e -> true)); + }); + return pipeline; + } + + private Pipeline modifyFindFirst(Pipeline pipeline) { + pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); + return pipeline; + } + + private Pipeline modifyFindAny(Pipeline pipeline) { + pipeline.ordered(false); + pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); + return pipeline; + } + + private Optional> getPredicate(final TerminalOperation operation) { + final Object[] arguments = operation.arguments(); + + if (arguments.length != 1) { + return Optional.empty(); + } + + if (arguments[0] instanceof SpeedmentPredicate) { + return Optional.of((SpeedmentPredicate) arguments[0]); + } + + return Optional.empty(); + } + } diff --git a/provider/termopmodifier-standard/src/main/java9/module-info.java b/provider/termopmodifier-standard/src/main/java9/module-info.java index 06f5abb6b..b088b8c84 100644 --- a/provider/termopmodifier-standard/src/main/java9/module-info.java +++ b/provider/termopmodifier-standard/src/main/java9/module-info.java @@ -12,6 +12,7 @@ */ module jpastreamer.termopmodifier.standard { requires transitive jpastreamer.termopmodifier; + requires jpastreamer.rootfactory; exports com.speedment.jpastreamer.termopmodifier.standard; diff --git a/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/StandardTerminalOperationModifierFactoryTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/StandardTerminalOperationModifierFactoryTest.java new file mode 100644 index 000000000..11a65650a --- /dev/null +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/StandardTerminalOperationModifierFactoryTest.java @@ -0,0 +1,16 @@ +package com.speedment.jpastreamer.termopmodifier.standard; + +import com.speedment.jpastreamer.termopmodifier.TerminalOperationModifierFactory; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class StandardTerminalOperationModifierFactoryTest { + + @Test + void get() { + final TerminalOperationModifierFactory terminalOperationModifierFactory = new StandardTerminalOperatorModifierFactory(); + assertNotNull(terminalOperationModifierFactory.get()); + } + +} diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/AnyMatchTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/AnyMatchTest.java similarity index 84% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/AnyMatchTest.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/AnyMatchTest.java index f6095a13b..ef87937a9 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/AnyMatchTest.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/AnyMatchTest.java @@ -1,15 +1,14 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal; -import com.speedment.jpastreamer.field.ComparableField; -import com.speedment.jpastreamer.field.ShortField; import com.speedment.jpastreamer.field.predicate.SpeedmentPredicate; import com.speedment.jpastreamer.pipeline.Pipeline; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film$; -import java.math.BigDecimal; import java.util.function.Predicate; import java.util.stream.Stream; -final class AnyMatchTest extends StandardTerminalOperationOptimizerTest { +public class AnyMatchTest extends StandardTerminalOperationModifierTest { @Override Class getEntityClass() { @@ -24,7 +23,7 @@ protected Stream> pipelines() { anyMatchSpeedmentPredicate() ); } - + private PipelineTestCase noAnyMatch() { final Pipeline noAnyMatch = createPipeline( tof.createAllMatch(s -> s.equals("test")), @@ -66,8 +65,8 @@ private PipelineTestCase anyMatchSpeedmentPredicate() { final Pipeline anyMatchExpected = createPipeline( tof.createAnyMatch(s -> true), iof.createLimit(100), - iof.createLimit(1), - iof.createFilter(predicate) + iof.createFilter(predicate), + iof.createLimit(1) ); return new PipelineTestCase<>("Any Match Speedment Predicate", anyMatch, anyMatchExpected); diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindAnyTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindAnyTest.java similarity index 82% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindAnyTest.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindAnyTest.java index 4986b7791..22772a85a 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindAnyTest.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindAnyTest.java @@ -1,13 +1,14 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal; -import com.speedment.jpastreamer.field.predicate.SpeedmentPredicate; import com.speedment.jpastreamer.pipeline.Pipeline; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film$; import java.util.function.Predicate; import java.util.stream.Stream; -public class FindAnyTest extends StandardTerminalOperationOptimizerTest { - +public class FindAnyTest extends StandardTerminalOperationModifierTest { + @Override Class getEntityClass() { return Film.class; @@ -53,5 +54,4 @@ private PipelineTestCase findAny() { return new PipelineTestCase<>("Find Any", findAny, findAnyExpected); } - } diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindFirstTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindFirstTest.java similarity index 83% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindFirstTest.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindFirstTest.java index 0bd058518..2fb273414 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindFirstTest.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/FindFirstTest.java @@ -1,11 +1,13 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal; import com.speedment.jpastreamer.pipeline.Pipeline; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film$; import java.util.function.Predicate; import java.util.stream.Stream; -public class FindFirstTest extends StandardTerminalOperationOptimizerTest { +public class FindFirstTest extends StandardTerminalOperationModifierTest { @Override Class getEntityClass() { @@ -52,5 +54,5 @@ private PipelineTestCase findFirst() { return new PipelineTestCase<>("Find First", findFirst, findFirstExpected); } - + } diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/NoneMatchTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/NoneMatchTest.java similarity index 84% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/NoneMatchTest.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/NoneMatchTest.java index ec624ea84..87f29aa84 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/NoneMatchTest.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/NoneMatchTest.java @@ -1,12 +1,15 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal; + import com.speedment.jpastreamer.field.predicate.SpeedmentPredicate; import com.speedment.jpastreamer.pipeline.Pipeline; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film; +import com.speedment.jpastreamer.termopmodifier.standard.internal.model.Film$; import java.util.function.Predicate; import java.util.stream.Stream; -public class NoneMatchTest extends StandardTerminalOperationOptimizerTest{ +public class NoneMatchTest extends StandardTerminalOperationModifierTest{ @Override Class getEntityClass() { @@ -24,7 +27,7 @@ protected Stream> pipelines() { private PipelineTestCase noNoneMatch() { final Predicate p = f -> f.getTitle().startsWith("A"); - + final Pipeline noAnyMatch = createPipeline( tof.createAllMatch(p), iof.createLimit(100) @@ -65,11 +68,11 @@ private PipelineTestCase noneMatchSpeedmentPredicate() { final Pipeline anyMatchExpected = createPipeline( tof.createNoneMatch(s -> true), iof.createLimit(100), - iof.createLimit(1), - iof.createFilter(p) + iof.createFilter(p), + iof.createLimit(1) ); return new PipelineTestCase<>("None Match Speedment Predicate", anyMatch, anyMatchExpected); } - + } diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizerTest.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperationModifierTest.java similarity index 89% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizerTest.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperationModifierTest.java index e8fc5ab0c..b1f730e8d 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizerTest.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/StandardTerminalOperationModifierTest.java @@ -1,4 +1,4 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal; import com.speedment.jpastreamer.pipeline.Pipeline; import com.speedment.jpastreamer.pipeline.PipelineFactory; @@ -7,7 +7,7 @@ import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationFactory; import com.speedment.jpastreamer.rootfactory.RootFactory; -import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizer; +import com.speedment.jpastreamer.termopmodifier.TerminalOperationModifier; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; @@ -19,19 +19,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.DynamicTest.dynamicTest; -abstract class StandardTerminalOperationOptimizerTest { - +abstract class StandardTerminalOperationModifierTest { + protected final PipelineFactory pipelineFactory = RootFactory.getOrThrow(PipelineFactory.class, ServiceLoader::load); protected final IntermediateOperationFactory iof = RootFactory.getOrThrow(IntermediateOperationFactory.class, ServiceLoader::load); protected final TerminalOperationFactory tof = RootFactory.getOrThrow(TerminalOperationFactory.class, ServiceLoader::load); - protected final TerminalOperationOptimizer optimizer = new StandardTerminalOperationOptimizer(); - + protected final TerminalOperationModifier modifier = new StandardTerminalOperatorModifier(); + abstract Class getEntityClass(); - + @TestFactory - Stream optimize() { + Stream modify() { return pipelines().map(testCase -> dynamicTest(testCase.getName(), () -> { - this.optimizer.optimize(testCase.getPipeline()); + this.modifier.modify(testCase.getPipeline()); assertTestCase(testCase); })); @@ -45,8 +45,8 @@ protected Pipeline createPipeline(final TerminalOperation terminal for (IntermediateOperation operation : operations) { pipeline.intermediateOperations().add(operation); } - - pipeline.terminatingOperation(terminalOperation); + + pipeline.terminatingOperation(terminalOperation); return pipeline; } diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film$.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film$.java similarity index 88% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film$.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film$.java index 389820db3..a32e055bc 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film$.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film$.java @@ -1,21 +1,13 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal.model; import com.speedment.jpastreamer.field.ComparableField; -import com.speedment.jpastreamer.field.ReferenceField; import com.speedment.jpastreamer.field.ShortField; import com.speedment.jpastreamer.field.StringField; import java.math.BigDecimal; import java.sql.Timestamp; -/** - * The generated base for entity {@link Film} representing entities of the - * {@code film}-table in the database. - *

This file has been automatically generated by JPAStreamer. - * - * @author JPAStreamer - */ -public final class Film$ { +public class Film$ { /** * This Field corresponds to the {@link Film} field "length". @@ -44,7 +36,7 @@ public final class Film$ { Film::getReplacementCost, false ); - + /** * This Field corresponds to the {@link Film} field "rating". */ diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film.java b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film.java similarity index 95% rename from provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film.java rename to provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film.java index b37d66b29..dfe68e0d8 100644 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/Film.java +++ b/provider/termopmodifier-standard/src/test/java/com/speedment/jpastreamer/termopmodifier/standard/internal/model/Film.java @@ -1,17 +1,20 @@ -package com.speedment.jpastreamer.termopoptimizer.standard.internal; +package com.speedment.jpastreamer.termopmodifier.standard.internal.model; import jakarta.persistence.*; + import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.HashSet; @Entity @Table(name = "film", schema = "sakila") public class Film { - public Film() {} + public Film() { + } + public Film(short filmId) { this.filmId = filmId; } + public Film(String description) { this.description = description; } @@ -104,9 +107,13 @@ public void setRentalDuration(short rentalDuration) { this.rentalDuration = rentalDuration; } - public String getRating() { return rating; } + public String getRating() { + return rating; + } - public void setRating(String rating) { this.rating = rating; } + public void setRating(String rating) { + this.rating = rating; + } public BigDecimal getRentalRate() { return rentalRate; @@ -131,6 +138,7 @@ public BigDecimal getReplacementCost() { public void setReplacementCost(BigDecimal replacementCost) { this.replacementCost = replacementCost; } + public Timestamp getLastUpdate() { return lastUpdate; } @@ -138,7 +146,7 @@ public Timestamp getLastUpdate() { public void setLastUpdate(Timestamp lastUpdate) { this.lastUpdate = lastUpdate; } - + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/provider/termopoptimizer-standard/pom.xml b/provider/termopoptimizer-standard/pom.xml index d3d3d5d7d..546fecf3e 100644 --- a/provider/termopoptimizer-standard/pom.xml +++ b/provider/termopoptimizer-standard/pom.xml @@ -39,26 +39,7 @@ com.speedment.jpastreamer termopoptimizer - - - com.speedment.jpastreamer - pipeline - - - - com.speedment.jpastreamer - rootfactory - - - - com.speedment.jpastreamer - pipeline-standard - test - - - com.speedment.jpastreamer - field - + diff --git a/provider/termopoptimizer-standard/src/main/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizer.java b/provider/termopoptimizer-standard/src/main/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizer.java index 57cbf11b9..47d1bd897 100644 --- a/provider/termopoptimizer-standard/src/main/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizer.java +++ b/provider/termopoptimizer-standard/src/main/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizer.java @@ -12,96 +12,20 @@ */ package com.speedment.jpastreamer.termopoptimizer.standard.internal; -import static java.util.Objects.requireNonNull; - -import com.speedment.jpastreamer.criteria.PredicateFactory; -import com.speedment.jpastreamer.field.predicate.SpeedmentPredicate; import com.speedment.jpastreamer.pipeline.Pipeline; -import com.speedment.jpastreamer.pipeline.intermediate.IntermediateOperationFactory; -import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; -import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationFactory; -import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationType; -import com.speedment.jpastreamer.rootfactory.RootFactory; import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizer; -import java.util.Optional; -import java.util.ServiceLoader; +import static java.util.Objects.requireNonNull; final class StandardTerminalOperationOptimizer implements TerminalOperationOptimizer { - - private final IntermediateOperationFactory intermediateOperationFactory; - private final TerminalOperationFactory terminalOperationFactory; - - public StandardTerminalOperationOptimizer() { - this.intermediateOperationFactory = RootFactory.getOrThrow(IntermediateOperationFactory.class, ServiceLoader::load); - this.terminalOperationFactory = RootFactory.getOrThrow(TerminalOperationFactory.class, ServiceLoader::load); - } @Override public Pipeline optimize(Pipeline pipeline) { requireNonNull(pipeline); - - final TerminalOperationType terminalOperationType = pipeline.terminatingOperation().type(); - - switch (terminalOperationType) { - case ANY_MATCH: - return optimizeAnyMatch(pipeline); - case NONE_MATCH: - return optimizeNoneMatch(pipeline); - case FIND_FIRST: - return optimizeFindFirst(pipeline); - case FIND_ANY: - return optimizeFindAny(pipeline); - default: - return pipeline; - } - } - - private Pipeline optimizeAnyMatch(Pipeline pipeline) { - this.getPredicate(pipeline.terminatingOperation()).ifPresent(speedmentPredicate -> { - pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); - pipeline.intermediateOperations().add( - intermediateOperationFactory.createFilter(speedmentPredicate)); - pipeline.terminatingOperation(terminalOperationFactory.createAnyMatch(p -> true)); - }); - return pipeline; - } - - private Pipeline optimizeNoneMatch(Pipeline pipeline) { - this.getPredicate(pipeline.terminatingOperation()).ifPresent(speedmentPredicate -> { - pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); - pipeline.intermediateOperations().add(intermediateOperationFactory.createFilter(speedmentPredicate)); - // NoneMatch() - If the stream is empty then true is returned and the predicate is not evaluated. - // If the expression is evaluated => There is a match and the expression is always false. - pipeline.terminatingOperation(terminalOperationFactory.createNoneMatch(e -> false)); - }); - return pipeline; - } - - private Pipeline optimizeFindFirst(Pipeline pipeline) { - pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); - return pipeline; - } - - private Pipeline optimizeFindAny(Pipeline pipeline) { - pipeline.ordered(false); - pipeline.intermediateOperations().add(intermediateOperationFactory.createLimit(1)); + // For now, just return whatever we get. + return pipeline; } - - private Optional> getPredicate(final TerminalOperation operation) { - final Object[] arguments = operation.arguments(); - - if (arguments.length != 1) { - return Optional.empty(); - } - - if (arguments[0] instanceof SpeedmentPredicate) { - return Optional.of((SpeedmentPredicate) arguments[0]); - } - - return Optional.empty(); - } } diff --git a/provider/termopoptimizer-standard/src/main/java9/module-info.java b/provider/termopoptimizer-standard/src/main/java9/module-info.java index 169c0eb0f..46961365a 100644 --- a/provider/termopoptimizer-standard/src/main/java9/module-info.java +++ b/provider/termopoptimizer-standard/src/main/java9/module-info.java @@ -12,8 +12,6 @@ */ module jpastreamer.termopoptimizer.standard { requires transitive jpastreamer.termopoptimizer; - requires jpastreamer.rootfactory; - requires jpastreamer.predicate; exports com.speedment.jpastreamer.termopoptimizer.standard; diff --git a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/StandardTerminalOperationOptimizerFactoryTest.java b/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/StandardTerminalOperationOptimizerFactoryTest.java deleted file mode 100644 index 85c1d5cc6..000000000 --- a/provider/termopoptimizer-standard/src/test/java/com/speedment/jpastreamer/termopoptimizer/standard/StandardTerminalOperationOptimizerFactoryTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.speedment.jpastreamer.termopoptimizer.standard; - -import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizerFactory; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -final class StandardTerminalOperationOptimizerFactoryTest { - - @Test - void get() { - final TerminalOperationOptimizerFactory terminalOperationOptimizerFactory = new StandardTerminalOperationOptimizerFactory(); - assertNotNull(terminalOperationOptimizerFactory.get()); - } - -}