Пример #1
0
  /** Closes database resources at the end. */
  protected void stopDb() {
    if (!useDatabase) {
      return;
    }

    if (log != null) {
      log.info("database shutdown");
    }

    if (jtxManager != null) {
      jtxManager.close();
    }

    if (connectionProvider != null) {
      connectionProvider.close();
    }
  }
Пример #2
0
  /**
   * Initializes database. First, creates connection pool. and transaction manager. Then, Jodds
   * DbOomManager is configured. It is also configured automagically, by scanning the class path for
   * entities.
   */
  @SuppressWarnings("unchecked")
  protected void startDb() {
    if (!useDatabase) {
      log.info("database is not used");
      return;
    }

    log.info("database initialization");

    // connection pool
    petite.registerPetiteBean(CoreConnectionPool.class, PETITE_DBPOOL, null, null, false);
    connectionProvider = (ConnectionProvider) petite.getBean(PETITE_DBPOOL);
    connectionProvider.init();

    // transactions manager
    jtxManager = createJtxTransactionManager(connectionProvider);
    jtxManager.setValidateExistingTransaction(true);

    AnnotationTxAdviceManager annTxAdviceManager =
        new AnnotationTxAdviceManager(jtxManager, jtxScopePattern);
    annTxAdviceManager.registerAnnotations(jtxAnnotations);
    AnnotationTxAdviceSupport.manager = annTxAdviceManager;

    DbSessionProvider sessionProvider = new DbJtxSessionProvider(jtxManager);

    // global settings
    DbManager dbManager = DbManager.getInstance();
    dbManager.setConnectionProvider(connectionProvider);
    dbManager.setSessionProvider(sessionProvider);
    petite.addBean(PETITE_DB, dbManager);

    DbOomManager dbOomManager = DbOomManager.getInstance();
    petite.addBean(PETITE_DBOOM, dbOomManager);

    // automatic configuration
    registerDbEntities(dbOomManager);
  }