[prev in list] [next in list] [prev in thread] [next in thread] 

List:       juddi-cvs
Subject:    svn commit: r719792 - in
From:       jfaath () apache ! org
Date:       2008-11-22 2:51:20
Message-ID: 20081122025121.29D722388961 () eris ! apache ! org
[Download RAW message or body]

Author: jfaath
Date: Fri Nov 21 18:51:20 2008
New Revision: 719792

URL: http://svn.apache.org/viewvc?rev=719792&view=rev
Log:
Added inquiry API support for embedded find_tmodel finds and tmodel bag finds

Added:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java \
(with props)  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java \
(with props) Modified:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java
  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java
  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java
  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java
  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java
  webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java


Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java \
Fri Nov 21 18:51:20 2008 @@ -31,7 +31,9 @@
 import org.apache.juddi.query.FindBusinessByDiscoveryURLQuery;
 import org.apache.juddi.query.FindBusinessByIdentifierQuery;
 import org.apache.juddi.query.FindBusinessByNameQuery;
+import org.apache.juddi.query.FindBusinessByTModelKeyQuery;
 import org.apache.juddi.query.FindServiceByNameQuery;
+import org.apache.juddi.query.FindServiceByTModelKeyQuery;
 import org.apache.juddi.query.FindTModelByIdentifierQuery;
 import org.apache.juddi.query.FindTModelByNameQuery;
 import org.apache.juddi.query.PersistenceManager;
@@ -58,6 +60,7 @@
 import org.uddi.api_v3.TModelDetail;
 import org.uddi.api_v3.TModelList;
 import org.uddi.api_v3.ListDescription;
+import org.uddi.api_v3.TModelBag;
 import org.uddi.v3_service.DispositionReportFaultMessage;
 import org.uddi.v3_service.UDDIInquiryPortType;
 import org.apache.juddi.api.datatype.GetPublisherDetail;
@@ -87,6 +90,12 @@
 		findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());
 
 		List<?> keysFound = null;
+
+		// First perform the embedded FindTModel search which will augment the tModel bag \
with any resulting tModel keys. +		if (body.getTModelBag() == null)
+			body.setTModelBag(new TModelBag());
+		doFindTModelEmbeddedSearch(em, body.getFindQualifiers(), body.getFindTModel(), \
body.getTModelBag()); +		
 		keysFound = FindBindingByTModelKeyQuery.select(em, findQualifiers, \
body.getTModelBag(), body.getServiceKey(), keysFound);  //keysFound = \
FindBindingByCategoryQuery.select(em, findQualifiers, tmodelKeys, \
body.getServiceKey(), keysFound);  
@@ -127,7 +136,13 @@
 		org.apache.juddi.query.util.FindQualifiers findQualifiers = new \
org.apache.juddi.query.util.FindQualifiers();  \
findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());  
+		// First perform the embedded FindTModel search which will augment the tModel bag \
with any resulting tModel keys. +		if (body.getTModelBag() == null)
+			body.setTModelBag(new TModelBag());
+		doFindTModelEmbeddedSearch(em, body.getFindQualifiers(), body.getFindTModel(), \
body.getTModelBag()); +		
 		List<?> keysFound = null;
+		keysFound = FindBusinessByTModelKeyQuery.select(em, findQualifiers, \
body.getTModelBag(), keysFound);  keysFound = \
FindBusinessByIdentifierQuery.select(em, findQualifiers, body.getIdentifierBag(), \
keysFound);  keysFound = FindBusinessByDiscoveryURLQuery.select(em, findQualifiers, \
body.getDiscoveryURLs(), keysFound);  //keysFound = \
FindBusinessByCategoryQuery.select(em, findQualifiers, body.getCategoryBag(), \
keysFound); @@ -178,7 +193,13 @@
 		org.apache.juddi.query.util.FindQualifiers findQualifiers = new \
org.apache.juddi.query.util.FindQualifiers();  \
findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());  
+		// First perform the embedded FindTModel search which will augment the tModel bag \
with any resulting tModel keys. +		if (body.getTModelBag() == null)
+			body.setTModelBag(new TModelBag());
+		doFindTModelEmbeddedSearch(em, body.getFindQualifiers(), body.getFindTModel(), \
body.getTModelBag()); +		
 		List<?> keysFound = null;
