You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by jf...@apache.org on 2008/10/29 05:50:21 UTC
svn commit: r708776 [1/2] - in
/webservices/juddi/branches/v3_trunk/juddi-core/src:
main/java/org/apache/juddi/api/impl/ main/java/org/apache/juddi/mapping/
main/java/org/apache/juddi/query/ main/java/org/apache/juddi/query/util/
main/java/org/apache/j...
Author: jfaath
Date: Tue Oct 28 21:50:20 2008
New Revision: 708776
URL: http://svn.apache.org/viewvc?rev=708776&view=rev
Log:
Adding lots of inquiry API functionality mainly involving searching entities. Includes dynamic query builder and queries specific to each UDDI search metric. Some features still require further development.
Added:
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByIdentifierQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByNamesQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindServiceByNameQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindTModelByIdentifierQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindTModelByNameQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/TModelQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/util/
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/util/DynamicQuery.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/util/FindQualifiers.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/util/KeyedRefTModelComparator.java (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/businessEntity1.xml
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/businessEntity2.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/businessEntity3.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/businessService1.xml
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/businessService2.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/findBinding1.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/findBusiness1.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/findService1.xml (with props)
webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/findTModel1.xml (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/mapping/MappingModelToApi.java
webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JPAUtil.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/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java?rev=708776&r1=708775&r2=708776&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 Tue Oct 28 21:50:20 2008
@@ -28,6 +28,20 @@
import org.apache.juddi.config.ResourceConfig;
import org.apache.juddi.error.UDDIErrorHelper;
import org.apache.juddi.mapping.MappingModelToApi;
+import org.apache.juddi.query.FetchBindingTemplatesQuery;
+import org.apache.juddi.query.FetchBusinessEntitiesQuery;
+import org.apache.juddi.query.FetchBusinessServicesQuery;
+import org.apache.juddi.query.FetchTModelsQuery;
+import org.apache.juddi.query.FindBindingByTModelKeyQuery;
+import org.apache.juddi.query.BindingTemplateQuery;
+import org.apache.juddi.query.FindBusinessByDiscoveryURLQuery;
+import org.apache.juddi.query.FindBusinessByIdentifierQuery;
+import org.apache.juddi.query.FindBusinessByNameQuery;
+import org.apache.juddi.query.FindServiceByNameQuery;
+import org.apache.juddi.query.BusinessServiceQuery;
+import org.apache.juddi.query.FindTModelByIdentifierQuery;
+import org.apache.juddi.query.FindTModelByNameQuery;
+import org.apache.juddi.query.util.DynamicQuery;
import org.apache.juddi.util.JPAUtil;
import org.uddi.api_v3.BindingDetail;
import org.uddi.api_v3.BusinessDetail;
@@ -51,20 +65,106 @@
import org.uddi.v3_service.DispositionReportFaultMessage;
import org.uddi.v3_service.UDDIInquiryPortType;
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
@WebService(serviceName="UDDIInquiryService",
endpointInterface="org.uddi.v3_service.UDDIInquiryPortType")
public class UDDIInquiryImpl implements UDDIInquiryPortType {
public BindingDetail findBinding(FindBinding body)
throws DispositionReportFaultMessage {
- // TODO Auto-generated method stub
- return null;
+
+ org.uddi.api_v3.BindingDetail result = new org.uddi.api_v3.BindingDetail();
+
+ // TODO: Perform necessary authentication logic
+ String authInfo = body.getAuthInfo();
+
+ // TODO: Validate input here
+ org.uddi.api_v3.TModelBag tmodelKeys = body.getTModelBag();
+ org.uddi.api_v3.CategoryBag categories = body.getCategoryBag();
+
+ org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+ findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());
+
+ EntityManager em = JPAUtil.getEntityManager();
+ EntityTransaction tx = em.getTransaction();
+ tx.begin();
+
+ List<?> keysFound = null;
+ if (body.getServiceKey() == null || body.getServiceKey().length() == 0) {
+ keysFound = FindBindingByTModelKeyQuery.select(em, findQualifiers, tmodelKeys, keysFound);
+ //keysFound = FindBindingByCategoryQuery.select(em, findQualifiers, tmodelKeys, keysFound);
+ }
+ else {
+ DynamicQuery.Parameter keyRestriction = new DynamicQuery.Parameter(BindingTemplateQuery.ENTITY_ALIAS + "." + BusinessServiceQuery.KEY_NAME, body.getServiceKey(), DynamicQuery.PREDICATE_EQUALS);
+ keysFound = FindBindingByTModelKeyQuery.select(em, findQualifiers, tmodelKeys, keysFound, keyRestriction);
+ //keysFound = FindBindingByCategoryQuery.select(em, findQualifiers, tmodelKeys, keysFound, keyRestriction);
+ }
+
+ // Sort and retrieve the final results with paging taken into account
+ List<?> queryResults = FetchBindingTemplatesQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead());
+
+ for (Object item : queryResults) {
+ org.apache.juddi.model.BindingTemplate modelBindingTemplate = (org.apache.juddi.model.BindingTemplate)item;
+ org.uddi.api_v3.BindingTemplate apiBindingTemplate = new org.uddi.api_v3.BindingTemplate();
+
+ MappingModelToApi.mapBindingTemplate(modelBindingTemplate, apiBindingTemplate);
+
+ result.getBindingTemplate().add(apiBindingTemplate);
+ }
+
+ tx.commit();
+ em.close();
+
+ return result;
}
public BusinessList findBusiness(FindBusiness body)
throws DispositionReportFaultMessage {
- // TODO Auto-generated method stub
- return null;
+
+ org.uddi.api_v3.BusinessList result = new org.uddi.api_v3.BusinessList();
+
+ // TODO: Perform necessary authentication logic
+ String authInfo = body.getAuthInfo();
+
+ // TODO: Validate input here
+ org.uddi.api_v3.IdentifierBag identifiers = body.getIdentifierBag();
+ org.uddi.api_v3.DiscoveryURLs discURLs = body.getDiscoveryURLs();
+ org.uddi.api_v3.CategoryBag categories = body.getCategoryBag();
+ List<org.uddi.api_v3.Name> names = body.getName();
+
+ org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+ findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());
+
+ EntityManager em = JPAUtil.getEntityManager();
+ EntityTransaction tx = em.getTransaction();
+ tx.begin();
+
+ List<?> keysFound = null;
+ keysFound = FindBusinessByIdentifierQuery.select(em, findQualifiers, identifiers, keysFound);
+ keysFound = FindBusinessByDiscoveryURLQuery.select(em, findQualifiers, discURLs, keysFound);
+ //keysFound = FindBusinessByCategoryQuery.select(em, findQualifiers, categories, keysFound);
+ keysFound = FindBusinessByNameQuery.select(em, findQualifiers, names, keysFound);
+
+ // Sort and retrieve the final results taking paging into account
+ List<?> queryResults = FetchBusinessEntitiesQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead());
+ if (queryResults != null && queryResults.size() > 0)
+ result.setBusinessInfos(new org.uddi.api_v3.BusinessInfos());
+
+ for (Object item : queryResults) {
+ org.apache.juddi.model.BusinessEntity modelBusinessEntity = (org.apache.juddi.model.BusinessEntity)item;
+ org.uddi.api_v3.BusinessInfo apiBusinessInfo = new org.uddi.api_v3.BusinessInfo();
+
+ MappingModelToApi.mapBusinessInfo(modelBusinessEntity, apiBusinessInfo);
+
+ result.getBusinessInfos().getBusinessInfo().add(apiBusinessInfo);
+ }
+
+ tx.commit();
+ em.close();
+
+ return result;
}
public RelatedBusinessesList findRelatedBusinesses(
@@ -75,14 +175,91 @@
public ServiceList findService(FindService body)
throws DispositionReportFaultMessage {
- // TODO Auto-generated method stub
- return null;
+
+ org.uddi.api_v3.ServiceList result = new org.uddi.api_v3.ServiceList();
+
+ // TODO: Perform necessary authentication logic
+ String authInfo = body.getAuthInfo();
+
+ // TODO: Validate input here
+ org.uddi.api_v3.CategoryBag categories = body.getCategoryBag();
+ List<org.uddi.api_v3.Name> names = body.getName();
+
+ org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+ findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());
+
+
+ EntityManager em = JPAUtil.getEntityManager();
+ EntityTransaction tx = em.getTransaction();
+ tx.begin();
+
+ List<?> keysFound = null;
+ //keysFound = FindServiceByCategoryQuery.select(em, findQualifiers, categories, keysFound);
+ keysFound = FindServiceByNameQuery.select(em, findQualifiers, names, keysFound);
+
+ // Sort and retrieve the final results taking paging into account
+ List<?> queryResults = FetchBusinessServicesQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead());
+ if (queryResults != null && queryResults.size() > 0)
+ result.setServiceInfos(new org.uddi.api_v3.ServiceInfos());
+
+ for (Object item : queryResults) {
+ org.apache.juddi.model.BusinessService modelBusinessService = (org.apache.juddi.model.BusinessService)item;
+ org.uddi.api_v3.ServiceInfo apiServiceInfo = new org.uddi.api_v3.ServiceInfo();
+
+ MappingModelToApi.mapServiceInfo(modelBusinessService, apiServiceInfo);
+
+ result.getServiceInfos().getServiceInfo().add(apiServiceInfo);
+ }
+
+ tx.commit();
+ em.close();
+
+ return result;
}
public TModelList findTModel(FindTModel body)
throws DispositionReportFaultMessage {
- // TODO Auto-generated method stub
- return null;
+
+ org.uddi.api_v3.TModelList result = new org.uddi.api_v3.TModelList();
+
+ // TODO: Perform necessary authentication logic
+ String authInfo = body.getAuthInfo();
+
+ // TODO: Validate input here
+ org.uddi.api_v3.IdentifierBag identifiers = body.getIdentifierBag();
+ org.uddi.api_v3.CategoryBag categories = body.getCategoryBag();
+ org.uddi.api_v3.Name name = body.getName();
+
+ org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
+ findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());
+
+ EntityManager em = JPAUtil.getEntityManager();
+ EntityTransaction tx = em.getTransaction();
+ tx.begin();
+
+ List<?> keysFound = null;
+ keysFound = FindTModelByIdentifierQuery.select(em, findQualifiers, identifiers, keysFound);
+ //keysFound = FindTModelByCategoryQuery.select(em, findQualifiers, identifiers, keysFound);
+ keysFound = FindTModelByNameQuery.select(em, findQualifiers, name, keysFound);
+
+ // Sort and retrieve the final results taking paging into account
+ List<?> queryResults = FetchTModelsQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead());
+ if (queryResults != null && queryResults.size() > 0)
+ result.setTModelInfos(new org.uddi.api_v3.TModelInfos());
+
+ for (Object item : queryResults) {
+ org.apache.juddi.model.Tmodel modelTModel = (org.apache.juddi.model.Tmodel)item;
+ org.uddi.api_v3.TModelInfo apiTModelInfo = new org.uddi.api_v3.TModelInfo();
+
+ MappingModelToApi.mapTModelInfo(modelTModel, apiTModelInfo);
+
+ result.getTModelInfos().getTModelInfo().add(apiTModelInfo);
+ }
+
+ tx.commit();
+ em.close();
+
+ return result;
}
public BindingDetail getBindingDetail(GetBindingDetail body)
Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java?rev=708776&r1=708775&r2=708776&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java Tue Oct 28 21:50:20 2008
@@ -528,5 +528,60 @@
apiTModel.setCategoryBag(apiCategoryBag);
}
+ public static void mapBusinessInfo(org.apache.juddi.model.BusinessEntity modelBusinessEntity,
+ org.uddi.api_v3.BusinessInfo apiBusinessInfo)
+ throws DispositionReportFaultMessage {
+
+ apiBusinessInfo.setBusinessKey(modelBusinessEntity.getBusinessKey());
+
+ mapBusinessNames(modelBusinessEntity.getBusinessNames(), apiBusinessInfo.getName());
+ mapBusinessDescriptions(modelBusinessEntity.getBusinessDescrs(), apiBusinessInfo.getDescription());
+
+ mapServiceInfos(modelBusinessEntity.getBusinessServices(), apiBusinessInfo.getServiceInfos(), apiBusinessInfo);
+
+ }
+
+ public static void mapServiceInfos(Set<org.apache.juddi.model.BusinessService> modelBusinessServiceList,
+ org.uddi.api_v3.ServiceInfos apiServiceInfos,
+ org.uddi.api_v3.BusinessInfo apiBusinessInfo)
+ throws DispositionReportFaultMessage {
+ if (apiServiceInfos == null)
+ apiServiceInfos = new org.uddi.api_v3.ServiceInfos();
+
+ List<org.uddi.api_v3.ServiceInfo> apiServiceInfoList = apiServiceInfos.getServiceInfo();
+ apiServiceInfoList.clear();
+
+ for (org.apache.juddi.model.BusinessService modelBusinessService : modelBusinessServiceList) {
+ org.uddi.api_v3.ServiceInfo apiServiceInfo = new org.uddi.api_v3.ServiceInfo();
+
+ mapServiceInfo(modelBusinessService, apiServiceInfo);
+
+ apiServiceInfos.getServiceInfo().add(apiServiceInfo);
+ }
+ apiBusinessInfo.setServiceInfos(apiServiceInfos);
+ }
+
+ public static void mapServiceInfo(org.apache.juddi.model.BusinessService modelBusinessService,
+ org.uddi.api_v3.ServiceInfo apiServiceInfo)
+ throws DispositionReportFaultMessage {
+
+ apiServiceInfo.setBusinessKey(modelBusinessService.getBusinessEntity().getBusinessKey());
+ apiServiceInfo.setServiceKey(modelBusinessService.getServiceKey());
+
+ mapServiceNames(modelBusinessService.getServiceNames(), apiServiceInfo.getName());
+ }
+
+ public static void mapTModelInfo(org.apache.juddi.model.Tmodel modelTModel,
+ org.uddi.api_v3.TModelInfo apiTModelInfo)
+ throws DispositionReportFaultMessage {
+
+ apiTModelInfo.setTModelKey(modelTModel.getTmodelKey());
+ org.uddi.api_v3.Name apiName = new org.uddi.api_v3.Name();
+ apiName.setValue(modelTModel.getName());
+ apiTModelInfo.setName(apiName);
+
+ mapTModelDescriptions(modelTModel.getTmodelDescrs(), apiTModelInfo.getDescription());
+
+ }
}
Added: 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/main/java/org/apache/juddi/query/BindingTemplateQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class BindingTemplateQuery extends EntityQuery {
+
+ public static final String ENTITY_NAME = "BindingTemplate";
+ public static final String ENTITY_ALIAS = "b";
+ public static final String KEY_NAME = "bindingKey";
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct "+ ENTITY_ALIAS + "." + KEY_NAME + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static String getSelectSQL() {
+ return selectSQL;
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BindingTemplateQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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/main/java/org/apache/juddi/query/BusinessEntityQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class BusinessEntityQuery extends EntityQuery {
+
+ public static final String ENTITY_NAME = "BusinessEntity";
+ public static final String ENTITY_ALIAS = "b";
+ public static final String KEY_NAME = "businessKey";
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct "+ ENTITY_ALIAS + "." + KEY_NAME + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static String getSelectSQL() {
+ return selectSQL;
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessEntityQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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/main/java/org/apache/juddi/query/BusinessServiceQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class BusinessServiceQuery extends EntityQuery {
+
+ public static final String ENTITY_NAME = "BusinessService";
+ public static final String ENTITY_ALIAS = "s";
+ public static final String KEY_NAME = "serviceKey";
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct "+ ENTITY_ALIAS + "." + KEY_NAME + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static String getSelectSQL() {
+ return selectSQL;
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/BusinessServiceQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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/main/java/org/apache/juddi/query/EntityQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,56 @@
+/*
+ * 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 javax.persistence.Query;
+
+import org.apache.juddi.query.util.DynamicQuery;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public abstract class EntityQuery {
+ public static final String GENERAL_KEYWORD_TMODEL = "uddi:uddi-org:general_keywords";
+
+ public static String buildAlias(String entityName) {
+ if (entityName == null || entityName.length() == 0)
+ return "x";
+
+ return entityName.substring(0, entityName.length() - 3);
+ }
+
+ public static List<?> getPagedResult(EntityManager em, DynamicQuery dynamicQry, Integer maxRows, Integer listHead) {
+
+ if (maxRows == null || maxRows <= 0)
+ maxRows = 10; //TODO: set to system default
+
+ if (listHead == null || listHead <= 0)
+ listHead = 0;
+
+
+ Query qry = dynamicQry.buildJPAQuery(em);
+ qry.setMaxResults(maxRows);
+ qry.setFirstResult(listHead);
+
+ return qry.getResultList();
+
+
+ }
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/EntityQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,89 @@
+/*
+ * 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.Collections;
+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.v3_service.DispositionReportFaultMessage;
+
+/**
+ * The "select" 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 <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FetchBindingTemplatesQuery extends BindingTemplateQuery {
+
+ private static Logger log = Logger.getLogger(FetchBindingTemplatesQuery.class);
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct " + ENTITY_ALIAS + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, List<?> keysIn, Integer maxRows, Integer listHead) throws DispositionReportFaultMessage {
+
+ // If keysIn is null or empty, then nothing to fetch.
+ if ((keysIn == null) || (keysIn.size() == 0))
+ return Collections.emptyList();
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendSortTables(dynamicQry);
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+ appendSortCriteria(dynamicQry, fq);
+
+ log.debug(dynamicQry);
+
+ return getPagedResult(em, dynamicQry, maxRows, listHead);
+ }
+
+ private static void appendSortTables(DynamicQuery qry) {
+ // BindingTemplates can only be sorted by date.
+ qry.WHERE().pad().append("1=1").pad();
+ }
+
+ /*
+ * BindingTemplates can only be sorted by date.
+ */
+ private static void appendSortCriteria(DynamicQuery qry, FindQualifiers fq) {
+
+ qry.ORDERBY().pad();
+
+ if (fq.isSortByDateAsc())
+ qry.append(ENTITY_ALIAS + ".lastUpdate").pad().append(DynamicQuery.SORT_ASC);
+ else
+ qry.append(ENTITY_ALIAS + ".lastUpdate").pad().append(DynamicQuery.SORT_DESC);
+
+ qry.pad();
+
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBindingTemplatesQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.Collections;
+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.v3_service.DispositionReportFaultMessage;
+
+/**
+ * The "select" 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 <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FetchBusinessEntitiesQuery extends BusinessEntityQuery {
+
+ private static Logger log = Logger.getLogger(FetchBusinessEntitiesQuery.class);
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct " + ENTITY_ALIAS + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, List<?> keysIn, Integer maxRows, Integer listHead) throws DispositionReportFaultMessage {
+
+ // If keysIn is null or empty, then nothing to fetch.
+ if ((keysIn == null) || (keysIn.size() == 0))
+ return Collections.emptyList();
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendSortTables(dynamicQry);
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+ appendSortCriteria(dynamicQry, fq);
+
+ log.debug(dynamicQry);
+
+ return getPagedResult(em, dynamicQry, maxRows, listHead);
+ }
+
+ private static void appendSortTables(DynamicQuery qry) {
+ qry.pad().comma().pad().append(FindBusinessByNameQuery.ENTITY_NAME_CHILD).pad().append(buildAlias(FindBusinessByNameQuery.ENTITY_NAME_CHILD)).pad();
+ qry.WHERE().pad().append(ENTITY_ALIAS + "." + KEY_NAME).pad();
+ qry.append(DynamicQuery.PREDICATE_EQUALS).pad();
+ qry.append(buildAlias(FindBusinessByNameQuery.ENTITY_NAME_CHILD) + ".id." + KEY_NAME).pad();
+ }
+
+ /*
+ * Default ordering is name ascending and date descending. If a name item is set, then it will always go first. If only a date item is set, then date will
+ * go first, and the name sort will occur second in ascending order.
+ */
+ private static void appendSortCriteria(DynamicQuery qry, FindQualifiers fq) {
+
+ String nameTerm = buildAlias(FindBusinessByNameQuery.ENTITY_NAME_CHILD) + ".name";
+ if (fq.isCaseInsensitiveSort())
+ nameTerm = "upper(" + nameTerm + ")";
+
+ String dateTerm = ENTITY_ALIAS + ".lastUpdate";
+
+ String orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ if (fq.isSortByNameAsc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ }
+ else if (fq.isSortByNameDesc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ else
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ }
+ else if (fq.isSortByDateAsc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_ASC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+ else if (fq.isSortByDateDesc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_DESC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+
+ qry.ORDERBY().pad();
+ qry.append(orderClause);
+ qry.pad();
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessEntitiesQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.Collections;
+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.v3_service.DispositionReportFaultMessage;
+
+/**
+ * The "select" 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 <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FetchBusinessServicesQuery extends BusinessServiceQuery {
+
+ private static Logger log = Logger.getLogger(FetchBusinessServicesQuery.class);
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct " + ENTITY_ALIAS + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, List<?> keysIn, Integer maxRows, Integer listHead) throws DispositionReportFaultMessage {
+
+ // If keysIn is null or empty, then nothing to fetch.
+ if ((keysIn == null) || (keysIn.size() == 0))
+ return Collections.emptyList();
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendSortTables(dynamicQry);
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+ appendSortCriteria(dynamicQry, fq);
+
+ log.debug(dynamicQry);
+
+ return getPagedResult(em, dynamicQry, maxRows, listHead);
+ }
+
+ private static void appendSortTables(DynamicQuery qry) {
+ qry.pad().comma().pad().append(FindServiceByNameQuery.ENTITY_NAME_CHILD).pad().append(buildAlias(FindServiceByNameQuery.ENTITY_NAME_CHILD)).pad();
+ qry.WHERE().pad().append(ENTITY_ALIAS + "." + KEY_NAME).pad();
+ qry.append(DynamicQuery.PREDICATE_EQUALS).pad();
+ qry.append(buildAlias(FindServiceByNameQuery.ENTITY_NAME_CHILD) + ".id." + KEY_NAME).pad();
+ }
+
+ /*
+ * Default ordering is name ascending and date descending. If a name item is set, then it will always go first. If only a date item is set, then date will
+ * go first, and the name sort will occur second in ascending order.
+ */
+ private static void appendSortCriteria(DynamicQuery qry, FindQualifiers fq) {
+
+ String nameTerm = buildAlias(FindServiceByNameQuery.ENTITY_NAME_CHILD) + ".name";
+ if (fq.isCaseInsensitiveSort())
+ nameTerm = "upper(" + nameTerm + ")";
+
+ String dateTerm = ENTITY_ALIAS + ".lastUpdate";
+
+ String orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ if (fq.isSortByNameAsc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ }
+ else if (fq.isSortByNameDesc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ else
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ }
+ else if (fq.isSortByDateAsc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_ASC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+ else if (fq.isSortByDateDesc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_DESC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+
+ qry.ORDERBY().pad();
+ qry.append(orderClause);
+ qry.pad();
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchBusinessServicesQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java Tue Oct 28 21:50:20 2008
@@ -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.Collections;
+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.v3_service.DispositionReportFaultMessage;
+
+/**
+ * The "select" 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 <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FetchTModelsQuery extends BusinessEntityQuery {
+
+ private static Logger log = Logger.getLogger(FetchTModelsQuery.class);
+
+ protected static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select distinct " + ENTITY_ALIAS + " from " + ENTITY_NAME + " " + ENTITY_ALIAS + " ");
+ selectSQL = sql.toString();
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, List<?> keysIn, Integer maxRows, Integer listHead) throws DispositionReportFaultMessage {
+
+ // If keysIn is null or empty, then nothing to fetch.
+ if ((keysIn == null) || (keysIn.size() == 0))
+ return Collections.emptyList();
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendSortTables(dynamicQry);
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+ appendSortCriteria(dynamicQry, fq);
+
+ log.debug(dynamicQry);
+
+ return getPagedResult(em, dynamicQry, maxRows, listHead);
+ }
+
+ private static void appendSortTables(DynamicQuery qry) {
+ // TModels don't need the join table, the single name is in the main table.
+ qry.WHERE().pad().append("1=1").pad();
+ }
+
+ /*
+ * Default ordering is name ascending and date descending. If a name item is set, then it will always go first. If only a date item is set, then date will
+ * go first, and the name sort will occur second in ascending order.
+ */
+ private static void appendSortCriteria(DynamicQuery qry, FindQualifiers fq) {
+
+ String nameTerm = ENTITY_ALIAS + ".name";
+ if (fq.isCaseInsensitiveSort())
+ nameTerm = "upper(" + nameTerm + ")";
+
+ String dateTerm = ENTITY_ALIAS + ".lastUpdate";
+
+ String orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ if (fq.isSortByNameAsc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_ASC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ }
+ else if (fq.isSortByNameDesc()) {
+ if (fq.isSortByDateAsc())
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_ASC;
+ else
+ orderClause = nameTerm + " " + DynamicQuery.SORT_DESC + ", " + dateTerm + " " + DynamicQuery.SORT_DESC;
+ }
+ else if (fq.isSortByDateAsc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_ASC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+ else if (fq.isSortByDateDesc())
+ orderClause = dateTerm + " " + DynamicQuery.SORT_DESC + ", " + nameTerm + " " + DynamicQuery.SORT_ASC;
+
+ qry.ORDERBY().pad();
+ qry.append(orderClause);
+ qry.pad();
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FetchTModelsQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBindingByTModelKeyQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,155 @@
+/*
+ * 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 javax.persistence.Query;
+
+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 "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.
+ * 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.
+ *
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindBindingByTModelKeyQuery extends BindingTemplateQuery {
+
+ private static Logger log = Logger.getLogger(FindBindingByTModelKeyQuery.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);
+
+ // TODO: Break up the IN clause into an amount that is configurable (see JUDDI-146)
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+
+ log.debug(dynamicQry);
+
+ Query qry = dynamicQry.buildJPAQuery(em);
+ List<?> result = qry.getResultList();
+
+ return result;
+ }
+
+
+ /*
+ * 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) {
+
+ 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." + KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + KEY_NAME + " ");
+ thetaJoins.append(DynamicQuery.OPERATOR_AND + " ");
+ }
+ }
+ else {
+ qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild + tblCount).pad();
+ thetaJoins.append(ENTITY_ALIAS + "." + KEY_NAME + " = " + entityAliasChild + tblCount + ".id." + KEY_NAME + " ");
+ thetaJoins.append(DynamicQuery.OPERATOR_AND + " ");
+ }
+ }
+
+ qry.WHERE().pad().openParen().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/FindBindingByTModelKeyQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,143 @@
+/*
+ * 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 javax.persistence.Query;
+import javax.xml.bind.JAXBElement;
+
+import org.apache.juddi.query.util.DynamicQuery;
+import org.apache.juddi.query.util.FindQualifiers;
+import org.uddi.api_v3.CategoryBag;
+import org.uddi.api_v3.KeyedReference;
+import org.uddi.api_v3.KeyedReferenceGroup;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindBusinessByCategoryQuery {
+ // TODO: Move this value somewhere else
+ private static String GENERAL_KEYWORD_TMODEL = "uddi:uddi-org:general_keywords";
+
+ private static String selectSQL;
+
+ static {
+ StringBuffer sql = new StringBuffer(200);
+ sql.append("select bc.id.businessKey from BusinessCategory bc ");
+ selectSQL = sql.toString();
+ }
+
+ public static List<?> select(FindQualifiers fq, CategoryBag categories, List<Object> keysIn, EntityManager em) {
+ // If keysIn is not null and empty, then search is over.
+ if ((keysIn != null) && (keysIn.size() == 0))
+ return keysIn;
+
+ if (categories == null)
+ return keysIn;
+
+ List<JAXBElement<?>> catElems = categories.getContent();
+ if (catElems == null || catElems.size() == 0)
+ return keysIn;
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendConditions(dynamicQry, fq, catElems, keysIn);
+
+ System.out.println(dynamicQry);
+
+ Query qry = dynamicQry.buildJPAQuery(em);
+ List<?> result = qry.getResultList();
+
+ return result;
+ }
+
+ public static void appendConditions(DynamicQuery qry, FindQualifiers fq, List<JAXBElement<?>> catElems, List<Object> keysIn) {
+ String predicate = DynamicQuery.PREDICATE_EQUALS;
+ if (fq.isApproximateMatch()) {
+ predicate = DynamicQuery.PREDICATE_LIKE;
+ }
+
+ int count = 0;
+ qry.WHERE().pad().openParen().pad();
+ for(JAXBElement<?> elem : catElems) {
+ String tmodelKey = null;
+ String keyValue = null;
+ String keyName = null;
+
+ if (elem != null && elem.getValue() instanceof KeyedReference) {
+ KeyedReference kr = (KeyedReference)elem.getValue();
+ tmodelKey = kr.getTModelKey();
+ keyValue = kr.getKeyValue();
+ keyName = kr.getKeyName();
+ }
+ else if (elem != null && elem.getValue() instanceof KeyedReferenceGroup) {
+
+ }
+
+ if (fq.isApproximateMatch()) {
+ keyValue = keyValue.endsWith(DynamicQuery.WILDCARD)?keyValue:keyValue + DynamicQuery.WILDCARD;
+ keyName = keyName.endsWith(DynamicQuery.WILDCARD)?keyName:keyName + DynamicQuery.WILDCARD;
+ }
+
+ String keyValueTerm = "bc.keyValue";
+ String keyNameTerm = "bc.keyName";
+ if (fq.isCaseInsensitiveMatch()) {
+ keyValueTerm = "upper(bc.keyValue)";
+ keyValue = keyValue.toUpperCase();
+
+ keyNameTerm = "upper(bc.keyName)";
+ keyName = keyName.toUpperCase();
+ }
+
+ if (GENERAL_KEYWORD_TMODEL.equals(tmodelKey)) {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter("bc.tmodelKeyRef", tmodelKey, DynamicQuery.PREDICATE_EQUALS),
+ new DynamicQuery.Parameter(keyValueTerm, keyValue, predicate),
+ new DynamicQuery.Parameter(keyNameTerm, keyName, predicate));
+ }
+ else {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter("bc.tmodelKeyRef", tmodelKey, DynamicQuery.PREDICATE_EQUALS),
+ new DynamicQuery.Parameter(keyValueTerm, keyValue, predicate));
+
+ }
+
+ if (count + 1 < catElems.size()) {
+ if (fq.isOrAllKeys())
+ qry.OR().pad();
+ else
+ qry.AND().pad();
+ }
+
+ count++;
+ }
+ qry.closeParen().pad();
+
+ qry.appendInList("bc.id.businessKey", keysIn);
+ }
+
+ public static void appendGrouping(DynamicQuery qry, FindQualifiers fq, int elemCount) {
+ qry.GROUPBY().pad().append("bc.id.businessKey").pad();
+
+ // By default, all the "keys" switches in find qualifiers are turned off. The default behavior for categories is to "AND" the keyed references.
+ if (fq.isOrAllKeys()) {
+ // do nothing
+ }
+ else
+ qry.HAVING().pad().append("count(bc.id.businessKey >=" + elemCount).pad();
+
+ }
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByCategoryQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,126 @@
+/*
+ * 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 javax.persistence.Query;
+
+import org.apache.juddi.query.util.DynamicQuery;
+import org.apache.juddi.query.util.FindQualifiers;
+import org.apache.log4j.Logger;
+import org.uddi.api_v3.DiscoveryURLs;
+import org.uddi.api_v3.DiscoveryURL;
+
+/**
+ *
+ * Returns the list of business keys possessing the DiscoveryUrls in the passed DiscoveryUrl list.
+ * Output is restricted by list of business keys passed in. If null, all businesses are searched.
+ * Output is produced by building the appropriate JPA query based on input and find qualifiers.
+ *
+ * From specification:
+ * "This is a list of discoveryURL structures to be matched against the discoveryURL data associated with registered businessEntity
+ * information. To search for URL without regard to useType attribute values, omit the useType attribute or pass it as an empty
+ * attribute. If useType values are included, the match occurs only on registered information that matches both the useType and
+ * URL value. The returned businessList contains businessInfo structures matching any of the URL's passed (logical OR)."
+ *
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindBusinessByDiscoveryURLQuery extends BusinessEntityQuery {
+
+ private static Logger log = Logger.getLogger(FindBusinessByDiscoveryURLQuery.class);
+
+ private static final String ENTITY_NAME_CHILD = "DiscoveryUrl";
+
+ private static String entityAliasChild;;
+
+ static {
+ entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, DiscoveryURLs discURLs, 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 (discURLs == null)
+ return keysIn;
+
+ List<DiscoveryURL> discURLlist = discURLs.getDiscoveryURL();
+ if (discURLlist == null || discURLlist.size() == 0)
+ return keysIn;
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendConditions(dynamicQry, fq, discURLlist);
+ if (restrictions != null && restrictions.length > 0)
+ dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+
+ // TODO: Break up the IN clause into an amount that is configurable (see JUDDI-146)
+ dynamicQry.appendInList(ENTITY_ALIAS + "." + KEY_NAME, keysIn);
+
+ log.debug(dynamicQry);
+
+ Query qry = dynamicQry.buildJPAQuery(em);
+ List<?> result = qry.getResultList();
+
+ return result;
+ }
+
+ /*
+ * Appends the conditions to the query based on the discovery url list. By default, the urls are OR'd and this cannot be changed.
+ *
+ */
+ public static void appendConditions(DynamicQuery qry, FindQualifiers fq, List<DiscoveryURL> discURLs) {
+
+ // Append the necessary tables (one will always be added connecting the entity to its discovery url table).
+ appendJoinTables(qry, fq, discURLs);
+ qry.AND().pad().openParen().pad();
+
+ int count = 0;
+ for(DiscoveryURL discURL : discURLs) {
+ String urlTerm = entityAliasChild + ".url";
+ String urlValue = discURL.getValue();
+
+ if (discURL.getUseType() == null || discURL.getUseType().length() == 0 ) {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter(urlTerm, urlValue, DynamicQuery.PREDICATE_EQUALS));
+ }
+ else {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter(urlTerm, urlValue, DynamicQuery.PREDICATE_EQUALS),
+ new DynamicQuery.Parameter(entityAliasChild + ".useType", discURL.getUseType(), DynamicQuery.PREDICATE_EQUALS));
+ }
+
+ if (count + 1 < discURLs.size())
+ qry.OR().pad();
+
+ count++;
+ }
+ qry.closeParen().pad();
+
+ }
+
+ /*
+ * Appends the necessary join table for the child entity
+ */
+ public static void appendJoinTables(DynamicQuery qry, FindQualifiers fq, List<DiscoveryURL> discURLs) {
+ qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild).pad();
+ qry.WHERE().pad().openParen().pad();
+ qry.append(ENTITY_ALIAS + "." + KEY_NAME + " = " + entityAliasChild + ".id." + KEY_NAME + " ");
+ qry.closeParen().pad();
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByDiscoveryURLQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.FindQualifiers;
+import org.uddi.api_v3.IdentifierBag;
+
+/**
+ * Returns the list of business keys possessing the keyedReferences in the passed identifier bag.
+ * Output is restricted by list of business keys passed in. If null, all business entities are searched.
+ * Output is produced by building the appropriate JPA query based on input and find qualifiers.
+ *
+ * From specification:
+ * "This is a list of business identifier references in the form of keyedReference elements. The returned
+ * businessList contains businessInfo structures matching any of the identifiers passed (logical OR by default).
+ * Specifying the appropriate findQualifiers can override this behavior"
+ *
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindBusinessByIdentifierQuery {
+
+ private static final String ENTITY_NAME_CHILD = "BusinessIdentifier";
+
+ private static FindEntityByIdentifierQuery findQuery;
+
+ static {
+ findQuery = new FindEntityByIdentifierQuery(BusinessEntityQuery.ENTITY_NAME, BusinessEntityQuery.ENTITY_ALIAS, BusinessEntityQuery.KEY_NAME, ENTITY_NAME_CHILD);
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, IdentifierBag identifiers, List<?> keysIn) {
+ return findQuery.select(em, fq, identifiers, keysIn);
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByIdentifierQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.FindQualifiers;
+import org.uddi.api_v3.Name;
+
+/**
+ * Returns the list of business keys possessing the Names in the passed Name list.
+ * Output is restricted by list of business keys passed in. If null, all businesses are searched.
+ * Output is produced by building the appropriate JPA query based on input and find qualifiers.
+ *
+ * From specification:
+ * "This optional collection of string values represents one or more names potentially qualified with xml:lang attributes.
+ * Since "exactMatch" is the default behavior, the value supplied for the name argument must be an exact match. If the "approximateMatch"
+ * findQualifier is used together with an appropriate wildcard character in the name, then any businessEntity matching this name with
+ * wildcards and the other criteria will be referenced in the results. For more on wildcard matching, see Section 5.1.6 About Wildcards.
+ * The businessList returned contains businessInfo structures for businesses whose name matches the value(s) passed
+ * (lexical-order match i.e., leftmost in left-to-right languages). If multiple name values are passed, the match occurs on a
+ * logical OR basis. Each 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 businesses 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 FindBusinessByNameQuery {
+
+ public static final String ENTITY_NAME_CHILD = "BusinessName";
+
+ private static FindEntityByNamesQuery findQuery;
+
+ static {
+ findQuery = new FindEntityByNamesQuery(BusinessEntityQuery.ENTITY_NAME, BusinessEntityQuery.ENTITY_ALIAS, BusinessEntityQuery.KEY_NAME, ENTITY_NAME_CHILD);
+ }
+
+ public static List<?> select(EntityManager em, FindQualifiers fq, List<Name> names, List<?> keysIn) {
+ return findQuery.select(em, fq, names, keysIn);
+ }
+
+}
Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindBusinessByNameQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByIdentifierQuery.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByIdentifierQuery.java?rev=708776&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByIdentifierQuery.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/query/FindEntityByIdentifierQuery.java Tue Oct 28 21:50:20 2008
@@ -0,0 +1,271 @@
+/*
+ * 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 java.util.Collections;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.juddi.query.util.DynamicQuery;
+import org.apache.juddi.query.util.FindQualifiers;
+import org.apache.juddi.query.util.KeyedRefTModelComparator;
+import org.apache.log4j.Logger;
+import org.uddi.api_v3.IdentifierBag;
+import org.uddi.api_v3.KeyedReference;
+
+/**
+ * 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.
+ * 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.
+ *
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class FindEntityByIdentifierQuery extends EntityQuery {
+
+ private Logger log = Logger.getLogger(FindEntityByIdentifierQuery.class);
+
+ private String entityName;
+ private String entityAlias;
+ private String keyName;
+ private String entityNameChild;
+ private String entityAliasChild;
+ private String selectSQL;
+
+ public FindEntityByIdentifierQuery(String entityName, String entityAlias, String keyName, String entityNameChild) {
+ this.entityName = entityName;
+ this.entityAlias = entityAlias;
+ this.keyName = keyName;
+ 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 getEntityNameChild() {
+ return entityNameChild;
+ }
+
+ public String getEntityAliasChild() {
+ return entityAliasChild;
+ }
+
+ public String getSelectSQL() {
+ return selectSQL;
+ }
+
+
+ public List<?> select(EntityManager em, FindQualifiers fq, IdentifierBag identifiers, 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 (identifiers == null)
+ return keysIn;
+
+ List<KeyedReference> keyedRefs = identifiers.getKeyedReference();
+ if (keyedRefs == null || keyedRefs.size() == 0)
+ return keysIn;
+
+ DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
+ appendConditions(dynamicQry, fq, keyedRefs);
+ if (restrictions != null && restrictions.length > 0)
+ dynamicQry.AND().pad().appendGroupedAnd(restrictions);
+
+ // TODO: Break up the IN clause into an amount that is configurable (see JUDDI-146)
+ dynamicQry.appendInList(entityAlias + "." + keyName, keysIn);
+
+ log.debug(dynamicQry);
+
+ Query qry = dynamicQry.buildJPAQuery(em);
+ List<?> result = qry.getResultList();
+
+ return result;
+ }
+
+
+ /*
+ * Appends the conditions to the query based on the keyedReference list. With the default or when "andAllKeys" is passed, the keyedReferences are autonomous and are
+ * all OR'd or AND'd respectively. However, "orLikeKeys" requires special treatment. The goal is to create the conditions in this format:
+ *
+ * (likeKey1 = X or likeKey1 = Y) and (likeKey2 = A or likeKey2 = B or likeKey2 = C)
+ *
+ * ie. the "like" KeyedReferences are OR'd and the groups of "like" KeyedReferences are AND'd with each other.
+ */
+ public void appendConditions(DynamicQuery qry, FindQualifiers fq, List<KeyedReference> keyedRefs) {
+
+ // Append the necessary tables (one will always be added connecting the entity to its identifier table).
+ appendJoinTables(qry, fq, keyedRefs);
+ qry.AND().pad().openParen().pad();
+
+ String predicate = DynamicQuery.PREDICATE_EQUALS;
+ if (fq.isApproximateMatch()) {
+ predicate = DynamicQuery.PREDICATE_LIKE;
+ }
+
+ // Sorting the collection by tModel Key
+ Collections.sort(keyedRefs, new KeyedRefTModelComparator());
+
+ String prevTModelKey = null;
+ int count = 0;
+ int tblCount = -1;
+ for(KeyedReference keyedRef : keyedRefs) {
+ String tmodelKey = keyedRef.getTModelKey();
+ String keyValue = keyedRef.getKeyValue();
+ String keyName = keyedRef.getKeyName();
+
+ if (fq.isApproximateMatch()) {
+ keyValue = keyValue.endsWith(DynamicQuery.WILDCARD)?keyValue:keyValue + DynamicQuery.WILDCARD;
+ keyName = keyName.endsWith(DynamicQuery.WILDCARD)?keyName:keyName + DynamicQuery.WILDCARD;
+ }
+
+ // Either opening up (and AND'ing) a new "group" of like keys or simply appending an "or". If this is not "orLikeKeys", then just need to increment
+ // the table count.
+ if (fq.isOrLikeKeys()) {
+ if (count == 0) {
+ qry.openParen().pad();
+ tblCount++;
+ }
+ else {
+ if (!tmodelKey.equals(prevTModelKey)) {
+ qry.closeParen().pad().AND().pad().openParen().pad();
+ tblCount++;
+ }
+ else
+ qry.OR().pad();
+ }
+ }
+ else
+ tblCount++;
+
+ String keyValueTerm = (fq.isAndAllKeys()||fq.isOrLikeKeys()?entityAliasChild + tblCount:entityAlias + "0") + ".keyValue";
+ String keyNameTerm = (fq.isAndAllKeys()||fq.isOrLikeKeys()?entityAliasChild + tblCount:entityAlias + "0") + ".keyName";
+ String tmodelKeyTerm = (fq.isAndAllKeys()||fq.isOrLikeKeys()?entityAliasChild + tblCount:entityAlias + "0") + ".tmodelKeyRef";
+ if (fq.isCaseInsensitiveMatch()) {
+ keyValueTerm = "upper(" + (fq.isAndAllKeys()||fq.isOrLikeKeys()?entityAliasChild + tblCount:entityAlias + "0") + ".keyValue)";
+ keyValue = keyValue.toUpperCase();
+
+ keyNameTerm = "upper(" + (fq.isAndAllKeys()||fq.isOrLikeKeys()?entityAliasChild + tblCount:entityAlias + "0") + ".keyName)";
+ keyName = keyName.toUpperCase();
+ }
+
+
+ // According to specification, if the "general keyword" tmodel is used, then the keyName must be part of the query.
+ if (GENERAL_KEYWORD_TMODEL.equals(tmodelKey)) {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter(tmodelKeyTerm, tmodelKey, DynamicQuery.PREDICATE_EQUALS),
+ new DynamicQuery.Parameter(keyValueTerm, keyValue, predicate),
+ new DynamicQuery.Parameter(keyNameTerm, keyName, predicate));
+ }
+ else {
+ qry.appendGroupedAnd(new DynamicQuery.Parameter(tmodelKeyTerm, tmodelKey, DynamicQuery.PREDICATE_EQUALS),
+ new DynamicQuery.Parameter(keyValueTerm, keyValue, predicate));
+
+ }
+
+ if (count + 1 < keyedRefs.size())
+ if (fq.isAndAllKeys())
+ qry.AND().pad();
+ else if (fq.isOrLikeKeys()) {
+ }
+ else
+ qry.OR().pad();
+
+ // The "orLikeKeys" will always leave an unclosed parenthesis. This will close it.
+ if (fq.isOrLikeKeys() && (count + 1 == keyedRefs.size()))
+ qry.closeParen().pad();
+
+ prevTModelKey = tmodelKey;
+ count++;
+ }
+ qry.closeParen().pad();
+
+ }
+
+ /*
+ * Appends the necessary join table for the child entity and additional tables for when keys are AND'd. When "orLikeKeys" is used,
+ * we only need an extra table for each distinct tmodelKey.
+ */
+ public void appendJoinTables(DynamicQuery qry, FindQualifiers fq, List<KeyedReference> keyedRefs) {
+
+ if (keyedRefs != null & keyedRefs.size() > 0) {
+ // Sorting the collection by tModel Key
+ Collections.sort(keyedRefs, new KeyedRefTModelComparator());
+
+ StringBuffer thetaJoins = new StringBuffer(200);
+ int tblCount = 0;
+ int count = 0;
+ String curTModelKey = null;
+ String prevTModelKey = null;
+ for(KeyedReference kr : keyedRefs) {
+ curTModelKey = kr.getTModelKey();
+ if (count != 0) {
+ if (fq.isOrLikeKeys() && curTModelKey.equals(prevTModelKey)) {
+ // Do nothing
+ }
+ else {
+ tblCount++;
+ qry.comma().pad().append(entityNameChild + " " + entityAliasChild + tblCount).pad();
+ thetaJoins.append(entityAliasChild + (tblCount - 1) + ".id." + keyName + " = " + entityAliasChild + tblCount + ".id." + keyName + " ");
+ thetaJoins.append(DynamicQuery.OPERATOR_AND + " ");
+ }
+
+ }
+ else {
+ qry.comma().pad().append(entityNameChild + " " + entityAliasChild + tblCount).pad();
+ thetaJoins.append(entityAlias + "." + keyName + " = " + entityAliasChild + tblCount + ".id." + keyName + " ");
+ thetaJoins.append(DynamicQuery.OPERATOR_AND + " ");
+ }
+ prevTModelKey = curTModelKey;
+ count++;
+ }
+
+ qry.WHERE().pad().openParen().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/FindEntityByIdentifierQuery.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