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

org.onetwo.dbm.query.DbmQueryWrapperImpl Maven / Gradle / Ivy

The newest version!
package org.onetwo.dbm.query;

import java.util.List;
import java.util.Map;

import org.onetwo.common.db.AbstractQueryWrapper;
import org.onetwo.common.db.spi.QueryWrapper;
import org.onetwo.common.utils.LangUtils;
import org.onetwo.dbm.dialet.DBDialect.LockInfo;
import org.springframework.jdbc.core.RowMapper;

public class DbmQueryWrapperImpl extends AbstractQueryWrapper {
	
	private DbmQuery dbmQuery;
	/***
	 * 是否自动生成分页sql片段
	 */
//	private boolean useAutoLimitSqlIfPagination = true;
	
	public DbmQueryWrapperImpl(DbmQuery jfishQuery) {
		super();
		this.dbmQuery = jfishQuery;
	}
	
	public boolean isUseAutoLimitSqlIfPagination() {
		return dbmQuery.isUseAutoLimitSqlIfPagination();
	}

	public void setUseAutoLimitSqlIfPagination(boolean useAutoLimitSqlIfPagination) {
		this.dbmQuery.setUseAutoLimitSqlIfPagination(useAutoLimitSqlIfPagination);
	}

	public QueryWrapper setLockInfo(LockInfo lockInfo){
		this.dbmQuery.setLockInfo(lockInfo);
		return this;
	}
	
	@Override
	public int executeUpdate() {
		return dbmQuery.executeUpdate();
	}

	@Override
	public  List getResultList() {
		// DbmQueryImpl#getResultList
		return dbmQuery.getResultList();
	}

	/***
	 * 查找唯一结果,如果找不到则返回null,找到多个则抛异常 IncorrectResultSizeDataAccessException,详见:DataAccessUtils.requiredSingleResult
	 */
	@Override
	public  T getSingleResult() {
		return dbmQuery.getSingleResult();
	}

	@Override
	public QueryWrapper setFirstResult(int startPosition) {
		dbmQuery.setFirstResult(startPosition);
		return this;
	}

	@Override
	public QueryWrapper setMaxResults(int maxResult) {
		dbmQuery.setMaxResults(maxResult);
		return this;
	}

	@Override
	public QueryWrapper setParameter(int position, Object value) {
		dbmQuery.setParameter(position, value);
		return this;
	}

	@Override
	public QueryWrapper setParameter(String name, Object value) {
		dbmQuery.setParameter(name, value);
		return this;
	}

	@Override
	public QueryWrapper setParameters(Map params) {
		dbmQuery.setParameters(params);
		return this;
	}

	@Override
	public QueryWrapper setParameters(List params) {
		dbmQuery.setParameters(params);
		return this;
	}

	@Override
	public QueryWrapper setParameters(Object[] params) {
		dbmQuery.setParameters(LangUtils.asList(params));
		return this;
	}


	@Override
	public QueryWrapper setLimited(Integer first, Integer size) {
		if (first >= 0) {
			dbmQuery.setFirstResult(first);
		}
		if (size >= 1) {
			dbmQuery.setMaxResults(size);
		}
		return this;
	}

	@Override
	public  T getRawQuery(Class clazz) {
		return clazz.cast(dbmQuery);
	}

	public DbmQuery getJfishQuery() {
		return dbmQuery;
	}

	@Override
	public void setRowMapper(RowMapper rowMapper) {
		this.dbmQuery.setRowMapper(rowMapper);
	}

	@Override
	public  T unwarp(Class clazz) {
		return clazz.cast(dbmQuery);
	}

	@Override
	public Map getParameters() {
		return dbmQuery.getParameters();
	}

	public String toString() {
		return this.dbmQuery.toString();
	}

}