git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@378023 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-02-15 15:51:11 +00:00
parent 1667ce651b
commit 911177eb6c
5 changed files with 42 additions and 12 deletions

View File

@ -66,6 +66,7 @@ public class JDBCMessageStore implements MessageStore {
try { try {
adapter.doAddMessage(c, message.getMessageId(), destination, data, message.getExpiration()); adapter.doAddMessage(c, message.getMessageId(), destination, data, message.getExpiration());
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker message: " + message.getMessageId() + " in container: " throw IOExceptionSupport.create("Failed to broker message: " + message.getMessageId() + " in container: "
+ e, e); + e, e);
} finally { } finally {
@ -79,6 +80,7 @@ public class JDBCMessageStore implements MessageStore {
try { try {
adapter.doAddMessageReference(c, messageId, destination, expirationTime, messageRef); adapter.doAddMessageReference(c, messageId, destination, expirationTime, messageRef);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: "
+ e, e); + e, e);
} finally { } finally {
@ -102,6 +104,7 @@ public class JDBCMessageStore implements MessageStore {
} catch (IOException e) { } catch (IOException e) {
throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -118,6 +121,7 @@ public class JDBCMessageStore implements MessageStore {
} catch (IOException e) { } catch (IOException e) {
throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -132,6 +136,7 @@ public class JDBCMessageStore implements MessageStore {
try { try {
adapter.doRemoveMessage(c, seq); adapter.doRemoveMessage(c, seq);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker message: " + ack.getLastMessageId() + " in container: " + e, e); throw IOExceptionSupport.create("Failed to broker message: " + ack.getLastMessageId() + " in container: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -155,6 +160,7 @@ public class JDBCMessageStore implements MessageStore {
} }
}); });
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to recover container. Reason: " + e, e); throw IOExceptionSupport.create("Failed to recover container. Reason: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -176,6 +182,7 @@ public class JDBCMessageStore implements MessageStore {
try { try {
adapter.doRemoveAllMessages(c, destination); adapter.doRemoveAllMessages(c, destination);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to broker remove all messages: " + e, e); throw IOExceptionSupport.create("Failed to broker remove all messages: " + e, e);
} finally { } finally {
c.close(); c.close();

View File

@ -87,6 +87,7 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
} catch (IOException e) { } catch (IOException e) {
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} finally { } finally {
try { try {
@ -125,6 +126,7 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
try { try {
return getAdapter().doGetLastMessageBrokerSequenceId(c); return getAdapter().doGetLastMessageBrokerSequenceId(c);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to get last broker message id: " + e, e); throw IOExceptionSupport.create("Failed to get last broker message id: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -141,7 +143,8 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
try { try {
getAdapter().doCreateTables(transactionContext); getAdapter().doCreateTables(transactionContext);
} catch (SQLException e) { } catch (SQLException e) {
log.warn("Cannot create tables due to: " + e, e); log.warn("Cannot create tables due to: " + e);
JDBCPersistenceAdapter.log("Failure Details: ",e);
} }
} finally { } finally {
transactionContext.commit(); transactionContext.commit();
@ -176,7 +179,8 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
} catch (IOException e) { } catch (IOException e) {
log.warn("Old message cleanup failed due to: " + e, e); log.warn("Old message cleanup failed due to: " + e, e);
} catch (SQLException e) { } catch (SQLException e) {
log.warn("Old message cleanup failed due to: " + e, e); log.warn("Old message cleanup failed due to: " + e);
JDBCPersistenceAdapter.log("Failure Details: ",e);
} finally { } finally {
try { try {
c.close(); c.close();
@ -237,10 +241,9 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
} }
} catch (SQLException e) { } catch (SQLException e) {
log log.warn("JDBC error occurred while trying to detect database type. Will use default JDBC implementation: "
.warn("JDBC error occured while trying to detect database type. Will use default JDBC implementation: "
+ e.getMessage()); + e.getMessage());
log.debug("Reason: " + e, e); JDBCPersistenceAdapter.log("Failure Details: ",e);
} }
} else { } else {
@ -348,6 +351,7 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences()); getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences());
getAdapter().doCreateTables(c); getAdapter().doCreateTables(c);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create(e); throw IOExceptionSupport.create(e);
} finally { } finally {
c.close(); c.close();
@ -361,4 +365,14 @@ public class JDBCPersistenceAdapter implements PersistenceAdapter {
public void setUseExternalMessageReferences(boolean useExternalMessageReferences) { public void setUseExternalMessageReferences(boolean useExternalMessageReferences) {
this.useExternalMessageReferences = useExternalMessageReferences; this.useExternalMessageReferences = useExternalMessageReferences;
} }
static public void log(String msg, SQLException e) {
String s = msg+e.getMessage();
while( e.getNextException() != null ) {
e = e.getNextException();
s += ", due to: "+e.getMessage();
}
log.debug(s, e);
}
} }

View File

@ -48,6 +48,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
try { try {
adapter.doSetLastAck(c, destination, clientId, subscriptionName, seq); adapter.doSetLastAck(c, destination, clientId, subscriptionName, seq);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to store acknowledgment for: " + clientId + " on message " throw IOExceptionSupport.create("Failed to store acknowledgment for: " + clientId + " on message "
+ messageId + " in container: " + e, e); + messageId + " in container: " + e, e);
} finally { } finally {
@ -76,6 +77,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
} }
}); });
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to recover subscription: " + clientId + ". Reason: " + e, e); throw IOExceptionSupport.create("Failed to recover subscription: " + clientId + ". Reason: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -93,6 +95,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
c = persistenceAdapter.getTransactionContext(); c = persistenceAdapter.getTransactionContext();
adapter.doSetSubscriberEntry(c, destination, clientId, subscriptionName, selector, retroactive); adapter.doSetSubscriberEntry(c, destination, clientId, subscriptionName, selector, retroactive);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport throw IOExceptionSupport
.create("Failed to lookup subscription for info: " + clientId + ". Reason: " + e, e); .create("Failed to lookup subscription for info: " + clientId + ". Reason: " + e, e);
} finally { } finally {
@ -109,6 +112,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
try { try {
return adapter.doGetSubscriberEntry(c, destination, clientId, subscriptionName); return adapter.doGetSubscriberEntry(c, destination, clientId, subscriptionName);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to lookup subscription for: " + clientId + ". Reason: " + e, e); throw IOExceptionSupport.create("Failed to lookup subscription for: " + clientId + ". Reason: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -120,6 +124,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
try { try {
adapter.doDeleteSubscription(c, destination, clientId, subscriptionName); adapter.doDeleteSubscription(c, destination, clientId, subscriptionName);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to remove subscription for: " + clientId + ". Reason: " + e, e); throw IOExceptionSupport.create("Failed to remove subscription for: " + clientId + ". Reason: " + e, e);
} finally { } finally {
c.close(); c.close();
@ -131,6 +136,7 @@ public class JDBCTopicMessageStore extends JDBCMessageStore implements TopicMess
try { try {
return adapter.doGetAllSubscriptions(c, destination); return adapter.doGetAllSubscriptions(c, destination);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("JDBC Failure: ",e);
throw IOExceptionSupport.create("Failed to lookup subscriptions. Reason: " + e, e); throw IOExceptionSupport.create("Failed to lookup subscriptions. Reason: " + e, e);
} finally { } finally {
c.close(); c.close();

View File

@ -24,6 +24,8 @@ import java.sql.SQLException;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.activemq.util.IOExceptionSupport; import org.apache.activemq.util.IOExceptionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* Helps keep track of the current transaction/JDBC connection. * Helps keep track of the current transaction/JDBC connection.
@ -32,8 +34,7 @@ import org.apache.activemq.util.IOExceptionSupport;
*/ */
public class TransactionContext { public class TransactionContext {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory private static final Log log = LogFactory.getLog(TransactionContext.class);
.getLog(TransactionContext.class);
private final DataSource dataSource; private final DataSource dataSource;
private Connection connection; private Connection connection;
@ -52,6 +53,7 @@ public class TransactionContext {
connection = dataSource.getConnection(); connection = dataSource.getConnection();
connection.setAutoCommit(!inTx); connection.setAutoCommit(!inTx);
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("Could not get JDBC connection: ", e);
throw IOExceptionSupport.create(e); throw IOExceptionSupport.create(e);
} }
@ -117,6 +119,7 @@ public class TransactionContext {
} }
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("Error while closing connection: ", e);
throw IOExceptionSupport.create(e); throw IOExceptionSupport.create(e);
} finally { } finally {
try { try {
@ -146,11 +149,7 @@ public class TransactionContext {
executeBatch(); executeBatch();
connection.commit(); connection.commit();
} catch (SQLException e) { } catch (SQLException e) {
log.info("commit failed: "+e.getMessage(), e); JDBCPersistenceAdapter.log("Commit failed: ", e);
while( e.getNextException() !=null ) {
e = e.getNextException();
log.info("Nested exception: "+e);
}
throw IOExceptionSupport.create(e); throw IOExceptionSupport.create(e);
} finally { } finally {
inTx=false; inTx=false;
@ -177,6 +176,7 @@ public class TransactionContext {
connection.rollback(); connection.rollback();
} catch (SQLException e) { } catch (SQLException e) {
JDBCPersistenceAdapter.log("Rollback failed: ", e);
throw IOExceptionSupport.create(e); throw IOExceptionSupport.create(e);
} finally { } finally {
inTx=false; inTx=false;

View File

@ -30,6 +30,7 @@ import org.apache.activemq.command.MessageId;
import org.apache.activemq.command.SubscriptionInfo; import org.apache.activemq.command.SubscriptionInfo;
import org.apache.activemq.store.jdbc.JDBCAdapter; import org.apache.activemq.store.jdbc.JDBCAdapter;
import org.apache.activemq.store.jdbc.JDBCMessageRecoveryListener; import org.apache.activemq.store.jdbc.JDBCMessageRecoveryListener;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.store.jdbc.StatementProvider; import org.apache.activemq.store.jdbc.StatementProvider;
import org.apache.activemq.store.jdbc.TransactionContext; import org.apache.activemq.store.jdbc.TransactionContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -112,6 +113,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
log.warn("Could not create JDBC tables; they could already exist." + log.warn("Could not create JDBC tables; they could already exist." +
" Failure was: " + createStatments[i] + " Message: " + e.getMessage() + " Failure was: " + createStatments[i] + " Message: " + e.getMessage() +
" SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() ); " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() );
JDBCPersistenceAdapter.log("Failure details: ",e);
} }
} }
} }
@ -142,6 +144,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
log.warn("Could not drop JDBC tables; they may not exist." + log.warn("Could not drop JDBC tables; they may not exist." +
" Failure was: " + dropStatments[i] + " Message: " + e.getMessage() + " Failure was: " + dropStatments[i] + " Message: " + e.getMessage() +
" SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() ); " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() );
JDBCPersistenceAdapter.log("Failure details: ",e);
} }
} }
c.getConnection().commit(); c.getConnection().commit();