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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */1718package org.apache.juddi.query;
1920import java.util.List;
21import javax.persistence.EntityManager;
22import javax.persistence.Query;
2324import org.apache.commons.logging.Log;
25import org.apache.commons.logging.LogFactory;
26import org.apache.juddi.query.util.DynamicQuery;
2728/**29 * 30 * Returns the list of PublisherAssertions that contain the input businessKeys as their from or to key31 * * 32 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>33 */34publicclassDeletePublisherAssertionByBusinessQueryextendsPublisherAssertionQuery {
3536privatestaticfinal Log log = LogFactory.getLog(DeletePublisherAssertionByBusinessQuery.class);
3738publicstaticint delete(EntityManager em, List<?> businessKeys) {
39if ((businessKeys == null) || (businessKeys.size() == 0))
40return 0;
4142 DynamicQuery dynamicQry = newDynamicQuery(deleteSQL);
43 appendConditions(dynamicQry, businessKeys);
4445 log.debug(dynamicQry);
4647 Query qry = dynamicQry.buildJPAQuery(em);
48int result = qry.executeUpdate();
4950return result;
51 }
5253/*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 */56publicstaticvoid appendConditions(DynamicQuery qry, List<?> businessKeys) {
5758 qry.WHERE().pad().openParen().pad();
5960 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();
646566 }
676869 }