本文整理汇总了Java中org.compiere.util.Env.switchContext方法的典型用法代码示例。如果您正苦于以下问题:Java Env.switchContext方法的具体用法?Java Env.switchContext怎么用?Java Env.switchContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.compiere.util.Env
的用法示例。
在下文中一共展示了Env.switchContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAsSystem
import org.compiere.util.Env; //导入方法依赖的package包/类
@Override
public void executeAsSystem(ContextRunnable runnable)
{
final Properties sysCtx = Env.createSysContext(Env.getCtx());
final String logMigrationScriptsOld = Ini.getProperty(Ini.P_LOGMIGRATIONSCRIPT);
DB.saveConstraints();
try (final IAutoCloseable contextRestorer = Env.switchContext(sysCtx))
{
DB.getConstraints().addAllowedTrxNamePrefix(ITrx.TRXNAME_PREFIX_LOCAL);
DB.getConstraints().incMaxTrx(1);
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, true);
runnable.run(sysCtx);
}
finally
{
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, logMigrationScriptsOld);
DB.restoreConstraints();
}
}
示例2: onEvent
import org.compiere.util.Env; //导入方法依赖的package包/类
@Override
public void onEvent(@NonNull final IEventBus eventBus, @NonNull final Event event)
{
final MaterialEvent lightWeightEvent = materialEventConverter.toMaterialEvent(event);
logger.info("Received MaterialEvent={}", lightWeightEvent);
//
// make sure that every record we create has the correct AD_Client_ID and AD_Org_ID
final Properties temporaryCtx = Env.copyCtx(Env.getCtx());
Env.setContext(temporaryCtx, Env.CTXNAME_AD_Client_ID, lightWeightEvent.getEventDescriptor().getClientId());
Env.setContext(temporaryCtx, Env.CTXNAME_AD_Org_ID, lightWeightEvent.getEventDescriptor().getOrgId());
try (final IAutoCloseable c = Env.switchContext(temporaryCtx))
{
invokeListenerInTrx(lightWeightEvent);
}
}
示例3: loadPMMProductAndProcess
import org.compiere.util.Env; //导入方法依赖的package包/类
/**
* Loads the {@link I_PMM_Product} for the given <code>product_uuid</code>, then creates and updates a temporary context and invokes the given <code>processor</code>.
*
* @param product_uuid
* @param processor
*/
private void loadPMMProductAndProcess(final String product_uuid, final IEventProcessor processor)
{
final int pmmProductId = SyncUUIDs.getPMM_Product_ID(product_uuid);
if (pmmProductId <= 0)
{
throw new AdempiereException("@[email protected] @[email protected] for UUID=" + product_uuid);
}
final Properties tempCtx = Env.newTemporaryCtx();
final I_PMM_Product pmmProduct = InterfaceWrapperHelper.create(tempCtx, pmmProductId, I_PMM_Product.class, ITrx.TRXNAME_None);
if (pmmProduct == null)
{
throw new AdempiereException("@[email protected] @[email protected] for ID=" + pmmProductId + " (record not found)");
}
// required because if the ctx contains #AD_Client_ID = 0, we might not get the term's C_Flatrate_DataEntries from the DAO further down,
// and also the new even record needs to have the PMM_Product's AD_Client_ID and AD_Org_ID
Env.setContext(tempCtx, Env.CTXNAME_AD_Client_ID, pmmProduct.getAD_Client_ID());
Env.setContext(tempCtx, Env.CTXNAME_AD_Org_ID, pmmProduct.getAD_Org_ID());
try (final IAutoCloseable contextRestorer = Env.switchContext(tempCtx))
{
Services.get(ITrxManager.class).run(new TrxRunnableAdapter()
{
@Override
public void run(final String localTrxName) throws Exception
{
final IContextAware context = PlainContextAware.newWithThreadInheritedTrx(tempCtx);
processor.processEvent(context, pmmProduct);
}
});
}
}
示例4: switchContextIfNeeded
import org.compiere.util.Env; //导入方法依赖的package包/类
private IAutoCloseable switchContextIfNeeded()
{
if (switchContextWhenRunning)
{
return Env.switchContext(pi.getCtx());
}
else
{
return NullAutoCloseable.instance;
}
}
示例5: importCamt54v02
import org.compiere.util.Env; //导入方法依赖的package包/类
private ESRStatement importCamt54v02(final MultiVersionStreamReaderDelegate mxsr)
{
final ESRDataImporterCamt54v02 importerV02 = new ESRDataImporterCamt54v02(header, mxsr);
final BankToCustomerDebitCreditNotificationV02 bkToCstmrDbtCdtNtfctn = importerV02.loadXML();
if (bkToCstmrDbtCdtNtfctn.getGrpHdr() != null && bkToCstmrDbtCdtNtfctn.getGrpHdr().getAddtlInf() != null)
{
Loggables.get().withLogger(logger, Level.INFO).addLog("The given input is a test file: bkToCstmrDbtCdtNtfctn/grpHdr/addtlInf={}", bkToCstmrDbtCdtNtfctn.getGrpHdr().getAddtlInf());
}
try (final IAutoCloseable switchContext = Env.switchContext(InterfaceWrapperHelper.getCtx(header, true)))
{
return importerV02.createESRStatement(bkToCstmrDbtCdtNtfctn);
}
}
示例6: importCamt54v06
import org.compiere.util.Env; //导入方法依赖的package包/类
private ESRStatement importCamt54v06(final MultiVersionStreamReaderDelegate mxsr)
{
final ESRDataImporterCamt54v06 importerV06 = new ESRDataImporterCamt54v06(header, mxsr);
final BankToCustomerDebitCreditNotificationV06 bkToCstmrDbtCdtNtfctn = importerV06.loadXML();
if (bkToCstmrDbtCdtNtfctn.getGrpHdr() != null && bkToCstmrDbtCdtNtfctn.getGrpHdr().getAddtlInf() != null)
{
Loggables.get().withLogger(logger, Level.INFO).addLog("The given input is a test file: bkToCstmrDbtCdtNtfctn/grpHdr/addtlInf={}", bkToCstmrDbtCdtNtfctn.getGrpHdr().getAddtlInf());
}
try (final IAutoCloseable switchContext = Env.switchContext(InterfaceWrapperHelper.getCtx(header, true)))
{
return importerV06.createESRStatement(bkToCstmrDbtCdtNtfctn);
}
}
示例7: report
import org.compiere.util.Env; //导入方法依赖的package包/类
@Override
public byte[] report(int processId, int pinstanceId, final String adLanguage, final OutputType outputType) throws Exception
{
//
// Load process info
final ProcessInfo processInfo = ProcessInfo.builder()
.setCtx(Env.newTemporaryCtx())
.setCreateTemporaryCtx()
.setAD_Process_ID(processId)
.setAD_PInstance_ID(pinstanceId)
.setReportLanguage(adLanguage)
.setJRDesiredOutputType(outputType)
.build();
//
// If there is no AD_PInstance already, we need to create it now
if(processInfo.getAD_PInstance_ID() <= 0)
{
Services.get(IADPInstanceDAO.class).saveProcessInfoOnly(processInfo);
}
// Override the context using the values from record (if any)
// NOTE: setting the AD_Org_ID from document (if any) is very important for retrieving things like organization logo which is displayed in reports.
updateContextFromRecord(processInfo);
//
// Create report context based on processInfo
final ReportContext reportContext = ReportContext.builder()
.setCtx(processInfo.getCtx())
.setAD_Process_ID(processInfo.getAD_Process_ID())
.setAD_PInstance_ID(processInfo.getAD_PInstance_ID())
.setRecord(processInfo.getTable_ID(), processInfo.getRecord_ID())
.setAD_Language(processInfo.getReportAD_Language())
.setOutputType(processInfo.getJRDesiredOutputType())
.setReportTemplatePath(processInfo.getReportTemplate().orElse(null))
.setSQLStatement(processInfo.getSQLStatement().orElse(null))
.setApplySecuritySettings(processInfo.isReportApplySecuritySettings())
.build();
//
// Create the report
try (final IAutoCloseable contextRestorer = Env.switchContext(reportContext.getCtx()))
{
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final IReportEngine engine = createReportEngine(reportContext);
engine.report(reportContext, out);
return out.toByteArray();
}
catch (Exception e)
{
throw AdempiereException.wrapIfNeeded(e);
}
}