File Source: JPAAutoPingManagerImpl.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * 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.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  package org.apache.roller.weblogger.business.jpa;
    19  
    20  import org.apache.commons.logging.Log;
    21  import org.apache.commons.logging.LogFactory;
    22  import org.apache.roller.weblogger.WebloggerException;
    23  import org.apache.roller.weblogger.business.pings.AutoPingManager;
    24  import org.apache.roller.weblogger.business.pings.PingQueueManager;
    25  import org.apache.roller.weblogger.config.PingConfig;
    26  import org.apache.roller.weblogger.pojos.AutoPing;
    27  import org.apache.roller.weblogger.pojos.PingTarget;
    28  import org.apache.roller.weblogger.pojos.WeblogEntry;
    29  import org.apache.roller.weblogger.pojos.Weblog;
    30  import java.util.Collection;
    31  import java.util.Collections;
    32  import java.util.Iterator;
    33  import java.util.List;
    34  import javax.persistence.Query;
    35  import org.apache.roller.weblogger.business.jpa.JPAPersistenceStrategy;
    36  import org.apache.roller.weblogger.business.Weblogger;
    37  
    38  /*
    39   * JPAAutoPingManagerImpl.java
    40   *
    41   * Created on May 29, 2006, 11:29 AM
    42   *
    43   */
    44  @com.google.inject.Singleton
    45  public class JPAAutoPingManagerImpl implements AutoPingManager {
    46  
    47      private final Weblogger roller;
    48      private final JPAPersistenceStrategy strategy;
    49      /**
    50       * The logger instance for this class.
    51       */
             /* 
    P/P       *  Method: org.apache.roller.weblogger.business.jpa.JPAAutoPingManagerImpl__static_init
              * 
              *  Presumptions:
              *    org.apache.commons.logging.LogFactory:getFactory(...)@52 != null
              * 
              *  Postconditions:
              *    init'ed(logger)
              */
    52      private static Log logger = LogFactory.getFactory().getInstance(JPAAutoPingManagerImpl.class);
    53  
    54      /**
    55       * Creates a new instance of JPAAutoPingManagerImpl
    56       */
    57      @com.google.inject.Inject
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.business.jpa.JPAAutoPingManagerImpl(Weblogger, JPAPersistenceStrategy)
              * 
              *  Postconditions:
              *    this.roller == roller
              *    init'ed(this.roller)
              *    this.strategy == strategy
              *    init'ed(this.strategy)
              */
    58      protected JPAAutoPingManagerImpl(Weblogger roller, JPAPersistenceStrategy strategy) {
    59          this.roller = roller;
    60          this.strategy = strategy;
    61      }
    62  
    63      public AutoPing getAutoPing(String id) throws WebloggerException {
                 /* 
    P/P           *  Method: AutoPing getAutoPing(String)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    64          return (AutoPing) strategy.load(AutoPing.class, id);
    65      }
    66  
    67      public void saveAutoPing(AutoPing autoPing) throws WebloggerException {
                 /* 
    P/P           *  Method: void saveAutoPing(AutoPing)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  */
    68          strategy.store(autoPing);
    69      }
    70  
    71      public void removeAutoPing(AutoPing autoPing) throws WebloggerException {
                 /* 
    P/P           *  Method: void removeAutoPing(AutoPing)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  */
    72          strategy.remove(autoPing);
    73      }
    74  
    75      public void removeAutoPing(PingTarget pingTarget, Weblog website) throws WebloggerException {
                 /* 
    P/P           *  Method: void removeAutoPing(PingTarget, Weblog)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Presumptions:
                  *    javax.persistence.EntityManager:createNamedQuery(...)@301 != null
                  */
    76          Query q = strategy.getNamedUpdate("AutoPing.removeByPingTarget&Website");
    77          q.setParameter(1, pingTarget);
    78          q.setParameter(2, website);
    79          q.executeUpdate();
    80      }
    81  
    82      public void removeAutoPings(Collection autopings) throws WebloggerException {
                 /* 
    P/P           *  Method: void removeAutoPings(Collection)
                  * 
                  *  Preconditions:
                  *    autopings != null
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  */
    83          strategy.removeAll(autopings);
    84      }
    85  
    86      public void removeAllAutoPings() throws WebloggerException {
                 /* 
    P/P           *  Method: void removeAllAutoPings()
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Presumptions:
                  *    javax.persistence.EntityManager:createNamedQuery(...)@301 != null
                  *    javax.persistence.Query:getResultList(...)@88 != null
                  */
    87          Query q = strategy.getNamedUpdate("AutoPing.getAll");
    88          removeAutoPings(q.getResultList());
    89      }
    90  
    91      public void queueApplicableAutoPings(WeblogEntry changedWeblogEntry) throws WebloggerException {
                 /* 
    P/P           *  Method: void queueApplicableAutoPings(WeblogEntry)
                  * 
                  *  Preconditions:
                  *    org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
                  *    (soft) changedWeblogEntry != null
                  *    (soft) logger != null
                  *    (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
                  *    (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
                  *    (soft) org/apache/roller/weblogger/business/jpa/JPAPingQueueManagerImpl.log != null
                  *    (soft) org/apache/roller/weblogger/pojos/AutoPing.pcInheritedFieldCount <= 232-3
                  *    (soft) this.roller != null
                  *    (soft) this.roller.pingQueueManager != null
                  *    (soft) this.roller.pingQueueManager.strategy != null
                  *    ...
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@102 != null
                  *    javax.persistence.Query:getResultList(...)@110 != null
                  *    pingQueueMgr.strategy.emf@100 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@101: {0}, {1}
                  *    org.apache.commons.logging.Log:isDebugEnabled(...)@93: {0}, {1}
                  */
    92          if (PingConfig.getSuspendPingProcessing()) {
    93              if (logger.isDebugEnabled()) {
    94                  logger.debug("Ping processing is suspended." + " No auto pings will be queued.");
    95              }
    96              return;
    97          }
    98  
    99          PingQueueManager pingQueueMgr = roller.getPingQueueManager();
   100          List applicableAutopings = getApplicableAutoPings(changedWeblogEntry);
   101          for (Iterator i = applicableAutopings.iterator(); i.hasNext();) {
   102              AutoPing autoPing = (AutoPing) i.next();
   103              pingQueueMgr.addQueueEntry(autoPing);
   104          }
   105      }
   106  
   107      public List getAutoPingsByWebsite(Weblog website) throws WebloggerException {
                 /* 
    P/P           *  Method: List getAutoPingsByWebsite(Weblog)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   108          Query q = strategy.getNamedQuery("AutoPing.getByWebsite");
   109          q.setParameter(1, website);
   110          return q.getResultList();
   111      }
   112  
   113      public List getAutoPingsByTarget(PingTarget pingTarget) throws WebloggerException {
                 /* 
    P/P           *  Method: List getAutoPingsByTarget(PingTarget)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   114          Query q = strategy.getNamedQuery("AutoPing.getByPingTarget");
   115          q.setParameter(1, pingTarget);
   116          return q.getResultList();
   117      }
   118  
   119      public List getApplicableAutoPings(WeblogEntry changedWeblogEntry) throws WebloggerException {
                 /* 
    P/P           *  Method: List getApplicableAutoPings(WeblogEntry)
                  * 
                  *  Preconditions:
                  *    changedWeblogEntry != null
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   120          return getAutoPingsByWebsite(changedWeblogEntry.getWebsite());
   121          //        return (List)strategy.newQuery(AutoPing.class, "AutoPing.getByWebsite")
   122          //            .execute(changedWeblogEntry.getWebsite());
   123      }
   124  
   125      public List getCategoryRestrictions(AutoPing autoPing) throws WebloggerException {
                 /* 
    P/P           *  Method: List getCategoryRestrictions(AutoPing)
                  * 
                  *  Presumptions:
                  *    init'ed(java.util.Collections.EMPTY_LIST)
                  * 
                  *  Postconditions:
                  *    return_value == java.util.Collections.EMPTY_LIST
                  *    (soft) init'ed(return_value)
                  */
   126          return Collections.EMPTY_LIST;
   127      }
   128  
   129      public void setCategoryRestrictions(AutoPing autoPing, Collection newCategories) {
   130          // NOT YET IMPLEMENTED
             /* 
    P/P       *  Method: void setCategoryRestrictions(AutoPing, Collection)
              */
   131      }
   132  
   133      public void release() {
             /* 
    P/P       *  Method: void release()
              */
   134      }
   135  }








SofCheck Inspector Build Version : 2.18479
JPAAutoPingManagerImpl.java 2009-Jan-02 14:25:46
JPAAutoPingManagerImpl.class 2009-Sep-04 03:12:30