<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: What is different among ways to execute as system ?</title><link>https://answers.axonivy.com/questions/2603/what-is-different-among-ways-to-execute-as-system</link><description>&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;During the time i've worked with ivy, i see there is some ways to execute code with system permission:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; - ServerFactory.getServer().getSecurityManager().executeAsSystem(callable) 
 - ServerFactory.getServer().getSecurityManager().executeAsSystem2(callable) 
 - Ivy.wf().getSecurityContext().executeAsSystemUser(callable)
 - SecurityManagerFactory.getSecurityManager().executeAsSystem(callable)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It make me confused, so can anyone explain the differences?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2603/what-is-different-among-ways-to-execute-as-system" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 03 May 2017 02:45:30 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/2603/what-is-different-among-ways-to-execute-as-system/2604</link><description>&lt;p&gt;These are all calls to the same method: &lt;code&gt;ISecurityManager.executeAsSystem(callable)&lt;/code&gt;. Just the navigation to that implementation is different:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ServerFactory.getServer().getSecurityManager().executeAsSystem(callable) 
Ivy.wf().getSecurityContext().executeAsSystemUser(callable)
SecurityManagerFactory.getSecurityManager().executeAsSystem(callable)
DiCore.getGlobalInjector.getInstance(ISecurityManager.class).executeAsSystem(callable)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/executeAsSystem_jdoc_hMHMo2o.png"&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;executeAsSystem2(Callable)&lt;/code&gt; is slightly different. It wraps the may thrown exception as &lt;code&gt;PersistencyException&lt;/code&gt;. Since &lt;code&gt;PersistencyException&lt;/code&gt; is also a &lt;code&gt;RuntimeException&lt;/code&gt;, this method does not require a catch block to handle exceptional cases.
&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/executAsSystem2_jdoc.png"&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Wed, 03 May 2017 02:45:30 -0400</pubDate><guid>https://answers.axonivy.com/questions/2603/what-is-different-among-ways-to-execute-as-system/2604</guid></item></channel></rss>