From: Daniele G. (JIRA) <no...@at...> - 2006-05-27 11:57:17
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-160?page=comments#action_23171 ] Daniele Gariboldi commented on HHH-160: --------------------------------------- I vote for one standard naming convention for bitwise functions in Hibernate distribution standard dialects. Here is how I implement bitwise function (and aggregate bitwise functions found in group by clause) for PostgreSQL 8.1, hibernate 3.1.2. Thank you for your work, hibernate community. import java.util.List; import org.hibernate.Hibernate; import org.hibernate.QueryException; import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.engine.Mapping; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.type.Type; /** * Implements bitwise varargs (max 4) functions for PostgreSQL. Overload bit_and * and bit_or functions using 1 arg as aggreagate bitwise function. */ public class PostgreSQLDialect extends org.hibernate.dialect.PostgreSQLDialect { public PostgreSQLDialect() { super(); registerFunction("bit_and", new SQLFunctionTemplates(Hibernate.INTEGER, "bit_and(?1)", "?1 & ?2 & ?3 & ?4")); registerFunction("bit_not", new SQLFunctionTemplate(Hibernate.INTEGER, "~?1")); registerFunction("bit_or", new SQLFunctionTemplates(Hibernate.INTEGER, "bit_or(?1)", "?1 & ?2 & ?3 & ?4")); } public static class SQLFunctionTemplates implements SQLFunction { private SQLFunctionTemplate template1arg; private SQLFunctionTemplate templateNarg; public SQLFunctionTemplates(Type type, String template1arg, String templateNarg) { this.template1arg = new SQLFunctionTemplate(type, template1arg); this.templateNarg = new SQLFunctionTemplate(type, templateNarg); } private SQLFunctionTemplate getSQLFunctionTemplate(List args) { if (args.size() == 1) return template1arg; return templateNarg; } public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { return template1arg.getReturnType(columnType, mapping); } public boolean hasArguments() { return true; } public boolean hasParenthesesIfNoArguments() { return true; } public String render(List args, SessionFactoryImplementor factory) throws QueryException { return getSQLFunctionTemplate(args).render(args, factory); } } } > New query parser does not allow bitwise operations > -------------------------------------------------- > > Key: HHH-160 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-160 > Project: Hibernate3 > Type: Improvement > Components: core > Versions: 3.0 rc 1 > Environment: Hibernate 3.0 rc1, MySQL > Reporter: Markus Jessenitschnig > Priority: Minor > > > The new query parser does not allow bitwise operations like bitwise-and and bitwise-or. > Example: > SELECT FIRSTNAME, SURNAME FROM EMPLOYEE WHERE (STATUS & 1) > 0 > The Exception is: > org.hibernate.QueryException: unexpected char: '&' -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |