Compare commits

..

No commits in common. "9160b13c9469b7cd7689b60202c40e90a45bc756" and "f11d7c9cadb45d4a2b561d9f4e61c1a7288fbf52" have entirely different histories.

4 changed files with 28 additions and 103 deletions

View File

@ -4,7 +4,7 @@
<groupId>dev.struchkov.haiti.filter</groupId>
<artifactId>haiti-filter-jooq</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.3.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Haiti Filter JOOQ</name>

View File

@ -31,9 +31,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException.filterJooqException;
import static java.util.stream.Collectors.toList;
@ -209,34 +207,24 @@ public class CriteriaJooqFilter {
if (!joinTables.isEmpty()) {
for (JoinTable joinTable : joinTables) {
final String tableName = joinTable.getTableName();
String fieldBase = joinTable.getFieldBase();
String fieldReference = joinTable.getFieldReference();
Table<Record> dlsJoinTableName = DSL.table(tableName);
if (joinTable.getAlias() != null) {
dlsJoinTableName = dlsJoinTableName.as(joinTable.getAlias());
fieldReference = joinTable.getAlias() + "." + fieldReference;
} else {
fieldReference = tableName + "." + fieldReference;
}
final Set<Condition> joinConditions = joinTable.getFieldReferences().stream()
.map(reference -> {
String fieldBase = reference.getBaseField();
String fieldReference = reference.getReferenceField();
if (joinTable.getAlias() != null) {
fieldReference = joinTable.getAlias() + "." + fieldReference;
} else {
fieldReference = tableName + "." + fieldReference;
}
final Field dslFieldBase = field(fieldBase);
final Field dslFieldReference = field(fieldReference);
return dslFieldBase.eq(dslFieldReference);
})
.collect(Collectors.toSet());
final JoinTypeOperation joinType = joinTable.getJoinTypeOperation();
final Condition on = DSL.and(joinConditions);
final Field dslFieldBase = field(fieldBase);
final Field dslFieldReference = field(fieldReference);
final Condition on = dslFieldBase.eq(dslFieldReference);
switch (joinType) {
case LEFT:
from = from.leftJoin(dlsJoinTableName).on(on);

View File

@ -1,31 +0,0 @@
package dev.struchkov.haiti.filter.jooq.join;
import java.util.Set;
public class JoinFieldReference {
private final String baseField;
private final String referenceField;
public JoinFieldReference(String baseField, String referenceField) {
this.baseField = baseField;
this.referenceField = referenceField;
}
public String getBaseField() {
return baseField;
}
public String getReferenceField() {
return referenceField;
}
public static JoinFieldReference of(String baseField, String referenceField) {
return new JoinFieldReference(baseField, referenceField);
}
public static Set<JoinFieldReference> ofSingletonSet(String baseField, String referenceField) {
return Set.of(new JoinFieldReference(baseField, referenceField));
}
}

View File

@ -2,10 +2,6 @@ package dev.struchkov.haiti.filter.jooq.join;
import dev.struchkov.haiti.utils.Inspector;
import java.util.Set;
import static dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException.filterJooqException;
/**
* Контейнер для соединения с таблицами.
*
@ -14,87 +10,59 @@ import static dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException
public class JoinTable {
private final String tableName;
private final Set<JoinFieldReference> fieldReferences;
private final String fieldBase;
private final String fieldReference;
private final JoinTypeOperation joinTypeOperation;
private String alias;
private JoinTable(String tableName, JoinTypeOperation joinTypeOperation, Set<JoinFieldReference> fieldReferences, String alias) {
private JoinTable(String tableName, String fieldBase, String fieldReference, JoinTypeOperation joinTypeOperation, String alias) {
this.tableName = tableName;
this.fieldBase = fieldBase;
this.fieldReference = fieldReference;
this.joinTypeOperation = joinTypeOperation;
this.fieldReferences = fieldReferences;
this.alias = alias;
}
public static JoinTable ofLeft(String tableName, String fieldBase, String fieldReference) {
Inspector.isNotNull(tableName, fieldBase, fieldReference);
return new JoinTable(tableName, JoinTypeOperation.LEFT, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), null);
}
public static JoinTable ofLeft(String tableName, Set<JoinFieldReference> fieldReferences) {
Inspector.isNotNull(tableName, fieldReferences);
Inspector.isNotEmpty(fieldReferences, filterJooqException("fieldReferences is empty: {0}", fieldReferences));
return new JoinTable(tableName, JoinTypeOperation.LEFT, fieldReferences, null);
return new JoinTable(tableName, fieldBase, fieldReference, JoinTypeOperation.LEFT, null);
}
public static JoinTable ofLeft(String tableName, String fieldBase, String fieldReference, String alias) {
Inspector.isNotNull(tableName, fieldBase, fieldReference, alias);
return new JoinTable(tableName, JoinTypeOperation.LEFT, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), alias);
}
public static JoinTable ofLeft(String tableName, Set<JoinFieldReference> fieldReferences, String alias) {
Inspector.isNotNull(tableName, fieldReferences, alias);
Inspector.isNotEmpty(fieldReferences, filterJooqException("fieldReferences is empty: {0}", fieldReferences));
return new JoinTable(tableName, JoinTypeOperation.LEFT, fieldReferences, alias);
return new JoinTable(tableName, fieldBase, fieldReference, JoinTypeOperation.LEFT, alias);
}
public static JoinTable onRight(String tableName, String fieldBase, String fieldReference) {
Inspector.isNotNull(tableName, fieldBase, fieldReference);
return new JoinTable(tableName, JoinTypeOperation.RIGHT, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), null);
}
public static JoinTable onRight(String tableName, Set<JoinFieldReference> fieldReferences) {
Inspector.isNotNull(tableName, fieldReferences);
Inspector.isNotEmpty(fieldReferences, filterJooqException("fieldReferences is empty: {0}", fieldReferences));
return new JoinTable(tableName, JoinTypeOperation.RIGHT, fieldReferences, null);
return new JoinTable(tableName, fieldBase, fieldReference, JoinTypeOperation.RIGHT, null);
}
public static JoinTable onRight(String tableName, String fieldBase, String fieldReference, String alias) {
Inspector.isNotNull(tableName, fieldBase, fieldReference, alias);
return new JoinTable(tableName, JoinTypeOperation.RIGHT, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), alias);
}
public static JoinTable onRight(String tableName, Set<JoinFieldReference> fieldReferences, String alias) {
Inspector.isNotNull(tableName, fieldReferences, alias);
Inspector.isFalse(fieldReferences.isEmpty(), filterJooqException("fieldReferences is empty: {0}", fieldReferences));
return new JoinTable(tableName, JoinTypeOperation.RIGHT, fieldReferences, alias);
return new JoinTable(tableName, fieldBase, fieldReference, JoinTypeOperation.RIGHT, alias);
}
public static JoinTable of(String tableName, String fieldBase, String fieldReference, JoinTypeOperation joinType) {
Inspector.isNotNull(tableName, fieldBase, fieldReference);
return new JoinTable(tableName, joinType, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), null);
}
public static JoinTable of(String tableName, Set<JoinFieldReference> fieldReferences, JoinTypeOperation joinType) {
Inspector.isNotNull(tableName, fieldReferences);
return new JoinTable(tableName, joinType, fieldReferences, null);
return new JoinTable(tableName, fieldBase, fieldReference, joinType, null);
}
public static JoinTable of(String tableName, String fieldBase, String fieldReference, JoinTypeOperation joinType, String alias) {
Inspector.isNotNull(tableName, fieldBase, fieldReference, alias);
return new JoinTable(tableName, joinType, JoinFieldReference.ofSingletonSet(fieldBase, fieldReference), alias);
}
public static JoinTable of(String tableName, Set<JoinFieldReference> fieldReferences, JoinTypeOperation joinType, String alias) {
Inspector.isNotNull(tableName, fieldReferences, alias);
return new JoinTable(tableName, joinType, fieldReferences, alias);
return new JoinTable(tableName, fieldBase, fieldReference, joinType, alias);
}
public String getTableName() {
return tableName;
}
public Set<JoinFieldReference> getFieldReferences() {
return fieldReferences;
public String getFieldBase() {
return fieldBase;
}
public String getFieldReference() {
return fieldReference;
}
public JoinTypeOperation getJoinTypeOperation() {