⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: Select.java,v 1.4.2.1 2003/11/27 15:28:38 oneovthafew Exp $
package net.sf.hibernate.sql;

/**
 * A simple SQL <tt>SELECT</tt> statement
 * @author Gavin King
 */
public class Select {
	
	private String selectClause; 
	private String fromClause;
	private String outerJoinsAfterFrom; 
	private String whereClause;
	private String outerJoinsAfterWhere;
	private String orderByClause;

	/**
	 * Construct an SQL <tt>SELECT</tt> statement from the given clauses
	 */
	public String toStatementString() {
		StringBuffer buf = new StringBuffer(
			selectClause.length() + 
			fromClause.length() + 
			outerJoinsAfterFrom.length() + 
			whereClause.length() + 
			outerJoinsAfterWhere.length() + 
			20
		);
		buf.append("select ").append(selectClause)
			.append(" from ").append(fromClause)
			.append(outerJoinsAfterFrom)
			.append(" where ").append(whereClause)
			.append(outerJoinsAfterWhere);
		if (orderByClause!=null && orderByClause.trim().length() > 0 ) {
			buf.append(" order by ")
			.append(orderByClause);
		}
		return buf.toString();
	} 

	/**
	 * Sets the fromClause.
	 * @param fromClause The fromClause to set
	 */
	public Select setFromClause(String fromClause) {
		this.fromClause = fromClause;
		return this;
	}

	public Select setFromClause(String tableName, String alias) {
		this.fromClause = tableName + ' ' + alias;
		return this;
	}

	/**
	 * Sets the orderByClause.
	 * @param orderByClause The orderByClause to set
	 */
	public Select setOrderByClause(String orderByClause) {
		this.orderByClause = orderByClause;
		return this;
	}

	/**
	 * Sets the outerJoins.
	 * @param outerJoinsAfterFrom The outerJoinsAfterFrom to set
	 * @param outerJoinsAfterWhere The outerJoinsAfterWhere to set
	 */
	public Select setOuterJoins(String outerJoinsAfterFrom, String outerJoinsAfterWhere) {
		this.outerJoinsAfterFrom = outerJoinsAfterFrom;
		this.outerJoinsAfterWhere = outerJoinsAfterWhere;
		return this;
	}


	/**
	 * Sets the selectClause.
	 * @param selectClause The selectClause to set
	 */
	public Select setSelectClause(String selectClause) {
		this.selectClause = selectClause;
		return this;
	}

	/**
	 * Sets the whereClause.
	 * @param whereClause The whereClause to set
	 */
	public Select setWhereClause(String whereClause) {
		this.whereClause = whereClause;
		return this;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -