Java Code Examples for javax.jms.JMSContext#SESSION_TRANSACTED
The following examples show how to use
javax.jms.JMSContext#SESSION_TRANSACTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsConnector.java From smallrye-reactive-messaging with Apache License 2.0 | 7 votes |
private JMSContext createContext(ConnectionFactory factory, String username, String password, String mode) { int sessionMode; switch (mode.toUpperCase()) { case "AUTO_ACKNOWLEDGE": sessionMode = JMSContext.AUTO_ACKNOWLEDGE; break; case "SESSION_TRANSACTED": sessionMode = JMSContext.SESSION_TRANSACTED; break; case "CLIENT_ACKNOWLEDGE": sessionMode = JMSContext.CLIENT_ACKNOWLEDGE; break; case "DUPS_OK_ACKNOWLEDGE": sessionMode = JMSContext.DUPS_OK_ACKNOWLEDGE; break; default: throw ex.illegalStateUnknowSessionMode(mode); } if (username != null) { return factory.createContext(username, password, sessionMode); } else { return factory.createContext(sessionMode); } }
Example 2
Source File: TomEERAConnectionFactory.java From tomee with Apache License 2.0 | 6 votes |
@Override public JMSContext createContext(final String userName, final String password) { int mode; boolean xa; switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = JMSContext.AUTO_ACKNOWLEDGE; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } return new JMSContextImpl(this, mode, userName, password, xa); }
Example 3
Source File: TomEERAConnectionFactory.java From tomee with Apache License 2.0 | 6 votes |
@Override public JMSContext createContext(final int sessionMode) { int mode; boolean xa; switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = sessionMode; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } return new JMSContextImpl(this, mode, null, null, xa); }
Example 4
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testRuntimeExceptionOnRollbackFailure() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); Mockito.doThrow(IllegalStateException.class).when(session).rollback(); try { context.rollback(); fail("Should throw ISRE"); } catch (IllegalStateRuntimeException isre) { } finally { context.close(); } }
Example 5
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testRuntimeExceptionOnCommitFailure() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); Mockito.doThrow(IllegalStateException.class).when(session).commit(); try { context.commit(); fail("Should throw ISRE"); } catch (IllegalStateRuntimeException isre) { } finally { context.close(); } }
Example 6
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testAcknowledgeNoopSessionTransacted() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); try { context.acknowledge(); } finally { context.close(); } Mockito.verify(session, Mockito.times(0)).acknowledge(ACK_TYPE.ACCEPTED); }
Example 7
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testRollbackPassthrough() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); try { context.rollback(); } finally { context.close(); } Mockito.verify(session, Mockito.times(1)).rollback(); }
Example 8
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testCommitPassthrough() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsSession session = Mockito.mock(JmsSession.class); Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); try { context.commit(); } finally { context.close(); } Mockito.verify(session, Mockito.times(1)).commit(); }
Example 9
Source File: TomEEManagedConnectionProxy.java From tomee with Apache License 2.0 | 5 votes |
@Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { int mode; boolean xa; TransactionSupportLevel transactionSupportLevel; if (connection instanceof TomEEManagedConnection) { transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel(); } else if (!transacted) { transactionSupportLevel = TransactionSupportLevel.NoTransaction; } else { transactionSupportLevel = TransactionSupportLevel.XATransaction; } switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = acknowledgeMode; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } if (xa) { return createXASession(); } else { return connection.getPhysicalConnection().createSession(mode); } }
Example 10
Source File: TomEEManagedConnectionProxy.java From tomee with Apache License 2.0 | 5 votes |
@Override public Session createSession() throws JMSException { int mode; boolean xa; TransactionSupportLevel transactionSupportLevel; if (connection instanceof TomEEManagedConnection) { transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel(); } else { transactionSupportLevel = TransactionSupportLevel.XATransaction; } switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = JMSContext.AUTO_ACKNOWLEDGE; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } if (xa) { return createXASession(); } else { return connection.getPhysicalConnection().createSession(mode); } }
Example 11
Source File: TomEERAConnectionFactory.java From tomee with Apache License 2.0 | 5 votes |
@Override public JMSContext createContext() { // See notes here. We _do_ allow the user to override session mode at the // connectionFactory level, otherwise we follow the spec. // https://docs.oracle.com/javaee/7/api/javax/jms/ConnectionFactory.html#createContext-int- int mode; boolean xa; switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = JMSContext.AUTO_ACKNOWLEDGE; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } return new JMSContextImpl(this, mode, null, null, xa); }
Example 12
Source File: JmsContextTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testStopPassthrough() throws JMSException { JmsConnection connection = Mockito.mock(JmsConnection.class); JmsContext context = new JmsContext(connection, JMSContext.SESSION_TRANSACTED); try { context.stop(); } finally { context.close(); } Mockito.verify(connection, Mockito.times(1)).stop(); }
Example 13
Source File: JmsSession.java From qpid-jms with Apache License 2.0 | 5 votes |
static void validateSessionMode(int mode) { switch (mode) { case JMSContext.AUTO_ACKNOWLEDGE: case JMSContext.CLIENT_ACKNOWLEDGE: case JMSContext.DUPS_OK_ACKNOWLEDGE: case JMSContext.SESSION_TRANSACTED: case INDIVIDUAL_ACKNOWLEDGE: case ARTEMIS_PRE_ACKNOWLEDGE: case NO_ACKNOWLEDGE: return; default: throw new JMSRuntimeException("Invalid Session Mode: " + mode); } }
Example 14
Source File: ActiveMQConnectionFactory.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void validateSessionMode(int mode) { switch (mode) { case JMSContext.AUTO_ACKNOWLEDGE: case JMSContext.CLIENT_ACKNOWLEDGE: case JMSContext.DUPS_OK_ACKNOWLEDGE: case JMSContext.SESSION_TRANSACTED: case ActiveMQJMSConstants.PRE_ACKNOWLEDGE: case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE: { return; } default: throw new JMSRuntimeException("Invalid Session Mode: " + mode); } }
Example 15
Source File: MockJMSSession.java From pooled-jms with Apache License 2.0 | 5 votes |
static void validateSessionMode(int mode) { switch (mode) { case JMSContext.AUTO_ACKNOWLEDGE: case JMSContext.CLIENT_ACKNOWLEDGE: case JMSContext.DUPS_OK_ACKNOWLEDGE: case JMSContext.SESSION_TRANSACTED: return; default: throw new JMSRuntimeException("Invalid Session Mode: " + mode); } }
Example 16
Source File: JmsPoolJMSContext.java From pooled-jms with Apache License 2.0 | 5 votes |
private void validateSessionMode(int mode) { switch (mode) { case JMSContext.SESSION_TRANSACTED: case JMSContext.AUTO_ACKNOWLEDGE: case JMSContext.CLIENT_ACKNOWLEDGE: case JMSContext.DUPS_OK_ACKNOWLEDGE: return; default: throw new JMSRuntimeException("Invalid Session Mode: " + mode); } }
Example 17
Source File: JmsContext.java From qpid-jms with Apache License 2.0 | 4 votes |
@Override public boolean getTransacted() { return sessionMode == JMSContext.SESSION_TRANSACTED; }
Example 18
Source File: MockJMSContext.java From pooled-jms with Apache License 2.0 | 4 votes |
@Override public boolean getTransacted() { return sessionMode == JMSContext.SESSION_TRANSACTED; }
Example 19
Source File: TomEEManagedConnectionProxy.java From tomee with Apache License 2.0 | 4 votes |
@Override public Session createSession(final int acknowledgeMode) throws JMSException { // For the next three methods, we ignore the requested session mode per the // spec: // https://docs.oracle.com/javaee/7/api/javax/jms/Connection.html#createSession-int- // // But we also allow the user to override this behavior. If they set // transactionSupport on the connection factory // we will not return to them a xa session, even though the underlying physical // connection may support XA. int mode; boolean xa; TransactionSupportLevel transactionSupportLevel; if (connection instanceof TomEEManagedConnection) { transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel(); } else { transactionSupportLevel = TransactionSupportLevel.XATransaction; } switch (transactionSupportLevel) { case XATransaction: if (JMS2.inTx()) { mode = -1; xa = true; break; } case NoTransaction: mode = acknowledgeMode; xa = false; break; case LocalTransaction: mode = JMSContext.SESSION_TRANSACTED; xa = false; break; default: throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel); } if (xa) { return createXASession(); } else { return connection.getPhysicalConnection().createSession(mode); } }
Example 20
Source File: JmsPoolJMSContext.java From pooled-jms with Apache License 2.0 | 4 votes |
@Override public boolean getTransacted() { return sessionMode == JMSContext.SESSION_TRANSACTED; }