예제 #1
0
 /**
  * Turns a path into an AST.
  *
  * @param path The path.
  * @param factory The AST factory to use.
  * @return An HQL AST representing the path.
  */
 public static AST parsePath(String path, ASTFactory factory) {
   String[] identifiers = StringHelper.split(".", path);
   AST lhs = null;
   for (int i = 0; i < identifiers.length; i++) {
     String identifier = identifiers[i];
     AST child = ASTUtil.create(factory, HqlSqlTokenTypes.IDENT, identifier);
     if (i == 0) {
       lhs = child;
     } else {
       lhs = ASTUtil.createBinarySubtree(factory, HqlSqlTokenTypes.DOT, ".", lhs, child);
     }
   }
   if (LOG.isDebugEnabled()) {
     LOG.debugf("parsePath() : %s -> %s", path, ASTUtil.getDebugString(lhs));
   }
   return lhs;
 }
 /** 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 == 1) {
     generateSingleScalarColumn(node, i);
   } else {
     ASTFactory factory = node.getASTFactory();
     AST n = node;
     n.setText(sqlColumns[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 > 0) {
         n = ASTUtil.createSibling(factory, SqlTokenTypes.SQL_TOKEN, sqlColumns[j], n);
       }
       n =
           ASTUtil.createSibling(
               factory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarName(i, j), n);
     }
   }
 }
 static void generateSingleScalarColumn(HqlSqlWalkerNode node, int i) {
   ASTFactory factory = node.getASTFactory();
   ASTUtil.createSibling(
       factory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarName(i, 0), node);
 }