TSK-56 refactor Exceptions. Introduce TaskanaException and TaskanaRuntimeException

This commit is contained in:
BerndBreier 2017-11-27 11:03:33 +01:00
parent 9031d44df1
commit c2fa208e5d
8 changed files with 70 additions and 13 deletions

View File

@ -5,7 +5,7 @@ package pro.taskana.exceptions;
*
*/
@SuppressWarnings("serial")
public class AutocommitFailedException extends RuntimeException {
public class AutocommitFailedException extends TaskanaRuntimeException {
public AutocommitFailedException(Throwable cause) {
super("Autocommit failed", cause);
}

View File

@ -5,7 +5,7 @@ package pro.taskana.exceptions;
*
*/
@SuppressWarnings("serial")
public class ConnectionNotSetException extends RuntimeException {
public class ConnectionNotSetException extends TaskanaRuntimeException {
public ConnectionNotSetException() {
super("Connection not set");

View File

@ -4,7 +4,7 @@ package pro.taskana.exceptions;
* This exception is used to communicate a not authorized user.
*/
@SuppressWarnings("serial")
public class NotAuthorizedException extends Exception {
public class NotAuthorizedException extends TaskanaException {
public NotAuthorizedException(String msg) {
super(msg);

View File

@ -4,7 +4,7 @@ package pro.taskana.exceptions;
* This exception will be thrown if a specific object is not in the database.
*/
@SuppressWarnings("serial")
public class NotFoundException extends Exception {
public class NotFoundException extends TaskanaException {
public NotFoundException(String id) {
super(id);

View File

@ -0,0 +1,30 @@
package pro.taskana.exceptions;
/**
* common base class for Taskana's checked exceptions.
* @author bbr
*
*/
public class TaskanaException extends Exception {
public TaskanaException() {
super();
}
public TaskanaException(String message) {
super(message);
}
public TaskanaException(Throwable cause) {
super(cause);
}
public TaskanaException(String message, Throwable cause) {
super(message, cause);
}
public TaskanaException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,31 @@
package pro.taskana.exceptions;
/**
* Common base class for Taskana's runtime exceptions.
* @author bbr
*
*/
public class TaskanaRuntimeException extends RuntimeException {
public TaskanaRuntimeException() {
super();
}
public TaskanaRuntimeException(String message) {
super(message);
}
public TaskanaRuntimeException(Throwable cause) {
super(cause);
}
public TaskanaRuntimeException(String message, Throwable cause) {
super(message, cause);
}
public TaskanaRuntimeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -115,7 +115,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
this.connection = connection;
mode = ConnectionManagementMode.EXPLICIT;
sessionManager.startManagedSession(connection);
} else {
} else if (this.connection != null) {
this.connection = null;
if (sessionManager.isManagedSessionStarted()) {
sessionManager.close();

View File

@ -78,7 +78,7 @@ public class WorkbasketServiceImplIntExplicitTest {
workbasket.setName("Megabasket");
workBasketService.createWorkbasket(workbasket);
Assert.assertEquals(before + 1, workBasketService.getWorkbaskets().size());
connection.close();
taskanaEngineImpl.closeConnection();
}
@Test
@ -104,7 +104,7 @@ public class WorkbasketServiceImplIntExplicitTest {
workBasketService.createWorkbasket(workbasket2);
Assert.assertEquals(before + THREE, workBasketService.getWorkbaskets().size());
connection.commit();
connection.close();
taskanaEngineImpl.closeConnection();
}
@Test
@ -130,7 +130,7 @@ public class WorkbasketServiceImplIntExplicitTest {
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId());
connection.commit();
connection.close();
taskanaEngineImpl.closeConnection();
}
@Test(expected = WorkbasketNotFoundException.class)
@ -140,7 +140,7 @@ public class WorkbasketServiceImplIntExplicitTest {
workBasketService = taskanaEngine.getWorkbasketService();
workBasketService.getWorkbasket("fail");
connection.commit();
connection.close();
taskanaEngineImpl.closeConnection();
}
@Test
@ -168,7 +168,6 @@ public class WorkbasketServiceImplIntExplicitTest {
Assert.assertEquals(id2, foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
connection.commit();
connection.close();
}
@Test
@ -213,7 +212,6 @@ public class WorkbasketServiceImplIntExplicitTest {
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
workBasketService.getWorkbasket(id3).getModified());
connection.commit();
connection.close();
}
@Test
@ -231,7 +229,6 @@ public class WorkbasketServiceImplIntExplicitTest {
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
connection.commit();
connection.close();
}
@Test
@ -255,7 +252,6 @@ public class WorkbasketServiceImplIntExplicitTest {
Assert.assertEquals("Zaphod Beeblebrox",
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
connection.commit();
connection.close();
}
@After