Search in sources :

Example 1 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException in project cxf by apache.

the class RMTxStore method removeSourceSequence.

public void removeSourceSequence(Identifier sid) {
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    try {
        beginTransaction();
        stmt = getStatement(con, DELETE_SRC_SEQUENCE_STMT_STR);
        stmt.setString(1, sid.getValue());
        stmt.execute();
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        releaseResources(stmt, null);
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException in project cxf by apache.

the class RMTxStore method persistOutgoing.

public void persistOutgoing(SourceSequence seq, RMMessage msg) {
    Connection con = verifyConnection();
    SQLException conex = null;
    try {
        beginTransaction();
        updateSourceSequence(con, seq);
        if (msg != null && msg.getContent() != null) {
            storeMessage(con, seq.getIdentifier(), msg, true);
        }
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } catch (IOException ex) {
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) IOException(java.io.IOException)

Example 3 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException in project cxf by apache.

the class RMTxStore method removeMessages.

public void removeMessages(Identifier sid, Collection<Long> messageNrs, boolean outbound) {
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    try {
        stmt = getStatement(con, outbound ? DELETE_OUTBOUND_MESSAGE_STMT_STR : DELETE_INBOUND_MESSAGE_STMT_STR);
        beginTransaction();
        stmt.setString(1, sid.getValue());
        for (Long messageNr : messageNrs) {
            stmt.setLong(2, messageNr);
            stmt.execute();
        }
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        releaseResources(stmt, null);
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 4 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException in project cxf by apache.

the class RMTxStoreTestBase method testCreateDeleteSrcSequences.

@Test
public void testCreateDeleteSrcSequences() {
    SourceSequence seq = control.createMock(SourceSequence.class);
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createSourceSequence(seq);
    control.verify();
    control.reset();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    try {
        store.createSourceSequence(seq);
        fail("Expected RMStoreException was not thrown.");
    } catch (RMStoreException ex) {
        SQLException se = (SQLException) ex.getCause();
        // duplicate key value
        assertEquals("23505", se.getSQLState());
    }
    control.verify();
    control.reset();
    Identifier sid2 = new Identifier();
    sid2.setValue("sequence2");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
    EasyMock.expect(seq.getExpires()).andReturn(new Date());
    Identifier sid3 = new Identifier();
    sid3.setValue("offeringSequence3");
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(sid3);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createSourceSequence(seq);
    control.verify();
    store.removeSourceSequence(sid1);
    store.removeSourceSequence(sid2);
    // deleting once again is a no-op
    store.removeSourceSequence(sid2);
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SQLException(java.sql.SQLException) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Date(java.util.Date) Test(org.junit.Test)

Example 5 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException in project cxf by apache.

the class RMTxStoreTest method testReconnect.

@Test
public void testReconnect() throws Exception {
    // set the initial reconnect delay to 100 msec for testing
    long ird = store.getInitialReconnectDelay();
    store.setInitialReconnectDelay(100);
    SourceSequence seq = control.createMock(SourceSequence.class);
    Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
    sid1.setValue("sequence1");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    // intentionally invalidate the connection
    try {
        store.getConnection().close();
    } catch (SQLException ex) {
    // ignore
    }
    control.replay();
    try {
        store.createSourceSequence(seq);
        fail("Expected RMStoreException was not thrown.");
    } catch (RMStoreException ex) {
        SQLException se = (SQLException) ex.getCause();
        // expects a transient or non-transient connection exception
        assertTrue(se.getSQLState().startsWith("08"));
    }
    // wait 200 msecs to make sure an reconnect is attempted
    Thread.sleep(200);
    control.reset();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createSourceSequence(seq);
    control.verify();
    // revert to the old initial reconnect delay
    store.setInitialReconnectDelay(ird);
    store.removeSourceSequence(sid1);
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SQLException(java.sql.SQLException) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)11 RMStoreException (org.apache.cxf.ws.rm.persistence.RMStoreException)11 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)6 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 Date (java.util.Date)2 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)2 Blob (java.sql.Blob)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Message (org.apache.cxf.common.i18n.Message)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)1 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)1 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)1