Java Code Examples for org.apache.ibatis.session.Configuration#addMapper()
The following examples show how to use
org.apache.ibatis.session.Configuration#addMapper() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NpeExtendsTest.java From mybaties with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: BindingTest.java From mybaties with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: SqlBundle.java From soabase with Apache License 2.0 | 5 votes |
@Override public void run(T configuration, Environment environment) throws Exception { SqlConfiguration sqlConfiguration = ComposedConfigurationAccessor.access(configuration, environment, SqlConfiguration.class); try { try ( InputStream stream = Resources.getResource(sqlConfiguration.getMybatisConfigUrl()).openStream() ) { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream); Configuration mybatisConfiguration = sqlSessionFactory.getConfiguration(); mybatisConfiguration.addMapper(AttributeEntityMapper.class); final SqlSession session = sqlSessionFactory.openSession(true); SoaBundle.getFeatures(environment).putNamed(session, SqlSession.class, sqlConfiguration.getName()); Managed managed = new Managed() { @Override public void start() throws Exception { } @Override public void stop() throws Exception { session.close(); } }; environment.lifecycle().manage(managed); } } catch ( Exception e ) { log.error("Could not initialize MyBatis", e); throw new RuntimeException(e); } }
Example 4
Source File: ProcessEngineConfigurationImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
protected void initCustomMybatisMappers(Configuration configuration) { if (getCustomMybatisMappers() != null) { for (Class<?> clazz : getCustomMybatisMappers()) { configuration.addMapper(clazz); } } }
Example 5
Source File: JsonHandlersTestApi.java From mybatis-jackson with MIT License | 5 votes |
protected static SqlSessionFactory setUpDb(DataSource ds, String initSql) throws SQLException, IOException { try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) { st.execute(getResourceAsString(initSql)); } // Init mybatis TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("jneat", transactionFactory, ds); Configuration configuration = new Configuration(environment); configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis"); configuration.addMapper(JsonMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 6
Source File: NpeExtendsTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void testNoConstructorConfiguration() { Configuration configuration = new Configuration(); configuration.addMapper(StudentMapper.class); configuration.addMapper(TeacherMapper.class); configuration.getMappedStatementNames(); }
Example 7
Source File: MultipleCrossIncludeTest.java From mybatis with Apache License 2.0 | 5 votes |
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); configuration.addMapper(MultipleCrossIncludePersonMapper.class); configuration.addMapper(MultipleCrossIncludePetMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 8
Source File: NpeExtendsTest.java From mybaties with Apache License 2.0 | 5 votes |
@Test public void testNoConstructorConfiguration() { Configuration configuration = new Configuration(); configuration.addMapper(StudentMapper.class); configuration.addMapper(TeacherMapper.class); configuration.getMappedStatementNames(); }
Example 9
Source File: NpeExtendsTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void testWithConstructorConfiguration() { Configuration configuration = new Configuration(); configuration.addMapper(StudentConstructorMapper.class); configuration.addMapper(TeacherMapper.class); configuration.getMappedStatementNames(); }
Example 10
Source File: LineStringTypeHandlerTest.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 5 votes |
@BeforeClass public static void setUp() throws Exception{ setupSqlSessionFactory("com/eyougo/mybatis/postgis/type/LineStringTypeHandlerTest.sql"); Configuration configuration = sqlSessionFactory.getConfiguration(); configuration.getTypeHandlerRegistry().register(LineStringTypeHandler.class); configuration.addMapper(LineStringMapper.class); }
Example 11
Source File: ResultMapExtendsTest.java From mybatis with Apache License 2.0 | 5 votes |
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); configuration.addMapper(ResultMapReferencePersonMapper.class); configuration.addMapper(ResultMapReferencePetMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 12
Source File: ResultMapExtendsTest.java From mybaties with Apache License 2.0 | 5 votes |
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); configuration.addMapper(ResultMapReferencePersonMapper.class); configuration.addMapper(ResultMapReferencePetMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 13
Source File: MultipleIncludeTest.java From mybaties with Apache License 2.0 | 5 votes |
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); configuration.addMapper(MultipleIncludePersonMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 14
Source File: Utils.java From ClosureTableCateogryStore with MIT License | 5 votes |
public static SqlSession createSqlSession(DataSource dataSource) { TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("test", transactionFactory, dataSource); Configuration config = new Configuration(); config.setCacheEnabled(false); config.addMapper(CategoryMapper.class); config.setEnvironment(environment); SqlSessionFactory sessionFactory = new DefaultSqlSessionFactory(config); return sessionFactory.openSession(); }
Example 15
Source File: DmnEngineConfiguration.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void initCustomMybatisMappers(Configuration configuration) { if (getCustomMybatisMappers() != null) { for (Class<?> clazz : getCustomMybatisMappers()) { configuration.addMapper(clazz); } } }
Example 16
Source File: JsonHandlersTestApi.java From mybatis-gson with MIT License | 5 votes |
protected static SqlSessionFactory setUpDb(DataSource ds, String initSql) throws SQLException, IOException { try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) { st.execute(getResourceAsString(initSql)); } // Init mybatis TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("jneat", transactionFactory, ds); Configuration configuration = new Configuration(environment); configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis"); configuration.addMapper(JsonMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 17
Source File: FormEngineConfiguration.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void initCustomMybatisMappers(Configuration configuration) { if (getCustomMybatisMappers() != null) { for (Class<?> clazz : getCustomMybatisMappers()) { configuration.addMapper(clazz); } } }
Example 18
Source File: ResultMapReferenceTest.java From mybaties with Apache License 2.0 | 5 votes |
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); configuration.addMapper(ResultMapReferencePersonMapper.class); configuration.addMapper(ResultMapReferencePetMapper.class); return new SqlSessionFactoryBuilder().build(configuration); }
Example 19
Source File: QueryTasksAccTest.java From taskana with Apache License 2.0 | 4 votes |
@WithAccessId(user = "admin") @Test void testQueryTaskByCustomAttributes() throws NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, NoSuchFieldException, IllegalAccessException { Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A"); newTask.setPrimaryObjRef( createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567")); newTask.setClassificationKey("T2100"); Map<String, String> customAttributesForCreate = createSimpleCustomProperties(20000); // about 1 Meg newTask.setCustomAttributes(customAttributesForCreate); Task createdTask = taskService.createTask(newTask); assertThat(createdTask).isNotNull(); // query the task by custom attributes TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine); try { SqlSession session = engineProxy.getSqlSession(); Configuration config = session.getConfiguration(); if (!config.hasMapper(TaskTestMapper.class)) { config.addMapper(TaskTestMapper.class); } TaskTestMapper mapper = session.getMapper(TaskTestMapper.class); engineProxy.openConnection(); List<TaskImpl> queryResult = mapper.selectTasksByCustomAttributeLike("%Property Value of Property_1339%"); assertThat(queryResult).hasSize(1); Task retrievedTask = queryResult.get(0); assertThat(retrievedTask.getId()).isEqualTo(createdTask.getId()); // verify that the map is correctly retrieved from the database Map<String, String> customAttributesFromDb = retrievedTask.getCustomAttributes(); assertThat(customAttributesFromDb).isNotNull(); assertThat(customAttributesFromDb).isEqualTo(customAttributesForCreate); } finally { engineProxy.returnConnection(); } }
Example 20
Source File: TaskanaEngineImpl.java From taskana with Apache License 2.0 | 4 votes |
/** * This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers and * sets the databaseId attribute. * * @return a {@link SqlSessionFactory} */ protected SqlSessionManager createSqlSessionManager() { Environment environment = new Environment( DEFAULT, this.transactionFactory, taskanaEngineConfiguration.getDatasource()); Configuration configuration = new Configuration(environment); // set databaseId String databaseProductName; try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) { databaseProductName = con.getMetaData().getDatabaseProductName(); String databaseProductId = DB.getDatabaseProductId(databaseProductName); configuration.setDatabaseId(databaseProductId); } catch (SQLException e) { throw new SystemException( "Method createSqlSessionManager() could not open a connection " + "to the database. No databaseId has been set.", e.getCause()); } // register type handlers configuration.getTypeHandlerRegistry().register(new MapTypeHandler()); configuration.getTypeHandlerRegistry().register(Instant.class, new InstantTypeHandler()); configuration.getTypeHandlerRegistry().register(JdbcType.TIMESTAMP, new InstantTypeHandler()); // add mappers configuration.addMapper(TaskMapper.class); configuration.addMapper(MonitorMapper.class); configuration.addMapper(WorkbasketMapper.class); configuration.addMapper(DistributionTargetMapper.class); configuration.addMapper(ClassificationMapper.class); configuration.addMapper(WorkbasketAccessMapper.class); configuration.addMapper(ObjectReferenceMapper.class); configuration.addMapper(WorkbasketQueryMapper.class); configuration.addMapper(TaskQueryMapper.class); configuration.addMapper(TaskCommentMapper.class); configuration.addMapper(ClassificationQueryMapper.class); configuration.addMapper(AttachmentMapper.class); configuration.addMapper(JobMapper.class); SqlSessionFactory localSessionFactory = new SqlSessionFactoryBuilder().build(configuration); return SqlSessionManager.newInstance(localSessionFactory); }