package baseclass.tools;

import java.util.HashMap;

import p2.p2server.P2Server;
import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;

public class GetP2Type {
	PaoSetRemote ps_objectcols;
	String objectname;
	public static HashMap<String, HashMap<String, String>> objectp2typesmap = new HashMap<String, HashMap<String, String>>();

	public GetP2Type(String objectname) throws P2Exception {
		this.objectname = objectname.toUpperCase();
		if (!objectp2typesmap.containsKey(objectname)) {
			this.ps_objectcols = P2Server.getP2Server()
					.getPaoSet("ps_objectcols",
							P2Server.getP2Server().getSystemUserInfo());
			ps_objectcols.setWhere("objectname='" + objectname + "'");
			ps_objectcols.reset();
			HashMap<String, String> map = new HashMap<String, String>(16);
			int i = 0;
			PaoRemote pao = null;
			while ((pao = ps_objectcols.getPao(i)) != null) {
				map.put(pao.getString("fieldname"), pao.getString("p2type"));
				i++;
			}
			objectp2typesmap.put(objectname, map);
			ps_objectcols.close();
		}
	}

	/**
	 * 获取P2数据表字段数值类型 ECRBINX DECIMAL TEXT SMALLINT ECRBIN DATETIME TIME UPCASE
	 * INTERVAL FLOAT DATE CURRENCY STRING LOWCASE INTEGER REMARK BOOLEAN
	 *
	 * @param fieldname
	 * @return
	 * @throws P2Exception
	 */
	public String getP2Type(String fieldname) throws P2Exception {
		return objectp2typesmap.get(objectname).get(fieldname.toUpperCase());
	}

}
