Open Source Repository

Home /hibernate/hibernate-3.2.6.ga | Repository Home



org/hibernate/hql/ast/util/ColumnHelper.java
// $Id: ColumnHelper.java 7460 2005-07-12 20:27:29Z steveebersole $
package org.hibernate.hql.ast.util;

import org.hibernate.hql.NameGenerator;
import org.hibernate.hql.antlr.SqlTokenTypes;
import org.hibernate.hql.ast.tree.HqlSqlWalkerNode;

import antlr.ASTFactory;
import antlr.collections.AST;

/**
 * Provides utility methods for dealing with arrays of SQL column names.
 *
 @author josh Jan 3, 2005 9:08:47 AM
 */
public final class ColumnHelper {

  /**
   @deprecated (tell clover to filter this out)
   */
  private ColumnHelper() {
  }

  public static void generateSingleScalarColumn(HqlSqlWalkerNode node, int i) {
    ASTFactory factory = node.getASTFactory();
    ASTUtil.createSiblingfactory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarNamei, ), node );
  }

  /**
   * Generates the scalar column AST nodes for a given array of SQL columns
   */
  public static void generateScalarColumns(HqlSqlWalkerNode node, String sqlColumns[]int i) {
    if sqlColumns.length == ) {
      generateSingleScalarColumnnode, i );
    }
    else {
      ASTFactory factory = node.getASTFactory();
      AST n = node;
      n.setTextsqlColumns[0] );  // Use the DOT node to emit the first column name.
      // Create the column names, folled by the column aliases.
      for int j = 0; j < sqlColumns.length; j++ ) {
        if j > ) {
          n = ASTUtil.createSiblingfactory, SqlTokenTypes.SQL_TOKEN, sqlColumns[j], n );
        }
        n = ASTUtil.createSiblingfactory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarNamei, j ), n );
      }
    }
  }
}