Skip to content

Commit

Permalink
runtime-join: Cleanup and improved testing
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Feb 20, 2018
1 parent 2839dd3 commit cd9bfe3
Show file tree
Hide file tree
Showing 13 changed files with 845 additions and 569 deletions.
Expand Up @@ -7,7 +7,7 @@


import com.speedment.runtime.field.predicate.Inclusion; import com.speedment.runtime.field.predicate.Inclusion;
import com.speedment.runtime.field.trait.HasComparableOperators; import com.speedment.runtime.field.trait.HasComparableOperators;
import com.speedment.runtime.join.stage.OperatorType; import com.speedment.runtime.join.stage.JoinPredicateType;
import com.speedment.runtime.join.trait.HasOnPredicates; import com.speedment.runtime.join.trait.HasOnPredicates;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import java.util.function.BiFunction; import java.util.function.BiFunction;
Expand All @@ -34,32 +34,32 @@ class BaseAfterJoin<T, R> implements HasOnPredicates<R> {


@Override @Override
public R equal(HasComparableOperators<?, ?> joinedField) { public R equal(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.EQUAL, joinedField); return operation(JoinPredicateType.EQUAL, joinedField);
} }


@Override @Override
public R notEqual(HasComparableOperators<?, ?> joinedField) { public R notEqual(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.NOT_EQUAL, joinedField); return operation(JoinPredicateType.NOT_EQUAL, joinedField);
} }


@Override @Override
public R lessThan(HasComparableOperators<?, ?> joinedField) { public R lessThan(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.LESS_THAN, joinedField); return operation(JoinPredicateType.LESS_THAN, joinedField);
} }


@Override @Override
public R lessOrEqual(HasComparableOperators<?, ?> joinedField) { public R lessOrEqual(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.LESS_OR_EQUAL, joinedField); return operation(JoinPredicateType.LESS_OR_EQUAL, joinedField);
} }


@Override @Override
public R greaterThan(HasComparableOperators<?, ?> joinedField) { public R greaterThan(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.GREATER_THAN, joinedField); return operation(JoinPredicateType.GREATER_THAN, joinedField);
} }


@Override @Override
public R greaterOrEqual(HasComparableOperators<?, ?> joinedField) { public R greaterOrEqual(HasComparableOperators<?, ?> joinedField) {
return operation(OperatorType.GREATER_OR_EQUAL, joinedField); return operation(JoinPredicateType.GREATER_OR_EQUAL, joinedField);
} }


