1 package org.hibernate.hql.ast.util; 3 4 import org.hibernate.hql.NameGenerator; 5 import org.hibernate.hql.antlr.SqlTokenTypes; 6 import org.hibernate.hql.ast.tree.HqlSqlWalkerNode; 7 8 import antlr.ASTFactory; 9 import antlr.collections.AST; 10 11 16 public final class ColumnHelper { 17 18 21 private ColumnHelper() { 22 } 23 24 public static void generateSingleScalarColumn(HqlSqlWalkerNode node, int i) { 25 ASTFactory factory = node.getASTFactory(); 26 ASTUtil.createSibling( factory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarName( i, 0 ), node ); 27 } 28 29 32 public static void generateScalarColumns(HqlSqlWalkerNode node, String sqlColumns[], int i) { 33 if ( sqlColumns.length == 1 ) { 34 generateSingleScalarColumn( node, i ); 35 } 36 else { 37 ASTFactory factory = node.getASTFactory(); 38 AST n = node; 39 n.setText( sqlColumns[0] ); for ( int j = 0; j < sqlColumns.length; j++ ) { 42 if ( j > 0 ) { 43 n = ASTUtil.createSibling( factory, SqlTokenTypes.SQL_TOKEN, sqlColumns[j], n ); 44 } 45 n = ASTUtil.createSibling( factory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarName( i, j ), n ); 46 } 47 } 48 } 49 } 50 | Popular Tags |