KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > ast > util > ColumnHelper


1 // $Id: ColumnHelper.java,v 1.1 2005/07/12 20:27:22 steveebersole Exp $
2
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 /**
12  * Provides utility methods for dealing with arrays of SQL column names.
13  *
14  * @author josh Jan 3, 2005 9:08:47 AM
15  */

16 public final class ColumnHelper {
17
18     /**
19      * @deprecated (tell clover to filter this out)
20      */

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     /**
30      * Generates the scalar column AST nodes for a given array of SQL columns
31      */

32     public static void generateScalarColumns(HqlSqlWalkerNode node, String JavaDoc 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] ); // Use the DOT node to emit the first column name.
40
// Create the column names, folled by the column aliases.
41
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