Last active
May 23, 2024 12:44
-
-
Save rayalex/a450de5674d2ff743a63892c9e93a765 to your computer and use it in GitHub Desktop.
Array Ops support for Postgres ad Hibernate 5
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
public class PostgreSQLIndexedSearchFunction implements SQLFunction { | |
@Override | |
public boolean hasArguments() { | |
return true; | |
} | |
@Override | |
public boolean hasParenthesesIfNoArguments() { | |
return true; | |
} | |
@Override | |
public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException { | |
return new BooleanType(); | |
} | |
@Override | |
public String render( | |
Type firstArgumentType, | |
List arguments, | |
SessionFactoryImplementor factory | |
) throws QueryException { | |
if (arguments.size() != 2) { | |
throw new IllegalArgumentException("Function must be passed 2 arguments"); | |
} | |
var array = (String) arguments.get(0); | |
var search = (String) arguments.get(1); | |
return String.format("%s @> ARRAY[%s]::varchar[]", array, search); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment