org.mule.module.jpa.command.Query.java Source code

Java tutorial

Introduction

Here is the source code for org.mule.module.jpa.command.Query.java

Source

/**
 *
 *
 *
 * <!DOCTYPE html>
 * <html>
 *   <head>
 *     <meta charset='utf-8'>
 *     <meta http-equiv="X-UA-Compatible" content="IE=edge">
 *         <title>LICENSE_HEADER.txt at master from mulesoft/mongo-connector - GitHub</title>
 *     <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
 *     <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub" />
 *
 *
 *
 *
 *     <meta content="authenticity_token" name="csrf-param" />
 * <meta content="T42cQ8rsmP0zdGpjeiQdNdXtRZz5jTF84a9vffF0mGc=" name="csrf-token" />
 *
 *     <link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-3a4af5bff8824b8813507ee46b062db917fd7a4b.css" media="screen" rel="stylesheet" type="text/css" />
 *     <link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-dd77b20d63df63993a44b1db3e3ed3daeb33b4bd.css" media="screen" rel="stylesheet" type="text/css" />
 *
 *
 *     <script src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/jquery-1e75833f765514d7e7efe0099020c2ad4ff15e5b.js" type="text/javascript"></script>
 *     <script src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/github-f3512ee4bf6c871bcfebe3f14bc225f08f7f7328.js" type="text/javascript"></script>
 *
 *
 *       <link rel='permalink' href='/mulesoft/mongo-connector/blob/8e7d08d7da221425154e37b28dfa2a59046724e5/LICENSE_HEADER.txt'>
 *
 *     <meta name="description" content="mongo-connector - MongoDB Connector for Mule" />
 *   <link href="https://github.com/mulesoft/mongo-connector/commits/master.atom" rel="alternate" title="Recent Commits to mongo-connector:master" type="application/atom+xml" />
 *
 *   </head>
 *
 *
 *   <body class="logged_out page-blob  vis-public env-production ">
 *
 *
 *
 *
 *
 *       <div id="header" class="true clearfix">
 *         <div class="container clearfix">
 *           <a class="site-logo" href="https://github.com">
 *             <!--[if IE]>
 *             <img alt="GitHub" class="github-logo" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7.png?1323882716" />
 *             <img alt="GitHub" class="github-logo-hover" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7-hover.png?1324325358" />
 *             <![endif]-->
 *             <img alt="GitHub" class="github-logo-4x" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x.png?1323882716" />
 *             <img alt="GitHub" class="github-logo-4x-hover" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x-hover.png?1324325358" />
 *           </a>
 *
 *                   <!--
 *       make sure to use fully qualified URLs here since this nav
 *       is used on error pages on other domains
 *     -->
 *     <ul class="top-nav logged_out">
 *         <li class="pricing"><a href="https://github.com/plans">Signup and Pricing</a></li>
 *         <li class="explore"><a href="https://github.com/explore">Explore GitHub</a></li>
 *       <li class="features"><a href="https://github.com/features">Features</a></li>
 *         <li class="blog"><a href="https://github.com/blog">Blog</a></li>
 *       <li class="login"><a href="https://github.com/login?return_to=%2Fmulesoft%2Fmongo-connector%2Fblob%2Fmaster%2FLICENSE_HEADER.txt">Login</a></li>
 *     </ul>
 *
 *
 *
 *
 *         </div>
 *       </div>
 *
 *
 *
 *             <div class="site">
 *       <div class="container">
 *         <div class="pagehead repohead instapaper_ignore readability-menu">
 *
 *
 *         <div class="title-actions-bar">
 *           <h1>
 *             <a href="/mulesoft">mulesoft</a> /
 *             <strong><a href="/mulesoft/mongo-connector" class="js-current-repository">mongo-connector</a></strong>
 *           </h1>
 *
 *
 *
 *
 *               <ul class="pagehead-actions">
 *
 *
 *           <li><a href="/login?return_to=%2Fmulesoft%2Fmongo-connector" class="minibutton btn-watch watch-button entice tooltipped leftwards" rel="nofollow" title="You must be logged in to use this feature"><span><span class="icon"></span>Watch</span></a></li>
 *           <li><a href="/login?return_to=%2Fmulesoft%2Fmongo-connector" class="minibutton btn-fork fork-button entice tooltipped leftwards" rel="nofollow" title="You must be logged in to use this feature"><span><span class="icon"></span>Fork</span></a></li>
 *
 *
 *       <li class="repostats">
 *         <ul class="repo-stats">
 *           <li class="watchers ">
 *             <a href="/mulesoft/mongo-connector/watchers" title="Watchers" class="tooltipped downwards">
 *               10
 *             </a>
 *           </li>
 *           <li class="forks">
 *             <a href="/mulesoft/mongo-connector/network" title="Forks" class="tooltipped downwards">
 *               4
 *             </a>
 *           </li>
 *         </ul>
 *       </li>
 *     </ul>
 *
 *         </div>
 *
 *
 *
 *   <ul class="tabs">
 *     <li><a href="/mulesoft/mongo-connector" class="selected" highlight="repo_sourcerepo_downloadsrepo_commitsrepo_tagsrepo_branches">Code</a></li>
 *     <li><a href="/mulesoft/mongo-connector/network" highlight="repo_networkrepo_fork_queue">Network</a>
 *     <li><a href="/mulesoft/mongo-connector/pulls" highlight="repo_pulls">Pull Requests <span class='counter'>1</span></a></li>
 *
 *       <li><a href="/mulesoft/mongo-connector/issues" highlight="repo_issues">Issues <span class='counter'>6</span></a></li>
 *
 *
 *     <li><a href="/mulesoft/mongo-connector/graphs" highlight="repo_graphsrepo_contributors">Stats &amp; Graphs</a></li>
 *
 *   </ul>
 *
 *
 * <div class="frame frame-center tree-finder" style="display:none"
 *       data-tree-list-url="/mulesoft/mongo-connector/tree-list/8e7d08d7da221425154e37b28dfa2a59046724e5"
 *       data-blob-url-prefix="/mulesoft/mongo-connector/blob/8e7d08d7da221425154e37b28dfa2a59046724e5"
 *     >
 *
 *   <div class="breadcrumb">
 *     <b><a href="/mulesoft/mongo-connector">mongo-connector</a></b> /
 *     <input class="tree-finder-input js-navigation-enable" type="text" name="query" autocomplete="off" spellcheck="false">
 *   </div>
 *
 *     <div class="octotip">
 *       <p>
 *         <a href="/mulesoft/mongo-connector/dismiss-tree-finder-help" class="dismiss js-dismiss-tree-list-help" title="Hide this notice forever" rel="nofollow">Dismiss</a>
 *         <strong>Octotip:</strong> You've activated the <em>file finder</em>
 *         by pressing <span class="kbd">t</span> Start typing to filter the
 *         file list. Use <span class="kbd badmono"></span> and
 *         <span class="kbd badmono"></span> to navigate,
 *         <span class="kbd">enter</span> to view files.
 *       </p>
 *     </div>
 *
 *   <table class="tree-browser" cellpadding="0" cellspacing="0">
 *     <tr class="js-header"><th>&nbsp;</th><th>name</th></tr>
 *     <tr class="js-no-results no-results" style="display: none">
 *       <th colspan="2">No matching files</th>
 *     </tr>
 *     <tbody class="js-results-list js-navigation-container">
 *     </tbody>
 *   </table>
 * </div>
 *
 * <div id="jump-to-line" style="display:none">
 *   <h2>Jump to Line</h2>
 *   <form>
 *     <input class="textfield" type="text">
 *     <div class="full-button">
 *       <button type="submit" class="classy">
 *         <span>Go</span>
 *       </button>
 *     </div>
 *   </form>
 * </div>
 *
 *
 * <div class="subnav-bar">
 *
 *   <ul class="actions subnav">
 *     <li><a href="/mulesoft/mongo-connector/tags" class="" highlight="repo_tags">Tags <span class="counter">6</span></a></li>
 *     <li><a href="/mulesoft/mongo-connector/downloads" class="blank downloads-blank" highlight="repo_downloads">Downloads <span class="counter">0</span></a></li>
 *
 *   </ul>
 *
 *   <ul class="scope">
 *     <li class="switcher">
 *
 *       <div class="context-menu-container js-menu-container">
 *         <a href="#"
 *            class="minibutton bigger switcher js-menu-target js-commitish-button btn-branch repo-tree"
 *            data-master-branch="master"
 *            data-ref="master">
 *           <span><span class="icon"></span><i>branch:</i> master</span>
 *         </a>
 *
 *         <div class="context-pane commitish-context js-menu-content">
 *           <a href="javascript:;" class="close js-menu-close"></a>
 *           <div class="context-title">Switch Branches/Tags</div>
 *           <div class="context-body pane-selector commitish-selector js-filterable-commitishes">
 *             <div class="filterbar">
 *               <div class="placeholder-field js-placeholder-field">
 *                 <label class="placeholder" for="context-commitish-filter-field" data-placeholder-mode="sticky">Filter branches/tags</label>
 *                 <input type="text" id="context-commitish-filter-field" class="commitish-filter" />
 *               </div>
 *
 *               <ul class="tabs">
 *                 <li><a href="#" data-filter="branches" class="selected">Branches</a></li>
 *                 <li><a href="#" data-filter="tags">Tags</a></li>
 *               </ul>
 *             </div>
 *
 *               <div class="commitish-item branch-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/gh-pages/LICENSE_HEADER.txt" data-name="gh-pages" rel="nofollow">gh-pages</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item branch-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/master/LICENSE_HEADER.txt" data-name="master" rel="nofollow">master</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item branch-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/studio/LICENSE_HEADER.txt" data-name="studio" rel="nofollow">studio</a>
 *                 </h4>
 *               </div>
 *
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/2.0.1/LICENSE_HEADER.txt" data-name="2.0.1" rel="nofollow">2.0.1</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/2.0/LICENSE_HEADER.txt" data-name="2.0" rel="nofollow">2.0</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/1.3/LICENSE_HEADER.txt" data-name="1.3" rel="nofollow">1.3</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/1.2/LICENSE_HEADER.txt" data-name="1.2" rel="nofollow">1.2</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/1.1/LICENSE_HEADER.txt" data-name="1.1" rel="nofollow">1.1</a>
 *                 </h4>
 *               </div>
 *               <div class="commitish-item tag-commitish selector-item">
 *                 <h4>
 *                     <a href="/mulesoft/mongo-connector/blob/1.0/LICENSE_HEADER.txt" data-name="1.0" rel="nofollow">1.0</a>
 *                 </h4>
 *               </div>
 *
 *             <div class="no-results" style="display:none">Nothing to show</div>
 *           </div>
 *         </div><!-- /.commitish-context-context -->
 *       </div>
 *
 *     </li>
 *   </ul>
 *
 *   <ul class="subnav with-scope">
 *
 *     <li><a href="/mulesoft/mongo-connector" class="selected" highlight="repo_source">Files</a></li>
 *     <li><a href="/mulesoft/mongo-connector/commits/master" highlight="repo_commits">Commits</a></li>
 *     <li><a href="/mulesoft/mongo-connector/branches" class="" highlight="repo_branches" rel="nofollow">Branches <span class="counter">3</span></a></li>
 *   </ul>
 *
 * </div>
 *
 *
 *
 *
 *
 *
 *
 *
 *         </div><!-- /.repohead -->
 *
 *
 *
 *
 *
 *
 *
 *   <p class="last-commit">Latest commit to the <strong>master</strong> branch</p>
 *
 * <div class="commit commit-tease js-details-container">
 *   <p class="commit-title ">
 *       <a href="/mulesoft/mongo-connector/commit/8e7d08d7da221425154e37b28dfa2a59046724e5" class="message">[maven-release-plugin] prepare for next development iteration</a>
 *
 *   </p>
 *   <div class="commit-meta">
 *     <a href="/mulesoft/mongo-connector/commit/8e7d08d7da221425154e37b28dfa2a59046724e5" class="sha-block">commit <span class="sha">8e7d08d7da</span></a>
 *     <span class="js-clippy clippy-button " data-clipboard-text="8e7d08d7da221425154e37b28dfa2a59046724e5" data-copied-hint="copied!" data-copy-hint="Copy SHA"></span>
 *
 *     <div class="authorship">
 *       <img class="gravatar" height="20" src="https://secure.gravatar.com/avatar/1fae43c02afb621a4c6624386ddfd337?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" width="20" />
 *       <span class="author-name"><a href="/federecio">federecio</a></span>
 *       authored <time class="js-relative-date" datetime="2012-01-12T11:23:35-08:00" title="2012-01-12 11:23:35">January 12, 2012</time>
 *
 *     </div>
 *   </div>
 * </div>
 *
 *
 * <!-- block_view_fragment_key: views4/v8/blob:v16:ce8263a09d200b97ec013846a31fa41c -->
 *   <div id="slider">
 *
 *     <div class="breadcrumb" data-path="LICENSE_HEADER.txt/">
 *       <b><a href="/mulesoft/mongo-connector/tree/8e7d08d7da221425154e37b28dfa2a59046724e5" class="js-rewrite-sha">mongo-connector</a></b> / LICENSE_HEADER.txt <span class="js-clippy clippy-button " data-clipboard-text="LICENSE_HEADER.txt" data-copied-hint="copied!" data-copy-hint="copy to clipboard"></span>
 *     </div>
 *
 *     <div class="frames">
 *       <div class="frame frame-center" data-path="LICENSE_HEADER.txt/" data-permalink-url="/mulesoft/mongo-connector/blob/8e7d08d7da221425154e37b28dfa2a59046724e5/LICENSE_HEADER.txt" data-title="LICENSE_HEADER.txt at master from mulesoft/mongo-connector - GitHub" data-type="blob">
 *           <ul class="big-actions">
 *             <li><a class="file-edit-link minibutton js-rewrite-sha" href="/mulesoft/mongo-connector/edit/8e7d08d7da221425154e37b28dfa2a59046724e5/LICENSE_HEADER.txt" data-method="post" rel="nofollow"><span>Edit this file</span></a></li>
 *           </ul>
 *
 *         <div id="files" class="bubble">
 *           <div class="file">
 *             <div class="meta">
 *               <div class="info">
 *                 <span class="icon"><img alt="Txt" height="16" src="https://a248.e.akamai.net/assets.github.com/images/icons/txt.png?1310086001" width="16" /></span>
 *                 <span class="mode" title="File Mode">100644</span>
 *                   <span>9 lines (5 sloc)</span>
 *                 <span>0.266 kb</span>
 *               </div>
 *               <ul class="actions">
 *                 <li><a href="/mulesoft/mongo-connector/raw/master/LICENSE_HEADER.txt" id="raw-url">raw</a></li>
 *                   <li><a href="/mulesoft/mongo-connector/blame/master/LICENSE_HEADER.txt">blame</a></li>
 *                 <li><a href="/mulesoft/mongo-connector/commits/master/LICENSE_HEADER.txt" rel="nofollow">history</a></li>
 *               </ul>
 *             </div>
 *               <div class="data type-text">
 *       <table cellpadding="0" cellspacing="0" class="lines">
 *         <tr>
 *           <td>
 *             <pre class="line_numbers"><span id="L1" rel="#L1">1</span>
 * <span id="L2" rel="#L2">2</span>
 * <span id="L3" rel="#L3">3</span>
 * <span id="L4" rel="#L4">4</span>
 * <span id="L5" rel="#L5">5</span>
 * <span id="L6" rel="#L6">6</span>
 * <span id="L7" rel="#L7">7</span>
 * <span id="L8" rel="#L8">8</span>
 * </pre>
 *           </td>
 *           <td width="100%">
 *                 <div class="highlight"><pre><div class='line' id='LC1'>Mule Mongo Connector</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com</div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>The software in this package is published under the terms of the CPAL v1.0</div><div class='line' id='LC6'>license, a copy of which has been included with this distribution in the</div><div class='line' id='LC7'>LICENSE.txt file.</div><div class='line' id='LC8'><br/></div></pre></div>
 *           </td>
 *         </tr>
 *       </table>
 *   </div>
 *
 *           </div>
 *         </div>
 *       </div>
 *     </div>
 *
 *   </div>
 *
 * <div class="frame frame-loading" style="display:none;" data-tree-list-url="/mulesoft/mongo-connector/tree-list/8e7d08d7da221425154e37b28dfa2a59046724e5" data-blob-url-prefix="/mulesoft/mongo-connector/blob/8e7d08d7da221425154e37b28dfa2a59046724e5">
 *   <img src="https://a248.e.akamai.net/assets.github.com/images/modules/ajax/big_spinner_336699.gif?1315867479" height="32" width="32">
 * </div>
 *
 *       </div>
 *       <div class="context-overlay"></div>
 *     </div>
 *
 *
 *       <!-- footer -->
 *       <div id="footer" >
 *
 *   <div class="upper_footer">
 *      <div class="container clearfix">
 *
 *        <!--[if IE]><h4 id="blacktocat_ie">GitHub Links</h4><![endif]-->
 *        <![if !IE]><h4 id="blacktocat">GitHub Links</h4><![endif]>
 *
 *        <ul class="footer_nav">
 *          <h4>GitHub</h4>
 *          <li><a href="https://github.com/about">About</a></li>
 *          <li><a href="https://github.com/blog">Blog</a></li>
 *          <li><a href="https://github.com/features">Features</a></li>
 *          <li><a href="https://github.com/contact">Contact &amp; Support</a></li>
 *          <li><a href="https://github.com/training">Training</a></li>
 *          <li><a href="http://enterprise.github.com/">GitHub Enterprise</a></li>
 *          <li><a href="http://status.github.com/">Site Status</a></li>
 *        </ul>
 *
 *        <ul class="footer_nav">
 *          <h4>Tools</h4>
 *          <li><a href="http://get.gaug.es/">Gauges: Analyze web traffic</a></li>
 *          <li><a href="http://speakerdeck.com">Speaker Deck: Presentations</a></li>
 *          <li><a href="https://gist.github.com">Gist: Code snippets</a></li>
 *          <li><a href="http://mac.github.com/">GitHub for Mac</a></li>
 *          <li><a href="http://mobile.github.com/">Issues for iPhone</a></li>
 *          <li><a href="http://jobs.github.com/">Job Board</a></li>
 *        </ul>
 *
 *        <ul class="footer_nav">
 *          <h4>Extras</h4>
 *          <li><a href="http://shop.github.com/">GitHub Shop</a></li>
 *          <li><a href="http://octodex.github.com/">The Octodex</a></li>
 *        </ul>
 *
 *        <ul class="footer_nav">
 *          <h4>Documentation</h4>
 *          <li><a href="http://help.github.com/">GitHub Help</a></li>
 *          <li><a href="http://developer.github.com/">Developer API</a></li>
 *          <li><a href="http://github.github.com/github-flavored-markdown/">GitHub Flavored Markdown</a></li>
 *          <li><a href="http://pages.github.com/">GitHub Pages</a></li>
 *        </ul>
 *
 *      </div><!-- /.site -->
 *   </div><!-- /.upper_footer -->
 *
 * <div class="lower_footer">
 *   <div class="container clearfix">
 *     <!--[if IE]><div id="legal_ie"><![endif]-->
 *     <![if !IE]><div id="legal"><![endif]>
 *       <ul>
 *           <li><a href="https://github.com/site/terms">Terms of Service</a></li>
 *           <li><a href="https://github.com/site/privacy">Privacy</a></li>
 *           <li><a href="https://github.com/security">Security</a></li>
 *       </ul>
 *
 *       <p>&copy; 2012 <span title="0.04983s from fe9.rs.github.com">GitHub</span> Inc. All rights reserved.</p>
 *     </div><!-- /#legal or /#legal_ie-->
 *
 *       <div class="sponsor">
 *         <a href="http://www.rackspace.com" class="logo">
 *           <img alt="Dedicated Server" height="36" src="https://a248.e.akamai.net/assets.github.com/images/modules/footer/rackspace_logo.png?v2" width="38" />
 *         </a>
 *         Powered by the <a href="http://www.rackspace.com ">Dedicated
 *         Servers</a> and<br/> <a href="http://www.rackspacecloud.com">Cloud
 *         Computing</a> of Rackspace Hosting<span>&reg;</span>
 *       </div>
 *   </div><!-- /.site -->
 * </div><!-- /.lower_footer -->
 *
 *       </div><!-- /#footer -->
 *
 *
 *
 * <div id="keyboard_shortcuts_pane" class="instapaper_ignore readability-extra" style="display:none">
 *   <h2>Keyboard Shortcuts <small><a href="#" class="js-see-all-keyboard-shortcuts">(see all)</a></small></h2>
 *
 *   <div class="columns threecols">
 *     <div class="column first">
 *       <h3>Site wide shortcuts</h3>
 *       <dl class="keyboard-mappings">
 *         <dt>s</dt>
 *         <dd>Focus site search</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>?</dt>
 *         <dd>Bring up this help dialog</dd>
 *       </dl>
 *     </div><!-- /.column.first -->
 *
 *     <div class="column middle" style='display:none'>
 *       <h3>Commit list</h3>
 *       <dl class="keyboard-mappings">
 *         <dt>j</dt>
 *         <dd>Move selection down</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>k</dt>
 *         <dd>Move selection up</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>c <em>or</em> o <em>or</em> enter</dt>
 *         <dd>Open commit</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>y</dt>
 *         <dd>Expand URL to its canonical form</dd>
 *       </dl>
 *     </div><!-- /.column.first -->
 *
 *     <div class="column last" style='display:none'>
 *       <h3>Pull request list</h3>
 *       <dl class="keyboard-mappings">
 *         <dt>j</dt>
 *         <dd>Move selection down</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>k</dt>
 *         <dd>Move selection up</dd>
 *       </dl>
 *       <dl class="keyboard-mappings">
 *         <dt>o <em>or</em> enter</dt>
 *         <dd>Open issue</dd>
 *       </dl>
 *     </div><!-- /.columns.last -->
 *
 *   </div><!-- /.columns.equacols -->
 *
 *   <div style='display:none'>
 *     <div class="rule"></div>
 *
 *     <h3>Issues</h3>
 *
 *     <div class="columns threecols">
 *       <div class="column first">
 *         <dl class="keyboard-mappings">
 *           <dt>j</dt>
 *           <dd>Move selection down</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>k</dt>
 *           <dd>Move selection up</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>x</dt>
 *           <dd>Toggle selection</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>o <em>or</em> enter</dt>
 *           <dd>Open issue</dd>
 *         </dl>
 *       </div><!-- /.column.first -->
 *       <div class="column middle">
 *         <dl class="keyboard-mappings">
 *           <dt>I</dt>
 *           <dd>Mark selection as read</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>U</dt>
 *           <dd>Mark selection as unread</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>e</dt>
 *           <dd>Close selection</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>y</dt>
 *           <dd>Remove selection from view</dd>
 *         </dl>
 *       </div><!-- /.column.middle -->
 *       <div class="column last">
 *         <dl class="keyboard-mappings">
 *           <dt>c</dt>
 *           <dd>Create issue</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>l</dt>
 *           <dd>Create label</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>i</dt>
 *           <dd>Back to inbox</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>u</dt>
 *           <dd>Back to issues</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>/</dt>
 *           <dd>Focus issues search</dd>
 *         </dl>
 *       </div>
 *     </div>
 *   </div>
 *
 *   <div style='display:none'>
 *     <div class="rule"></div>
 *
 *     <h3>Issues Dashboard</h3>
 *
 *     <div class="columns threecols">
 *       <div class="column first">
 *         <dl class="keyboard-mappings">
 *           <dt>j</dt>
 *           <dd>Move selection down</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>k</dt>
 *           <dd>Move selection up</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>o <em>or</em> enter</dt>
 *           <dd>Open issue</dd>
 *         </dl>
 *       </div><!-- /.column.first -->
 *     </div>
 *   </div>
 *
 *   <div style='display:none'>
 *     <div class="rule"></div>
 *
 *     <h3>Network Graph</h3>
 *     <div class="columns equacols">
 *       <div class="column first">
 *         <dl class="keyboard-mappings">
 *           <dt><span class="badmono">?</span> <em>or</em> h</dt>
 *           <dd>Scroll left</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt><span class="badmono"></span> <em>or</em> l</dt>
 *           <dd>Scroll right</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt><span class="badmono"></span> <em>or</em> k</dt>
 *           <dd>Scroll up</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt><span class="badmono"></span> <em>or</em> j</dt>
 *           <dd>Scroll down</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>t</dt>
 *           <dd>Toggle visibility of head labels</dd>
 *         </dl>
 *       </div><!-- /.column.first -->
 *       <div class="column last">
 *         <dl class="keyboard-mappings">
 *           <dt>shift <span class="badmono">?</span> <em>or</em> shift h</dt>
 *           <dd>Scroll all the way left</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>shift <span class="badmono"></span> <em>or</em> shift l</dt>
 *           <dd>Scroll all the way right</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>shift <span class="badmono"></span> <em>or</em> shift k</dt>
 *           <dd>Scroll all the way up</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>shift <span class="badmono"></span> <em>or</em> shift j</dt>
 *           <dd>Scroll all the way down</dd>
 *         </dl>
 *       </div><!-- /.column.last -->
 *     </div>
 *   </div>
 *
 *   <div >
 *     <div class="rule"></div>
 *     <div class="columns threecols">
 *       <div class="column first" >
 *         <h3>Source Code Browsing</h3>
 *         <dl class="keyboard-mappings">
 *           <dt>t</dt>
 *           <dd>Activates the file finder</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>l</dt>
 *           <dd>Jump to line</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>w</dt>
 *           <dd>Switch branch/tag</dd>
 *         </dl>
 *         <dl class="keyboard-mappings">
 *           <dt>y</dt>
 *           <dd>Expand URL to its canonical form</dd>
 *         </dl>
 *       </div>
 *     </div>
 *   </div>
 * </div>
 *
 *     <div id="markdown-help" class="instapaper_ignore readability-extra">
 *   <h2>Markdown Cheat Sheet</h2>
 *
 *   <div class="cheatsheet-content">
 *
 *   <div class="mod">
 *     <div class="col">
 *       <h3>Format Text</h3>
 *       <p>Headers</p>
 *       <pre>
 * # This is an &lt;h1&gt; tag
 * ## This is an &lt;h2&gt; tag
 * ###### This is an &lt;h6&gt; tag</pre>
 *      <p>Text styles</p>
 *      <pre>
 * *This text will be italic*
 * _This will also be italic_
 * **This text will be bold**
 * __This will also be bold__
 *
 * *You **can** combine them*
 * </pre>
 *     </div>
 *     <div class="col">
 *       <h3>Lists</h3>
 *       <p>Unordered</p>
 *       <pre>
 * * Item 1
 * * Item 2
 *   * Item 2a
 *   * Item 2b</pre>
 *      <p>Ordered</p>
 *      <pre>
 * 1. Item 1
 * 2. Item 2
 * 3. Item 3
 *    * Item 3a
 *    * Item 3b</pre>
 *     </div>
 *     <div class="col">
 *       <h3>Miscellaneous</h3>
 *       <p>Images</p>
 *       <pre>
 * ![GitHub Logo](/images/logo.png)
 * Format: ![Alt Text](url)
 * </pre>
 *      <p>Links</p>
 *      <pre>
 * http://github.com - automatic!
 * [GitHub](http://github.com)</pre>
 * <p>Blockquotes</p>
 *      <pre>
 * As Kanye West said:
 *
 * > We're living the future so
 * > the present is our past.
 * </pre>
 *     </div>
 *   </div>
 *   <div class="rule"></div>
 *
 *   <h3>Code Examples in Markdown</h3>
 *   <div class="col">
 *       <p>Syntax highlighting with <a href="http://github.github.com/github-flavored-markdown/" title="GitHub Flavored Markdown" target="_blank">GFM</a></p>
 *       <pre>
 * ```javascript
 * function fancyAlert(arg) {
 *   if(arg) {
 *     $.facebox({div:'#foo'})
 *   }
 * }
 * ```</pre>
 *     </div>
 *     <div class="col">
 *       <p>Or, indent your code 4 spaces</p>
 *       <pre>
 * Here is a Python code example
 * without syntax highlighting:
 *
 *     def foo:
 *       if not bar:
 *         return true</pre>
 *     </div>
 *     <div class="col">
 *       <p>Inline code for comments</p>
 *       <pre>
 * I think you should use an
 * `&lt;addr&gt;` element here instead.</pre>
 *     </div>
 *   </div>
 *
 *   </div>
 * </div>
 *
 *
 *     <div class="ajax-error-message">
 *       <p><span class="icon"></span> Something went wrong with that request. Please try again. <a href="javascript:;" class="ajax-error-dismiss">Dismiss</a></p>
 *     </div>
 *
 *
 *
 *
 *     <span id='server_response_time' data-time='0.05161' data-host='fe9'></span>
 *   </body>
 * </html>
 */

