Open Source Repository

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



org/hibernate/dialect/function/ConditionalParenthesisFunction.java
//$Id: ConditionalParenthesisFunction.java,v 1.4 2005/04/26 18:08:01 oneovthafew Exp $
package org.hibernate.dialect.function;

import java.util.List;

import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.Type;

/**
 * Essentially the same as {@link org.hibernate.dialect.function.StandardSQLFunction},
 * except that here the parentheses are not included when no arguments are given.
 *
 @author Jonathan Levinson
 */
public class ConditionalParenthesisFunction extends StandardSQLFunction {

  public ConditionalParenthesisFunction(String name) {
    supername );
  }

  public ConditionalParenthesisFunction(String name, Type type) {
    supername, type );
  }

  public boolean hasParenthesesIfNoArguments() {
    return false;
  }

  public String render(List args, SessionFactoryImplementor factory) {
    final boolean hasArgs = !args.isEmpty();
    StringBuffer buf = new StringBuffer();
    buf.appendgetName() );
    if hasArgs ) {
      buf.append"(" );
      for int i = 0; i < args.size(); i++ ) {
        buf.appendargs.get) );
        if i < args.size() ) {
          buf.append", " );
        }
      }
      buf.append")" );
    }
    return buf.toString();
  }
}