File Source: JPAPingQueueManagerImpl.java

     1  
     2  /*
     3   * Licensed to the Apache Software Foundation (ASF) under one or more
     4   *  contributor license agreements.  The ASF licenses this file to You
     5   * under the Apache License, Version 2.0 (the "License"); you may not
     6   * use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.  For additional information regarding
    16   * copyright in this work, please see the NOTICE file in the top level
    17   * directory of this distribution.
    18   */
    19  package org.apache.roller.weblogger.business.jpa;
    20  
    21  import java.sql.Timestamp;
    22  import java.util.List;
    23  import javax.persistence.Query;
    24  
    25  import org.apache.commons.logging.Log;
    26  import org.apache.commons.logging.LogFactory;
    27  import org.apache.roller.weblogger.business.jpa.JPAPersistenceStrategy;
    28  
    29  import org.apache.roller.weblogger.WebloggerException;
    30  import org.apache.roller.weblogger.business.Weblogger;
    31  
    32  import org.apache.roller.weblogger.business.pings.PingQueueManager;
    33  import org.apache.roller.weblogger.pojos.AutoPing;
    34  import org.apache.roller.weblogger.pojos.PingQueueEntry;
    35  
    36  /*
    37   * JPAPingQueueManagerImpl.java
    38   *
    39   * Created on May 28, 2006, 4:11 PM
    40   *
    41   */
    42  @com.google.inject.Singleton
    43  public class JPAPingQueueManagerImpl implements PingQueueManager {
    44  
             /* 
    P/P       *  Method: org.apache.roller.weblogger.business.jpa.JPAPingQueueManagerImpl__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    45      private static Log log = LogFactory.getLog(
    46          JPAPingQueueManagerImpl.class);
    47  
    48      /** The strategy for this manager. */
    49      private final Weblogger roller;
    50      private final JPAPersistenceStrategy strategy;
    51      
    52  
    53      /**
    54       * Creates a new instance of JPAPingQueueManagerImpl
    55       */
    56      @com.google.inject.Inject
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.business.jpa.JPAPingQueueManagerImpl(Weblogger, JPAPersistenceStrategy)
              * 
              *  Postconditions:
              *    this.roller == roller
              *    init'ed(this.roller)
              *    this.strategy == strategy
              *    init'ed(this.strategy)
              */
    57      protected JPAPingQueueManagerImpl(Weblogger roller, JPAPersistenceStrategy strategy) {
    58          this.roller = roller;
    59          this.strategy =  strategy;
    60      }
    61  
    62      
    63      public PingQueueEntry getQueueEntry(String id) 
    64              throws WebloggerException {
                 /* 
    P/P           *  Method: PingQueueEntry getQueueEntry(String)
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    65          return (PingQueueEntry)strategy.load(
    66              PingQueueEntry.class, id);
    67      }
    68  
    69      public void saveQueueEntry(PingQueueEntry pingQueueEntry) 
    70              throws WebloggerException {
                 /* 
    P/P           *  Method: void saveQueueEntry(PingQueueEntry)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  */
    71          log.debug("Storing ping queue entry: " + pingQueueEntry);
    72          strategy.store(pingQueueEntry);
    73      }
    74  
    75      public void removeQueueEntry(PingQueueEntry pingQueueEntry) 
    76              throws WebloggerException {
                 /* 
    P/P           *  Method: void removeQueueEntry(PingQueueEntry)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  */
    77          log.debug("Removing ping queue entry: " + pingQueueEntry);
    78          strategy.remove(pingQueueEntry);
    79      }
    80  
    81      
    82      public void addQueueEntry(AutoPing autoPing) throws WebloggerException {
                 /* 
    P/P           *  Method: void addQueueEntry(AutoPing)
                  * 
                  *  Preconditions:
                  *    autoPing != null
                  *    init'ed(autoPing.pcStateManager)
                  *    init'ed(autoPing.pingTarget)
                  *    init'ed(autoPing.website)
                  *    log != null
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) org/apache/roller/weblogger/pojos/AutoPing.pcInheritedFieldCount <= 232-3
                  *    (soft) this.strategy.emf != null
                  */
    83          log.debug("Creating new ping queue entry for auto ping configuration: " 
    84              + autoPing);
    85          
    86          // First check if there is an existing ping queue entry 
    87          // for the same target and website
    88          if (isAlreadyQueued(autoPing)) {
    89              log.debug("A ping queue entry is already present" +
    90                  " for this ping target and website: " + autoPing);
    91              return;
    92          }
    93  
    94          Timestamp now = new Timestamp(System.currentTimeMillis());
    95          PingQueueEntry pingQueueEntry =
    96                  new PingQueueEntry(
    97                      null, now, autoPing.getPingTarget(), 
    98                      autoPing.getWebsite(), 0);
    99          this.saveQueueEntry(pingQueueEntry);
   100      }
   101  
   102      public List getAllQueueEntries() 
   103              throws WebloggerException {
                 /* 
    P/P           *  Method: List getAllQueueEntries()
                  * 
                  *  Preconditions:
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   104          return (List)strategy.getNamedQuery(
   105                  "PingQueueEntry.getAllOrderByEntryTime").getResultList();
   106      }
   107  
   108      // private helper to determine if an has already been queued 
   109      // for the same website and ping target.
   110      private boolean isAlreadyQueued(AutoPing autoPing) 
   111          throws WebloggerException {
   112          // first, determine if an entry already exists
                 /* 
    P/P           *  Method: bool isAlreadyQueued(AutoPing)
                  * 
                  *  Preconditions:
                  *    autoPing != null
                  *    init'ed(autoPing.pcStateManager)
                  *    init'ed(autoPing.pingTarget)
                  *    init'ed(autoPing.website)
                  *    this.strategy != null
                  *    this.strategy.threadLocalEntityManager != null
                  *    (soft) org/apache/roller/weblogger/pojos/AutoPing.pcInheritedFieldCount <= 232-3
                  *    (soft) this.strategy.emf != null
                  * 
                  *  Presumptions:
                  *    javax.persistence.Query:getResultList(...)@116 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   113          Query q = strategy.getNamedQuery("PingQueueEntry.getByPingTarget&Website");
   114          q.setParameter(1, autoPing.getPingTarget());
   115          q.setParameter(2, autoPing.getWebsite());
   116          return q.getResultList().size() > 0;
   117      }
   118  
             /* 
    P/P       *  Method: void release()
              */
   119      public void release() {}
   120      
   121  
   122  }








SofCheck Inspector Build Version : 2.18479
JPAPingQueueManagerImpl.java 2009-Jan-02 14:25:16
JPAPingQueueManagerImpl.class 2009-Sep-04 03:12:31