|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
ADempiere + Jasper call Stored Procedure (Postgres)
分類:未分類資料夾
2011/10/13 13:45
分享
Facebook Plurk YAHOO!
ADempiere + Jasper call Stored Procedure (Postgres)
用 ADempiere 呼叫 Jasper
StartReport.java
會傳遞給 Jasper report
(1)參數堆疊
if (Record_ID > 0)
params.put("RECORD_ID", new Integer( Record_ID));
// contribution from Ricardo (ralexsander)
// in iReports you can 'SELECT' AD_Client_ID, AD_Org_ID and AD_User_ID using only AD_PINSTANCE_ID
params.put("AD_PINSTANCE_ID", new Integer( AD_PInstance_ID));
// FR [3123850] - Add continuosly needed parameters to Jasper Starter - Carlos Ruiz - GlobalQSS
params.put("AD_CLIENT_ID", new Integer( Env.getAD_Client_ID(Env.getCtx())));
params.put("AD_ROLE_ID", new Integer( Env.getAD_Role_ID(Env.getCtx())));
params.put("AD_USER_ID", new Integer( Env.getAD_User_ID(Env.getCtx())));
(2)參數取用
Connection conn = null;
try {
conn = getConnection();
jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
if (reportData.isDirectPrint() || !processInfo.isPrintPreview())
{
log.info( "ReportStarter.startProcess print report -" + jasperPrint.getName());
================================================
讓 Jasper 取用 Procedure
================================================
if (IsReport && ProcedureName.length() > 0 && !isJasper)
{
m_pi.setReportingProcess(true);
if (!startDBProcess(ProcedureName))
{
unlock();
return;
}
} // Pre-Report
if (isJasper)
{
m_pi.setReportingProcess(true);
if (ProcedureName.length() > 0)
{
// m_pi.setReportingProcess(true);
if (!startDBProcess(ProcedureName))
{
unlock();
return;
}
} // Pre-Report
m_pi.setClassName(ProcessUtil.JASPER_STARTER_CLASS);
startProcess();
unlock();
return;
}
//---------------------------------------
ADempiere + Jasper call Stored Procedure (Postgres) SP實作
分類:未分類資料夾
2011/10/13 13:54
分享
Facebook Plurk YAHOO!
創新與超越
一路領先
開源軟件
技術轉移顧問
專注 轉移
專注 整合
專注 客戶的自主的維護能力
-- SET search_path to ADEMPIERE, PUBLIC
DROP FUNCTION "public"."zz_sp_bpartner"()
DROP TYPE "public"."zz_type_bpartner"
CREATE TYPE "public"."zz_type_bpartner" AS
(
p_instance_id numeric(10),
ad_client_id numeric(10),
ad_org_id numeric(10),
c_bpartner_id numeric(10),
bpvalue varchar(40),
bpname varchar(80)
)
select * from "public"."zz_sp_bpartner" ()
CREATE OR REPLACE FUNCTION "public"."zz_sp_bpartner1" (p_PInstance_ID numeric)
RETURNS setof zz_type_bpartner AS
$BODY$
DECLARE
Cur_Parameter RECORD;
Cur_Rec RECORD;
p RECORD;
cur_bp CURSOR (x_value varchar, x_value_to varchar)
IS
SELECT * FROM c_bpartner
WHERE value BETWEEN x_value AND x_value_to;
cur_PInstance_para CURSOR (x_PInstance numeric)
IS
SELECT pi.record_id,pi.ad_client_id,pi.ad_org_id,
pp.parametername,
pp.p_string, pp.p_number, pp.p_date,
pp.p_string_TO, pp.p_number_TO, pp.p_date_tO
FROM ad_pinstance pi
LEFT OUTER JOIN ad_pinstance_para pp ON(pi.ad_pinstance_id = pp.ad_pinstance_id)
AND pi.ad_pinstance_id = x_PInstance
ORDER BY pp.SeqNo;
returnrec zz_type_bpartner;
p_Record_ID NUMERIC(10) := 0;
p_C_BPartner_ID NUMERIC(10) := 0;
p_C_DocType_ID NUMERIC(10) := 0;
p_C_BPartner_ID_TO NUMERIC(10) := 0;
p_C_DocType_ID_TO NUMERIC(10) := 0;
p_C_BPartner_Value VARCHAR(40) := 0;
p_C_DocType_Value VARCHAR(40) := 0;
p_C_BPartner_Value_TO VARCHAR(40) := '';
p_C_DocType_Value_TO VARCHAR(40) := '';
p_MovementDate DATE;
p_MovementDate_TO DATE;
v_message VARCHAR (400) := '';
v_NextNo NUMERIC(10) := 0;
ResultStr VARCHAR (200);
-- roleaccesslevelwin VARCHAR (200);
sqlins VARCHAR (2000);
-- p RECORD;
-- r RECORD;
-- inv RECORD;
BEGIN
v_message :='程式開始:: 更新[呼叫程序]紀錄檔...開始執行時間(created)..程序執行中(isprocessing)..';
BEGIN
ResultStr := 'PInstanceNotFound';
UPDATE ad_pinstance
SET created = SYSDATE,
isprocessing = 'Y'
WHERE ad_pinstance_id = pinstance_id;
COMMIT;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
v_message :='讀取使用者輸入列印發票(C_Invoice) 區間參數..(C_BPartner_ID/C_DocType_ID)';
FOR p IN cur_PInstance_para(p_PInstance_ID)
LOOP
p_Record_ID := p.record_id;
IF p.parametername = 'MovementDate' THEN p_MovementDate = p.p_date;
p_MovementDate_TO = p.p_date_to;
ELSE IF p.parametername = 'C_BPartner_ID' THEN p_C_BPartner_ID = p.p_number;
p_C_BPartner_ID_TO = p.p_number_to;
ELSE IF p.parametername = 'C_DocType_ID' THEN p_C_DocType_ID = p.p_number;
p_C_DocType_ID_TO = p.p_number_to;
END IF;
END IF;
END IF;
END LOOP;
BEGIN
CREATE TEMPORARY TABLE tmp_zz_bpartner
(
p_instance_id numeric(10),
ad_client_id numeric(10),
ad_org_id numeric(10),
c_bpartner_id numeric(10),
bpvalue varchar(40),
bpname varchar(80)
);
EXCEPTION WHEN OTHERS THEN
TRUNCATE TABLE tmp_zz_bpartner; -- TRUNCATE if the table already exists within the session.
END;
FOR Cur_Rec IN cur_bp('1','Z') LOOP
insert into tmp_zz_bpartner VALUES (1,1,1,Cur_Rec.c_bpartner_id,Cur_Rec.value,Cur_Rec.name);
-- v_NextNo = nextidbytablename('an_c_shipment_t','N');
-- sqlins := 'INSERT INTO an_c_shipment_t ('
-- ||'an_c_shipment_t_id,ad_client_id,ad_org_id,isactive,created,'
-- ||'createdby, updated, updatedby, sales_name, pd_name,'
-- ||'bp_name, matching_qty,AD_PInstance_ID,MovementDate'
-- ||') VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)';
-- EXECUTE sqlins USING
-- v_NextNo,r.ad_client_id,r.ad_org_id,'Y',NOW(),
-- 0,NOW(),0,r.sales_name,r.pd_name,
-- r.bp_name,r.matching_qty,pinstance,p_MovementDate;
END LOOP;
FOR returnrec IN SELECT * FROM tmp_zz_bpartner LOOP
RETURN NEXT returnrec;
END LOOP;
v_message :='程式完成:: 更新[呼叫程序]紀錄檔...完成執行時間(updated)..程序執行完成(isprocessing)..';
BEGIN
UPDATE adempiere.ad_pinstance
SET updated = SYSDATE,
isprocessing = 'N',
result = 1,
errormsg = Message
WHERE ad_pinstance_id = pinstance_ID;
COMMIT;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
EXCEPTION
WHEN OTHERS THEN
BEGIN
sqlins := 'INSERT INTO an_c_shipment_t (an_c_shipment_t_id, bp_name) VALUES($1, $2)';
EXECUTE sqlins USING 9, v_message;
v_message :='程式失敗:: 寫入(an_c_shipment_t)執行過的程序..';
END;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
////-------------------------------- |
|