All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yqjr.framework.component.dialect.db.OracleDialect Maven / Gradle / Ivy

/**
 * Copyright © YQJR All rights reserved.
 */
package com.yqjr.framework.component.dialect.db;

/**
 * Oracle的方言实现
 * 
 * @author poplar.yfyang
 * @version 1.0 2010-10-10 下午12:31
 * @since JDK 1.5
 */
public class OracleDialect extends AbstractDialect {
	@Override
	public boolean supportsLimit() {
		return true;
	}

	@Override
	public String getLimitString(String sql, int offset, int limit) {
		return getLimitString(sql, offset, Integer.toString(offset), Integer.toString(limit));
	}

	/**
	 * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换.
	 * 
	 * 
	 * 如mysql
	 * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
	 * select * from user limit :offset,:limit
	 * 
* * @param sql * 实际SQL语句 * @param offset * 分页开始纪录条数 * @param offsetPlaceholder * 分页开始纪录条数-占位符号 * @param limitPlaceholder * 分页纪录条数占位符号 * @return 包含占位符的分页sql */ public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) { sql = sql.trim(); boolean isForUpdate = false; if (sql.toLowerCase().endsWith(" for update")) { sql = sql.substring(0, sql.length() - 11); isForUpdate = true; } StringBuilder pagingSelect = new StringBuilder(sql.length() + 100); if (offset > 0) { pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); } else { pagingSelect.append("select * from ( "); } pagingSelect.append(sql); if (offset > 0) { String endString = offsetPlaceholder + "+" + limitPlaceholder; pagingSelect.append(" ) row_ where rownum <= " + endString + ") where rownum_ > ") .append(offsetPlaceholder); } else { pagingSelect.append(" ) where rownum <= " + limitPlaceholder); } if (isForUpdate) { pagingSelect.append(" for update"); } return pagingSelect.toString(); } /* * (non-Javadoc) * * @see com.yqjr.framework.component.dialect.Dialect#getDateFormat() */ @Override public DBDateInfo getDateFormat() { DBDateInfo dateInfo = new DBDateInfo("yyyy", "mm", "dd", "hh24", "mi", "ss"); dateInfo.setToCharMethod("TO_CHAR"); dateInfo.setToDateMethod("TO_DATE"); dateInfo.setSysDateMethod("SYSDATE"); return dateInfo; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy