17
17
18
18
import java .util .NoSuchElementException ;
19
19
import java .util .function .Function ;
20
+ import java .util .function .Predicate ;
20
21
21
22
import org .jspecify .annotations .NullMarked ;
23
+ import org .jspecify .annotations .Nullable ;
24
+ import org .mybatis .dynamic .sql .AbstractSingleValueCondition ;
22
25
import org .mybatis .dynamic .sql .BindableColumn ;
23
26
import org .mybatis .dynamic .sql .render .RenderingContext ;
24
27
import org .mybatis .dynamic .sql .util .FragmentAndParameters ;
25
- import org .mybatis .dynamic .sql .where .condition .IsLike ;
26
28
27
29
@ NullMarked
28
- public class IsLikeEscape <T > extends IsLike <T > {
29
- private static final IsLikeEscape <?> EMPTY = new IsLikeEscape <Object >(-1 , "" ) {
30
+ public class IsLikeEscape <T > extends AbstractSingleValueCondition <T > {
31
+ private static final IsLikeEscape <?> EMPTY = new IsLikeEscape <Object >(-1 , null ) {
30
32
@ Override
31
33
public Object value () {
32
34
throw new NoSuchElementException ("No value present" ); //$NON-NLS-1$
@@ -44,28 +46,46 @@ public static <T> IsLikeEscape<T> empty() {
44
46
return t ;
45
47
}
46
48
47
- private final String escapeString ;
49
+ private final @ Nullable Character escapeCharacter ;
48
50
49
- protected IsLikeEscape (T value , String escapeString ) {
51
+ protected IsLikeEscape (T value , @ Nullable Character escapeCharacter ) {
50
52
super (value );
51
- this .escapeString = escapeString ;
53
+ this .escapeCharacter = escapeCharacter ;
54
+ }
55
+
56
+ @ Override
57
+ public String operator () {
58
+ return "like" ;
52
59
}
53
60
54
61
@ Override
55
62
public FragmentAndParameters renderCondition (RenderingContext renderingContext , BindableColumn <T > leftColumn ) {
56
- return super .renderCondition (renderingContext , leftColumn ).mapFragment (this ::addEscape );
63
+ var fragment = super .renderCondition (renderingContext , leftColumn );
64
+ if (escapeCharacter != null ) {
65
+ fragment = fragment .mapFragment (this ::addEscape );
66
+ }
67
+
68
+ return fragment ;
57
69
}
58
70
59
71
private String addEscape (String s ) {
60
- return s + " ESCAPE '" + escapeString + "'" ;
72
+ return s + " ESCAPE '" + escapeCharacter + "'" ;
61
73
}
62
74
63
75
@ Override
64
- public <R > IsLike <R > map (Function <? super T , ? extends R > mapper ) {
65
- return mapSupport (mapper , v -> new IsLikeEscape <>(v , escapeString ), IsLikeEscape ::empty );
76
+ public IsLikeEscape <T > filter (Predicate <? super T > predicate ) {
77
+ return filterSupport (predicate , IsLikeEscape ::empty , this );
78
+ }
79
+
80
+ public <R > IsLikeEscape <R > map (Function <? super T , ? extends R > mapper ) {
81
+ return mapSupport (mapper , v -> new IsLikeEscape <>(v , escapeCharacter ), IsLikeEscape ::empty );
82
+ }
83
+
84
+ public static <T > IsLikeEscape <T > isLike (T value ) {
85
+ return new IsLikeEscape <>(value , null );
66
86
}
67
87
68
- public static <T > IsLikeEscape <T > isLike (T value , String escapeString ) {
69
- return new IsLikeEscape <>(value , escapeString );
88
+ public static <T > IsLikeEscape <T > isLike (T value , Character escapeCharacter ) {
89
+ return new IsLikeEscape <>(value , escapeCharacter );
70
90
}
71
91
}
0 commit comments