This project has retired. For details please refer to its Attic page.
DeletePublisherAssertionByBusinessQuery xref
View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package org.apache.juddi.query;
19  
20  import java.util.List;
21  import javax.persistence.EntityManager;
22  import javax.persistence.Query;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.juddi.query.util.DynamicQuery;
27  
28  /**
29   * 
30   * Returns the list of PublisherAssertions that contain the input businessKeys as their from or to key
31   *  * 
32   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
33   */
34  public class DeletePublisherAssertionByBusinessQuery extends PublisherAssertionQuery {
35  
36  	private static final Log log = LogFactory.getLog(DeletePublisherAssertionByBusinessQuery.class);
37  
38  	public static int delete(EntityManager em, List<?> businessKeys) {
39  		if ((businessKeys == null) || (businessKeys.size() == 0))
40  			return 0;
41  		
42  		DynamicQuery dynamicQry = new DynamicQuery(deleteSQL);
43  		appendConditions(dynamicQry, businessKeys);
44  		
45  		log.debug(dynamicQry);
46  		
47  		Query qry = dynamicQry.buildJPAQuery(em);
48  		int result = qry.executeUpdate();
49  		
50  		return result;
51  	}
52  	
53  	/*
54  	 * Appends the conditions to the query based on the businessKey list.  The keys can either be in the fromKey or toKey of the publisher assertion.
55  	 */
56  	public static void appendConditions(DynamicQuery qry, List<?> businessKeys) {
57  		
58  		qry.WHERE().pad().openParen().pad();
59  		
60  		qry.appendInList(ENTITY_ALIAS + "." + FROM_KEY_NAME, businessKeys);
61  		qry.pad().OR().pad();
62  		qry.appendInList(ENTITY_ALIAS + "." + TO_KEY_NAME, businessKeys);
63  		qry.closeParen().pad();
64  		
65  		
66  	}
67  	
68  	
69  }