當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment類代碼示例

本文整理匯總了Java中org.apache.ibatis.mapping.Environment的典型用法代碼示例。如果您正苦於以下問題:Java Environment類的具體用法?Java Environment怎麽用?Java Environment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Environment類屬於org.apache.ibatis.mapping包,在下文中一共展示了Environment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: environmentsElement

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
private void environmentsElement(XNode context) throws Exception {
    if (context != null) {
        if (environment == null) {
            environment = context.getStringAttribute("default");
        }
        for (XNode child : context.getChildren()) {
            String id = child.getStringAttribute("id");
            if (isSpecifiedEnvironment(id)) {
                TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
                DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
                DataSource dataSource = dsFactory.getDataSource();
                Environment.Builder environmentBuilder = new Environment.Builder(id)
                        .transactionFactory(txFactory)
                        .dataSource(dataSource);
                configuration.setEnvironment(environmentBuilder.build());
            }
        }
    }
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:20,代碼來源:MybatisXMLConfigBuilder.java

示例2: createSqlSessionManager

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
/**
 * This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers
 *
 * @return a {@link SqlSessionFactory}
 */
private SqlSessionManager createSqlSessionManager() {
    Environment environment = new Environment(DEFAULT, this.transactionFactory,
        taskanaEngineConfiguration.getDatasource());
    Configuration configuration = new Configuration(environment);
    // add mappers
    configuration.addMapper(TaskMapper.class);
    configuration.addMapper(TaskMonitorMapper.class);
    configuration.addMapper(WorkbasketMapper.class);
    configuration.addMapper(DistributionTargetMapper.class);
    configuration.addMapper(ClassificationMapper.class);
    configuration.addMapper(WorkbasketAccessMapper.class);
    configuration.addMapper(ObjectReferenceMapper.class);
    configuration.addMapper(QueryMapper.class);
    configuration.addMapper(AttachmentMapper.class);
    configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
    return sessionManager;
}
 
開發者ID:Taskana,項目名稱:taskana,代碼行數:25,代碼來源:TaskanaEngineImpl.java

示例3: getSqlSession

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
/**
 * 獲取SqlSession
 * @return
 * @throws IOException
 */
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setCallSettersOnNulls(true); // 設計null調用setter方法
    config.setMapUnderscoreToCamelCase(true);   // 駝峰命名支持

    // 設置mapper
    config.addMappers(targetPackage);
    // 設置數據源,事務
    PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
    dataSourceFactory.setProperties(DBHelper.properties);
    DataSource dataSource = dataSourceFactory.getDataSource();
    JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();

    Environment environment = new Environment("test", transactionFactory, dataSource);
    config.setEnvironment(environment);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
    return sqlSessionFactory.openSession(true);
}
 
開發者ID:itfsw,項目名稱:mybatis-generator-plugin,代碼行數:24,代碼來源:MyBatisGeneratorTool.java

示例4: DBManager

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
public DBManager(AppConfiguration appConfig) {

        this.appConfig = appConfig;

        boolean isDev = appConfig.getBool(CONFIG_KEY_APP_DEV_MODE, true);

        String dbHost = appConfig.get(CONFIG_KEY_MYSQL_HOST, DEFAULT_MYSQL_HOST);
        int dbPort = appConfig.getInt(CONFIG_KEY_MYSQL_PORT, DEFAULT_MYSQL_PORT);
        String dbName = appConfig.get(CONFIG_KEY_MYSQL_DBNAME, DEFAULT_MEYSQL_DBNAME);
        String dbUser = appConfig.get(CONFIG_KEY_MYSQL_USER, "");
        String dbPass = appConfig.get(CONFIG_KEY_MYSQL_PASS, "");
        String dbDriver = "com.mysql.cj.jdbc.Driver";
        String connString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "?autoReconnect=true&useSSL=false&useUnicode=true";

        DataSource dataSource = new PooledDataSource(dbDriver, connString, dbUser, dbPass);
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        Environment environment = new Environment(isDev ? "development" : "production", transactionFactory, dataSource);
        configuration = new Configuration(environment);

        configuration.addMappers("com.elune.dao");

        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    }
 
開發者ID:thundernet8,項目名稱:Elune,代碼行數:24,代碼來源:DBManager.java

示例5: init

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@Override
public void init(DbConnection connection) throws Exception {
    JdbcConnectionPool pool = JdbcConnectionPool.create(connection.uri, connection.username, connection.password);

    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("jdblender", transactionFactory, pool);

    Configuration cfg = new Configuration(environment);
    cfg.setMapUnderscoreToCamelCase(true);
    cfg.addMapper(BrandsMapper.class);
    cfg.addMapper(SeriesMapper.class);
    cfg.addMapper(ModelsMapper.class);
    cfg.addMapper(SparesMapper.class);

    //Create session
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(cfg);
}
 
開發者ID:rumatoest,項目名稱:jdblender,代碼行數:18,代碼來源:RunnerMybatis.java

