Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
weilong.hu
committed
Dec 8, 2020
1 parent
8b0b801
commit 9a1506c
Showing
14 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ebatis-core/src/main/java/io/manbang/ebatis/core/builder/NestedQueryBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.manbang.ebatis.core.builder; | ||
|
||
import io.manbang.ebatis.core.annotation.Nested; | ||
import io.manbang.ebatis.core.exception.AttributeNotFoundException; | ||
import io.manbang.ebatis.core.meta.ConditionMeta; | ||
import io.manbang.ebatis.core.provider.PathProvider; | ||
import org.apache.lucene.search.join.ScoreMode; | ||
import org.elasticsearch.index.query.NestedQueryBuilder; | ||
import org.elasticsearch.index.query.QueryBuilders; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author weilong.hu | ||
* @since 2020/12/4 11:27 | ||
*/ | ||
class NestedQueryBuilderFactory extends AbstractQueryBuilderFactory<NestedQueryBuilder, Nested> { | ||
public static final NestedQueryBuilderFactory INSTANCE = new NestedQueryBuilderFactory(); | ||
|
||
@Override | ||
protected NestedQueryBuilder doCreate(ConditionMeta conditionMeta, Object condition) { | ||
String path = null; | ||
ScoreMode scoreMod = null; | ||
if (condition instanceof PathProvider) { | ||
PathProvider provider = (PathProvider) condition; | ||
path = provider.getPath(); | ||
scoreMod = provider.getScoreMode(); | ||
} | ||
final Nested nested = | ||
Optional.ofNullable(conditionMeta).flatMap(c -> c.findAttributeAnnotation(Nested.class)).orElse(null); | ||
if (Objects.nonNull(nested)) { | ||
path = nested.path(); | ||
scoreMod = nested.scoreMode(); | ||
} | ||
if (Objects.isNull(path)) { | ||
throw new AttributeNotFoundException("条件必须实现 PathProvider或在注解上表明nest"); | ||
} | ||
return QueryBuilders.nestedQuery(path, AutoQueryBuilderFactory.INSTANCE.create(conditionMeta, condition), scoreMod); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
ebatis-core/src/main/java/io/manbang/ebatis/core/provider/PathProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.manbang.ebatis.core.provider; | ||
|
||
import org.apache.lucene.search.join.ScoreMode; | ||
|
||
/** | ||
* @author weilong.hu | ||
* @since 2020/12/4 11:47 | ||
*/ | ||
@FunctionalInterface | ||
public interface PathProvider extends Provider { | ||
/** | ||
* nested path | ||
* | ||
* @return nested path | ||
*/ | ||
String getPath(); | ||
|
||
/** | ||
* ScoreMode | ||
* | ||
* @return ScoreMode | ||
*/ | ||
default ScoreMode getScoreMode() { | ||
return ScoreMode.None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters