| With the SqlFunctionRegistry we have the possibility to hide the fact that there are different implementations of a function, for example based on the given dialect. This allows us to have the same name for an H2 function, as well as an Oracle function located in a plsql package. This already works inside HQL but fails if used inside @Formula:
@Entity
public class SomeEntity {
@Formula("get_action_status(id)")
private String actionStatus;
}
public class GCOSqlFunctionRegistrar implements HibernateSqlFunctionRegistrar {
@Override
public Map<String, SQLFunction> getSqlFunctions(Dialect dialect) {
Map<String, SQLFunction> sqlFunctions = new HashMap<>();
if (dialect instanceof HSQLDialect) {
registerFunction(sqlFunctions, "get_action_status",
new StandardSQLFunction("get_action_status", StandardBasicTypes.STRING));
} else if (dialect instanceof Oracle12cDialect) {
registerFunction(sqlFunctions, "get_action_status",
new StandardSQLFunction("somepkg.get_action_status", StandardBasicTypes.STRING));
}
return sqlFunctions;
}
}
I believe the Template class already provides the necessary code to identify if the function is registered or not: isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry) |