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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations