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

📄 mprocess.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 Model
 *
 *  @author Jorg Janke
 *  @version $Id: MProcess.java,v 1.3 2003/04/22 05:33:19 jjanke Exp $
 */
public class MProcess extends PO
{
	/**
	 * 	Standard Constructor
	 *	@param ctx context
	 *	@param AD_Process_ID process
	 */
	public MProcess (Properties ctx, int AD_Process_ID)
	{
		super (ctx, AD_Process_ID);
		if (AD_Process_ID == 0)
		{
			setIsReport (false);
			setAccessLevel (null);
			setEntityType (null);
			setValue (null);
			setIsUserStartable (false);
			setName (null);
			setAD_Process_ID (0);
		}
	}	//	MProcess

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

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

	private MProcess_Para[]		m_parameters = null;

	public MProcess_Para[] getParameter()
	{
		if (m_parameters != null)
			return m_parameters;
		ArrayList list = new ArrayList();
		//
		String sql = "SELECT * FROM AD_Process_Para WHERE AD_Process_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 MProcess_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 MProcess_Para[list.size()];
		list.toArray(m_parameters);
		return m_parameters;
	}	//	getParameters

	public boolean save ()
	{
		log.debug ("save");
		return super.save ();
	}

	public String toString ()
	{
		StringBuffer sb = new StringBuffer ("MProcess[").append (getID ()).
						  append ("]");
		return sb.toString ();
	}

	public void setHelp (String Help)
	{
		setValue ("Help", Help);
	}

	public String getHelp ()
	{
		return (String)getValue ("Help");
	}

	public void setProcedureName (String ProcedureName)
	{
		setValue ("ProcedureName", ProcedureName);
	}

	public String getProcedureName ()
	{
		return (String)getValue ("ProcedureName");
	}

	public void setDescription (String Description)
	{
		setValue ("Description", Description);
	}

	public String getDescription ()
	{
		return (String)getValue ("Description");
	}

	public void setIsReport (boolean IsReport)
	{
		setValue ("IsReport", new Boolean (IsReport));
	}

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

	public static final String AccessLevel_SystemClient = "6";
	public static final String AccessLevel_Organization = "1";
	public static final String AccessLevel_ClientOrganization = "3";
	public static final String AccessLevel_SystemOnly = "4";
	public static final String AccessLevel_All = "7";

	public void setAccessLevel (String AccessLevel)
	{
		if (AccessLevel.equals ("6") || AccessLevel.equals ("1")
		  || AccessLevel.equals ("3") || AccessLevel.equals ("4")
		  || AccessLevel.equals ("7"))
			;
		else
			throw new IllegalArgumentException (
			  "AccessLevel Invalid value - Reference_ID=5 - 6 - 1 - 3 - 4 - 7");
		if (AccessLevel == null)
			throw new IllegalArgumentException ("AccessLevel is mandatory");
		setValue ("AccessLevel", AccessLevel);
	}

	public String getAccessLevel ()
	{
		return (String)getValue ("AccessLevel");
	}

	public void setClassname (String Classname)
	{
		setValue ("Classname", Classname);
	}

	public String getClassname ()
	{
		return (String)getValue ("Classname");
	}

	public void setAD_ReportView_ID (int AD_ReportView_ID)
	{
		setValue ("AD_ReportView_ID", new Integer (AD_ReportView_ID));
	}

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

	public void setStatistic_Seconds (int Statistic_Seconds)
	{
		setValue ("Statistic_Seconds", new Integer (Statistic_Seconds));
	}

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

	public void setAD_PrintFormat_ID (int AD_PrintFormat_ID)
	{
		setValue ("AD_PrintFormat_ID", new Integer (AD_PrintFormat_ID));
	}

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

	public static final String EntityType_Dictionary = "D";
	public static final String EntityType_Compiere = "C";
	public static final String EntityType_UserMaintained = "U";
	public static final String EntityType_Applications = "A";

	public void setEntityType (String EntityType)
	{
		if (EntityType.equals ("D") || EntityType.equals ("C")
		  || EntityType.equals ("U") || EntityType.equals ("A"))
			;
		else
			throw new IllegalArgumentException (
			  "EntityType Invalid value - Reference_ID=245 - D - C - U - A");
		if (EntityType == null)
			throw new IllegalArgumentException ("EntityType is mandatory");
		setValue ("EntityType", EntityType);
	}

	public String getEntityType ()
	{
		return (String)getValue ("EntityType");
	}

	public void setValue (String Value)
	{
		if (Value == null)
			throw new IllegalArgumentException ("Value is mandatory");
		setValue ("Value", Value);
	}

	public String getValue ()
	{
		return (String)getValue ("Value");
	}

	public void setIsDirectPrint (boolean IsDirectPrint)
	{
		setValue ("IsDirectPrint", new Boolean (IsDirectPrint));
	}

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

	public void setStatistic_Count (int Statistic_Count)
	{
		setValue ("Statistic_Count", new Integer (Statistic_Count));
	}

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

	public void setIsUserStartable (boolean IsUserStartable)
	{
		setValue ("IsUserStartable", new Boolean (IsUserStartable));
	}

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

	public void setName (String Name)
	{
		if (Name == null)
			throw new IllegalArgumentException ("Name is mandatory");
		setValue ("Name", Name);
	}

	public String getName ()
	{
		return (String)getValue ("Name");
	}

	void setAD_Process_ID (int AD_Process_ID)
	{
		setValueNoCheck ("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 ();
	}

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

	/**
	 * 	Process w/o parameter
	 *	@param Record_ID record
	 *	@return Process Instance
	 */
	public MPInstance process (int Record_ID)
	{
		MPInstance pi = new MPInstance (this, Record_ID);
		//	Lock
		pi.setIsProcessing(true);
		pi.save();

		boolean ok = true;

		//	PL/SQL Procedure
		String ProcedureName = getProcedureName();
		if (ProcedureName != null && ProcedureName.length() > 0)
		{
			ok = startProcess (ProcedureName, pi);
		}

		//	Unlock
		pi.setIsProcessing(false);
		pi.save();
		//
		pi.log();
		return pi;
	}	//	process

	/**
	 *  Start Database Process
	 *  @param ProcedureName PL/SQL procedure name
	 *  @param pi process instance
	 *  @return true if success
	 */
	private boolean startProcess (String ProcedureName, MPInstance pi)
	{
		int AD_PInstance_ID = pi.getAD_PInstance_ID();
		//  execute on this thread/connection
		log.info("startProcess - " + ProcedureName + "(" + AD_PInstance_ID + ")");
		try
		{
			String sql = "{CALL " + ProcedureName + "(?)}";
			CallableStatement cstmt = DB.prepareCall(sql);	//	ro??
			cstmt.setInt(1, AD_PInstance_ID);
			cstmt.executeUpdate();
			cstmt.close();
		}
		catch (Exception e)
		{
			log.error("startProcess", e);
			pi.setResult(MPInstance.RESULT_ERROR);
			pi.setErrorMsg(e.getLocalizedMessage());
			return false;
		}
		pi.setResult(MPInstance.RESULT_OK);
		return true;
	}   //  startProcess


}	//	MProcess

⌨️ 快捷键说明

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