FileDocCategorySizeDatePackage
SelectFragment.javaAPI DocHibernate 3.2.53875Thu Jul 14 18:56:54 BST 2005org.hibernate.sql

SelectFragment

public class SelectFragment extends Object
A fragment of an SQL SELECT clause
author
Gavin King

Fields Summary
private String
suffix
private List
columns
private List
columnAliases
private String
extraSelectList
private String[]
usedAliases
Constructors Summary
public SelectFragment()

	
	  
Methods Summary
public org.hibernate.sql.SelectFragmentaddColumn(java.lang.String columnName)

		addColumn(null, columnName);
		return this;
	
public org.hibernate.sql.SelectFragmentaddColumn(java.lang.String tableAlias, java.lang.String columnName)

		return addColumn(tableAlias, columnName, columnName);
	
public org.hibernate.sql.SelectFragmentaddColumn(java.lang.String tableAlias, java.lang.String columnName, java.lang.String columnAlias)

		columns.add( StringHelper.qualify(tableAlias, columnName) );
		//columns.add(columnName);
		//aliases.add(tableAlias);
		columnAliases.add(columnAlias);
		return this;
	
public org.hibernate.sql.SelectFragmentaddColumns(java.lang.String tableAlias, java.lang.String[] columnNames)

		for (int i=0; i<columnNames.length; i++) addColumn( tableAlias, columnNames[i] );
		return this;
	
public org.hibernate.sql.SelectFragmentaddColumns(java.lang.String tableAlias, java.lang.String[] columnNames, java.lang.String[] columnAliases)

		for (int i=0; i<columnNames.length; i++) {
			if ( columnNames[i]!=null ) addColumn( tableAlias, columnNames[i], columnAliases[i] );
		}
		return this;
	
public org.hibernate.sql.SelectFragmentaddColumns(java.lang.String[] columnNames)

		for (int i=0; i<columnNames.length; i++) addColumn( columnNames[i] );
		return this;
	
public org.hibernate.sql.SelectFragmentaddFormula(java.lang.String tableAlias, java.lang.String formula, java.lang.String formulaAlias)

		columns.add( StringHelper.replace(formula, Template.TEMPLATE, tableAlias) );
		columnAliases.add(formulaAlias);
		return this;
	
public org.hibernate.sql.SelectFragmentaddFormulas(java.lang.String tableAlias, java.lang.String[] formulas, java.lang.String[] formulaAliases)

		for ( int i=0; i<formulas.length; i++ ) {
			if ( formulas[i]!=null ) addFormula( tableAlias, formulas[i], formulaAliases[i] );
		}
		return this;
	
public org.hibernate.sql.SelectFragmentsetExtraSelectList(java.lang.String extraSelectList)

		this.extraSelectList = extraSelectList;
		return this;
	
public org.hibernate.sql.SelectFragmentsetExtraSelectList(CaseFragment caseFragment, java.lang.String fragmentAlias)

		setExtraSelectList( caseFragment.setReturnColumnName(fragmentAlias, suffix).toFragmentString() );
		return this;
	
public org.hibernate.sql.SelectFragmentsetSuffix(java.lang.String suffix)

		this.suffix = suffix;
		return this;
	
public org.hibernate.sql.SelectFragmentsetUsedAliases(java.lang.String[] aliases)

		usedAliases = aliases;
		return this;
	
public java.lang.StringtoFragmentString()

		StringBuffer buf = new StringBuffer( columns.size() * 10 );
		Iterator iter = columns.iterator();
		Iterator columnAliasIter = columnAliases.iterator();
		//HashMap columnsUnique = new HashMap();
		HashSet columnsUnique = new HashSet();
		if (usedAliases!=null) columnsUnique.addAll( Arrays.asList(usedAliases) );
		while ( iter.hasNext() ) {
			String column = (String) iter.next();
			String columnAlias = (String) columnAliasIter.next();
			//TODO: eventually put this back in, once we think all is fixed
			//Object otherAlias = columnsUnique.put(qualifiedColumn, columnAlias);
			/*if ( otherAlias!=null && !columnAlias.equals(otherAlias) ) {
				throw new AssertionFailure("bug in Hibernate SQL alias generation");
			}*/
			if ( columnsUnique.add(columnAlias) ) {
				buf.append(", ")
					.append(column)
					.append(" as ");
				if (suffix==null) {
					buf.append(columnAlias);
				}
				else {
					buf.append( new Alias(suffix).toAliasString(columnAlias) );
				}
			}
		}
		if (extraSelectList!=null) {
			buf.append(", ")
				.append(extraSelectList);
		}
		return buf.toString();