Exemplo n.º 1
0
  @Override
  protected void installFixturesIfRequired() throws IsisSystemException {

    fixtureInstaller = obtainFixturesInstaller();
    if (isNoop(fixtureInstaller)) {
      return;
    }

    IsisContext.openSession(new InitialisationSession());
    fixtureInstaller.installFixtures();
    try {

      // only allow logon fixtures if not in production mode.
      if (!getDeploymentType().isProduction()) {
        logonFixture = fixtureInstaller.getLogonFixture();
      }
    } finally {
      IsisContext.closeSession();
    }
  }
Exemplo n.º 2
0
  /**
   * A template method that executes a piece of code in a session. If there is an open session then
   * it is reused, otherwise a temporary one is created.
   *
   * @param callable The piece of code to run.
   * @return The result of the code execution.
   */
  public static <R> R doInSession(Callable<R> callable) {
    boolean noSession = !inSession();
    try {
      if (noSession) {
        openSession(new InitialisationSession());
      }

      return callable.call();
    } catch (Exception x) {
      throw new RuntimeException(
          String.format(
              "An error occurred while executing code in %s session",
              noSession ? "a temporary" : "a"),
          x);
    } finally {
      if (noSession) {
        closeSession();
      }
    }
  }