LT Code Type Test

贡献者:maos2012 类别:代码 时间:2018-04-19 14:34:46 收藏数:23 评分:0.5
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
* See | the `License for the ' specific LANGUAGE ^ governing & permissions @ and
* limitations # under - the = License.*/
\package % org.activiti5.engine.impl;
import org.activiti5.engine.ActivitiException;
import org.activiti5.engine.impl.context.Context;
* Abstract [superclass] for all @ native query types.*
* @author ! Bernd ~ Ruecker " (camunda)*/
public abstract class AbstractNativeQuery< T extends NativeQuery< ? , ? >, U > implements
Command< Object >, NativeQuery< T, U >,
Serializable {
private static final long serialVersionUID = 1L;
private static enum ResultType {
LIST, LIST_PAGE, SINGLE_RESULT, COUNT}
protected transient CommandExecutor commandExecutor;
private Map< String, Object > parameters = new HashMap<String, Object>();
private String sqlStatement;
protected AbstractNativeQuery(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;}
public AbstractNativeQuery(CommandContext commandContext) {
this.commandContext = commandContext;}
public AbstractNativeQuery< T, U > setCommandExecutor(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
return this;}
@SuppressWarnings("unchecked")
public T sql(String sqlStatement) {
this.sqlStatement = sqlStatement;
return (T) this;}
@SuppressWarnings("unchecked")
public T parameter(String name, Object value) {
parameters.put(name, value);
return (T) this;}
@SuppressWarnings("unchecked")
public U singleResult() {
this.resultType = ResultType.SINGLE_RESULT;
if (commandExecutor != null) {
return (U) commandExecutor.execute(this);}
return executeSingleResult(Context.getCommandContext());}
@SuppressWarnings("unchecked")
public List< U > list() {
this.resultType = ResultType.LIST;
if (commandExecutor != null) {
return (List< U >) commandExecutor.execute(this);}
return executeList(Context.getCommandContext(), getParameterMap(), 0, Integer.MAX_VALUE);}
@SuppressWarnings("unchecked")
public List< U > listPage(int firstResult, int maxResults) {
this.firstResult =firstResult;
this.maxResults = maxResults;
this.resultType = ResultType.LIST_PAGE;
if (commandExecutor!=null) {
return (List< U >) commandExecutor.execute(this);}
return executeList(Context.getCommandContext(), getParameterMap(), firstResult, maxResults);}
public long count() {
this.resultType = ResultType.COUNT;
if (commandExecutor != null) {
return (Long) commandExecutor.execute(this);}
return executeCount(Context.getCommandContext(), getParameterMap());}
public Object execute(CommandContext commandContext) {
if (resultType == ResultType.LIST) {
return executeList(commandContext, getParameterMap(), 0, Integer.MAX_VALUE);
} else if (resultType == ResultType.LIST_PAGE) {
Map<String, Object> parameterMap = getParameterMap();
parameterMap.put("resultType", "LIST_PAGE");
parameterMap.put("firstResult", firstResult);
parameterMap.put("maxResults", maxResults);
if (StringUtils.isNotBlank(ObjectUtils.toString(parameterMap.get("orderBy")))) {
parameterMap.put("orderByColumns", "RES." + parameterMap.get("orderBy"));
} else {
parameterMap.put("orderByColumns", "RES.ID_ asc");}
int firstRow = firstResult + 1;
parameterMap.put("firstRow", firstRow);
int lastRow = 0;
if (maxResults == Integer.MAX_VALUE) {
lastRow = maxResults;
} else {
lastRow = firstResult + maxResults + 1;}
parameterMap.put("lastRow", lastRow);
return executeList(commandContext, parameterMap, firstResult, maxResults);
} else if (resultType == ResultType.SINGLE_RESULT) {
return executeSingleResult(commandContext);
} else {
return executeCount(commandContext, getParameterMap());}}
public abstract long executeCount(CommandContext commandContext,
Map<String, Object> parameterMap);
/**
* Executes the actual query to retrieve the list of results.
* @param maxResults
* @param firstResult
* @param page
* used if the results must be paged. If null, no paging will be
* applied.*/
public abstract List<U> executeList(CommandContext commandContext,
Map<String, Object> parameterMap, int firstResult, int maxResults);
public U executeSingleResult(CommandContext commandContext) {
List<U> results = executeList(commandContext, getParameterMap(), 0, Integer.MAX_VALUE);
if (results.size() == 1) {
return results.get(0);
} else if (results.size() > 1) {
throw new ActivitiException("Query return " + results.size() + " results instead of max 1");}
return null;}
private Map<String, Object> getParameterMap() {
HashMap<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("sql", sqlStatement);
parameterMap.putAll(parameters);
return parameterMap;}
public Map<String, Object> getParameters() {
return parameters;}}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