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

📄 processinfo.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.process;

import java.text.*;
import java.sql.*;
import java.util.*;

import org.apache.log4j.Logger;

import org.compiere.util.*;

/**
 *  Process Information (Value Object)
 *
 *  @author     Jorg Janke
 *  @version    $Id: ProcessInfo.java,v 1.2 2003/03/15 07:04:16 jjanke Exp $
 */
public class ProcessInfo
{
	/**
	 *  Constructor
	 *  @param title Title
	 *  @param ad_Process_ID AD_Process_ID
	 *  @param record_ID Record_ID
	 */
	public ProcessInfo (String title, int ad_Process_ID, int record_ID)
	{
		this.Title = title;
		this.AD_Process_ID = ad_Process_ID;
		this.Record_ID = record_ID;
	}   //  ProcessInfo

	/** Title of the Process/Report */
	public String       Title;
	/** Process ID                  */
	public int          AD_Process_ID;
	/** Record ID if the Process    */
	public int          Record_ID;
	/**	Logger							*/
	protected Logger			log = Logger.getLogger (getClass());

	//  -- Optional --

	/** Pricess Instance ID         */
	public int          AD_PInstance_ID = 0;
	/** Summary of Execution        */
	public String       Summary = "";
	/** Execution had an error      */
	public boolean      Error = false;
	/** Additional Execution info   */
	public String       LogInfo = "";
	/*	General Data Object			*/
	public Object		Data = null;

	/** Estimated Runtime           */
	public int          EstSeconds = 5;
	/** Gerenric Object             */
	public Object       Value = null;

	/**
	 *  String representation
	 *  @return String representation
	 */
	public String toString()
	{
		StringBuffer sb = new StringBuffer("ProcessInfo[");
		sb.append(Title)
			.append(",Process_ID=").append(AD_Process_ID);
		if (AD_PInstance_ID != 0)
			sb.append(",AD_PInstance_ID=").append(AD_PInstance_ID);
		if (Record_ID != 0)
			sb.append(",Record_ID=").append(Record_ID);
		sb.append(",Error=").append(Error);
		if (Value != null)
			sb.append(",Value=").append(Value);
		sb.append(",Summary=").append(Summary)
			.append(",Log=").append(LogInfo);
		sb.append("]");
		return sb.toString();
	}   //  toString

	/*************************************************************************/

	private final static String s_Log_SQL =
		"SELECT P_Date, P_Number, P_ID, P_Msg "
		+ "FROM AD_PInstance_Log "
		+ "WHERE AD_PInstance_ID=? "
		+ "ORDER BY Log_ID";

	/**
	 *	Query PInstance for result.
	 *  Fill Summary and success in ProcessInfo
	 */
	public void setSummary ()
	{
		log.debug("setSummary - AD_PInstance_ID=" + AD_PInstance_ID);
		int sleepTime = 2000;	//	2 secomds
		int noRetry = 5;        //  10 seconds total
		//
		String SQL = "SELECT Result, ErrorMsg FROM AD_PInstance "
			+ "WHERE AD_PInstance_ID=?"
			+ " AND Result IS NOT NULL";

		try
		{
			PreparedStatement pstmt = DB.prepareStatement (SQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
			for (int noTry = 0; noTry < noRetry; noTry++)
			{
				pstmt.setInt(1, AD_PInstance_ID);
				ResultSet rs = pstmt.executeQuery();
				if (rs.next())
				{
					//	we have a result
					int i = rs.getInt(1);
					if (i == 1)
					{
						Summary = Msg.getMsg(Env.getCtx(), "Success");
					}
					else
					{
						Summary = Msg.getMsg(Env.getCtx(), "Failure");
						Error = true;
					}
					String Message = rs.getString(2);
					rs.close();
					pstmt.close();
					if (Message != null)
						Summary += "  (" +  Msg.parseTranslation(Env.getCtx(), Message)  + ")";
				//	log.debug("getInstanceInfo - done");
					return;
				}

				rs.close();
				//	sleep
				try
				{
					log.debug("setSummary - sleeping");
					Thread.currentThread().sleep(sleepTime);
				}
				catch (InterruptedException ie)
				{
					log.error("setSummary - Sleep Thread", ie);
				}
			}
			pstmt.close();
		}
		catch (SQLException e)
		{
			log.error("setSummary", e);
			Summary = e.getLocalizedMessage();
			Error = true;
			return;
		}
		Error = true;
		Summary = Msg.getMsg(Env.getCtx(), "Timeout");
	}	//	setSummary

	/**
	 *	Return ID List
	 *  @return ArrayList with Integer of IDs
	 */
	public ArrayList getIDList ()
	{
		log.debug("getIDList - AD_PInstance_ID=" + AD_PInstance_ID);
		ArrayList items = new ArrayList();
		//
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(s_Log_SQL);
			pstmt.setInt(1, AD_PInstance_ID);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				int i = rs.getInt("P_ID");
				if (!rs.wasNull())
					items.add (new Integer(i));
			}

			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			log.error("getIDList - " + e);
		}
		return items;
	}	//	getIDList

	/**
	 *	Set Log of Process
	 *  <pre>
	 *  - Translated Process Message
	 *  - List of log entries
	 *      Date - Number - Msg
	 *  </pre>
	 */
	public void setProcessLog ()
	{
		log.debug("setProcessLog - AD_PInstance_ID=" + AD_PInstance_ID);
		StringBuffer sb = new StringBuffer ();
		int count = 0;
		//
		SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.DateTime);
		try
		{
			PreparedStatement pstmt = DB.prepareStatement(s_Log_SQL);
			pstmt.setInt(1, AD_PInstance_ID);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				if (sb.length() > 0)
					sb.append("\n");
				//
			//	int i = rs.getInt("P_ID");
			//	if (!rs.wasNull())
			//		sb.append(i).append("\t ");
				//
				Timestamp t = rs.getTimestamp("P_Date");
				if (!rs.wasNull())
					sb.append(dateFormat.format(t)).append(" \t");
				//
				double d = rs.getDouble("P_Number");
				if (!rs.wasNull())
					sb.append(d).append(" \t");
				//
				String s = rs.getString("P_Msg");
				if (!rs.wasNull())
					sb.append(Msg.parseTranslation(Env.getCtx(), s));
				count++;
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			log.error("setProcessLog", e);
		}
		LogInfo = sb.toString();
		log.debug(toString());
	}	//	setProcessLog

}   //  ProcessInfo

⌨️ 快捷键说明

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