geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1103670 - in /geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query: FindEntityByNamesQuery.java FindTModelByNameQuery.java
Date Mon, 16 May 2011 10:09:42 GMT
Author: genspring
Date: Mon May 16 10:09:41 2011
New Revision: 1103670

URL: http://svn.apache.org/viewvc?rev=1103670&view=rev
Log:
If the name in query contains "%" , it sould be a like clause.

Added:
    geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java
    geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java

Added: geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java?rev=1103670&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java
(added)
+++ geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java
Mon May 16 10:09:41 2011
@@ -0,0 +1,166 @@
+/*
+ * 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")
+	private static Log log = LogFactory.getLog(FindEntityByNamesQuery.class);
+
+	private String entityName;
+	private String entityAlias;
+	private String keyName;
+	private String entityField;
+	private String entityNameChild;
+	private String entityAliasChild;
+	private String selectSQL;
+	
+	public FindEntityByNamesQuery(String entityName, String entityAlias, String keyName, String
entityField, String entityNameChild) {
+		this.entityName = entityName;
+		this.entityAlias = entityAlias;
+		this.keyName = keyName;
+		this.entityField = entityField;
+		this.entityNameChild = entityNameChild;
+		this.entityAliasChild = buildAlias(entityNameChild);
+		
+		StringBuffer sql = new StringBuffer(200);
+		sql.append("select distinct " + entityAlias + "." + keyName + " from " + entityName + "
" + entityAlias + " ");
+		selectSQL = sql.toString();
+	}
+
+	public String getEntityName() {
+		return entityName;
+	}
+
+	public String getEntityAlias() {
+		return entityAlias;
+	}
+
+	public String getKeyName() {
+		return keyName;
+	}
+	
+	public String getEntityField() {
+		return entityField;
+	}
+
+	public String getEntityNameChild() {
+		return entityNameChild;
+	}
+	
+	public String getEntityAliasChild() {
+		return entityAliasChild;
+	}
+
+	public String getSelectSQL() {
+		return selectSQL;
+	}
+	
+	
+	public List<?> select(EntityManager em, FindQualifiers fq, List<Name> names,
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 (names == null || names.size() == 0)
+			return keysIn;
+		
+		DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+		appendConditions(dynamicQry, fq, names);
+		if (restrictions != null && restrictions.length > 0)
+			dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+
+		return getQueryResult(em, dynamicQry, keysIn, entityAlias + "." + keyName);
+	}
+	
+	/*
+	 * 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).
+		appendJoinTables(qry, fq, names);
+		qry.AND().pad().openParen().pad();
+		
+		String namePredicate = DynamicQuery.PREDICATE_EQUALS;
+		if (fq.isApproximateMatch()) {
+			namePredicate = DynamicQuery.PREDICATE_LIKE;
+		}
+		
+		int count = 0;
+		for(Name n : names) {
+			String nameTerm = entityAliasChild + ".name";
+			String nameValue = n.getValue();
+			if (fq.isCaseInsensitiveMatch()) {
+				nameTerm = "upper(" + entityAliasChild + ".name)";
+				nameValue = n.getValue().toUpperCase();
+			}
+			
+            String tempNamePredicate = nameValue.indexOf("%") > -1 ? DynamicQuery.PREDICATE_LIKE
: namePredicate;
+			
+			// 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;
+			
+			if (n.getLang() == null || n.getLang().length() == 0 ) {
+				qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, tempNamePredicate));
+			}
+			else {
+				// Per spec, the language argument is always wildcarded and case insensitive
+				String langValue = n.getLang().endsWith(DynamicQuery.WILDCARD)?n.getLang().toUpperCase():n.getLang().toUpperCase()
+ DynamicQuery.WILDCARD;
+				qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, tempNamePredicate),

+									 new DynamicQuery.Parameter("upper(" + entityAliasChild + ".langCode)", langValue,
DynamicQuery.PREDICATE_LIKE));
+			}
+			
+			if (count + 1 < names.size())
+				qry.OR().pad();
+			
+			count++;
+		}
+		qry.closeParen().pad();
+		
+	}
+	
+	/*
+	 * Appends the necessary join table for the child entity 
+	 */
+	public void appendJoinTables(DynamicQuery qry, FindQualifiers fq, List<Name> names)
{
+		qry.comma().pad().append(entityNameChild + " " + entityAliasChild).pad();
+		qry.WHERE().pad().openParen().pad();
+		qry.append(entityAlias + "." + keyName + " = " + entityAliasChild + "." + entityField +
"." + keyName + " ");
+		qry.closeParen().pad();
+	}
+	
+}

