blob: b0166e6852848c0a7b5656a014d069d56c3f0e7c [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>FetchBindingTemplatesQuery.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core - OpenJPA</a> &gt; <a href="index.source.html" class="el_package">org.apache.juddi.query</a> &gt; <span class="el_source">FetchBindingTemplatesQuery.java</span></div><h1>FetchBindingTemplatesQuery.java</h1><pre class="source lang-java linenums">/*
* Copyright 2001-2008 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.juddi.query;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.persistence.EntityManager;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.config.AppConfig;
import org.apache.juddi.config.Property;
import org.apache.juddi.query.util.DynamicQuery;
import org.apache.juddi.query.util.FindQualifiers;
import org.uddi.v3_service.DispositionReportFaultMessage;
import org.uddi.api_v3.ListDescription;
/**
* The &quot;select&quot; method retrieves all the entities for the input key list and sorts according to the user settings. Paging is taken into account when retrieving
* the results. The result is a list of the entity objects containing all top level elements (restricted to the given page).
*
* NOTE: Results usually need multiple one-to-many collections to be fetched. Although this could be done in one query with eager fetching, this strategy is not
* recommended as it will lead to a potentially large Cartesian product. Therefore, the collections are initialized in separate queries during the mapping
* stage. If the returned results are small (maxRows parameters is set appropriately), a single query is likely faster, but probably not by enough to consider
* the optimization under these conditions.
*
* @author &lt;a href=&quot;mailto:jfaath@apache.org&quot;&gt;Jeff Faath&lt;/a&gt;
*/
<span class="nc" id="L47">public class FetchBindingTemplatesQuery extends BindingTemplateQuery {</span>
<span class="fc" id="L49"> private static final Log log = LogFactory.getLog(FetchBindingTemplatesQuery.class);</span>
protected static final String selectSQL;
static {
<span class="fc" id="L54"> StringBuilder sql = new StringBuilder(200);</span>
<span class="fc" id="L55"> sql.append(&quot;select &quot; + ENTITY_ALIAS + &quot; from &quot; + ENTITY_NAME + &quot; &quot; + ENTITY_ALIAS + &quot; &quot;);</span>
<span class="fc" id="L56"> selectSQL = sql.toString();</span>
<span class="fc" id="L57"> }</span>
public static List&lt;?&gt; select(EntityManager em, FindQualifiers fq, List&lt;?&gt; keysIn, Integer maxRowsUser, Integer listHead, ListDescription listDesc, DynamicQuery.Parameter... restrictions) throws DispositionReportFaultMessage {
// If keysIn is null or empty, then nothing to fetch.
<span class="pc bpc" id="L62" title="1 of 4 branches missed."> if ((keysIn == null) || (keysIn.size() == 0))</span>
<span class="fc" id="L63"> return Collections.emptyList();</span>
<span class="fc" id="L64"> int maxRows = DEFAULT_MAXROWS;</span>
try {
<span class="fc" id="L66"> maxRows = AppConfig.getConfiguration().getInteger(Property.JUDDI_MAX_ROWS, DEFAULT_MAXROWS);</span>
}
<span class="nc" id="L68"> catch(ConfigurationException ce) {</span>
<span class="nc" id="L69"> log.error(&quot;Configuration exception occurred retrieving: &quot; + Property.JUDDI_MAX_ROWS);</span>
<span class="fc" id="L70"> }</span>
<span class="fc" id="L71"> DynamicQuery dynamicQry = new DynamicQuery(selectSQL);</span>
<span class="pc bpc" id="L72" title="1 of 2 branches missed."> if (keysIn.size() &gt; maxRows) {</span>
<span class="nc" id="L73"> UUID uuid = UUID.randomUUID();</span>
<span class="nc" id="L74"> storeIntermediateKeySetResults(em, uuid.toString(), keysIn);</span>
<span class="nc" id="L75"> appendTempTable(dynamicQry);</span>
<span class="nc" id="L76"> appendSortTables(dynamicQry);</span>
<span class="nc" id="L77"> appendTempJoin(dynamicQry, uuid.toString());</span>
<span class="nc" id="L78"> }</span>
else {
<span class="fc" id="L80"> appendSortTables(dynamicQry);</span>
<span class="fc" id="L81"> dynamicQry.appendInListWithAnd(ENTITY_ALIAS + &quot;.&quot; + KEY_NAME, keysIn);</span>
}
<span class="pc bpc" id="L83" title="2 of 4 branches missed."> if (restrictions != null &amp;&amp; restrictions.length &gt; 0)</span>
<span class="nc" id="L84"> dynamicQry.AND().pad().appendGroupedAnd(restrictions);</span>
<span class="fc" id="L86"> appendSortCriteria(dynamicQry, fq);</span>
<span class="fc" id="L88"> log.debug(dynamicQry);</span>
<span class="fc" id="L90"> return getPagedResult(em, dynamicQry, maxRowsUser, listHead, listDesc);</span>
}
private static void appendTempTable(DynamicQuery qry) {
<span class="nc" id="L94"> qry.comma().append(TEMP_ENTITY_NAME + &quot; &quot; + TEMP_ENTITY_ALIAS );</span>
<span class="nc" id="L95"> }</span>
private static void appendTempJoin(DynamicQuery qry, String uuid) {
<span class="nc" id="L98"> qry.pad().AND().pad().append(TEMP_ENTITY_PK_KEY_NAME).append(DynamicQuery.PREDICATE_EQUALS);</span>
<span class="nc" id="L99"> qry.pad().append(ENTITY_ALIAS + &quot;.&quot; + KEY_NAME);</span>
<span class="nc" id="L100"> qry.pad().AND().pad().append(TEMP_ENTITY_PK_TXID_NAME).append(DynamicQuery.PREDICATE_EQUALS);</span>
<span class="nc" id="L101"> qry.append(&quot;'&quot; + uuid + &quot;'&quot;).pad();</span>
<span class="nc" id="L102"> }</span>
private static void appendSortTables(DynamicQuery qry) {
// BindingTemplates can only be sorted by date.
<span class="fc" id="L106"> qry.WHERE().pad().append(&quot;1=1&quot;).pad();</span>
<span class="fc" id="L107"> }</span>
/*
* BindingTemplates can only be sorted by date.
*/
private static void appendSortCriteria(DynamicQuery qry, FindQualifiers fq) {
<span class="fc" id="L114"> qry.ORDERBY().pad();</span>
<span class="fc bfc" id="L116" title="All 2 branches covered."> if (fq.isSortByDateAsc())</span>
<span class="fc" id="L117"> qry.append(ENTITY_ALIAS + &quot;.modified&quot;).pad().append(DynamicQuery.SORT_ASC);</span>
else
<span class="fc" id="L119"> qry.append(ENTITY_ALIAS + &quot;.modified&quot;).pad().append(DynamicQuery.SORT_DESC);</span>
<span class="fc" id="L121"> qry.pad();</span>
<span class="fc" id="L123"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>