⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbpersistenceservice.java

📁 workflow first jbpm
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    
    Exception flushException = flushSession();
    if (flushException!=null) {
      rollback();
      closeSession();
      closeConnection();
      throw new JbpmPersistenceException("hibernate flush failed", flushException);
    }

    Exception closeSessionException = closeSession();
    if (closeSessionException!=null) {
      closeConnection();
      throw new JbpmPersistenceException("hibernate close session failed", closeSessionException);
    }

    Exception closeConnectionException = closeConnection();
    if (closeConnectionException!=null) {
      throw new JbpmPersistenceException("hibernate close connection failed", closeConnectionException);
    }
  }

  Exception commit() {
    try {
      log.debug("committing hibernate transaction " + transaction.toString());
      mustSessionBeFlushed = false; // commit does a flush anyway 
      transaction.commit();
    } catch (StaleObjectStateException e) {
      log.info("optimistic locking failed");
      StaleObjectLogConfigurer.staleObjectExceptionsLog.error("optimistic locking failed", e);
      return e;
    } catch (Exception e) {
      log.error("hibernate commit failed", e);
      return e;
    }
    return null;
  }

  Exception flushSession() {
    if (mustSessionBeFlushed) {
      try {
        log.debug("flushing hibernate session " + session.toString());
        session.flush();
      } catch (Exception e) {
        log.error("hibernate flush failed", e);
        return e;
      }
    }
    return null;
  }

  Exception closeConnection() {
    if (mustConnectionBeClosed) {
      try {
        if ( (connection!=null)
            && (! connection.isClosed())
           ) {
          log.debug("closing jdbc connection");
          connection.close();
        } else {
          log.warn("jdbc connection was already closed");
        }
      } catch (Exception e) {
        log.error("hibernate session close failed", e);
        return e;
      }
    }
    return null;
  }

  Exception rollback() {
    try {
      log.debug("rolling back hibernate transaction");
      mustSessionBeFlushed = false; // flushing updates that will be rolled back is not very clever :-) 
      transaction.rollback();
    } catch (Exception e) {
      log.error("hibernate rollback failed", e);
      return e;
    }
    return null;
  }

  Exception closeSession() {
    if (mustSessionBeClosed) {
      try {
        if(session.isOpen()) {
          log.debug("closing hibernate session");
          session.close();
        } else {
          log.warn("hibernate session was already closed");
        }
      } catch (Exception e) {
        return e;
      }
    }
    return null;
  }

  public void assignId(Object object) {
    try {
      getSession().save(object);
    } catch (Exception e) {
      // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
      throw new JbpmPersistenceException("couldn't assign id to "+object, e);
    }
  }

  // getters and setters //////////////////////////////////////////////////////

  public GraphSession getGraphSession() {
    if (graphSession==null) {
      Session session = getSession();
      if (session!=null) {
        graphSession = new GraphSession(session);
      }
    }
    return graphSession;
  }
  public LoggingSession getLoggingSession() {
    if (loggingSession==null) {
      Session session = getSession();
      if (session!=null) {
        loggingSession = new LoggingSession(session);
      }
    }
    return loggingSession;
  }
  public JobSession getJobSession() {
    if (jobSession==null) {
      Session session = getSession();
      if (session!=null) {
        jobSession = new JobSession(session);
      }
    }
    return jobSession;
  }
  public ContextSession getContextSession() {
    if (contextSession==null) {
      Session session = getSession();
      if (session!=null) {
        contextSession = new ContextSession(session);
      }
    }
    return contextSession;
  }
  public TaskMgmtSession getTaskMgmtSession() {
    if (taskMgmtSession==null) {
      Session session = getSession();
      if (session!=null) {
        taskMgmtSession = new TaskMgmtSession(session);
      }
    }
    return taskMgmtSession;
  }

  public DataSource getDataSource() {
    return persistenceServiceFactory.dataSource;
  }

  /**
   * @deprecated use {@link org.jbpm.tx.TxService} instead.
   */
  public boolean isRollbackOnly() {
    TxService txService = (services!=null ? services.getTxService() : null);
    if (txService==null) {
      throw new JbpmException("no jbpm tx service configured");
    }
    return txService.isRollbackOnly();
  }
  /**
   * @deprecated use {@link org.jbpm.tx.TxService} instead.
   */
  public void setRollbackOnly(boolean isRollbackOnly) {
    throw new UnsupportedOperationException("method setRollbackOnly has been removed.  Use TxService instead.");
  }
  /**
   * @deprecated use {@link org.jbpm.tx.TxService} instead.
   */
  public void setRollbackOnly() {
    TxService txService = (services!=null ? services.getTxService() : null);
    if (txService==null) {
      throw new JbpmException("no jbpm tx service configured");
    }
    txService.setRollbackOnly();
  }

  public void setSession(Session session) {
    this.session = session;
    log.debug("injecting a session disables transaction");
    isTransactionEnabled = false;
  }

  public void setSessionWithoutDisablingTx(Session session) {
    this.session = session;
  }

  public void setConnection(Connection connection) {
    this.connection = connection;
  }
  public void setContextSession(ContextSession contextSession) {
    this.contextSession = contextSession;
  }
  public void setDataSource(DataSource dataSource) {
    this.persistenceServiceFactory.dataSource = dataSource;
  }
  public void setGraphSession(GraphSession graphSession) {
    this.graphSession = graphSession;
  }
  public void setLoggingSession(LoggingSession loggingSession) {
    this.loggingSession = loggingSession;
  }
  public void setJobSession(JobSession jobSession) {
    this.jobSession = jobSession;
  }
  public void setTaskMgmtSession(TaskMgmtSession taskMgmtSession) {
    this.taskMgmtSession = taskMgmtSession;
  }
  public void setSessionFactory(SessionFactory sessionFactory) {
    this.persistenceServiceFactory.sessionFactory = sessionFactory;
  }
  public Transaction getTransaction() {
    return transaction;
  }
  public void setTransaction(Transaction transaction) {
    this.transaction = transaction;
  }
  public boolean isTransactionEnabled() {
    return isTransactionEnabled;
  }
  public void setTransactionEnabled(boolean isTransactionEnabled) {
    this.isTransactionEnabled = isTransactionEnabled;
  }
  private static Log log = LogFactory.getLog(DbPersistenceService.class);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -