use of org.hibernate.query.sqm.LiteralNumberFormatException in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitBinaryLiteral.
@Override
public Object visitBinaryLiteral(HqlParser.BinaryLiteralContext ctx) {
final TerminalNode firstNode = (TerminalNode) ctx.getChild(0);
if (firstNode.getSymbol().getType() == HqlParser.BINARY_LITERAL) {
return binaryLiteral(firstNode.getText());
} else {
final StringBuilder text = new StringBuilder("x'");
final int size = ctx.getChildCount();
for (int i = 0; i < size; i++) {
final TerminalNode hex = (TerminalNode) ctx.getChild(i);
if (hex.getSymbol().getType() == HqlParser.HEX_LITERAL) {
final String hexText = hex.getText();
if (hexText.length() != 4) {
throw new LiteralNumberFormatException("not a byte: " + hexText);
}
text.append(hexText, 2, hexText.length());
}
}
return binaryLiteral(text.append("'").toString());
}
}
use of org.hibernate.query.sqm.LiteralNumberFormatException in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method hexLiteral.
private SqmLiteral<? extends Number> hexLiteral(String text) {
final String originalText = text;
text = text.substring(2);
try {
final Number value;
final BasicDomainType<? extends Number> type;
if (text.endsWith("l") || text.endsWith("L")) {
text = text.substring(0, text.length() - 1);
value = Long.parseUnsignedLong(text, 16);
type = resolveExpressibleTypeBasic(Long.class);
} else {
value = Integer.parseUnsignedInt(text, 16);
type = resolveExpressibleTypeBasic(Integer.class);
}
// noinspection unchecked
return new SqmLiteral<>(value, (SqmExpressible<Number>) type, creationContext.getNodeBuilder());
} catch (NumberFormatException e) {
throw new LiteralNumberFormatException("Unable to convert sqm literal [" + originalText + "]", e);
}
}
Aggregations