@Override @Override
Expand All @@ -69,7 +69,7 @@ public <ENTITY> R between(HasComparableOperators<ENTITY, ?> joinedFieldFrom, Has


@Override @Override
public <ENTITY> R between(HasComparableOperators<ENTITY, ?> joinedFieldFrom, HasComparableOperators<ENTITY, ?> joinedFieldTo, Inclusion inclusion) { public <ENTITY> R between(HasComparableOperators<ENTITY, ?> joinedFieldFrom, HasComparableOperators<ENTITY, ?> joinedFieldTo, Inclusion inclusion) {
return operation(OperatorType.BETWEEN, joinedFieldFrom, joinedFieldTo, inclusion); return operation(JoinPredicateType.BETWEEN, joinedFieldFrom, joinedFieldTo, inclusion);
} }


@Override @Override
Expand All @@ -79,22 +79,22 @@ public <ENTITY> R notBetween(HasComparableOperators<ENTITY, ?> joinedFieldFrom,


@Override @Override
public <ENTITY> R notBetween(HasComparableOperators<ENTITY, ?> joinedFieldFrom, HasComparableOperators<ENTITY, ?> joinedFieldTo, Inclusion inclusion) { public <ENTITY> R notBetween(HasComparableOperators<ENTITY, ?> joinedFieldFrom, HasComparableOperators<ENTITY, ?> joinedFieldTo, Inclusion inclusion) {
return operation(OperatorType.NOT_BETWEEN, joinedFieldFrom, joinedFieldTo, inclusion); return operation(JoinPredicateType.NOT_BETWEEN, joinedFieldFrom, joinedFieldTo, inclusion);
} }


private R operation(OperatorType operatorType, HasComparableOperators<?, ?> joinedField) { private R operation(JoinPredicateType operatorType, HasComparableOperators<?, ?> joinedField) {
stageBean.setOperatorType(operatorType); stageBean.setJoinPredicateType(operatorType);
stageBean.setForeignFirstField(joinedField); stageBean.setForeignFirstField(joinedField);
return constructor.apply(currentBuilderStage, stageBean); return constructor.apply(currentBuilderStage, stageBean);
} }


private <ENTITY> R operation( private <ENTITY> R operation(
final OperatorType operatorType, final JoinPredicateType operatorType,
final HasComparableOperators<ENTITY, ?> joinedFieldFrom, final HasComparableOperators<ENTITY, ?> joinedFieldFrom,
final HasComparableOperators<ENTITY, ?> joinedFieldTo, final HasComparableOperators<ENTITY, ?> joinedFieldTo,
final Inclusion inclusion final Inclusion inclusion
) { ) {
stageBean.setOperatorType(operatorType); stageBean.setJoinPredicateType(operatorType);
stageBean.setForeignFirstField(joinedFieldFrom); stageBean.setForeignFirstField(joinedFieldFrom);
stageBean.setForeignSecondField(joinedFieldTo); stageBean.setForeignSecondField(joinedFieldTo);
stageBean.setForeignInclusion(inclusion); stageBean.setForeignInclusion(inclusion);
Expand Down
@@ -1,6 +1,6 @@
package com.speedment.runtime.join.internal.component.join; package com.speedment.runtime.join.internal.component.join;


import com.speedment.runtime.join.stage.OperatorType; import com.speedment.runtime.join.stage.JoinPredicateType;
import com.speedment.runtime.join.stage.JoinType; import com.speedment.runtime.join.stage.JoinType;
import com.speedment.runtime.config.identifier.TableIdentifier; import com.speedment.runtime.config.identifier.TableIdentifier;
import com.speedment.runtime.field.predicate.Inclusion; import com.speedment.runtime.field.predicate.Inclusion;
Expand All @@ -23,10 +23,10 @@ public final class StageBean<T> {
private final TableIdentifier<T> identifier; private final TableIdentifier<T> identifier;
private final List<Predicate<? super T>> predicates; private final List<Predicate<? super T>> predicates;
private JoinType joinType; private JoinType joinType;
private HasComparableOperators<? extends T, ?> field; private HasComparableOperators<T, ?> field;
private OperatorType operatorType; private JoinPredicateType joinPredicateType;
private HasComparableOperators<?, ?> firstForeignField; private HasComparableOperators<?, ?> foreignFirstField;
private HasComparableOperators<?, ?> secondForeignField; private HasComparableOperators<?, ?> foreignSecondField;
private Inclusion foreignInclusion; private Inclusion foreignInclusion;


public StageBean(TableIdentifier<T> identifier) { public StageBean(TableIdentifier<T> identifier) {
Expand Down Expand Up @@ -60,32 +60,32 @@ public void setJoinType(JoinType joinType) {
return field; return field;
} }


public void setField(HasComparableOperators<? extends T, ?> field) { public void setField(HasComparableOperators<T, ?> field) {
this.field = requireNonNull(field); this.field = requireNonNull(field);
} }


public OperatorType getOperatorType() { public JoinPredicateType getJoinPredicateType() {
return operatorType; return joinPredicateType;
} }


public void setOperatorType(OperatorType operatorType) { public void setJoinPredicateType(JoinPredicateType joinPredicateType) {
this.operatorType = requireNonNull(operatorType); this.joinPredicateType = requireNonNull(joinPredicateType);
} }


public HasComparableOperators<?, ?> getForeignFirstField() { public HasComparableOperators<?, ?> getForeignFirstField() {
return firstForeignField; return foreignFirstField;
} }


public void setForeignFirstField(HasComparableOperators<?, ?> firstTableField) { public void setForeignFirstField(HasComparableOperators<?, ?> foreignFirstField) {
this.firstForeignField = requireNonNull(firstTableField); this.foreignFirstField = requireNonNull(foreignFirstField);
} }


public HasComparableOperators<?, ?> getForeignSecondField() { public HasComparableOperators<?, ?> getForeignSecondField() {
return secondForeignField; return foreignSecondField;
} }


public void setForeignSecondField(HasComparableOperators<?, ?> secondTableField) { public void setForeignSecondField(HasComparableOperators<?, ?> foreignSecondField) {
this.secondForeignField = requireNonNull(secondTableField); this.foreignSecondField = requireNonNull(foreignSecondField);
} }


public TableIdentifier<T> getIdentifier() { public TableIdentifier<T> getIdentifier() {
Expand Down Expand Up @@ -115,9 +115,9 @@ public Stage<T> asStage() {
predicates, predicates,
joinType, joinType,
field, field,
operatorType, joinPredicateType,
firstForeignField, foreignFirstField,
secondForeignField, foreignSecondField,
foreignInclusion foreignInclusion
); );
} }
Expand Down
Expand Up @@ -10,18 +10,18 @@
import com.speedment.runtime.join.Join; import com.speedment.runtime.join.Join;
import com.speedment.runtime.join.JoinStreamSupplierComponent; import com.speedment.runtime.join.JoinStreamSupplierComponent;
import com.speedment.runtime.join.internal.component.stream.exhaustive.ExhaustiveHasCreateJoin2; import com.speedment.runtime.join.internal.component.stream.exhaustive.ExhaustiveHasCreateJoin2;
import static java.util.Objects.requireNonNull;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import com.speedment.runtime.join.stage.Stage; import com.speedment.runtime.join.stage.Stage;
import com.speedment.runtime.join.trait.HasCreateJoin2; import com.speedment.runtime.join.trait.HasCreateJoin2;
import java.util.List; import java.util.List;
import static java.util.Objects.requireNonNull;
import java.util.function.BiFunction;
import java.util.stream.Stream;


/** /**
* *
* @author Per Minborg * @author Per Minborg
*/ */
public class DebugJoinStreamSupplierComponent implements JoinStreamSupplierComponent { public class ExhaustiveJoinStreamSupplierComponent implements JoinStreamSupplierComponent {


private HasCreateJoin2 join2Creator; private HasCreateJoin2 join2Creator;


Expand All @@ -32,57 +32,57 @@ void init(StreamSupplierComponent streamSupplier) {


@Override @Override
public <T1, T2, T> Join<T> createJoin( public <T1, T2, T> Join<T> createJoin(
final List<Stage<?>> p, final List<Stage<?>> stages,
final BiFunction<T1, T2, T> constructor, final BiFunction<T1, T2, T> constructor,
final TableIdentifier<T1> t1, final TableIdentifier<T1> t1,
final TableIdentifier<T2> t2 final TableIdentifier<T2> t2
) { ) {
return join2Creator.createJoin(p, constructor, t1, t2); return join2Creator.createJoin(stages, constructor, t1, t2);
} }


@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T1, T2, T3, T> Join<T> createJoin( public <T1, T2, T3, T> Join<T> createJoin(
final List<Stage<?>> p, final List<Stage<?>> stages,
final TriFunction<T1, T2, T3, T> constructor, final TriFunction<T1, T2, T3, T> constructor,
final TableIdentifier<T1> t1, final TableIdentifier<T1> t1,
final TableIdentifier<T2> t2, final TableIdentifier<T2> t2,
final TableIdentifier<T3> t3 final TableIdentifier<T3> t3
) { ) {
return (Join<T>) emptyJoin(p, constructor, t1, t2, t3); return (Join<T>) emptyJoin(stages, constructor, t1, t2, t3);
} }


@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T1, T2, T3, T4, T> Join<T> createJoin( public <T1, T2, T3, T4, T> Join<T> createJoin(
final List<Stage<?>> p, final List<Stage<?>> stages,
final QuadFunction<T1, T2, T3, T4, T> constructor, final QuadFunction<T1, T2, T3, T4, T> constructor,
final TableIdentifier<T1> t1, final TableIdentifier<T1> t1,
final TableIdentifier<T2> t2, final TableIdentifier<T2> t2,
final TableIdentifier<T3> t3, final TableIdentifier<T3> t3,
final TableIdentifier<T4> t4 final TableIdentifier<T4> t4
) { ) {
return (Join<T>) emptyJoin(p, constructor, t1, t2, t3, t4); return (Join<T>) emptyJoin(stages, constructor, t1, t2, t3, t4);
} }


@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T1, T2, T3, T4, T5, T> Join<T> createJoin( public <T1, T2, T3, T4, T5, T> Join<T> createJoin(
final List<Stage<?>> p, final List<Stage<?>> stages,
final Function5<T1, T2, T3, T4, T5, T> constructor, final Function5<T1, T2, T3, T4, T5, T> constructor,
final TableIdentifier<T1> t1, final TableIdentifier<T1> t1,
final TableIdentifier<T2> t2, final TableIdentifier<T2> t2,
final TableIdentifier<T3> t3, final TableIdentifier<T3> t3,
final TableIdentifier<T4> t4, final TableIdentifier<T4> t4,
final TableIdentifier<T5> t5 final TableIdentifier<T5> t5
) { ) {
return (Join<T>) emptyJoin(p, constructor, t1, t2, t3, t4, t5); return (Join<T>) emptyJoin(stages, constructor, t1, t2, t3, t4, t5);
} }


@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T1, T2, T3, T4, T5, T6, T> Join<T> createJoin( public <T1, T2, T3, T4, T5, T6, T> Join<T> createJoin(
final List<Stage<?>> p, final List<Stage<?>> stages,
final Function6<T1, T2, T3, T4, T5, T6, T> constructor, final Function6<T1, T2, T3, T4, T5, T6, T> constructor,
final TableIdentifier<T1> t1, final TableIdentifier<T1> t1,
final TableIdentifier<T2> t2, final TableIdentifier<T2> t2,
Expand All @@ -91,7 +91,7 @@ public <T1, T2, T3, T4, T5, T6, T> Join<T> createJoin(
final TableIdentifier<T5> t5, final TableIdentifier<T5> t5,
final TableIdentifier<T6> t6 final TableIdentifier<T6> t6
) { ) {
return (Join<T>) emptyJoin(p, constructor, t1, t2, t3, t4, t5, t6); return (Join<T>) emptyJoin(stages, constructor, t1, t2, t3, t4, t5, t6);
} }


private Join<?> emptyJoin(List<Stage<?>> p, Object unusedConstructor, TableIdentifier<?>... unusedIdentifiers) { private Join<?> emptyJoin(List<Stage<?>> p, Object unusedConstructor, TableIdentifier<?>... unusedIdentifiers) {
Expand All @@ -109,27 +109,6 @@ private void printPipeline(List<Stage<?>> p) {
.forEachOrdered(System.out::println); .forEachOrdered(System.out::println);
} }


private class ExhaustiveJoin2<T1, T2, T> implements Join<T> {

final List<Stage<?>> p;
final BiFunction<T1, T2, T> constructor;
final TableIdentifier<T1> t1;
final TableIdentifier<T2> t2;

ExhaustiveJoin2(List<Stage<?>> p, BiFunction<T1, T2, T> constructor, TableIdentifier<T1> t1, TableIdentifier<T2> t2) {
this.p = requireNonNull(p);
this.constructor = requireNonNull(constructor);
this.t1 = requireNonNull(t1);
this.t2 = requireNonNull(t2);
}

@Override
public Stream<T> stream() {
return Stream.empty();
}

}

private class EmptyJoin<T> implements Join<T> { private class EmptyJoin<T> implements Join<T> {


@Override @Override
Expand All @@ -138,5 +117,4 @@ public Stream<T> stream() {
} }


} }

} }

0 comments on commit cd9bfe3

Please sign in to comment.