FileDocCategorySizeDatePackage
PositionSubstringFunction.javaAPI DocHibernate 3.2.51343Fri Apr 29 10:32:30 BST 2005org.hibernate.dialect.function

PositionSubstringFunction

public class PositionSubstringFunction extends Object implements SQLFunction
Emulation of locate() on PostgreSQL
author
Gavin King

Fields Summary
Constructors Summary
Methods Summary
public org.hibernate.type.TypegetReturnType(org.hibernate.type.Type columnType, org.hibernate.engine.Mapping mapping)

		return Hibernate.INTEGER;
	
public booleanhasArguments()

		return true;
	
public booleanhasParenthesesIfNoArguments()

		return true;
	
public java.lang.Stringrender(java.util.List args, org.hibernate.engine.SessionFactoryImplementor factory)

		boolean threeArgs = args.size() > 2;
		Object pattern = args.get(0);
		Object string = args.get(1);
		Object start = threeArgs ? args.get(2) : null;

		StringBuffer buf = new StringBuffer();
		if (threeArgs) buf.append('(");
		buf.append("position(").append( pattern ).append(" in ");
		if (threeArgs) buf.append( "substring(");
		buf.append( string );
		if (threeArgs) buf.append( ", " ).append( start ).append(')");
		buf.append(')");
		if (threeArgs) buf.append('+").append( start ).append("-1)");
		return buf.toString();