コード例 #1
0
 private Executor newExecutor() throws SQLException {
   final Environment environment = configuration.getEnvironment();
   if (environment == null)
     throw new ExecutorException(
         "ResultLoader could not load lazily.  Environment was not configured.");
   final DataSource ds = environment.getDataSource();
   if (ds == null)
     throw new ExecutorException(
         "ResultLoader could not load lazily.  DataSource was not configured.");
   final TransactionFactory transactionFactory = environment.getTransactionFactory();
   final Transaction tx = transactionFactory.newTransaction(ds, null, false);
   return configuration.newExecutor(tx, ExecutorType.SIMPLE);
 }
コード例 #2
0
 private void databaseIdProviderElement(XNode context) throws Exception {
   DatabaseIdProvider databaseIdProvider = null;
   if (context != null) {
     String type = context.getStringAttribute("type");
     if ("VENDOR".equals(type)) type = "DB_VENDOR"; // awful patch to keep backward compatibility
     Properties properties = context.getChildrenAsProperties();
     databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance();
     databaseIdProvider.setProperties(properties);
   }
   Environment environment = configuration.getEnvironment();
   if (environment != null && databaseIdProvider != null) {
     String databaseId = databaseIdProvider.getDatabaseId(environment.getDataSource());
     configuration.setDatabaseId(databaseId);
   }
 }
コード例 #3
0
  /**
   * 資料庫管理員初始化
   *
   * @throws Exception
   */
  public static synchronized void init() throws Exception {
    // logger.debug("DBManager: MyBatis init() entry");

    try {
      if (init) return;
      StringBuilder sb = new StringBuilder();
      String config = "";
      try {
        String webapp = ApplicationContext.getWebAppName();
        sb.append("\ngetWebAppName: " + webapp);

        config = ApplicationContext.getMyBatisConfig();

        if (StringTK.isEmpty(config)) {
          config = resource;
        }

        sb.append("\nMyBatis Config Path: " + config);
        if (StringTK.isEmpty(config)) {
          config = resource;
        }
        Reader reader = Resources.getResourceAsReader(config);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

        Environment evnir = sqlSessionFactory.getConfiguration().getEnvironment();
        sb.append("\nApplied Environment: " + evnir.getId());
        setEnvironment(evnir.getId());
        init = true;
      } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        throw e;
      } finally {

      }

      logger.debug(sb.toString() + "\nDBManager: Database MyBatis initail successful.");

    } catch (Exception e) {
      logger.error("DBManager: init() fail");
      logger.debug(e.getMessage());
      throw e;
    } finally {

    }
    // logger.debug("DBManager: init() exit");
  }
コード例 #4
0
 private TransactionFactory getTransactionFactoryFromEnvironment(Environment environment) {
   if (environment == null || environment.getTransactionFactory() == null) {
     return managedTransactionFactory;
   }
   return environment.getTransactionFactory();
 }