| <?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>FindEntityByNamesQuery.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 Services</a> > <a href="index.source.html" class="el_package">org.apache.juddi.query</a> > <span class="el_source">FindEntityByNamesQuery.java</span></div><h1>FindEntityByNamesQuery.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2001-2008 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * 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 "AS IS" 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.List; |
| |
| import javax.persistence.EntityManager; |
| |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
| import org.apache.juddi.query.util.DynamicQuery; |
| import org.apache.juddi.query.util.FindQualifiers; |
| import org.uddi.api_v3.Name; |
| |
| /** |
| * Returns the list of "entity" keys possessing the Names in the passed Name list. |
| * Output is restricted by list of "entity" keys passed in. If null, all entities are searched. |
| * Output is produced by building the appropriate JPA query based on input and find qualifiers. |
| * |
| * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> |
| */ |
| public class FindEntityByNamesQuery extends EntityQuery { |
| |
| @SuppressWarnings("unused") |
| <span class="fc" id="L40"> private static Log log = LogFactory.getLog(FindEntityByNamesQuery.class);</span> |
| |
| private final String entityName; |
| private final String entityAlias; |
| private final String keyName; |
| private final String entityField; |
| private final String entityNameChild; |
| private final String entityAliasChild; |
| private final String selectSQL; |
| private String signaturePresent; |
| |
| public FindEntityByNamesQuery(String entityName, String entityAlias, String keyName, String entityField, |
| <span class="fc" id="L52"> String entityNameChild, String signaturePresent) {</span> |
| <span class="fc" id="L53"> this.entityName = entityName;</span> |
| <span class="fc" id="L54"> this.entityAlias = entityAlias;</span> |
| <span class="fc" id="L55"> this.keyName = keyName;</span> |
| <span class="fc" id="L56"> this.entityField = entityField;</span> |
| <span class="fc" id="L57"> this.entityNameChild = entityNameChild;</span> |
| <span class="fc" id="L58"> this.entityAliasChild = buildAlias(entityNameChild);</span> |
| <span class="fc" id="L59"> this.signaturePresent = signaturePresent;</span> |
| |
| <span class="fc" id="L61"> StringBuffer sql = new StringBuffer(200);</span> |
| <span class="fc" id="L62"> sql.append("select distinct " + entityAlias + "." + keyName + " from " + entityName + " " + entityAlias + " ");</span> |
| <span class="fc" id="L63"> selectSQL = sql.toString();</span> |
| <span class="fc" id="L64"> }</span> |
| |
| public String getEntityName() { |
| <span class="nc" id="L67"> return entityName;</span> |
| } |
| |
| public String getEntityAlias() { |
| <span class="nc" id="L71"> return entityAlias;</span> |
| } |
| |
| public String getKeyName() { |
| <span class="nc" id="L75"> return keyName;</span> |
| } |
| |
| public String getEntityField() { |
| <span class="nc" id="L79"> return entityField;</span> |
| } |
| |
| public String getEntityNameChild() { |
| <span class="nc" id="L83"> return entityNameChild;</span> |
| } |
| |
| public String getEntityAliasChild() { |
| <span class="nc" id="L87"> return entityAliasChild;</span> |
| } |
| |
| public String getSelectSQL() { |
| <span class="nc" id="L91"> return selectSQL;</span> |
| } |
| |
| public String getSignaturePresent() { |
| <span class="fc" id="L95"> return signaturePresent;</span> |
| } |
| |
| public void setSignaturePresent(String signaturePresent) { |
| <span class="nc" id="L99"> this.signaturePresent = signaturePresent;</span> |
| <span class="nc" id="L100"> }</span> |
| |
| public List<Object> select(EntityManager em, FindQualifiers fq, List<Name> names, List<Object> keysIn, DynamicQuery.Parameter... restrictions) { |
| // If keysIn is not null and empty, then search is over. |
| <span class="fc bfc" id="L104" title="All 4 branches covered."> if ((keysIn != null) && (keysIn.size() == 0))</span> |
| <span class="fc" id="L105"> return keysIn;</span> |
| |
| <span class="pc bpc" id="L107" title="1 of 4 branches missed."> if (names == null || names.size() == 0)</span> |
| <span class="fc" id="L108"> return keysIn;</span> |
| |
| <span class="fc" id="L110"> DynamicQuery dynamicQry = new DynamicQuery(selectSQL);</span> |
| <span class="fc" id="L111"> appendConditions(dynamicQry, fq, names);</span> |
| <span class="pc bpc" id="L112" title="2 of 4 branches missed."> if (restrictions != null && restrictions.length > 0)</span> |
| <span class="nc" id="L113"> dynamicQry.AND().pad().appendGroupedAnd(restrictions);</span> |
| |
| <span class="fc" id="L115"> return getQueryResult(em, dynamicQry, keysIn, entityAlias + "." + keyName);</span> |
| } |
| |
| /* |
| * Appends the conditions to the query based on the name list. |
| */ |
| public void appendConditions(DynamicQuery qry, FindQualifiers fq, List<Name> names) { |
| |
| // Append the necessary tables (one will always be added connecting the entity to its name table). |
| <span class="fc" id="L124"> appendJoinTables(qry, fq, names);</span> |
| <span class="fc" id="L125"> qry.AND().pad().openParen().pad();</span> |
| |
| <span class="fc" id="L127"> String namePredicate = DynamicQuery.PREDICATE_EQUALS;</span> |
| <span class="fc bfc" id="L128" title="All 2 branches covered."> if (fq.isApproximateMatch()) {</span> |
| <span class="fc" id="L129"> namePredicate = DynamicQuery.PREDICATE_LIKE;</span> |
| } |
| |
| <span class="fc" id="L132"> int count = 0;</span> |
| <span class="fc bfc" id="L133" title="All 2 branches covered."> for(Name n : names) {</span> |
| <span class="fc" id="L134"> String nameTerm = entityAliasChild + ".name";</span> |
| <span class="fc" id="L135"> String nameValue = n.getValue();</span> |
| <span class="fc bfc" id="L136" title="All 2 branches covered."> if (fq.isCaseInsensitiveMatch()) {</span> |
| <span class="fc" id="L137"> nameTerm = "upper(" + entityAliasChild + ".name)";</span> |
| <span class="fc" id="L138"> nameValue = n.getValue().toUpperCase();</span> |
| } |
| // JUDDI-235: wildcards are provided by user (only commenting in case a new interpretation arises) |
| //if (fq.isApproximateMatch()) |
| // nameValue = nameValue.endsWith(DynamicQuery.WILDCARD)?nameValue:nameValue + DynamicQuery.WILDCARD; |
| |
| <span class="pc bpc" id="L144" title="1 of 4 branches missed."> if (n.getLang() == null || n.getLang().length() == 0 ) {</span> |
| <span class="fc" id="L145"> qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate));</span> |
| } |
| else { |
| // Per spec, the language argument is always wildcarded and case insensitive |
| <span class="pc bpc" id="L149" title="1 of 2 branches missed."> String langValue = n.getLang().endsWith(DynamicQuery.WILDCARD)?n.getLang().toUpperCase():n.getLang().toUpperCase() + DynamicQuery.WILDCARD;</span> |
| <span class="fc" id="L150"> qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate), </span> |
| new DynamicQuery.Parameter("upper(" + entityAliasChild + ".langCode)", langValue, DynamicQuery.PREDICATE_LIKE)); |
| } |
| |
| <span class="fc bfc" id="L154" title="All 2 branches covered."> if (count + 1 < names.size())</span> |
| <span class="fc" id="L155"> qry.OR().pad();</span> |
| |
| <span class="fc" id="L157"> count++;</span> |
| <span class="fc" id="L158"> }</span> |
| <span class="fc" id="L159"> qry.closeParen().pad();</span> |
| |
| <span class="fc" id="L161"> }</span> |
| |
| /* |
| * Appends the necessary join table for the child entity |
| */ |
| public void appendJoinTables(DynamicQuery qry, FindQualifiers fq, List<Name> names) { |
| <span class="fc" id="L167"> qry.comma().pad().append(entityNameChild + " " + entityAliasChild).pad();</span> |
| <span class="fc" id="L168"> qry.WHERE().pad().openParen().pad();</span> |
| <span class="fc" id="L169"> qry.append(entityAlias + "." + keyName + " = " + entityAliasChild + "." + entityField + "." + keyName + " ");</span> |
| <span class="fc" id="L170"> qry.closeParen().pad();</span> |
| <span class="pc bpc" id="L171" title="1 of 4 branches missed."> if (fq!=null && fq.isSignaturePresent()) {</span> |
| <span class="fc" id="L172"> qry.AND().pad().openParen().pad().append(getSignaturePresent()).pad().closeParen().pad();</span> |
| } |
| <span class="fc" id="L174"> }</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> |