1717
1818import java .util .NoSuchElementException ;
1919import java .util .function .Function ;
20+ import java .util .function .Predicate ;
2021
2122import org .jspecify .annotations .NullMarked ;
23+ import org .jspecify .annotations .Nullable ;
24+ import org .mybatis .dynamic .sql .AbstractSingleValueCondition ;
2225import org .mybatis .dynamic .sql .BindableColumn ;
2326import org .mybatis .dynamic .sql .render .RenderingContext ;
2427import org .mybatis .dynamic .sql .util .FragmentAndParameters ;
25- import org .mybatis .dynamic .sql .where .condition .IsLike ;
2628
2729@ 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 ) {
3032 @ Override
3133 public Object value () {
3234 throw new NoSuchElementException ("No value present" ); //$NON-NLS-1$
@@ -44,28 +46,46 @@ public static <T> IsLikeEscape<T> empty() {
4446 return t ;
4547 }
4648
47- private final String escapeString ;
49+ private final @ Nullable Character escapeCharacter ;
4850
49- protected IsLikeEscape (T value , String escapeString ) {
51+ protected IsLikeEscape (T value , @ Nullable Character escapeCharacter ) {
5052 super (value );
51- this .escapeString = escapeString ;
53+ this .escapeCharacter = escapeCharacter ;
54+ }
55+
56+ @ Override
57+ public String operator () {
58+ return "like" ;
5259 }
5360
5461 @ Override
5562 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 ;
5769 }
5870
5971 private String addEscape (String s ) {
60- return s + " ESCAPE '" + escapeString + "'" ;
72+ return s + " ESCAPE '" + escapeCharacter + "'" ;
6173 }
6274
6375 @ 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 );
6686 }
6787
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 );
7090 }
7191}
0 commit comments