Author: agilliland
Date: Tue Apr 11 18:06:11 2006
New Revision: 393359
URL: http://svn.apache.org/viewcvs?rev=393359&view=rev
Log:
removing EOLed pingTarget.remove() method and moved logic to
pingTargetManager.removePingTarget().
Modified:
incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
incubator/roller/branches/roller-newbackend/src/org/roller/pojos/PingTargetData.java
incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
Modified:
incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java?rev=393359&r1=393358&r2=393359&view=diff
==============================================================================
---
incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
(original)
+++
incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
Tue Apr 11 18:06:11 2006
@@ -25,7 +25,11 @@
import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.roller.model.AutoPingManager;
import org.roller.model.PingTargetManager;
+import org.roller.model.RollerFactory;
+import org.roller.pojos.AutoPingData;
+import org.roller.pojos.PingQueueEntryData;
/**
@@ -67,9 +71,55 @@
public void removePingTarget(String id) throws RollerException {
- // The retrieval is necessary in order to do the necessary cleanup of
references in pingTarget.remove().
- PingTargetData pingTarget = retrievePingTarget(id);
- strategy.removeAndCommit(pingTarget);
+
+ try {
+ // begin transaction
+ this.strategy.getSession().beginTransaction();
+
+ PingTargetData pingTarget = retrievePingTarget(id);
+
+ // remove contents and then target
+ this.removePingTargetContents(pingTarget);
+ strategy.remove(pingTarget);
+
+ // commit changes
+ this.strategy.getSession().getTransaction().commit();
+ } catch (Throwable ex) {
+
+ try {
+ this.strategy.getSession().getTransaction().rollback();
+ } catch(Throwable he) {
+ log.error("Error doing rollback", he);
+ }
+
+ strategy.release();
+
+ throw new RollerException(ex);
+ }
+ }
+
+
+ /**
+ * Convenience method which removes any queued pings or auto pings that
+ * reference the given ping target.
+ */
+ private void removePingTargetContents(PingTargetData ping)
+ throws RollerException {
+
+ Session session = this.strategy.getSession();
+
+ // Remove the website's ping queue entries
+ Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+ criteria.add(Expression.eq("pingTarget", ping));
+ List queueEntries = criteria.list();
+
+ // Remove the website's auto ping configurations
+ AutoPingManager autoPingMgr =
RollerFactory.getRoller().getAutopingManager();
+ List autopings = autoPingMgr.getAutoPingsByTarget(ping);
+ Iterator it = autopings.iterator();
+ while(it.hasNext()) {
+ this.strategy.remove((AutoPingData) it.next());
+ }
}
@@ -117,11 +167,11 @@
// commit changes
this.strategy.getSession().getTransaction().commit();
- } catch (HibernateException ex) {
+ } catch (Throwable ex) {
try {
this.strategy.getSession().getTransaction().rollback();
- } catch(HibernateException he) {
+ } catch(Throwable he) {
log.error("Error doing rollback", he);
}
Modified:
incubator/roller/branches/roller-newbackend/src/org/roller/pojos/PingTargetData.java
URL:
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/pojos/PingTargetData.java?rev=393359&r1=393358&r2=393359&view=diff
==============================================================================
---
incubator/roller/branches/roller-newbackend/src/org/roller/pojos/PingTargetData.java
(original)
+++
incubator/roller/branches/roller-newbackend/src/org/roller/pojos/PingTargetData.java
Tue Apr 11 18:06:11 2006
@@ -260,23 +260,6 @@
/**
- * Remove the object.
- *
- * @throws RollerException
- * @see org.roller.pojos.PersistentObject#remove()
- */
- public void remove() throws RollerException
- {
- // First remove ping queue entries and auto ping configurations that
use this target.
- PingQueueManager pingQueueMgr =
RollerFactory.getRoller().getPingQueueManager();
- pingQueueMgr.removeQueueEntriesByPingTarget(this);
- AutoPingManager autoPingMgr =
RollerFactory.getRoller().getAutopingManager();
- List autopings = autoPingMgr.getAutoPingsByTarget(this);
- autoPingMgr.removeAutoPings(autopings);
- super.remove();
- }
-
- /**
* Generate a string form of the object appropriate for logging or
debugging.
*
* @return a string form of the object appropriate for logging or
debugging.
Modified:
incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
URL:
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java?rev=393359&r1=393358&r2=393359&view=diff
==============================================================================
---
incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
(original)
+++
incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
Tue Apr 11 18:06:11 2006
@@ -358,4 +358,13 @@
}
+
+ /**
+ * Test that we can properly remove a ping target when it has
+ * associated elements like auto pings and ping queue entries.
+ */
+ public void testRemoveLoadedPingTarget() throws Exception {
+ // TODO: implement this test
+ }
+
}