package org.mule.module.jpa.command;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mule.module.jpa.JPAException;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaQuery;
import java.util.List;
import java.util.Map;

/**
 * Perform a JPA query operation
 */
@SuppressWarnings({ "unchecked" })
public class Query implements JPACommand {

    protected transient Log logger = LogFactory.getLog(getClass());

    public Object execute(EntityManager entityManager, Object payload, Map<String, Object> parameters,
            Boolean flush) throws Exception {

        Object queryParameters = parameters.get("queryParameters");

        Object result;
        if (queryParameters instanceof CriteriaQuery) {
            logger.debug("Executing CriteriaQuery: " + queryParameters);
            result = entityManager.createQuery((CriteriaQuery) queryParameters).getResultList();
        } else if (parameters.containsKey("namedQuery")) {
            logger.debug("Executing Named Query: " + parameters.get("namedQuery"));
            javax.persistence.Query query = entityManager.createNamedQuery((String) parameters.get("namedQuery"));
            if (queryParameters != null) {
                setParameters(queryParameters, query);
            }
            result = query.getResultList();
        } else if (parameters.containsKey("statement")) {
            logger.debug("Executing JPQL statement: " + parameters.get("statement"));
            javax.persistence.Query query = entityManager.createQuery((String) parameters.get("statement"));
            if (queryParameters != null) {
                setParameters(queryParameters, query);
            }
            result = query.getResultList();
        } else {
            throw new JPAException(
                    "Couldn't resolve query from either the query parameters or the statement attribute");
        }

        if (flush) {
            entityManager.flush();
        }

        return result;
    }

    void setParameters(Object entity, javax.persistence.Query query) {
        if (entity instanceof Map) {
            Map<String, Object> parameters = (Map<String, Object>) entity;
            for (String key : parameters.keySet()) {
                if (logger.isDebugEnabled())
                    logger.debug(String.format("Setting query parameter %s to %s", key, parameters.get(key)));
                query.setParameter(key, parameters.get(key));
            }
        } else if (entity instanceof List) {
            List parameters = (List) entity;
            for (int i = 0; i < parameters.size(); i++) {
                if (logger.isDebugEnabled())
                    logger.debug(String.format("Setting query parameter index %d to %s", i + 1, parameters.get(i)));
                query.setParameter(i + 1, parameters.get(i));
            }
        } else {
            logger.warn("Payload should be a Map of parameters, List of parameters or null "
                    + "when using JPA-QL or named queries");
        }
    }
}