EJB 비동기식 커밋 및 액세스 프로세스 사용
package org.jboss.seam.core;
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.util.List;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.async.AbstractDispatcher;
import org.jboss.seam.async.CronSchedule;
import org.jboss.seam.async.Dispatcher;
import org.jboss.seam.async.Schedule;
import org.jboss.seam.async.TimerSchedule;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Expressions.MethodExpression;
import org.jboss.seam.core.Init.ObserverMethod;
import org.jboss.seam.core.Init.ObserverMethodExpression;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
/**
* Support for Seam component-driven events
*
* @author Gavin King
*
*/
@Scope(ScopeType.EVENT)
@BypassInterceptors
@Name("org.jboss.seam.core.events")
@Install(precedence=BUILT_IN)
public class Events
{
private static final LogProvider log = Logging.getLogProvider(Events.class);
/**
* Add a new listener for a given event type
*
* @param type the event type
* @param methodBindingExpression a method binding, expressed in EL
* @param argTypes the argument types of the method binding
*/
public void addListener(String type, String methodBindingExpression, Class... argTypes)
{
MethodExpression methodBinding = Expressions.instance().createMethodExpression(methodBindingExpression, Object.class, argTypes);
Init.instance().addObserverMethodExpression(type, methodBinding);
}
/**
* Raise an event that is to be processed synchronously
*
* @param type the event type
* @param parameters parameters to be passes to the listener method
*/
public void raiseEvent(String type, Object... parameters)
{
//TODO: find a way to map event parameters to params in an EL-defined listener
log.trace("Processing event:" + type);
List
list = Init.instance().getObserverMethodExpressions(type);
if (list!=null)
{
for (ObserverMethodExpression listener: list )
{
listener.getMethodBinding().invoke(parameters);
}
}
List
observers = Init.instance().getObserverMethods(type); if (observers!=null) { for (ObserverMethod observer: observers) { String name = observer.getComponent().getName(); Object listener = Component.getInstance( name, observer.isCreate(), false ); if ( observer.getComponent().hasUnwrapMethod() ) { listener = observer.getComponent().getScope().getContext().get(name); } if (listener!=null) { observer.getComponent().callComponentMethod(listener, observer.getMethod(), parameters); } } } } /** * Raise an event that is to be processed asynchronously * * @param type the event type * @param parameters parameters to be passes to the listener method */ public void raiseAsynchronousEvent(String type, Object... parameters) { getDispatcher().scheduleAsynchronousEvent(type, parameters); } /** * Raise an event that is to be processed according to a "schedule" * * @see TimerSchedule (EJB, quartz or JDK timer service) * @see CronSchedule (quartz timer service only) * * @param type the event type * @param schedule the schedule object, specific to the dispatcher strategy * @param parameters parameters to be passes to the listener method */ public void raiseTimedEvent(String type, Schedule schedule, Object... parameters) { getDispatcher().scheduleTimedEvent(type, schedule, parameters); } /** * Raise an event that is to be processed after successful completion of * the current transaction * * @param type the event type * @param parameters parameters to be passes to the listener method */ public void raiseTransactionSuccessEvent(String type, Object... parameters) { getDispatcher().scheduleTransactionSuccessEvent(type, parameters); } /** * Raise an event that is to be processed after the current transaction * ends * * @param type the event type * @param parameters parameters to be passes to the listener method */ public void raiseTransactionCompletionEvent(String type, Object... parameters) { getDispatcher().scheduleTransactionCompletionEvent(type, parameters); } /** * @return the Dispatcher object to use for dispatching asynchronous * and timed events */ protected Dispatcher getDispatcher() { return AbstractDispatcher.instance(); } public static boolean exists() { return Contexts.isEventContextActive() && instance()!=null; } public static Events instance() { return (Events) Component.getInstance(Events.class, ScopeType.EVENT); } }
2.비동기 코드 호출, 전역 변수 정의:public static final String BACKUP_MONTHLY_STOCK = "BACKUP_MONTHLY_STOCK";전송 매개 변수: BACKUP_MONTHLY_STOCK 문자열 이벤트.instance().raiseAsynchronousEvent(BACKUP_MONTHLY_STOCK, endPeriod, company, getUsername());Observer(String type)를 주입하면 비동기적으로 감청되는 이벤트에 도달하고 연결을 얻으며 액세스 프로세스를 호출합니다. BACKUP_MONTHLY_STOCK_PKG, 전달된 매개변수 가져오기 및 실행
@Observer("BACKUP_MONTHLY_STOCK")
public void backUpMonthlyStock(String endPeriod, String companyAid, String userName) throws SQLException {
Session session = (Session) entityManager.getDelegate();
@SuppressWarnings("deprecation")
Connection connection = session.connection();
CallableStatement callableStatement = null;
try {
callableStatement = connection.prepareCall(BACKUP_MONTHLY_STOCK_PKG);
callableStatement.setString(1, endPeriod); // endPeriod
callableStatement.setString(2, companyAid); // companyAid
callableStatement.setString(3, userName); // Month-End user name
callableStatement.registerOutParameter(4, java.sql.Types.VARCHAR); // Error Message
callableStatement.registerOutParameter(5, java.sql.Types.VARCHAR); // retcode
// execute BACKUP_MONTHLY_STOCK_PKG.fn_main
callableStatement.executeUpdate();
String errbuf = callableStatement.getString(4); // return Error Message
String retcode = callableStatement.getString(5);// return retcode
// retcode : 0 --> fail 1 --> success
// errbuf : when retcode = 0, shows error message.
// when retcode = 1, value is null.
System.out.println("UserName" + userName);
System.out.println("retcode" + retcode);
System.out.println("errbuf" + errbuf);
// if (retcode != null && retcode.equals(1)) {
// return;
// } else {
// throw new Exception(errbuf);
// }
} catch (SQLException e) {
throw e;
} finally {
if (callableStatement != null) {
callableStatement.close();
}
if (connection != null) {
connection.close();
}
if (session != null) {
session.disconnect();
}
}
}
3: 액세스 프로세스: BACKUP_MONTHLY_STOCK_PKG
create or replace
PACKAGE BODY BACKUP_MONTHLY_STOCK_PKG is
-----------------------------------------------------------------------------------
-- Main Program
-----------------------------------------------------------------------------------
procedure fn_main (x_p_end_period in varchar2,
x_p_aid_company in varchar2,
x_p_backup_user in varchar2,
errbuf out varchar2,
retcode out varchar2)is
--x_ln_end_period varchar2(10);
x_ln_ret_code number := 1;
begin
--x_ln_end_period := to_char(sysdate,'yyyy-MM');
delete_IM_ITEM_STOCK_PERIOD(x_p_end_period,x_p_aid_company);
INSERT INTO AGBS.IM_ITEM_STOCK_PERIOD (
AID,
AID_ITEM_STOCK,
AID_COMPANY,
AID_ITEM,
AID_WAREHOUSE,
END_PERIOD,
IN_MIT_QUANTITY,
QUANTITY,
ASSIGNED_QUANTITY,
RESERVED_QUANTITY,
DO_IN_PROGRESS_QUANTITY,
QC_QUANTITY,
OUT_MIT_QUANTITY,
DAILY_BEGIN_QUANTITY,
MONTH_BEGIN_QUANTITY,
LAST_MONTH_BEGIN_QUANTITY,
USER_CREATED,
DATE_CREATED,
USER_LAST_MODIFIED,
DATE_LAST_MODIFIED,
USER_BACKUP)
SELECT
fn_get_new_aid('IM_ITEM_STOCK_PERIOD'),
AID,
AID_COMPANY,
AID_ITEM,
AID_WAREHOUSE,
x_p_end_period,
IN_MIT_QUANTITY,
QUANTITY,
ASSIGNED_QUANTITY,
RESERVED_QUANTITY,
DO_IN_PROGRESS_QUANTITY,
QC_QUANTITY,
OUT_MIT_QUANTITY,
DAILY_BEGIN_QUANTITY,
MONTH_BEGIN_QUANTITY,
LAST_MONTH_BEGIN_QUANTITY,
USER_CREATED,
DATE_CREATED,
USER_LAST_MODIFIED,
DATE_LAST_MODIFIED,
x_p_backup_user
FROM AGBS.IM_ITEM_STOCK
WHERE AID_COMPANY = x_p_aid_company ;
retcode := x_ln_ret_code;
exception
when others then
x_ln_ret_code := 0;
errbuf := 'System Failure: ' ||SQLCODE||' -ERROR- '||SQLERRM;
end fn_main;
-----------------------------------------------------------------------------------
-- delete period record
-----------------------------------------------------------------------------------
procedure delete_IM_ITEM_STOCK_PERIOD(x_p_end_period in varchar2,
x_p_aid_company in varchar2)
is
BEGIN
delete from AGBS.IM_ITEM_STOCK_PERIOD
where END_PERIOD = x_p_end_period
and AID_COMPANY = x_p_aid_company;
END delete_IM_ITEM_STOCK_PERIOD;
-----------------------------------------------------------------------------------
-- New AID
-----------------------------------------------------------------------------------
FUNCTION fn_get_new_aid(x_in_table_name varchar2) return varchar2
is
x_ln_aid varchar2(16);
BEGIN
select ADDI.GENERATE_AID('AGBS', x_in_table_name) into x_ln_aid
FROM DUAL;
RETURN x_ln_aid;
END fn_get_new_aid;
end BACKUP_MONTHLY_STOCK_PKG;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.