休止状態とビット操作

判明したように、Hibernateはhqlリクエストの条件でビット操作を受け入れません。 たとえば、「type&mask <> 0のイベントから」はパーサー例外をスローしますが、ドキュメントにはビット操作もありません。 ただし、絶望しないでください。


public class BitwiseAndFunction extends StandardSQLFunction
implements SQLFunction {

public BitwiseAndFunction( String name) {
super(name);
}

public BitwiseAndFunction( String name, Type type) {
super(name, type);
}

public String render( List args, SessionFactoryImplementor factory)
throws QueryException {

if (args.size() != 2) {
throw new IllegalArgumentException( "the function must be passed 2 arguments" );
}

StringBuffer buffer = new StringBuffer(args. get (0).toString());
buffer.append( " & " ).append(args. get (1));
return buffer.toString();
}
}


* This source code was highlighted with Source Code Highlighter .


ダラは、現在のものを継承して、方言を作成する必要があります。

public class MySQLDialectFixed extends MySQL5Dialect {

public MySQLDialectFixed() {
super();
registerFunction( "bitwise_and" , new BitwiseAndFunction( "bitwise_and" , Hibernate.INTEGER));
}
}


* This source code was highlighted with Source Code Highlighter .


残念ながら、 type & mask <> 0も機能しませんbitwise_and(type, mask) <> 0です。 ただし、SQLクエリは必要に応じて表示されます。

Source: https://habr.com/ru/post/J50260/


All Articles