当前位置: 首页>>代码示例>>Java>>正文


Java JdbcTransactionFactory类代码示例

本文整理汇总了Java中org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory的典型用法代码示例。如果您正苦于以下问题:Java JdbcTransactionFactory类的具体用法?Java JdbcTransactionFactory怎么用?Java JdbcTransactionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JdbcTransactionFactory类属于org.apache.ibatis.transaction.jdbc包,在下文中一共展示了JdbcTransactionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSqlSession

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例2: DBManager

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例3: build

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的package包/类
/**
 * Create an instance of MyBatis.
 *
 * @param environment The dropwizard environment
 * @param config A Mybatis config object
 * @param dataSource
 * @param name The name of this mybatis factory used for metrics
 * @return An instance of MyBatis.
 */
public final SqlSessionFactory build(Environment environment,
        MyBatisConfiguration config,
        ManagedDataSource dataSource,
        String name) {

    SqlSessionFactory sessionFactory = null;

    // Try to use the mybatis configuration file if it is specified and exists.
    try (InputStream inputStream = Resources.getResourceAsStream(config.getConfigFile())) {
        sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    } catch (IOException ioe) {
        // Build session factory from configuration values given in the dropwizard config.
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        org.apache.ibatis.mapping.Environment myBatisEnvironment =
                new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
        Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
        sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
    }

    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register(name,
            new MyBatisHealthCheck(sessionFactory, config.getConfig().getValidationQuery()));

    return sessionFactory;
}
 
开发者ID:cvent,项目名称:dropwizard-mybatis,代码行数:35,代码来源:MyBatisFactory.java

示例4: init

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例5: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例6: testConfiguration

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例7: testGetMessageForEmptyDatabase

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例8: setUp

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例9: getSqlSessionFactoryWithConstructor

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例10: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例11: initialize

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的package包/类
@Override
protected void initialize() {
    initialDatabaseType();

    environmentId("default");
    useGeneratedKeys(true);
    mapUnderscoreToCamelCase(true);

    bindDataSourceProviderType(GossipDataSourceProvider.class);
    bindTransactionFactoryType(JdbcTransactionFactory.class);
    addSimpleAliases("me.yufan.gossip.mybatis.entity");
    addMapperClasses("me.yufan.gossip.mybatis.mapper");
    addTypeHandlerClasses("me.yufan.gossip.mybatis.handler");

    initialService();
}
 
开发者ID:syhily,项目名称:gossip,代码行数:17,代码来源:GossipDataModule.java

示例12: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的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

示例13: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的package包/类
@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER).newInstance();
    InputStream is = getClass().getResourceAsStream("/examples/generated/always/CreateGeneratedAlwaysDB.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(GeneratedAlwaysAnnotatedMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}
 
开发者ID:mybatis,项目名称:mybatis-dynamic-sql,代码行数:17,代码来源:GeneratedAlwaysAnnotatedMapperTest.java

示例14: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的package包/类
@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);
    InputStream is = getClass().getResourceAsStream("/examples/groupby/CreateGroupByDB.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(GroupByMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}
 
开发者ID:mybatis,项目名称:mybatis-dynamic-sql,代码行数:17,代码来源:GroupByTest.java

示例15: setup

import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; //导入依赖的package包/类
@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);
    InputStream is = getClass().getResourceAsStream("/examples/simple/CreateSimpleDB.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(SimpleTableAnnotatedMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}
 
开发者ID:mybatis,项目名称:mybatis-dynamic-sql,代码行数:17,代码来源:SimpleTableAnnotatedMapperTest.java


注:本文中的org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。