package de.ivu.elect.jee.exception;

import javax.persistence.OptimisticLockException;

public class ExceptionUtil {


  public static boolean isDatabaseLockException(Throwable t) {
    if (t == null) {
      return false;
    }

    if (t instanceof OptimisticLockException) {
      return true;
    }

    if (t.getMessage() != null) {
      if (t.getMessage().contains("Unable to acquire lock")) {
        return true;
      }
    }

    if (t.getClass().getName().contains("org.infinispan.util.concurrent.TimeoutException")) {
      return true;
    }
    return isDatabaseLockException(t.getCause());
  }
}