示例6: environmentsElement

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
private void environmentsElement(XNode context) throws Exception {
  if (context != null) {
    if (environment == null) {
      environment = context.getStringAttribute("default");
    }
    for (XNode child : context.getChildren()) {
      String id = child.getStringAttribute("id");
      if (isSpecifiedEnvironment(id)) {
        TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
        DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
        DataSource dataSource = dsFactory.getDataSource();
        Environment.Builder environmentBuilder = new Environment.Builder(id)
            .transactionFactory(txFactory)
            .dataSource(dataSource);
        configuration.setEnvironment(environmentBuilder.build());
      }
    }
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:20,代碼來源:XMLConfigBuilder.java

示例7: setup

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@BeforeClass
public static void setup() throws Exception {
  DataSource dataSource = BaseDataTest.createBlogDataSource();
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DDL);
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DATA);
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Production", transactionFactory, dataSource);
  Configuration configuration = new Configuration(environment);
  configuration.setLazyLoadingEnabled(true);
  configuration.setUseActualParamName(false); // to test legacy style reference (#{0} #{1})
  configuration.getTypeAliasRegistry().registerAlias(Blog.class);
  configuration.getTypeAliasRegistry().registerAlias(Post.class);
  configuration.getTypeAliasRegistry().registerAlias(Author.class);
  configuration.addMapper(BoundBlogMapper.class);
  configuration.addMapper(BoundAuthorMapper.class);
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:18,代碼來源:BindingTest.java

示例8: testConfiguration

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@Test
public void testConfiguration() {
    UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
    dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
    dataSourceProperties.put("username", "sa");
    dataSourceFactory.setProperties(dataSourceProperties);
    Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.getTypeAliasRegistry().registerAlias(Person.class);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(PersonMapper2.class);
    new DefaultSqlSessionFactory(configuration);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:17,代碼來源:EnumWithOgnlTest.java

示例9: testGetMessageForEmptyDatabase

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@Test
public void testGetMessageForEmptyDatabase() throws Exception {
  final Environment environment = new Environment("test", new JdbcTransactionFactory(), BaseDataTest.createBlogDataSource());
  final Configuration config = new Configuration(environment);
  config.addMapper(PostMapper.class);
  final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
  final SqlSession session = factory.openSession();
  
  PostMapper mapper = session.getMapper(PostMapper.class);
  List<AnnoPost> posts = mapper.getPosts(101);


  assertEquals(3,posts.size());
  assertEquals(3,posts.get(0).getTags().size());
  assertEquals(1,posts.get(1).getTags().size());
  assertEquals(0,posts.get(2).getTags().size());

  session.close();

}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:21,代碼來源:ManyAnnoTest.java

示例10: setUp

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(c);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  runner.runScript(reader);
  c.commit();
  reader.close();

  Configuration configuration = new Configuration();
  Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
  configuration.setEnvironment(environment);
  
  configuration.addMapper(SubstitutionInAnnotsMapper.class);
  
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:21,代碼來源:SubstitutionInAnnotsTest.java

示例11: getSqlSessionFactoryWithConstructor

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
    
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
    
    return new DefaultSqlSessionFactory(configuration);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:19,代碼來源:NpeExtendsTest.java

示例12: openSessionFromDataSource

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@SuppressWarnings("all")
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
    Transaction tx = null;
    try {
        final Environment environment = getConfiguration().getEnvironment();
        final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
        DataSource ds = DataSourceHolder.currentDataSource().getNative();
        if (ds == null) {
            ds = environment.getDataSource();
        }
        tx = transactionFactory.newTransaction(ds, level, autoCommit);
        final Executor executor = getConfiguration().newExecutor(tx, execType);
        return new DefaultSqlSession(getConfiguration(), executor, autoCommit);
    } catch (Exception e) {
        closeTransaction(tx); // may have fetched a connection so lets call close()
        throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
        ErrorContext.instance().reset();
    }
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:21,代碼來源:DynamicSqlSessionFactory.java

示例13: openSessionFromDataSource

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
/**
   * 源碼解析: 從數據源創建會話
   *
   * @param execType 執行類型
   * @param level 數據庫隔離級別
   * @param autoCommit 是否自動提交
   * @return
   */
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
  Transaction tx = null;
  try {
    // 源碼解析: 獲取環境
    final Environment environment = configuration.getEnvironment();
    // 源碼解析: 獲取事務工廠
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    // 源碼解析: 創建一個新的事務
    tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
    // 源碼解析: 創建執行器
    final Executor executor = configuration.newExecutor(tx, execType);
    // 源碼解析: 創建一個新的sql會話
    return new DefaultSqlSession(configuration, executor, autoCommit);
  } catch (Exception e) {
    // 源碼解析: 關閉事務
    closeTransaction(tx); // may have fetched a connection so lets call close()
    throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
  } finally {
    // 源碼解析: 錯誤上下文清空重置
    ErrorContext.instance().reset();
  }
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:31,代碼來源:DefaultSqlSessionFactory.java

示例14: setup

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@BeforeClass
public static void setup() throws Exception {
  DataSource dataSource = BaseDataTest.createBlogDataSource();
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DDL);
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DATA);
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Production", transactionFactory, dataSource);
  Configuration configuration = new Configuration(environment);
  configuration.setLazyLoadingEnabled(true);
  configuration.getTypeAliasRegistry().registerAlias(Blog.class);
  configuration.getTypeAliasRegistry().registerAlias(Post.class);
  configuration.getTypeAliasRegistry().registerAlias(Author.class);
  configuration.addMapper(BoundBlogMapper.class);
  configuration.addMapper(BoundAuthorMapper.class);
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:17,代碼來源:BindingTest.java

示例15: setup

import org.apache.ibatis.mapping.Environment; //導入依賴的package包/類
@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);
    InputStream is = getClass().getResourceAsStream("/examples/joins/CreateJoinDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }
    
    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(JoinMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}
 
開發者ID:mybatis,項目名稱:mybatis-dynamic-sql,代碼行數:17,代碼來源:JoinMapperTest.java


注:本文中的org.apache.ibatis.mapping.Environment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。