blob: 75be36be5508f4e710035c0f102f32525af38ffc [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>IsisJdoSupport :: Apache Isis</title>
<link rel="canonical" href="https://isis.apache.org/pjdo/2.0.0-M3/services/IsisJdoSupport.html">
<meta name="generator" content="Antora 2.2.0">
<link rel="stylesheet" href="../../../_/css/site.css">
<link rel="stylesheet" href="../../../_/css/site-custom.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i|Raleway:300,400,500,700,800|Montserrat:300,400,700" rel="stylesheet">
<link rel="home" href="https://isis.apache.org" title="Apache Isis">
<link rel="prev" href="../hints-and-tips.html" title="Hints-n-Tips">
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://isis.apache.org">
<span class="icon">
<img src="../../../_/img/isis-logo-48x48.png"></img>
</span>
<span>Apache Isis</span>
</a>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<a class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Quick Start</a>
<div class="navbar-dropdown">
<span class="navbar-item navbar-heading">Starter Apps</span>
<a class="navbar-item" href="../../../docs/latest/starters/helloworld.html">Hello World</a>
<a class="navbar-item" href="../../../docs/latest/starters/simpleapp.html">Simple App</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Demos &amp; Tutorials</span>
<a class="navbar-item" href="../../../docs/latest/demo/about.html">Demo App</a>
<a class="navbar-item" href="https://danhaywood.gitlab.io/isis-petclinic-tutorial-docs/petclinic/1.16.2/intro.html">Petclinic (tutorial)</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Resources</span>
<a class="navbar-item" href="../../../docs/latest/resources/cheatsheet.html">Cheatsheet</a>
<a class="navbar-item" href="../../../docs/latest/resources/icons.html">Icons</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Guides</a>
<div class="navbar-dropdown">
<span class="navbar-item navbar-heading">Development</span>
<a class="navbar-item" href="../../../setupguide/latest/about.html">Setup Guide</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Core</span>
<a class="navbar-item" href="../../../userguide/latest/about.html">User Guide</a>
<a class="navbar-item" href="../../../refguide/latest/about.html">Reference Guide</a>
<a class="navbar-item" href="../../../testing/latest/about.html">Testing Guide</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Libraries</a>
<div class="navbar-dropdown">
<span class="navbar-item navbar-heading">For Use in Apps</span>
<a class="navbar-item" href="../../../subdomains/latest/about.html">Subdomain Libraries</a>
<a class="navbar-item" href="../../../valuetypes/latest/about.html">Value Types</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Integrate between Apps</span>
<a class="navbar-item" href="../../../mappings/latest/about.html">Bounded Context Mapping Libraries</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Other</span>
<a class="navbar-item" href="../../../incubator/latest/about.html">Incubator</a>
<a class="navbar-item" href="../../../legacy/latest/about.html">Legacy</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Components</a>
<div class="navbar-dropdown">
<span class="navbar-item navbar-heading">Viewers</span>
<a class="navbar-item" href="../../../vw/latest/about.html">Wicket UI</a>
<a class="navbar-item" href="../../../vro/latest/about.html">Restful Objects (REST)</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Security</span>
<a class="navbar-item" href="../../../security/latest/about.html">Security Guide</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Persistence</span>
<a class="navbar-item" href="../../../pjdo/latest/about.html">DataNucleus (JDO)</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Extensions</span>
<a class="navbar-item" href="../../../extensions/latest/about.html">Extensions Catalog</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Support</a>
<div class="navbar-dropdown">
<span class="navbar-item navbar-heading">Contact</span>
<a class="navbar-item" href="../../../docs/latest/support/slack-channel.html">Slack</a>
<a class="navbar-item" href="../../../docs/latest/support/mailing-list.html">Mailing Lists</a>
<a class="navbar-item" href="https://issues.apache.org/jira/browse/ISIS">JIRA</a>
<a class="navbar-item" href="https://stackoverflow.com/questions/tagged/isis">Stack Overflow</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Releases</span>
<a class="navbar-item" href="../../../docs/latest/downloads/how-to.html">Downloads</a>
<a class="navbar-item" href="../../../relnotes/latest/about.html">Release Notes</a>
<a class="navbar-item" href="../../../docs/latest/archive/1-x.html">Archive (1.x)</a>
<hr class="navbar-divider"/>
<span class="navbar-item navbar-heading">Framework</span>
<a class="navbar-item" href="../../../conguide/latest/about.html">Contributors' Guide</a>
<a class="navbar-item" href="../../../comguide/latest/about.html">Committers' Guide</a>
<a class="navbar-item" href="../../../core/latest/about.html">Core Design</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">ASF</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="http://www.apache.org/">Apache Homepage</a>
<a class="navbar-item" href="https://www.apache.org/events/current-event">Events</a>
<a class="navbar-item" href="https://www.apache.org/licenses/">Licenses</a>
<a class="navbar-item" href="https://www.apache.org/security/">Security</a>
<a class="navbar-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a>
<a class="navbar-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a>
<hr class="navbar-divider"/>
<a class="navbar-item" href="https://whimsy.apache.org/board/minutes/Isis.html">PMC board minutes</a>
</div>
</div>
<a class="navbar-item" href="../../../docs/latest/about.html">
<span class="icon">
<img src="../../../_/img/home.png"></img>
</span>
</a>
</div>
</div>
</nav>
</header>
<div class="body ">
<div class="nav-container" data-component="pjdo" data-version="2.0.0-M3">
<aside class="nav">
<div class="panels">
<div class="nav-panel-pagination">
<a class="page-previous" rel="prev" href="../hints-and-tips.html" title="Hints-n-Tips"><span></span></a>
<a class="page-next disabled" rel="next"
href="" title=""><span></span></a>
<!--
page.parent doesn't seem to be set...
<a class="page-parent disabled" rel="prev" href="" title="Hints-n-Tips"><span></span></a>
-->
</div>
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="../about.html">JDO/DataNucleus</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../configuring.html">Configuring</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../jdo-mappings.html">JDO Mappings</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../db-schemas.html">DB Schemas</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../hints-and-tips.html">Hints-n-Tips</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Domain Services</span>
<ul class="nav-list">
<li class="nav-item is-current-page" data-depth="2">
<a class="nav-link" href="IsisJdoSupport.html">IsisJdoSupport</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">JDO/DataNucleus</span>
<span class="version">2.0.0-M3</span>
</div>
<ul class="components">
<li class="component">
<span class="title"> </span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../docs/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">BC Mappings Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../mappings/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Committers' Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../comguide/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Contributors' Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../conguide/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Design Docs</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../core/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Extensions Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../extensions/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Incubator Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../incubator/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component is-current">
<span class="title">JDO/DataNucleus</span>
<ul class="versions">
<li class="version is-current is-latest">
<a href="../about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Legacy Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../legacy/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Reference Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../refguide/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Release Notes</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../relnotes/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Restful Objects Viewer</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../vro/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Security Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../security/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Setup Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../setupguide/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Subdomains Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../subdomains/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Testing Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../testing/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">User Guide</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../userguide/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Value Types Catalog</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../valuetypes/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
<li class="component">
<span class="title">Wicket Viewer</span>
<ul class="versions">
<li class="version is-latest">
<a href="../../../vw/2.0.0-M3/about.html">2.0.0-M3</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main role="main">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<a href="../../../docs/2.0.0-M3/about.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="../about.html">JDO/DataNucleus</a></li>
<li>Domain Services</li>
<li><a href="IsisJdoSupport.html">IsisJdoSupport</a></li>
</ul>
</nav>
<div class="edit-this-page"><a href="https://github.com/apache/isis/edit/2.0.0-M3/persistence/jdo/adoc/modules/ROOT/pages/services/IsisJdoSupport.adoc">Edit</a></div>
</div>
<article class="doc">
<a name="section-top"></a>
<h1 class="page"><code>IsisJdoSupport</code></h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>The <code>IsisJdoSupport</code> service provides a number of general purpose methods for working with the JDO/DataNucleus objectstore.
In general these act at a lower-level of abstraction than the APIs normally used (specifically, those of <a href="../../../refguide/2.0.0-M3/applib-svc/RepositoryService.html" class="page"><code>RepositoryService</code></a>), but nevertheless deal with some of the most common use cases.
For service also provides access to the underlying JDO <code>PersistenceManager</code> for full control.</p>
</div>
<div class="paragraph">
<p>The following sections discuss the functionality provided by the service, broken out into categories.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="executing-sql"><a class="anchor" href="#executing-sql"></a>Executing SQL</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can use the <code>IsisJdoSupportService</code> to perform arbitrary SQL SELECTs or UPDATEs:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface IsisJdoSupport {
@Programmatic
List&lt;Map&lt;String, Object&gt;&gt; executeSql(String sql);
@Programmatic
Integer executeUpdate(String sql);
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>executeSql(&#8230;&#8203;)</code> method allows arbitrary SQL <code>SELECT</code> queries to be submitted:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">List&lt;Map&lt;String, Object&gt;&gt; results = isisJdoSupport.executeSql("select * from custMgmt.customers");</code></pre>
</div>
</div>
<div class="paragraph">
<p>The result set is automatically converted into a list of maps, where the map key is the column name.</p>
</div>
<div class="paragraph">
<p>In a similar manner, the <code>executeUpdate(&#8230;&#8203;)</code> allows arbitrary SQL <code>UPDATE</code>s to be performed.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">int count = isisJdoSupport.executeUpdate("select count(*) from custMgmt.customers);</code></pre>
</div>
</div>
<div class="paragraph">
<p>The returned value is the number of rows updated.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>As an alternative, consider using DataNucleus' <a href="http://www.datanucleus.org/products/accessplatform_4_0/jdo/jdoql_typesafe.html">type-safe JDO query API</a>, discussed <a href="#type-safe-query-api">below</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="type-safe-jdoql-queries"><a class="anchor" href="#type-safe-jdoql-queries"></a>Type-safe JDOQL Queries</h2>
<div class="sectionbody">
<div class="paragraph">
<p>DataNucleus provides an <a href="http://www.datanucleus.org/products/accessplatform_4_0/jdo/jdoql_typesafe.html">extension to JDO</a>, so that JDOQL queries can be built up and executed using a set of type-safe classes.</p>
</div>
<div class="paragraph">
<p>The types in question for type safe queries are not the domain entities, but rather are companion "Q&#8230;&#8203;" query classes.
These classes are generated dynamically by an <a href="https://www.jcp.org/en/jsr/detail?id=269">annotation processor</a> as a side-effect of compilation, one "Q&#8230;&#8203;" class for each of the <a href="../../../refguide/2.0.0-M3/applib-ant/PersistenceCapable.html" class="page"><code>@PersistenceCapable</code></a> domain entity in your application.
For example, a <code>ToDoItem</code> domain entity will give rise to a <code>QToDoItem</code> query class.
These "Q&#8230;&#8203;" classes mirror the structure of domain entity, but expose properties that allow predicates to be built up for querying instances, as well as other functions in support of order by, group by and other clauses.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The IntelliJ IDE automatically enables annotation processing by default, as does Maven.
Using Eclipse IDE you may need to configure annotation processing manually; see the <a href="../../../setupguide/2.0.0-M3/eclipse/about.html#enable-annotation-processing" class="page">Setup Guide</a>.
The DataNucleus' <a href="http://www.datanucleus.org/products/accessplatform_4_0/jdo/jdoql_typesafe.html">documentation</a> offers some guidance on confirming that APT is enabled.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>IsisJdoSupport</code> service offers two methods at different levels of abstraction:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface IsisJdoSupport {
@Programmatic
&lt;T&gt; List&lt;T&gt; executeQuery(final Class&lt;T&gt; cls, final BooleanExpression be);
@Programmatic
&lt;T&gt; T executeQueryUnique(final Class&lt;T&gt; cls, final BooleanExpression be);
@Programmatic
&lt;T&gt; TypesafeQuery&lt;T&gt; newTypesafeQuery(Class&lt;T&gt; cls);
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>executeQuery(&#8230;&#8203;)</code> method supports the common case of obtaining a set of objects that meet some criteria, filtered using the provided <code>BooleanExpression</code>.
To avoid memory leaks, the returned list is cloned and the underlying query closed.</p>
</div>
<div class="paragraph">
<p>For example, consider an implementation of <code>ToDoItemRepository</code> using type-safe queries.
The following JDOQL:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-sql hljs" data-lang="sql">SELECT
FROM todoapp.dom.module.todoitem.ToDoItem
WHERE atPath.indexOf(:atPath) == 0
&amp;&amp; complete == :complete")</code></pre>
</div>
</div>
<div class="paragraph">
<p>can be expressed using type-safe queries as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public List&lt;ToDoItem&gt; findByAtPathAndCategory(final String atPath, final Category category) {
final QToDoItem q = QToDoItem.candidate();
return isisJdoSupport.executeQuery(ToDoItem.class,
q.atPath.eq(atPath).and(
q.category.eq(category)));
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You can find the full example of the JDOQL equivalent in the <a href="../../../refguide/2.0.0-M3/applib-svc/RepositoryService.html" class="page"><code>RepositoryService</code></a></p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>executeUniqueQuery(&#8230;&#8203;)</code> method is similar to <code>executeQuery(&#8230;&#8203;)</code>, however expects the query to return at most a single object, which it returns (or <code>null</code> if none).</p>
</div>
<div class="paragraph">
<p>The <code>newTypesafeQuery(&#8230;&#8203;)</code> method is a lower-level API that allows a type safe query to be instantiated for most sophisticated querying, eg using group by or order by clauses.
See the DataNucleus <a href="http://www.datanucleus.org/products/accessplatform_4_0/jdo/jdoql_typesafe.html">documentation</a> for full details of using this.</p>
</div>
<div class="paragraph">
<p>One thing to be aware of is that after the query has been executed, it should be closed, using <code>query.closeAll()</code>.
If calling <code>query.executeList()</code> we also recommend cloning the resultant list first.
The following utility method does both of these tasks:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">private static &lt;T&gt; List&lt;T&gt; executeListAndClose(final TypesafeQuery&lt;T&gt; query) {
final List&lt;T&gt; elements = query.executeList();
final List&lt;T&gt; list = Lists.newArrayList(elements);
query.closeAll();
return list;
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="fixture-support"><a class="anchor" href="#fixture-support"></a>Fixture support</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When writing <a href="../../../testing/2.0.0-M3/integtestsupport/about.html" class="page">integration tests</a> you&#8217;ll usually need to tear down some/all mutable transactional data before each test.
One way to do that is to use the <code>executeUpdate(&#8230;&#8203;)</code> method described <a href="#executing-sql">above</a>.</p>
</div>
<div class="paragraph">
<p>Alternatively, the <code>deleteAll(&#8230;&#8203;)</code> method will let your test delete all instances of a class without resorting to SQL:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface IsisJdoSupport {
void deleteAll(Class&lt;?&gt;... pcClasses);
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class TearDownAll extends FixtureScriptAbstract {
@Override
protected void execute(final ExecutionContext ec) {
isisJdoSupport.deleteAll(Order.class);
isisJdoSupport.deleteAll(CustomerAddress.class);
isisJdoSupport.deleteAll(Customer.class);
}
@Inject
IsisJdoSupport isisJdoSupport;
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>It can occasionally be the case that Apache Isis' internal adapter for the domain object is still in memory.
JDO/DataNucleus seems to bump up the version of the object prior to its deletion, which under normal circumstances would cause Apache Isis to throw a concurrency exception.
Therefore to prevent this from happening (ie to <em>force</em> the deletion of all instances), concurrency checking is temporarily disabled while this method is performed.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="reloading-entities"><a class="anchor" href="#reloading-entities"></a>Reloading entities</h2>
<div class="sectionbody">
<div class="paragraph">
<p>An <a href="http://www.datanucleus.org:15080/products/accessplatform_5_0/jdo/mapping.html#one_many_relations">(intentional) limitation</a> of JDO/DataNucleus is that persisting a child entity (in a 1:n bidirectional relationship) does not cause the parent&#8217;s collection to be updated.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface IsisJdoSupport {
&lt;T&gt; T refresh(T domainObject);
void ensureLoaded(Collection&lt;?&gt; collectionOfDomainObjects);
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>refresh(T domainObject)</code> method can be used to reload the parent object (or indeed any object).
Under the covers it uses the JDO <code>PersistenceManager#refresh(&#8230;&#8203;)</code> API.</p>
</div>
<div class="paragraph">
<p>The <code>ensureLoaded(&#8230;&#8203;)</code> method allows a collection of domain objects to be loaded from the database in a single hit.
This can be valuable as a performance optimization to avoid multiple roundtrips to the database.
Under the covers it uses the <code>PersistenceManager#retrieveAll(&#8230;&#8203;)</code> API.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="jdo-persistencemanager"><a class="anchor" href="#jdo-persistencemanager"></a>JDO <code>PersistenceManager</code></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The functionality provided by <code>IsisJdoSupport</code> focus only on the most common use cases.
If you require more flexibility than this, eg for dynamically constructed queries, then you can use the service to access the underlying JDO <code>PersistenceManager</code> API:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface IsisJdoSupport {
@Programmatic
PersistenceManager getJdoPersistenceManager();
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class Orders {
public List&lt;Order&gt; findOrders( /* ... */ ) {
javax.jdo.PersistenceManager pm = isisJdoSupport.getPersistenceManager();
...
return someListOfOrders;
}
@Inject
IsisJdoSupport isisJdoSupport;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>TODO: v2: IsisJdoSupport_v3_2</p>
</div>
</div>
</div>
</article>
<aside class="article-aside toc" role="navigation">
<p class="toc-title">On this page</p>
<div id="article-toc"></div>
</aside>
</main>
</div>
<footer class="footer">
<div class="content">
<div class="copyright">
<p>
Copyright © 2010~2020 The Apache Software Foundation, licensed under the Apache License, v2.0.
<br/>
Apache, the Apache feather logo, Apache Isis, and the Apache Isis project logo are all trademarks of The Apache Software Foundation.
</p>
</div>
<div class="revision">
<p>Revision: SNAPSHOT</p>
</div>
</div>
</footer>
<script src="../../../_/js/site.js"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
<script src="../../../_/js/vendor/jquery-3.4.1.min.js"></script>
<script src="../../../_/js/vendor/jquery-ui-1.12.1.custom.widget-only.min.js"></script>
<script src="../../../_/js/vendor/jquery.tocify.min.js"></script>
<script>
$(function() {
$("#article-toc").tocify( {
showEffect: "slideDown",
hashGenerator: "pretty",
hideEffect: "slideUp",
selectors: "h2, h3",
scrollTo: 120,
smoothScroll: true,
theme: "jqueryui",
highlightOnScroll: true
} );
});
</script>
</body>
</html>