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

📄 mpinstance.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 Smart Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.process;

import java.util.*;
import java.sql.*;
import java.math.*;
import java.io.Serializable;

import org.compiere.model.*;
import org.compiere.util.DB;

/**
 *  Process Instance Model
 *
 *  @author Jorg Janke
 *  @version $Id: MPInstance.java,v 1.3 2003/04/22 05:33:19 jjanke Exp $
 */
public class MPInstance extends PO
{
	/**
	 * 	Standard Constructor
	 *	@param ctx context
	 *	@param AD_PInstance_ID instance or 0
	 */
	public MPInstance (Properties ctx, int AD_PInstance_ID)
	{
		super (ctx, AD_PInstance_ID);
		if (AD_PInstance_ID == 0)
		{
			setAD_Process_ID (0);
			setRecord_ID (0);
			setIsProcessing (false);
		}
	}	//	MPInstance

	/**
	 * 	Load Constructor
	 *	@param ctx context
	 *	@param rs result set
	 */
	public MPInstance (Properties ctx, ResultSet rs)
	{
		super (ctx, rs);
	}	//	MPInstance

	/**
	 * 	Create Process Instance from Process
	 *	@param process process
	 *	@param Record_ID Record
	 */
	public MPInstance (MProcess process, int Record_ID)
	{
		super (process.getCtx(), 0);
		setAD_Process_ID (process.getAD_Process_ID());
		setRecord_ID (Record_ID);
		setIsProcessing (false);
		save();		//	need to save for parameters
		//	Set Parameter Base Info
		MProcess_Para[] para = process.getParameter();
		for (int i = 0; i < para.length; i++)
		{
			MPInstance_Para pip = new MPInstance_Para (process.getCtx(), getAD_PInstance_ID(), para[i].getSeqNo(), para[i].getColumnName());
			pip.setInfo(para[i].getName());
			pip.save();
		}
	}	//	MPInstance

	protected POInfo initPO (Properties ctx)
	{
		int AD_Table_ID = 282;
		POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
		return poi;
	}

	/**	Parameters						*/
	private MPInstance_Para[]		m_parameters = null;

	/**
	 * 	Get Parameters
	 *	@return parameter array
	 */
	public MPInstance_Para[] getParameter()
	{
		if (m_parameters != null)
			return m_parameters;
		ArrayList list = new ArrayList();
		//
		String sql = "SELECT * FROM AD_PInstance_Para WHERE AD_PInstance_ID=?";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, getAD_Process_ID());
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				list.add(new MPInstance_Para(getCtx(), rs));
			}
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getParameter", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}
		//
		m_parameters = new MPInstance_Para[list.size()];
		list.toArray(m_parameters);
		return m_parameters;
	}	//	getParameters

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

	/**	Log Entries					*/
	private ArrayList	m_log	= new ArrayList();

	/**
	 *	Get Logs
	 *	@return array of logs
	 */
	public MPInstance_Log[] getLog()
	{
		//	load it from DB
		m_log.clear();
		String sql = "SELECT * FROM AD_PInstance_Log WHERE AD_PInstance_ID=? ORDER BY Log_ID";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, getAD_PInstance_ID());
			ResultSet rs = pstmt.executeQuery();
			while (rs.next())
			{
				m_log.add(new MPInstance_Log(rs));
			}
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getLog", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}

		MPInstance_Log[] retValue = new MPInstance_Log[m_log.size()];
		m_log.toArray(retValue);
		return retValue;
	}	//	getLog

	/**
	 *	@param P_Date date
	 *	@param P_ID id
	 *	@param P_Number number
	 *	@param P_Msg msg
	 */
	public void addLog (Timestamp P_Date, int P_ID, BigDecimal P_Number, String P_Msg)
	{
		MPInstance_Log log = new MPInstance_Log (getAD_PInstance_ID(), m_log.size()+1,
			P_Date, P_ID, P_Number, P_Msg);
		m_log.add(log);
		//	save it to DB ?
	//	log.save();
	}	//	addLog


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

	/**
	 * 	Save
	 * 	@return true if saved
	 */
	public boolean save ()
	{
		log.debug ("save");
		return super.save ();
	}	//	save

	public String toString ()
	{
		StringBuffer sb = new StringBuffer ("MPInstance[")
			.append (getID())
			.append(",OK=").append(isOK());
		String msg = getErrorMsg();
		if (msg != null && msg.length() > 0)
			sb.append(msg);
		sb.append ("]");
		return sb.toString ();
	}	//	toString

	public void log()
	{
		log.info(toString());
		MPInstance_Log[] pil = getLog();
		for (int i = 0; i < pil.length; i++)
			log.info(pil[i]);
	}	//	log

	public void setRecord_ID (int Record_ID)
	{
		setValue ("Record_ID", new Integer(Record_ID));
	}

	public int getRecord_ID ()
	{
		Integer ii = (Integer)getValue ("Record_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setIsProcessing (boolean IsProcessing)
	{
		setValue ("IsProcessing", new Boolean (IsProcessing));
	}

	public boolean isProcessing ()
	{
		Boolean bb = (Boolean)getValue ("IsProcessing");
		if (bb != null)
			return bb.booleanValue ();
		return false;
	}

	public void setAD_User_ID (int AD_User_ID)
	{
		setValue ("AD_User_ID", new Integer (AD_User_ID));
	}

	public int getAD_User_ID ()
	{
		Integer ii = (Integer)getValue ("AD_User_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setErrorMsg (String Errormsg)
	{
		setValue ("ErrorMsg", Errormsg);
	}

	public String getErrorMsg ()
	{
		return (String)getValue ("ErrorMsg");
	}

	public void setResult (int Result)
	{
		setValue ("Result", new Integer (Result));
	}

	public static final int		RESULT_OK = 1;
	public static final int		RESULT_ERROR = 0;

	public int getResult ()
	{
		Integer ii = (Integer)getValue ("Result");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public boolean isOK()
	{
		return getResult() == RESULT_OK;
	}

	public void setAD_Process_ID (int AD_Process_ID)
	{
		setValue ("AD_Process_ID", new Integer (AD_Process_ID));
	}

	public int getAD_Process_ID ()
	{
		Integer ii = (Integer)getValue ("AD_Process_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	void setAD_PInstance_ID (int AD_PInstance_ID)
	{
		setValueNoCheck ("AD_PInstance_ID", new Integer (AD_PInstance_ID));
	}

	public int getAD_PInstance_ID ()
	{
		Integer ii = (Integer)getValue ("AD_PInstance_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

}	//	MPInstance

⌨️ 快捷键说明

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