Added: geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java?rev=1103670&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java
(added)
+++ geronimo/server/trunk/plugins/uddi/uddi-war-repackage/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java
Mon May 16 10:09:41 2011
@@ -0,0 +1,106 @@
+/*
+ * 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 tmodel keys possessing the passed Name argument.
+ * Output is restricted by list of tModel keys passed in.  If null, all tModels are searched.
+ * Output is produced by building the appropriate JPA query based on input and find qualifiers.
+ * 
+ * From specification:
+ * "This string value  represents the name of the tModel elements to be found.  Since tModel
data only has a single 
+ * name, only a single name may be passed.  The argument must match exactly since "exactMatch"
is the default behavior, 
+ * but if the "approximateMatch" findQualifier is used together with the appropriate wildcard
character, then matching 
+ * is done according to wildcard rules. See Section 5.1.6 About Wildcards for additional
information.  The name MAY be 
+ * marked with an xml:lang adornment.  If a language markup is specified, the search results
report a match only on those 
+ * entries that match both the name value and language criteria. The match on language is
a leftmost case-insensitive 
+ * comparison of the characters supplied. This allows one to find all tModels whose name
begins with an "A" and are expressed 
+ * in any dialect of French, for example.  Values which can be passed in the language criteria
adornment MUST obey the rules 
+ * governing the xml:lang data type as defined in Section 3.3.2.3 name."
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindTModelByNameQuery extends TModelQuery {
+
+	@SuppressWarnings("unused")
+	private static Log log = LogFactory.getLog(FindTModelByNameQuery.class);
+
+	public static List<?> select(EntityManager em, FindQualifiers fq, Name name, 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 (name == null)
+			return keysIn;
+		
+		DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+		appendConditions(dynamicQry, fq, name);
+		// Since this is a tModel, don't need to search the lazily deleted ones.
+		dynamicQry.AND().pad().appendGroupedAnd(new DynamicQuery.Parameter(ENTITY_ALIAS + ".deleted",
new Boolean(false), DynamicQuery.PREDICATE_EQUALS));
+		if (restrictions != null && restrictions.length > 0)
+			dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+		
+		return getQueryResult(em, dynamicQry, keysIn, ENTITY_ALIAS + "." + KEY_NAME);
+	}
+	
+	public static void appendConditions(DynamicQuery qry, FindQualifiers fq, Name name) {
+		String namePredicate = DynamicQuery.PREDICATE_EQUALS;
+		if (fq.isApproximateMatch()) {
+			namePredicate = DynamicQuery.PREDICATE_LIKE;
+		}
+
+		qry.WHERE().pad().openParen().pad();
+
+		String nameTerm = ENTITY_ALIAS + ".name";
+		String nameValue = name.getValue();
+		
+		namePredicate = nameValue.indexOf("%") > -1 ? DynamicQuery.PREDICATE_LIKE : namePredicate;
+		
+		if (fq.isCaseInsensitiveMatch()) {
+			nameTerm = "upper(" + ENTITY_ALIAS + ".name)";
+			nameValue = name.getValue().toUpperCase();
+		}
+		// 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;
+		
+		if (name.getLang() == null || name.getLang().length() == 0 ) {
+			qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate));
+		}
+		else {
+			String langValue = name.getLang().endsWith(DynamicQuery.WILDCARD)?name.getLang().toUpperCase():name.getLang().toUpperCase()
+ DynamicQuery.WILDCARD;
+			qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate), 
+								 new DynamicQuery.Parameter("upper(" + ENTITY_ALIAS + ".langCode)", langValue, DynamicQuery.PREDICATE_LIKE));
+		}
+
+		qry.closeParen().pad();
+		
+	}
+	
+}



Mime
View raw message