@Override public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() ) + " as y" + position + '_'; }
return resolveBothSpaceTrimFunction().render( argumentType, args, factory ); return resolveBothSpaceTrimFromFunction().render( argumentType, args, factory ); return resolveBothSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveLeadingSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveTrailingSpaceTrimFunction().render( argumentType, argsToUse, factory ); return resolveBothTrimFunction().render( argumentType, argsToUse, factory ); return resolveLeadingTrimFunction().render( argumentType, argsToUse, factory ); return resolveTrailingTrimFunction().render( argumentType, argsToUse, factory );
@Override protected void endFunctionTemplate(AST node) { FunctionNode functionNode = (FunctionNode) node; SQLFunction sqlFunction = functionNode.getSQLFunction(); if ( sqlFunction == null ) { super.endFunctionTemplate( node ); } else { final Type functionType = functionNode.getFirstArgumentType(); // this function has a registered SQLFunction -> redirect output and catch the arguments FunctionArgumentsCollectingWriter functionArguments = (FunctionArgumentsCollectingWriter) writer; writer = outputStack.removeFirst(); out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) ); } }
@Override public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { final String functionFragment = getFunction( criteriaQuery ).render( criteriaQuery.getType( criteria, getPropertyName() ), buildFunctionParameterList( criteria, criteriaQuery ), criteriaQuery.getFactory() ); return functionFragment + " as y" + loc + '_'; }
@Override protected void afterMetadataBuilt(Metadata metadata) { Collection children = metadata.getCollectionBinding( Parent.class.getName() + ".children" ); Component childComponents = ( Component ) children.getElement(); Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next(); SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "length" ); if ( lengthFunction != null ) { ArrayList args = new ArrayList(); args.add( "bio" ); f.setFormula( lengthFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
child = child.getNextSibling(); final String text = function.render( null, expressions, context.getSessionFactory() ); return getASTFactory().create( OrderByTemplateTokenTypes.IDENT, text );
@Override protected void afterMetadataBuilt(Metadata metadata) { // Oracle and Postgres do not have year() functions, so we need to // redefine the 'User.person.yob' formula // // consider temporary until we add the capability to define // mapping formulas which can use dialect-registered functions... PersistentClass user = metadata.getEntityBinding( User.class.getName() ); org.hibernate.mapping.Property personProperty = user.getProperty( "person" ); Component component = ( Component ) personProperty.getValue(); Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next(); SQLFunction yearFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "year" ); if ( yearFunction == null ) { // the dialect not know to support a year() function, so rely on the // ANSI SQL extract function f.setFormula( "extract( year from dob )"); } else { List args = new ArrayList(); args.add( "dob" ); f.setFormula( yearFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
@Test public void testNativeQueryWithFormulaAttribute() { SQLFunction dateFunction = getDialect().getFunctions().get( "current_date" ); String dateFunctionRendered = dateFunction.render( null, java.util.Collections.EMPTY_LIST, sessionFactory() ); String sql = String.format( "select t.TABLE_NAME as {t.tableName}, %s as {t.daysOld} from ALL_TABLES t where t.TABLE_NAME = 'AUDIT_ACTIONS' ", dateFunctionRendered ); String sql2 = String.format( "select TABLE_NAME as t_name, %s as t_time from ALL_TABLES where TABLE_NAME = 'AUDIT_ACTIONS' ", dateFunctionRendered ); Session s = openSession(); s.beginTransaction(); s.createSQLQuery( sql ).addEntity( "t", AllTables.class ).list(); s.createSQLQuery( sql2 ).setResultSetMapping( "all" ).list(); SQLQuery q = s.createSQLQuery( sql2 ); q.addRoot( "t", AllTables.class ).addProperty( "tableName", "t_name" ).addProperty( "daysOld", "t_time" ); q.list(); s.getTransaction().commit(); s.close(); }
protected void endFunctionTemplate(AST m) { MethodNode methodNode = ( MethodNode ) m; SQLFunction template = methodNode.getSQLFunction(); if ( template == null ) { super.endFunctionTemplate( m ); } else { // this function has a template -> restore output, apply the template and write the result out FunctionArguments functionArguments = ( FunctionArguments ) writer; // TODO: Downcast to avoid using an interface? Yuck. writer = ( SqlWriter ) outputStack.removeFirst(); out( template.render( functionArguments.getArgs(), sessionFactory ) ); } }
.append(function.render(functionArgs, criteriaQuery.getFactory())) .append(" as y").append(loc).append('_') .toString();
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { Dialect dialect = criteriaQuery.getFactory().getDialect(); SQLFunction function = (SQLFunction) dialect.getFunctions().get(this.aggregate); //TODO: throw an exception if function is not registered //create function argument array List functionArgs = new ArrayList(1); functionArgs.add(criteriaQuery.getColumn(criteria, propertyName)); return new StringBuffer() .append(function.render(functionArgs, criteriaQuery.getFactory())) .append(" as y").append(loc).append('_') .toString(); }
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() ) + " as y" + position + '_'; }
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() ) + " as y" + position + '_'; }
private class InverseLikeExpression extends SimpleExpression{ private static final String CONST_HQL_FUNCTION_NAME_CONCAT = "concat"; private static final String CONST_LIKE = " like "; private static final String CONST_LIKE_SUFFIX = "'%'"; private final String propertyName; protected InverseLikeExpression(String pPropertyName, Object pValue) { super(pPropertyName, pValue, CONST_LIKE); propertyName = pPropertyName; } @Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); Dialect dialect = criteriaQuery.getFactory().getDialect(); SQLFunction concatFunction = (SQLFunction) dialect.getFunctions().get(CONST_HQL_FUNCTION_NAME_CONCAT); StringBuffer fragment = new StringBuffer(); if (columns.length>1) fragment.append('('); for ( int i=0; i<columns.length; i++ ) { String fieldName = concatFunction.render(Arrays.asList(new Object[] {columns[i], CONST_LIKE_SUFFIX}), criteriaQuery.getFactory()); fragment.append("?").append( getOp() ).append(fieldName); if ( i<columns.length-1 ) fragment.append(" and "); } if (columns.length>1) fragment.append(')'); return fragment.toString(); } }
@Override public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { String result = getFunction(criteriaQuery).render(StringType.INSTANCE, propertiesToColumns(criteria, criteriaQuery), criteriaQuery.getFactory()); return result + " as y" + loc + '_'; }
protected void endFunctionTemplate(AST m) { MethodNode methodNode = ( MethodNode ) m; SQLFunction template = methodNode.getSQLFunction(); if ( template == null ) { super.endFunctionTemplate( m ); } else { // this function has a template -> restore output, apply the template and write the result out FunctionArguments functionArguments = ( FunctionArguments ) writer; // TODO: Downcast to avoid using an interface? Yuck. writer = ( SqlWriter ) outputStack.removeFirst(); out( template.render( functionArguments.getArgs(), sessionFactory ) ); } }
@Override protected void endFunctionTemplate(AST node) { FunctionNode functionNode = ( FunctionNode ) node; SQLFunction sqlFunction = functionNode.getSQLFunction(); if ( sqlFunction == null ) { super.endFunctionTemplate( node ); } else { final Type functionType = functionNode.getFirstArgumentType(); // this function has a registered SQLFunction -> redirect output and catch the arguments FunctionArguments functionArguments = ( FunctionArguments ) writer; writer = outputStack.removeFirst(); out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) ); } }
@Override protected void endFunctionTemplate(AST node) { FunctionNode functionNode = ( FunctionNode ) node; SQLFunction sqlFunction = functionNode.getSQLFunction(); if ( sqlFunction == null ) { super.endFunctionTemplate( node ); } else { final Type functionType = functionNode.getFirstArgumentType(); // this function has a registered SQLFunction -> redirect output and catch the arguments FunctionArguments functionArguments = ( FunctionArguments ) writer; writer = outputStack.removeFirst(); out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) ); } }
/** * {@inheritDoc} */ public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { final String functionFragment = getFunction( criteriaQuery ).render( criteriaQuery.getType( criteria, getPropertyName() ), buildFunctionParameterList( criteria, criteriaQuery ), criteriaQuery.getFactory() ); return functionFragment + " as y" + loc + '_'; }
/** * {@inheritDoc} */ public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { final String functionFragment = getFunction( criteriaQuery ).render( criteriaQuery.getType( criteria, getPropertyName() ), buildFunctionParameterList( criteria, criteriaQuery ), criteriaQuery.getFactory() ); return functionFragment + " as y" + loc + '_'; }