Author: steve.ebersole(a)jboss.com
Date: 2008-10-01 17:09:20 -0400 (Wed, 01 Oct 2008)
New Revision: 15242
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java
Log:
HHH-3510 : HQL SQLFunction replacement not occuring when HQL text has no parenthesis
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java 2008-10-01
19:42:55 UTC (rev 15241)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java 2008-10-01
21:09:20 UTC (rev 15242)
@@ -38,6 +38,7 @@
import org.hibernate.util.StringHelper;
import java.util.List;
+import java.util.Collections;
/**
* Represents an identifier all by itself, which may be a function name,
@@ -128,6 +129,14 @@
// resolve this...
return;
}
+ else if ( result == UNKNOWN ) {
+ final SQLFunction sqlFunction = getSessionFactoryHelper().findSQLFunction( getText()
);
+ if ( sqlFunction != null ) {
+ setText( sqlFunction.render( Collections.EMPTY_LIST,
getSessionFactoryHelper().getFactory() ) );
+ setDataType( sqlFunction.getReturnType( null,
getSessionFactoryHelper().getFactory() ) );
+ setResolved();
+ }
+ }
}
// if we are still not resolved, we might represent a constant.
@@ -283,26 +292,29 @@
public Type getDataType() {
Type type = super.getDataType();
- if (type != null) return type;
+ if ( type != null ) {
+ return type;
+ }
FromElement fe = getFromElement();
- if (fe != null) return fe.getDataType();
- SQLFunction sf = getWalker().getSessionFactoryHelper().findSQLFunction(getText());
- return sf == null ? null : sf.getReturnType(null, null);
+ if ( fe != null ) {
+ return fe.getDataType();
+ }
+ return null;
}
public void setScalarColumnText(int i) throws SemanticException {
- if (nakedPropertyRef) {
+ if ( nakedPropertyRef ) {
// do *not* over-write the column text, as that has already been
// "rendered" during resolve
- ColumnHelper.generateSingleScalarColumn(this, i);
+ ColumnHelper.generateSingleScalarColumn( this, i );
}
else {
FromElement fe = getFromElement();
- if (fe != null) {
- setText(fe.renderScalarIdentifierSelect(i));
+ if ( fe != null ) {
+ setText( fe.renderScalarIdentifierSelect( i ) );
}
else {
- ColumnHelper.generateSingleScalarColumn(this, i);
+ ColumnHelper.generateSingleScalarColumn( this, i );
}
}
}
@@ -310,19 +322,19 @@
public String getDisplayText() {
StringBuffer buf = new StringBuffer();
- if (getType() == SqlTokenTypes.ALIAS_REF) {
- buf.append("{alias=").append(getOriginalText());
- if (getFromElement() == null) {
- buf.append(", no from element");
+ if ( getType() == SqlTokenTypes.ALIAS_REF ) {
+ buf.append( "{alias=" ).append( getOriginalText() );
+ if ( getFromElement() == null ) {
+ buf.append( ", no from element" );
}
else {
- buf.append(", className=").append(getFromElement().getClassName());
- buf.append(", tableAlias=").append(getFromElement().getTableAlias());
+ buf.append( ", className=" ).append( getFromElement().getClassName() );
+ buf.append( ", tableAlias=" ).append( getFromElement().getTableAlias() );
}
- buf.append("}");
+ buf.append( "}" );
}
else {
- buf.append("{originalText=" + getOriginalText()).append("}");
+ buf.append( "{originalText=" ).append( getOriginalText() ).append(
"}" );
}
return buf.toString();
}