+		FindServiceByTModelKeyQuery.select(em, findQualifiers, body.getTModelBag(), \
body.getBusinessKey(), keysFound);  //keysFound = \
FindServiceByCategoryQuery.select(em, findQualifiers, body.getCategoryBag(), \
body.getBusinessKey, keysFound);  keysFound = FindServiceByNameQuery.select(em, \
findQualifiers, body.getName(), body.getBusinessKey(), keysFound);  
@@ -436,4 +457,31 @@
 
 	}
 	
+	/*
+	 * Performs the necessary queries for the find_tModel search and adds resulting \
tModel keys to the tModelBag provided. +	 */
+	private void doFindTModelEmbeddedSearch(EntityManager em, 
+											org.uddi.api_v3.FindQualifiers fq, 
+											FindTModel findTmodel, 
+											TModelBag tmodelBag)
+			throws DispositionReportFaultMessage {
+
+		
+		if (findTmodel != null && tmodelBag != null) {
+			org.apache.juddi.query.util.FindQualifiers findQualifiers = new \
org.apache.juddi.query.util.FindQualifiers(); \
+			findQualifiers.mapApiFindQualifiers(fq); +
+			
+			List<?> tmodelKeysFound = null;
+			tmodelKeysFound = FindTModelByIdentifierQuery.select(em, findQualifiers, \
findTmodel.getIdentifierBag(), tmodelKeysFound); +			//tmodelKeysFound = \
FindTModelByCategoryQuery.select(em, findQualifiers, findTmodel.getCategoryBag(), \
tmodelKeysFound); +			tmodelKeysFound = FindTModelByNameQuery.select(em, \
findQualifiers, findTmodel.getName(), tmodelKeysFound); +			
+			if (tmodelKeysFound != null && tmodelKeysFound.size() > 0) {
+				for (Object item : tmodelKeysFound)
+					tmodelBag.getTModelKey().add((String)item);
+			}
+		}
+	}
+
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/BindingTemplateQuery.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java \
Fri Nov 21 18:51:20 2008 @@ -23,7 +23,7 @@
 public class BindingTemplateQuery extends EntityQuery {
 
 	public static final String ENTITY_NAME = "BindingTemplate";
-	public static final String ENTITY_ALIAS = "b";
+	public static final String ENTITY_ALIAS = "bt";
 	public static final String KEY_NAME = "bindingKey";
 	public static final String KEY_NAME_PARENT = "businessService." + \
BusinessServiceQuery.KEY_NAME;  

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/BusinessEntityQuery.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java \
Fri Nov 21 18:51:20 2008 @@ -23,7 +23,7 @@
 public class BusinessEntityQuery extends EntityQuery {
 
 	public static final String ENTITY_NAME = "BusinessEntity";
-	public static final String ENTITY_ALIAS = "b";
+	public static final String ENTITY_ALIAS = "be";
 	public static final String KEY_NAME = "businessKey";
 	
 	protected static String selectSQL;

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/BusinessServiceQuery.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java \
Fri Nov 21 18:51:20 2008 @@ -23,7 +23,7 @@
 public class BusinessServiceQuery extends EntityQuery {
 
 	public static final String ENTITY_NAME = "BusinessService";
-	public static final String ENTITY_ALIAS = "s";
+	public static final String ENTITY_ALIAS = "bs";
 	public static final String KEY_NAME = "serviceKey";
 	public static final String KEY_NAME_PARENT = "businessEntity." + \
BusinessEntityQuery.KEY_NAME;  

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/EntityQuery.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java \
Fri Nov 21 18:51:20 2008 @@ -109,6 +109,7 @@
 		// If keysIn is null, then no IN list is applied to the query - we simply need to \
run the query.  Otherwise, the IN list is chunked based on  // the application \
property.  if (keysIn == null) {
+			log.debug(dynamicQry);
 			Query qry = dynamicQry.buildJPAQuery(em);
 			result = qry.getResultList();
 		}

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java?rev=719792&r1=719791&r2=719792&view=diff
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java \
                (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java \
Fri Nov 21 18:51:20 2008 @@ -26,19 +26,24 @@
 import org.uddi.api_v3.TModelBag;
 
 /**
- * Returns the list of "entity" keys possessing the keyedReferences in the passed \
                identifier bag.
- * Output is restricted by list of "entity" keys passed in.  If null, all entities \
are searched. + * Returns the list of binding keys possessing the tModels in the \
passed tModelBag. + * Output is restricted by list of binding keys passed in.  If \
                null, all bindings are searched.
  * Output is produced by building the appropriate JPA query based on input and find \
                qualifiers.
  * 
- * NOTES:
- * 1) Identifiers are grouped with a logical OR by default.
- * 2) In the case that the "andAllKeys" find qualifier is used the identifiers are \
                AND'd together.  The only way this can be done
- *    with a single query was to create a self-join for each identifier.  If there \
                are a lot of identifiers, the performance could suffer.
- *    TODO:  Test performance with multiple AND'd identifiers.  If too slow, look to \
                process this query in multiple steps.
- * 3) The "orLikeKeys" qualifier complicates matters.  The "like" keys are OR'd \
                together and these groups of "like" keys are AND'd together.
- *    As with "andAllKeys", self-joins are created but only one for each group of \
                "like" keys.  If none of the keyedReferences passed are alike then \
                this
- *    will reduce to an "andAllKeys" query.  If all are alike, then this will query \
will exhibit the default behavior of OR'ing all keys. + * From specification:
+ * "This collection of tModelKey elements represent in part or in whole the \
technical fingerprint of the bindingTemplate  + * structures for which the search is \
being performed. At least one of either a tModelBag or a find_tModel argument SHOULD \
be  + * supplied, unless a categoryBag based search is being used.  
+
+ * If a find_tModel argument is specified (see above), it is treated as an embedded \
inquiry.  The tModelKeys returned as a  + * result of this embedded find_tModel \
argument are used as if they had been  + * supplied in a tModelBag argument. Changing \
the order of the keys in the collection or specifying the same tModelKey more than  + \
                * once does not change the behavior of the find.  
  * 
+ * By default, only bindingTemplates that have a technical fingerprint containing 
+ * all of the supplied tModelKeys match (logical AND). Specifying appropriate \
findQualifiers can override this behavior so that  + * bindingTemplates with a \
technical fingerprint containing any of the specified tModelKeys are returned \
(logical OR)."  + *  
  * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 public class FindBindingByTModelKeyQuery extends BindingTemplateQuery {
@@ -47,7 +52,7 @@
 
 	public static final String ENTITY_NAME_CHILD = "TmodelInstanceInfo";
 
-	protected static String entityAliasChild;;
+	protected static String entityAliasChild;
 	
 	static {
 		entityAliasChild = buildAlias(ENTITY_NAME_CHILD);

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java?rev=719792&view=auto
 ==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java \
                (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java \
Fri Nov 21 18:51:20 2008 @@ -0,0 +1,159 @@
+/*
+ * 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.juddi.query.util.DynamicQuery;
+import org.apache.juddi.query.util.FindQualifiers;
+import org.apache.log4j.Logger;
+import org.uddi.api_v3.TModelBag;
+
+/**
+ * Returns the list of business keys with services that have bindings that possess \
the tModels in the passed tModelBag. + * Output is restricted by list of service keys \
passed in.  If null, all services are searched. + * Output is produced by building \
the appropriate JPA query based on input and find qualifiers. + * 
+ * From specification:
+ * "Every Web service instance exposed by a registered businessEntity is represented \
in UDDI by a bindingTemplate contained  + * within the businessEntity. Each \
bindingTemplate contains a collection of tModel references called its "technical \
fingerprint"  + * that specifies its type.  The tModelBag argument is a collection of \
tModelKey elements specifying that the search results are  + * to be limited to \
businesses that expose Web services with technical fingerprints that match. + *
+ * If a find_tModel argument is specified (see above), it is treated as an embedded \
inquiry.  The tModelKeys returned as a result  + * of this embedded find_tModel \
argument are used as if they had been supplied in a tModelBag argument. Changing the \
order of the  + * keys in the collection or specifying the same tModelKey more than \
once does not change the behavior of the find.  + *
+ * By default, only bindingTemplates that contain all of the tModelKeys in the \
technical fingerprint match (logical AND). Specifying  + * appropriate findQualifiers \
can override this behavior so that bindingTemplates containing any of the specified \
tModelKeys match  + * (logical OR)."
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindBusinessByTModelKeyQuery extends BusinessEntityQuery {
+	
+	private static Logger log = Logger.getLogger(FindBusinessByTModelKeyQuery.class);
+
+	public static final String ENTITY_NAME_CHILD = "TmodelInstanceInfo";
+
+	protected static String entityAliasChild;
+	
+	static {
+		entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
+	}
+
+	public static List<?> select(EntityManager em, FindQualifiers fq, TModelBag \
tModels, List<?> keysIn, DynamicQuery.Parameter... restrictions) { +		// If keysIn is \
not null and empty, then search is over. +		if ((keysIn != null) && (keysIn.size() == \
0)) +			return keysIn;
+		
+		if (tModels == null)
+			return keysIn;
+		
+		List<String> tmodelKeys = tModels.getTModelKey();
+		if (tmodelKeys == null || tmodelKeys.size() == 0)
+			return keysIn;
+		
+		DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+		appendConditions(dynamicQry, fq, tmodelKeys);
+		
+		if (restrictions != null && restrictions.length > 0)
+			dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+		
+		return getQueryResult(em, dynamicQry, keysIn, ENTITY_ALIAS + "." + KEY_NAME);
+	}
+	
+	
+	/*
+	 * Appends the conditions to the query based on the tModelKey list.  With the \
default or when "orAllKeys" is passed, the keyedReferences are autonomous and are +	 \
* all AND'd or OR'd respectively.   +	 *	 
+	 */
+	public static void appendConditions(DynamicQuery qry, FindQualifiers fq, \
List<String> tmodelKeys) { +		
+		// Append the necessary tables (one will always be added connecting the entity to \
its instanceinfo table). +		appendJoinTables(qry, fq, tmodelKeys);
+		qry.AND().pad().openParen().pad();
+		
+		int count = 0;
+		int tblCount = -1;
+		for(String tmodelKey : tmodelKeys) {
+			
+			tblCount++;
+			String tmodelKeyTerm = (fq.isOrAllKeys()?entityAliasChild + "0":entityAliasChild \
+ tblCount) + ".tmodelKey"; +			qry.appendGroupedAnd(new \
DynamicQuery.Parameter(tmodelKeyTerm, tmodelKey, DynamicQuery.PREDICATE_EQUALS)); \
+			 +			if (count + 1 < tmodelKeys.size()) {
+				if (fq.isOrAllKeys())
+					qry.OR().pad();
+				else
+					qry.AND().pad();
+			}
+			
+			count++;
+		}
+		qry.closeParen().pad();
+		
+	}
+	
+	/*
+	 * Appends the necessary join table for the child entity and additional tables for \
when keys are AND'd.  This is the default behavior  +	 * so only need to add \
additional tables if "orAllKeys" has not been set. +	 */
+	public static void appendJoinTables(DynamicQuery qry, FindQualifiers fq, \
List<String> tmodelKeys) { +		
+
+		if (tmodelKeys != null & tmodelKeys.size() > 0) {
+			qry.comma().pad().append(BusinessServiceQuery.ENTITY_NAME + " " + \
BusinessServiceQuery.ENTITY_ALIAS).pad(); \
+			qry.comma().pad().append(BindingTemplateQuery.ENTITY_NAME + " " + \
BindingTemplateQuery.ENTITY_ALIAS).pad(); +			
+			StringBuffer thetaJoins = new StringBuffer(200);
+			int tblCount = 0;
+			for(int count = 0; count < tmodelKeys.size(); count++) {
+				if (count != 0) {
+					if (!fq.isOrAllKeys()) {
+						tblCount++;
+						qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild + \
tblCount).pad(); +						thetaJoins.append(entityAliasChild + (tblCount - 1) + ".id." \
+ BindingTemplateQuery.KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + \
BindingTemplateQuery.KEY_NAME + " "); \
+						thetaJoins.append(DynamicQuery.OPERATOR_AND + " "); +					}
+				}
+				else {
+					qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild + \
tblCount).pad(); +					thetaJoins.append(BindingTemplateQuery.ENTITY_ALIAS + "." + \
BindingTemplateQuery.KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + \
BindingTemplateQuery.KEY_NAME + " "); \
+					thetaJoins.append(DynamicQuery.OPERATOR_AND + " "); +				}
+			}
+			
+			qry.WHERE().pad().openParen().pad();
+			
+			qry.append(ENTITY_ALIAS + "." + KEY_NAME + " = " + \
BusinessServiceQuery.ENTITY_ALIAS + ".businessEntity." + KEY_NAME).pad(); \
+			qry.AND().pad().append(BusinessServiceQuery.ENTITY_ALIAS + "." + \
BusinessServiceQuery.KEY_NAME + " = " + BindingTemplateQuery.ENTITY_ALIAS + \
".businessService." + BusinessServiceQuery.KEY_NAME).pad(); +			qry.AND().pad();
+			
+			String thetaJoinsStr = thetaJoins.toString();
+			if (thetaJoinsStr.endsWith(DynamicQuery.OPERATOR_AND + " "))
+				thetaJoinsStr = thetaJoinsStr.substring(0, thetaJoinsStr.length() - \
(DynamicQuery.OPERATOR_AND + " ").length()); +			qry.append(thetaJoinsStr);
+
+			qry.closeParen().pad();
+		}
+	}
+	
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByTModelKeyQuery.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java
                
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/m \
ain/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java?rev=719792&view=auto \
                ==============================================================================
                
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java \
                (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java \
Fri Nov 21 18:51:20 2008 @@ -0,0 +1,159 @@
+/*
+ * 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.juddi.query.util.DynamicQuery;
+import org.apache.juddi.query.util.FindQualifiers;
+import org.apache.log4j.Logger;
+import org.uddi.api_v3.TModelBag;
+
+/**
+ * Returns the list of service keys with bindings that possess the tModels in the \
passed tModelBag. + * Output is restricted by list of service keys passed in.  If \
null, all services are searched. + * Output is produced by building the appropriate \
JPA query based on input and find qualifiers. + * 
+ * From specification:
+ * "Every Web service instance is represented in UDDI by a bindingTemplate contained \
within some businessService. A  + * bindingTemplate contains a collection of  tModel \
references called its "technical fingerprint" that specifies its type.  + * The \
tModelBag argument is a collection of tModelKey values specifying that the search \
results are to be limited to  + * businessServices containing bindingTemplates with \
technical fingerprints that match. + *
+ * If a find_tModel argument is specified (see below), it is treated as an embedded \
inquiry.  The tModelKeys returned as a result  + * of this embedded find_tModel \
argument are used as if they had been supplied in a tModelBag argument. Changing the \
order of  + * the keys in the collection or specifying the same tModelKey more than \
once does not change the behavior of the find.  + *
+ * By default, only bindingTemplates that contain all of the tModelKeys in the \
technical fingerprint match (logical AND). Specifying  + * appropriate findQualifiers \
can override this behavior so that bindingTemplates containing any of the specified \
tModelKeys  + * match (logical OR)."
+ *  
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindServiceByTModelKeyQuery extends BusinessServiceQuery {
+	
+	private static Logger log = Logger.getLogger(FindServiceByTModelKeyQuery.class);
+
+	public static final String ENTITY_NAME_CHILD = "TmodelInstanceInfo";
+
+	protected static String entityAliasChild;
+	
+	static {
+		entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
+	}
+
+	public static List<?> select(EntityManager em, FindQualifiers fq, TModelBag \
tModels, String parentKey, List<?> keysIn, DynamicQuery.Parameter... restrictions) { \
+		// If keysIn is not null and empty, then search is over. +		if ((keysIn != null) \
&& (keysIn.size() == 0)) +			return keysIn;
+		
+		if (tModels == null)
+			return keysIn;
+		
+		List<String> tmodelKeys = tModels.getTModelKey();
+		if (tmodelKeys == null || tmodelKeys.size() == 0)
+			return keysIn;
+		
+		DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+		appendConditions(dynamicQry, fq, tmodelKeys);
+		if (parentKey != null && parentKey.length() > 0)
+			dynamicQry.AND().pad().appendGroupedAnd(new \
DynamicQuery.Parameter(BindingTemplateQuery.ENTITY_ALIAS + "." + \
BindingTemplateQuery.KEY_NAME_PARENT, parentKey, DynamicQuery.PREDICATE_EQUALS)); +		
+		if (restrictions != null && restrictions.length > 0)
+			dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+		
+		return getQueryResult(em, dynamicQry, keysIn, ENTITY_ALIAS + "." + KEY_NAME);
+	}
+	
+	
+	/*
+	 * Appends the conditions to the query based on the tModelKey list.  With the \
default or when "orAllKeys" is passed, the keyedReferences are autonomous and are +	 \
* all AND'd or OR'd respectively.   +	 *	 
+	 */
+	public static void appendConditions(DynamicQuery qry, FindQualifiers fq, \
List<String> tmodelKeys) { +		
+		// Append the necessary tables (one will always be added connecting the entity to \
its instanceinfo table). +		appendJoinTables(qry, fq, tmodelKeys);
+		qry.AND().pad().openParen().pad();
+		
+		int count = 0;
+		int tblCount = -1;
+		for(String tmodelKey : tmodelKeys) {
+			
+			tblCount++;
+			String tmodelKeyTerm = (fq.isOrAllKeys()?entityAliasChild + "0":entityAliasChild \
+ tblCount) + ".tmodelKey"; +			qry.appendGroupedAnd(new \
DynamicQuery.Parameter(tmodelKeyTerm, tmodelKey, DynamicQuery.PREDICATE_EQUALS)); \
+			 +			if (count + 1 < tmodelKeys.size()) {
+				if (fq.isOrAllKeys())
+					qry.OR().pad();
+				else
+					qry.AND().pad();
+			}
+			
+			count++;
+		}
+		qry.closeParen().pad();
+		
+	}
+	
+	/*
+	 * Appends the necessary join table for the child entity and additional tables for \
when keys are AND'd.  This is the default behavior  +	 * so only need to add \
additional tables if "orAllKeys" has not been set. +	 */
+	public static void appendJoinTables(DynamicQuery qry, FindQualifiers fq, \
List<String> tmodelKeys) { +		
+
+		if (tmodelKeys != null & tmodelKeys.size() > 0) {
+			qry.comma().pad().append(BindingTemplateQuery.ENTITY_NAME + " " + \
BindingTemplateQuery.ENTITY_ALIAS).pad(); +			
+			StringBuffer thetaJoins = new StringBuffer(200);
+			int tblCount = 0;
+			for(int count = 0; count < tmodelKeys.size(); count++) {
+				if (count != 0) {
+					if (!fq.isOrAllKeys()) {
+						tblCount++;
+						qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild + \
tblCount).pad(); +						thetaJoins.append(entityAliasChild + (tblCount - 1) + ".id." \
+ BindingTemplateQuery.KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + \
BindingTemplateQuery.KEY_NAME + " "); \
+						thetaJoins.append(DynamicQuery.OPERATOR_AND + " "); +					}
+				}
+				else {
+					qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild + \
tblCount).pad(); +					thetaJoins.append(BindingTemplateQuery.ENTITY_ALIAS + "." + \
BindingTemplateQuery.KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + \
BindingTemplateQuery.KEY_NAME + " "); \
+					thetaJoins.append(DynamicQuery.OPERATOR_AND + " "); +				}
+			}
+			
+			qry.WHERE().pad().openParen().pad();
+			
+			qry.append(ENTITY_ALIAS + "." + KEY_NAME + " = " + \
BindingTemplateQuery.ENTITY_ALIAS + ".businessService." + KEY_NAME).pad(); \
+			qry.AND().pad(); +		
+			String thetaJoinsStr = thetaJoins.toString();
+			if (thetaJoinsStr.endsWith(DynamicQuery.OPERATOR_AND + " "))
+				thetaJoinsStr = thetaJoinsStr.substring(0, thetaJoinsStr.length() - \
(DynamicQuery.OPERATOR_AND + " ").length()); +			qry.append(thetaJoinsStr);
+
+			qry.closeParen().pad();
+		}
+	}
+	
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByTModelKeyQuery.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic