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

📄 paramhelper.java

📁 Speedframework--基于类型元数据的羽量级ORM.完全基于Java类型元数据和反射机制同时不需要任何对象关系映射配置文件的轻量级ORM框架,它充分利用了类型本身的信息,使用Metadata
💻 JAVA
字号:
package org.speedframework.util;

import java.util.*;

import org.apache.log4j.Logger;
import org.speedframework.exception.ConnectionException;
import org.speedframework.exception.SpeedException;
import java.lang.reflect.InvocationTargetException;
import org.speedframework.entity.Pagination;

/**
 * <p>
 * Title: SpeedFrameworkWork持久层框架
 * </p>
 * 
 * <p>
 * Description: 参数帮助类
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * 
 * <p>
 * Company: SpeedFrameworkWork team
 * </p>
 * 
 * @author 李志峰 电话:13824431576 程伟杰 电话:
 * @version 1.0
 */
public class ParamHelper {
	private static final Logger log = Logger.getLogger(ParamHelper.class);

	public ParamHelper() {
	}

	/**
	 * 
	 * @param paramList
	 *            List
	 * @param entity
	 *            Object
	 * @return String[]
	 */

	public static String[] getParamType(List paramList, Object entity)
			throws NoSuchMethodException, InvocationTargetException,
			IllegalAccessException {
		String[] type = new String[paramList.size()];
		for (int i = 0; i < paramList.size(); i++) {
			type[i] = PropertyUtil.getPropertyType(entity,
					paramList.get(i).toString()).toString();
		}
		return type;
	}

	/**
	 * Parm value initialize
	 * 
	 * @param pramlist
	 *            List
	 * @param entity
	 *            Object
	 * @throws Exception
	 * @return String[]
	 */
	public static Object[] getParamValue(List paramlist, Object entity)
			throws SpeedException {
		Object[] paramvalue = null;
		// String[] paramvalue = null;
		try {
			if (paramlist != null) {
				paramvalue = new Object[paramlist.size()];
				for (int i = 0; i < paramlist.size(); i++) {
//					if (!"serialversionuid".equals(paramlist.get(i))) {
						paramvalue[i] = PropertyUtil.getProperty(entity,
								paramlist.get(i).toString());
//					}

				}
			}
		} catch (Exception e) {
			log.error(e);
			throw new SpeedException("entity do not parm");
		}
		return paramvalue;
	}

	/**
	 * 提取分页参数
	 * 
	 * @param param
	 *            String[]
	 * @param index
	 *            int
	 * @param max
	 *            int
	 * @throws ConnectionException
	 * @return String[]
	 */

	public static Object[] getQueryLimitParam(Object[] param, int index, int max)
			throws ConnectionException {
		if (param == null) {
			throw new ConnectionException("param must not null");
		}
		int length = param.length;
		Object[] new_param = new String[length + 2];
		for (int i = 0; i < length; i++) {
			new_param[i] = param[i];
		}
		if (max != 0) {
			new_param[length] = new Integer(index);
			new_param[length + 1] = new Integer(max);
		}
		return new_param;
	}

	/**
	 * 提取分页参数(分页类)
	 * 
	 * @param param
	 *            String[]
	 * @param pagination
	 *            Pagination
	 * @throws ConnectionException
	 * @return String[]
	 */
	public static Object[] getQueryLimitParam(String type, Object[] param,
			Pagination pagination) throws ConnectionException {
		if (param == null) {
			throw new ConnectionException("param must not null");
		}
		if (pagination == null) {
			throw new ConnectionException("pagination must not null");
		}
		int length = param.length;
		Object[] new_param = new Object[length + 2];
		for (int i = 0; i < length; i++) {
			new_param[i] = param[i];
		}
		if (type.equals("oracle")) {
			new_param[length] = Integer.toString(pagination.getPage()
					* pagination.getCount());
			new_param[length + 1] = new Integer((pagination.getPage() - 1)
					* pagination.getCount());
		}
		if (type.equals("mysql")) {
			new_param[length] = new Integer((pagination.getPage() - 1)
					* pagination.getCount());
			new_param[length + 1] = new Integer(pagination.getCount());

		}
		if (type.equals("microsoft sql server")) {

			new_param[length + 1] = new Integer((pagination.getPage() - 1)
					* pagination.getCount());
			new_param[length] = new Integer(pagination.getCount());
		}
		if (type.equals("postgresql")) {
			new_param[length] = new Integer(pagination.getCount());
			new_param[length + 1] = new Integer((pagination.getPage() - 1)
					* pagination.getCount());

		}
		if(type.indexOf("db2")!=-1){
			new_param[length] = new Integer((pagination.getPage() - 1)
					* pagination.getCount()+1);
			new_param[length + 1] = new Integer(pagination.getCount()*pagination.getPage());
		}
		
		if(type.indexOf("hsql")!=-1){
			new_param[0] = new Integer((pagination.getPage() - 1)
					* pagination.getCount());
			new_param[1] = new Integer(pagination.getCount()*pagination.getPage());			
			for (int j = 2; j < new_param.length; j++) {
				new_param[j] = param[j-2];
			}
			
		}
		

		return new_param;
	}

}

⌨️ 快捷键说明

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