202 lines
8.1 KiB
HTML
202 lines
8.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="google-site-verification" content="CPhbjooaiTdROm7Vs4E7kuHZvBfkeLUtonGgcVUbTL8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="description" content="">
|
|
<meta name="author" content="">
|
|
<link rel="shortcut icon" href="ico/favicon.ico">
|
|
|
|
<title>Strolch: Queries</title>
|
|
|
|
<!-- Bootstrap core CSS -->
|
|
<link href="css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
<!-- Custom styles for this template -->
|
|
<link href="css/custom.css" rel="stylesheet">
|
|
|
|
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --><!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
|
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]-->
|
|
</head>
|
|
<body>
|
|
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<a class="navbar-brand" href="index.html">Strolch</a>
|
|
</div>
|
|
<div class="collapse navbar-collapse">
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="index.html">Overview</a></li>
|
|
<li><a href="api.html">API</a></li>
|
|
<li class="active"><a href="documentation.html">Documentation</a></li>
|
|
<li><a href="tutorial.html">Tutorial</a></li>
|
|
<li><a href="downloads.html">Downloads</a></li>
|
|
<li><a href="development.html">Development</a></li>
|
|
<li><a href="blog.html">Blog</a></li>
|
|
</ul>
|
|
</div>
|
|
<!--/.nav-collapse -->
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
|
|
<div class="page-header">
|
|
<h1 class="page-title">Documentation: Queries</h1>
|
|
<p class="lead page-description">This page discusses Strolch Queries.</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
|
|
<p class="lead"><b>The Query API is deprecated and the search API should be used instead.</b>
|
|
</p>
|
|
|
|
<p>As is custom for every framework, querying the model must be possible. Strolch 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><code>OrderById</code></li>
|
|
<li><code>OrderByName</code></li>
|
|
<li><code>OrderByParameter</code></li>
|
|
<li><code>*ToDomVisitor</code></li>
|
|
<li><code>*ToSaxVisitor</code></li>
|
|
<li><code>*ToJsonVisitor</code></li>
|
|
<li><code>*ToFlatJsonVisitor</code></li>
|
|
</ul>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<Resource> query = ResourceQuery.query("Car");
|
|
query.withAny();
|
|
List<Resource> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car, order by Name and transform to JSON:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<JsonObject> query = ResourceQuery.query("Car", new ResourceToJsonVisitor(),
|
|
new OrderByName());
|
|
query.withAny();
|
|
List<JsonObject> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>the previous example can also be written as follows:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<JsonObject> query = new ResourceQuery<>();
|
|
query.setNavigation(new StrolchTypeNavigation("Car"));
|
|
query.setResourceVisitor(new ResourceToJsonVisitor());
|
|
query.withAny();
|
|
List<JsonObject> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car with color blue:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<Resource> query = ResourceQuery.query("Car");
|
|
query.with(ParameterSelection.stringSelection("parameters", "color", "blue", StringMatchMode.es()));
|
|
List<Resource> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car which are not blue:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<Resource> query = ResourceQuery.query("Car");
|
|
query.not(ParameterSelection.stringSelection("parameters", "color", "blue", StringMatchMode.es()));
|
|
List<Resource> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car with color blue or yellow:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<Resource> query = ResourceQuery.query("Car");
|
|
query.or().with(
|
|
ParameterSelection.stringSelection("parameters", "color", "blue", StringMatchMode.es()),
|
|
ParameterSelection.stringSelection("parameters", "color", "yellow", StringMatchMode.es()));
|
|
List<Resource> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<br />
|
|
<p>Example: Query all resources of type Car with color blue or yellow owned by Jill:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = openTx()) {
|
|
ResourceQuery<Resource> query = ResourceQuery.query("Car");
|
|
|
|
StringParameterSelection owner = ParameterSelection.stringSelection("parameters", "owner", "Jill", StringMatchMode.es());
|
|
OrSelection colors = new OrSelection().with(
|
|
ParameterSelection.stringSelection("parameters", "color", "blue", StringMatchMode.es()),
|
|
ParameterSelection.stringSelection("parameters", "color", "yellow", StringMatchMode.es()));
|
|
|
|
query.and().with(owner, colors);
|
|
|
|
List<Resource> cars = tx.doQuery(query);
|
|
}</pre>
|
|
|
|
<!-- content here -->
|
|
|
|
</div>
|
|
<!-- /.content -->
|
|
|
|
<div id="footer">
|
|
<div class="container">
|
|
<p class="text-muted">© Strolch / <a href="mailto:eitch@eitchnet.ch">Robert von Burg</a> / Hosting by
|
|
<a href="http://www.eitchnet.ch">eitchnet.ch</a></p>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<!-- /.container -->
|
|
|
|
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
|
|
<!-- Include all compiled plugins (below), or include individual xsd as needed -->
|
|
<script src="js/bootstrap.min.js"></script>
|
|
|
|
<!-- Piwik -->
|
|
<script type="text/javascript">
|
|
var _paq = _paq || [];
|
|
_paq.push(['trackPageView']);
|
|
_paq.push(['enableLinkTracking']);
|
|
(function () {
|
|
var u = (("https:" == document.location.protocol) ? "https" : "http") + "://piwik.eitchnet.ch/";
|
|
_paq.push(['setTrackerUrl', u + 'piwik.php']);
|
|
_paq.push(['setSiteId', 2]);
|
|
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
|
|
g.type = 'text/javascript';
|
|
g.defer = true;
|
|
g.async = true;
|
|
g.src = u + 'piwik.js';
|
|
s.parentNode.insertBefore(g, s);
|
|
})();
|
|
</script>
|
|
<noscript><p><img src="http://piwik.eitchnet.ch/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
|
|
<!-- End Piwik Code -->
|
|
|
|
</body>
|
|
</html>
|