org.hibernate.dialect.function
Class AvgWithArgumentCastFunction
java.lang.Object
org.hibernate.dialect.function.AvgFunction
org.hibernate.dialect.function.AvgWithArgumentCastFunction
- All Implemented Interfaces:
- SQLFunction
public class AvgWithArgumentCastFunction
- extends AvgFunction
Some databases strictly return the type of the of the aggregation value for AVG which is
problematic in the case of averaging integers because the decimals will be dropped. The usual workaround
is to cast the integer argument as some form of double/decimal.
A downside to this approach is that we always wrap the avg() argument in a cast even though we may not need or want
to. A more full-featured solution would be defining SQLFunction
such that we render based on the first
argument; essentially have SQLFunction
describe the basic metadata about the function and merge the
SQLFunction.getReturnType(org.hibernate.type.Type, org.hibernate.engine.Mapping)
and SQLFunction.render(java.util.List, org.hibernate.engine.SessionFactoryImplementor)
methods into a
- Author:
- Steve Ebersole
AvgWithArgumentCastFunction
public AvgWithArgumentCastFunction(String castType)
render
public String render(List args,
SessionFactoryImplementor factory)
throws QueryException
- Description copied from interface:
SQLFunction
- Render the function call as SQL fragment.
- Specified by:
render
in interface SQLFunction
- Overrides:
render
in class AvgFunction
- Parameters:
args
- The function argumentsfactory
- The SessionFactory
- Returns:
- The rendered function call
- Throws:
QueryException
- Indicates a problem rendering the
function call.
Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.