<!doctype html><htmllang=enclass="js csstransforms3d"><head><metacharset=utf-8><metaname=viewportcontent="width=device-width,initial-scale=1"><metaname=generatorcontent="Hugo 0.80.0"><metaname=descriptioncontent="Strolch is a parameterized framework for use on servers and IoT"><metaname=authorcontent="Strolch"><linkrel=iconhref=/favicon.icotype=image/ico><title>Queries - Strolch</title><linkhref=/css/nucleus.css?1626091328rel=stylesheet><linkhref=/css/fontawesome-all.min.css?1626091328rel=stylesheet><linkhref=/css/hybrid.css?1626091328rel=stylesheet><linkhref=/css/featherlight.min.css?1626091328rel=stylesheet><linkhref=/css/perfect-scrollbar.min.css?1626091328rel=stylesheet><linkhref=/css/auto-complete.css?1626091328rel=stylesheet><linkhref=/css/atom-one-dark-reasonable.css?1626091328rel=stylesheet><linkhref=/css/theme.css?1626091328rel=stylesheet><linkhref=/css/hugo-theme.css?1626091328rel=stylesheet><linkhref=/css/theme-green.css?1626091328rel=stylesheet><scriptsrc=/js/jquery-3.3.1.min.js?1626091328></script><style>:root#header+#content>#left>#rlblock_left{display:none!important}</style></head><bodydata-url=/documentation/queries/><navid=sidebar><divid=header-wrapper><divid=header><aid=logohref=/><imgsrc=/logo.png></a></div><divclass=searchbox><labelfor=search-by><iclass="fas fa-search"></i></label><inputdata-search-inputid=search-bytype=searchplaceholder=Search...>
parent"><ahref=/documentation/>Documentation</a><ul><lidata-nav-id=/documentation/architecture/title=Architectureclass=dd-item><ahref=/documentation/architecture/>Architecture</a></li><lidata-nav-id=/documentation/model/title=Modelclass=dd-item><ahref=/documentation/model/>Model</a></li><lidata-nav-id=/documentation/do-and-donts/title="Do and Don't"class=dd-item><ahref=/documentation/do-and-donts/>Do and Don't</a></li><lidata-nav-id=/documentation/runtime-configuration/title="Runtime Configuration"class=dd-item><ahref=/documentation/runtime-configuration/>Runtime Configuration</a></li><lidata-nav-id=/documentation/realms/title=Realmsclass=dd-item><ahref=/documentation/realms/>Realms</a></li><lidata-nav-id=/documentation/components/title=Componentsclass=dd-item><ahref=/documentation/components/>Components</a></li><lidata-nav-id=/documentation/services-and-commands/title="Services and Commands"class=dd-item><ahref=/documentation/services-and-commands/>Services and Commands</a></li><lidata-nav-id=/documentation/searches/title=Searchesclass=dd-item><ahref=/documentation/searches/>Searches</a></li><lidata-nav-id=/documentation/queries/title=Queriesclass="dd-item active"><ahref=/documentation/queries/>Queries</a></li><lidata-nav-id=/documentation/transactions/title=Transactionsclass=dd-item><ahref=/documentation/transactions/>Transactions</a></li><lidata-nav-id=/documentation/policies/title=Policiesclass=dd-item><ahref=/documentation/policies/>Policies</a></li><lidata-nav-id=/documentation/observers/title=Observersclass=dd-item><ahref=/documentation/observers/>Observers</a></li><lidata-nav-id=/documentation/versioning/title=Versioningclass=dd-item><ahref=/documentation/versioning/>Versioning</a></li><lidata-nav-id=/documentation/reports/title=Reportsclass=dd-item><ahref=/documentation/reports/>Reports</a></li><lidata-nav-id=/documentation/priviles/title=Privilegesclass=dd-item><ahref=/documentation/priviles/>Privileges</a></li></ul></li><lidata-nav-id=/plc/title=PLCclass=dd-item><ahref=/plc/>PLC</a><ul><lidata-nav-id=/plc/architecture/title=Architectureclass=dd-item><ahref=/plc/architecture/>Architecture</a></li><lidata-nav-id=/plc/example-set-up/title="Example Set-Up"class=dd-item><ahref=/plc/example-set-up/>Example Set-Up</a></li></ul></li><lidata-nav-id=/tutorial/title=Tutorialclass=dd-item><ahref=/tutorial/>Tutorial</a><ul><lidata-nav-id=/tutorial/configuration/title=Configurationclass=dd-item><ahref=/tutorial/configuration/>Configuration</a></li><lidata-nav-id=/tutorial/model/title=Modelclass=dd-item><ahref=/tutorial/model/>Model</a></li><lidata-nav-id=/tutorial/crud-book/title="CRUD Book"class=dd-item><ahref=/tutorial/crud-book/>CRUD Book</a></li></ul></li><lidata-nav-id=/download/title=Downloadclass=dd-item><ahref=/download/>Download</a></li><lidata-nav-id=/development/title=Developmentclass=dd-item><ahref=/development/>Development</a></li></ul><sectionid=shortcuts><h3>More</h3><ul><li><aclass=paddinghref=https://strolch.li/tags><iclass="fas fa-tags"></i>Tags</a></li><li><aclass=paddinghref=https://github.com/strolch-li><iclass="fab fa-github"></i>GitHub project</a></li></ul></section><sectionid=footer><p>Built with <ahref=https://github.com/matcornic/hugo-theme-learn><iclass="fas fa-heart"></i></a>from <ahref=https://getgrav.org>Grav</a> and <ahref=https://gohugo.io/>Hugo</a></p></section></div></nav><sectionid=body><divid=overlay></div><divclass="padding highlightable"><div><divid=top-bar><divid=top-github-link><aclass=github-linktitle="Edit this page"href=https://github.com/Pi4J/pi4j.github.io/tree/main/contentdocumentation/queries.mdtarget=blank><iclass="fas fa-code-branch"></i><spanid=top-github-link-text>Edit this page</span></a></div><divid=breadcrumbsitemscopeitemtype=http://data-vocabulary.org/Breadcrumb><spanid=sidebar-toggle-span><ahref=#id=sidebar-toggledata-sidebar-toggle><iclass="fas fa-bars"></i></a></span><spanid=toc-menu><iclass="fas fa-list-alt"></i></span><spanclass=links
queries are implemented using the <code>StrolchQuery</code> interface and one of its concrete
implementations: <code>ResourceQuery</code>, <code>OrderQuery</code>, <code>ActivityQuery</code>.</p><p>A Strolch element always has two identifiers: <code>Type</code> and <code>Id</code>. The type is important
as it classifies an element. So if a car and a house would be modelled in
Strolch, then those would both be a <code>Resource</code>, but one of type <code>Car</code> and the other
of type <code>House</code>. Both would have different parameters.</p><p>Thus one of the inputs for every query is it’s type, which is defined as the
navigation. It is said that we navigate to the Cars, or Houses. Thus when
instantiating a ResourceQuery, pass the navigation to the type of Resource as
well. Same applies for Orders and Activities.</p><p>Further input for a StrolchQuery are the selections. These selections get
translated into RDBMS <code>WHERE</code> clauses. Selections support boolean operations thus
allowing for complex querying.</p><p>StrolchQueries also support Ordering and object transformation. Following
classes provide the most used scenarios:</p><ul><li>OrderById</li><li>OrderByName</li><li>OrderByParameter</li><li>*ToDomVisitor</li><li>*ToSaxVisitor</li><li>*ToJsonVisitor</li><li>*ToFlatJsonVisitor</li></ul><p>Example: Query all resources of type Car:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>Example: Query all resources of type Car, order by Name and transform to JSON:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>the previous example can also be written as follows:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>Example: Query all resources of type Car with color blue:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>Example: Query all resources of type Car which are not blue:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>Example: Query all resources of type Car with color blue or yellow:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>
</code></pre></div><p>Example: Query all resources of type Car with color blue or yellow owned by Jill:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>try</span><spanstyle=color:#f92672>(</span>StrolchTransaction tx <spanstyle=color:#f92672>=</span> openTx<spanstyle=color:#f92672>())</span><spanstyle=color:#f92672>{</span>