1 45 package org.exolab.jms.messagemgr; 46 47 import java.sql.Connection ; 48 import javax.jms.JMSException ; 49 50 import org.exolab.jms.client.JmsDestination; 51 import org.exolab.jms.persistence.DatabaseService; 52 import org.exolab.jms.persistence.PersistenceException; 53 import org.exolab.jms.persistence.SQLHelper; 54 55 56 65 public class PersistentMessageHandle extends AbstractMessageHandle { 66 67 70 private final String _persistentId; 71 72 73 82 public PersistentMessageHandle(String messageId, int priority, 83 long acceptedTime, long sequenceNumber, 84 long expiryTime, 85 JmsDestination destination) { 86 this(messageId, priority, acceptedTime, sequenceNumber, expiryTime, 87 destination, null); 88 } 89 90 101 public PersistentMessageHandle(String messageId, int priority, 102 long acceptedTime, long sequenceNumber, 103 long expiryTime, 104 JmsDestination destination, 105 String persistentId) { 106 super(messageId, priority, acceptedTime, sequenceNumber, expiryTime, 107 destination); 108 if (persistentId == null) { 109 throw new IllegalArgumentException ( 110 "Argument 'persistentId' is null"); 111 } 112 _persistentId = persistentId; 113 } 114 115 120 public boolean isPersistent() { 121 return true; 122 } 123 124 130 public void add(Connection connection) throws PersistenceException { 131 DatabaseService.getAdapter().addMessageHandle(connection, this); 132 } 133 134 140 public void update(Connection connection) throws PersistenceException { 141 DatabaseService.getAdapter().updateMessageHandle(connection, this); 142 } 143 144 149 public void reference(MessageRef reference) throws JMSException { 150 reference.reference(); 151 setMessageRef(reference); 152 } 153 154 160 public void destroy() throws JMSException { 161 Connection connection = null; 162 163 try { 164 connection = DatabaseService.getConnection(); 165 destroy(connection); 166 connection.commit(); 167 } catch (Exception exception) { 168 SQLHelper.rollback(connection); 169 throw new JMSException (exception.getMessage()); 170 } finally { 171 SQLHelper.close(connection); 172 } 173 } 174 175 182 public String getConsumerPersistentId() { 183 return _persistentId; 184 } 185 186 187 195 public void destroy(Connection connection) 196 throws JMSException , PersistenceException { 197 DatabaseService.getAdapter().removeMessageHandle(connection, this); 198 super.destroy(connection); 199 } 200 } 201 202 | Popular Tags |