Added StmConfigurationException
This commit is contained in:
parent
f58503a1c3
commit
8605b85ab0
4 changed files with 18 additions and 17 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -33,4 +33,4 @@ tm.out
|
||||||
.classpath
|
.classpath
|
||||||
.idea
|
.idea
|
||||||
.scala_dependencies
|
.scala_dependencies
|
||||||
|
multiverse.log
|
||||||
|
|
@ -44,12 +44,12 @@ object TransactionContainer extends Logging {
|
||||||
.transactionContainer
|
.transactionContainer
|
||||||
} catch {
|
} catch {
|
||||||
case e: ClassNotFoundException =>
|
case e: ClassNotFoundException =>
|
||||||
throw new IllegalStateException(
|
throw new StmConfigurationException(
|
||||||
"JTA provider defined as 'atomikos', but the AtomikosTransactionService classes can not be found." +
|
"JTA provider defined as 'atomikos', but the AtomikosTransactionService classes can not be found." +
|
||||||
"\n\tPlease make sure you have 'akka-jta' JAR and its dependencies on your classpath.")
|
"\n\tPlease make sure you have 'akka-jta' JAR and its dependencies on your classpath.")
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
throw new IllegalStateException(
|
throw new StmConfigurationException(
|
||||||
"No UserTransaction on TransactionManager could be found in scope." +
|
"No UserTransaction on TransactionManager could be found in scope." +
|
||||||
"\n\tEither add 'akka-jta' to the classpath or make sure there is a" +
|
"\n\tEither add 'akka-jta' to the classpath or make sure there is a" +
|
||||||
"\n\tTransactionManager or UserTransaction defined in the JNDI.")
|
"\n\tTransactionManager or UserTransaction defined in the JNDI.")
|
||||||
|
|
@ -122,53 +122,53 @@ class TransactionContainer private (val tm: Either[Option[UserTransaction], Opti
|
||||||
def begin = tm match {
|
def begin = tm match {
|
||||||
case Left(Some(userTx)) => userTx.begin
|
case Left(Some(userTx)) => userTx.begin
|
||||||
case Right(Some(txMan)) => txMan.begin
|
case Right(Some(txMan)) => txMan.begin
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def commit = tm match {
|
def commit = tm match {
|
||||||
case Left(Some(userTx)) => userTx.commit
|
case Left(Some(userTx)) => userTx.commit
|
||||||
case Right(Some(txMan)) => txMan.commit
|
case Right(Some(txMan)) => txMan.commit
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def rollback = tm match {
|
def rollback = tm match {
|
||||||
case Left(Some(userTx)) => userTx.rollback
|
case Left(Some(userTx)) => userTx.rollback
|
||||||
case Right(Some(txMan)) => txMan.rollback
|
case Right(Some(txMan)) => txMan.rollback
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def getStatus = tm match {
|
def getStatus = tm match {
|
||||||
case Left(Some(userTx)) => userTx.getStatus
|
case Left(Some(userTx)) => userTx.getStatus
|
||||||
case Right(Some(txMan)) => txMan.getStatus
|
case Right(Some(txMan)) => txMan.getStatus
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def isInExistingTransaction = tm match {
|
def isInExistingTransaction = tm match {
|
||||||
case Left(Some(userTx)) => userTx.getStatus == Status.STATUS_ACTIVE
|
case Left(Some(userTx)) => userTx.getStatus == Status.STATUS_ACTIVE
|
||||||
case Right(Some(txMan)) => txMan.getStatus == Status.STATUS_ACTIVE
|
case Right(Some(txMan)) => txMan.getStatus == Status.STATUS_ACTIVE
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def isRollbackOnly = tm match {
|
def isRollbackOnly = tm match {
|
||||||
case Left(Some(userTx)) => userTx.getStatus == Status.STATUS_MARKED_ROLLBACK
|
case Left(Some(userTx)) => userTx.getStatus == Status.STATUS_MARKED_ROLLBACK
|
||||||
case Right(Some(txMan)) => txMan.getStatus == Status.STATUS_MARKED_ROLLBACK
|
case Right(Some(txMan)) => txMan.getStatus == Status.STATUS_MARKED_ROLLBACK
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def setRollbackOnly = tm match {
|
def setRollbackOnly = tm match {
|
||||||
case Left(Some(userTx)) => userTx.setRollbackOnly
|
case Left(Some(userTx)) => userTx.setRollbackOnly
|
||||||
case Right(Some(txMan)) => txMan.setRollbackOnly
|
case Right(Some(txMan)) => txMan.setRollbackOnly
|
||||||
case _ => throw new IllegalStateException("Does not have a UserTransaction or TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a UserTransaction or TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def suspend = tm match {
|
def suspend = tm match {
|
||||||
case Right(Some(txMan)) => txMan.suspend
|
case Right(Some(txMan)) => txMan.suspend
|
||||||
case _ => throw new IllegalStateException("Does not have a TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a TransactionManager in scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
def resume(tx: JtaTransaction) = tm match {
|
def resume(tx: JtaTransaction) = tm match {
|
||||||
case Right(Some(txMan)) => txMan.resume(tx)
|
case Right(Some(txMan)) => txMan.resume(tx)
|
||||||
case _ => throw new IllegalStateException("Does not have a TransactionManager in scope")
|
case _ => throw new StmConfigurationException("Does not have a TransactionManager in scope")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import org.multiverse.stms.alpha.AlphaStm
|
||||||
|
|
||||||
class NoTransactionInScopeException extends RuntimeException
|
class NoTransactionInScopeException extends RuntimeException
|
||||||
class TransactionRetryException(message: String) extends RuntimeException(message)
|
class TransactionRetryException(message: String) extends RuntimeException(message)
|
||||||
|
class StmConfigurationException(message: String) extends RuntimeException(message)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXDOC: document AtomicTemplate
|
* FIXDOC: document AtomicTemplate
|
||||||
|
|
@ -357,17 +358,17 @@ object Transaction {
|
||||||
private[akka] def register(uuid: String, storage: Committable) = persistentStateMap.put(uuid, storage)
|
private[akka] def register(uuid: String, storage: Committable) = persistentStateMap.put(uuid, storage)
|
||||||
|
|
||||||
private def ensureIsActive = if (status != TransactionStatus.Active)
|
private def ensureIsActive = if (status != TransactionStatus.Active)
|
||||||
throw new IllegalStateException(
|
throw new StmConfigurationException(
|
||||||
"Expected ACTIVE transaction - current status [" + status + "]: " + toString)
|
"Expected ACTIVE transaction - current status [" + status + "]: " + toString)
|
||||||
|
|
||||||
private def ensureIsActiveOrAborted =
|
private def ensureIsActiveOrAborted =
|
||||||
if (!(status == TransactionStatus.Active || status == TransactionStatus.Aborted))
|
if (!(status == TransactionStatus.Active || status == TransactionStatus.Aborted))
|
||||||
throw new IllegalStateException(
|
throw new StmConfigurationException(
|
||||||
"Expected ACTIVE or ABORTED transaction - current status [" + status + "]: " + toString)
|
"Expected ACTIVE or ABORTED transaction - current status [" + status + "]: " + toString)
|
||||||
|
|
||||||
private def ensureIsActiveOrNew =
|
private def ensureIsActiveOrNew =
|
||||||
if (!(status == TransactionStatus.Active || status == TransactionStatus.New))
|
if (!(status == TransactionStatus.Active || status == TransactionStatus.New))
|
||||||
throw new IllegalStateException(
|
throw new StmConfigurationException(
|
||||||
"Expected ACTIVE or NEW transaction - current status [" + status + "]: " + toString)
|
"Expected ACTIVE or NEW transaction - current status [" + status + "]: " + toString)
|
||||||
|
|
||||||
// For reinitialize transaction after sending it over the wire
|
// For reinitialize transaction after sending it over the wire
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ object TransactionManagement extends TransactionManagement {
|
||||||
|
|
||||||
private[akka] def getTransactionSet: CountDownCommitBarrier = {
|
private[akka] def getTransactionSet: CountDownCommitBarrier = {
|
||||||
val option = transactionSet.get
|
val option = transactionSet.get
|
||||||
if ((option eq null) || option.isEmpty) throw new IllegalStateException("No Transaction set in scope")
|
if ((option eq null) || option.isEmpty) throw new StmConfigurationException("No Transaction set in scope")
|
||||||
else option.get
|
else option.get
|
||||||
}
|
}
|
||||||
|
|
||||||
private[akka] def getTransaction: Transaction = {
|
private[akka] def getTransaction: Transaction = {
|
||||||
val option = transaction.get
|
val option = transaction.get
|
||||||
if ((option eq null) || option.isEmpty) throw new IllegalStateException("No Transaction in scope")
|
if ((option eq null) || option.isEmpty) throw new StmConfigurationException("No Transaction in scope")
|
||||||
option.get
|
option.get
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue