org.hibernate.sql.SimpleSelect Maven / Gradle / Ivy
//$Id: SimpleSelect.java 7627 2005-07-24 06:53:06Z oneovthafew $
package org.hibernate.sql;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.dialect.Dialect;
/**
* An SQL SELECT statement with no table joins
*
* @author Gavin King
*/
public class SimpleSelect {
public SimpleSelect(Dialect dialect) {
this.dialect = dialect;
}
//private static final Alias DEFAULT_ALIAS = new Alias(10, null);
private String tableName;
private String orderBy;
private Dialect dialect;
private LockMode lockMode = LockMode.READ;
private String comment;
private List columns = new ArrayList();
private Map aliases = new HashMap();
private List whereTokens = new ArrayList();
public SimpleSelect addColumns(String[] columnNames, String[] columnAliases) {
for ( int i=0; i0 ) {
whereTokens.add("and");
}
}
public SimpleSelect addCondition(String lhs, String op, String rhs) {
and();
whereTokens.add( lhs + ' ' + op + ' ' + rhs );
return this;
}
public SimpleSelect addCondition(String lhs, String condition) {
and();
whereTokens.add( lhs + ' ' + condition );
return this;
}
public SimpleSelect addCondition(String[] lhs, String op, String[] rhs) {
for ( int i=0; i 0 ) {
buf.append(" where ")
.append( toWhereClause() );
}
if (orderBy!=null) buf.append(orderBy);
if (lockMode!=null) {
buf.append( dialect.getForUpdateString(lockMode) );
}
return dialect.transformSelectString( buf.toString() );
}
public String toWhereClause() {
StringBuffer buf = new StringBuffer( whereTokens.size() * 5 );
Iterator iter = whereTokens.iterator();
while ( iter.hasNext() ) {
buf.append( iter.next() );
if ( iter.hasNext() ) buf.append(' ');
}
return buf.toString();
}
public SimpleSelect setOrderBy(String orderBy) {
this.orderBy = orderBy;
return this;
}
public SimpleSelect setComment(String comment) {
this.comment = comment;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy