List of usage examples for org.apache.ibatis.session Configuration addMapper
public <T> void addMapper(Class<T> type)
From source file:io.soabase.example.MockDatabase.java
License:Apache License
@SuppressWarnings("ParameterCanBeLocal") public static void main(String[] args) throws Exception { if (!Boolean.getBoolean("debug")) { OutputStream nullOut = new OutputStream() { @Override//w w w . ja v a2 s .c om public void write(int b) throws IOException { } }; System.setOut(new PrintStream(nullOut)); } args = new String[] { "--database.0", "mem:test", "--dbname.0", "xdb", "--port", "10064" }; Server.main(args); SqlSession session; try (InputStream stream = Resources.getResource("example-mybatis.xml").openStream()) { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream); Configuration mybatisConfiguration = sqlSessionFactory.getConfiguration(); mybatisConfiguration.addMapper(AttributeEntityMapper.class); session = sqlSessionFactory.openSession(true); } AttributeEntityMapper mapper = session.getMapper(AttributeEntityMapper.class); mapper.createTable(); mapper.insert(new AttributeEntity("test", "global")); mapper.insert(new AttributeEntity("test2", "hello", "one")); mapper.insert(new AttributeEntity("test2", "goodbye", "two")); List<AttributeEntity> attributeEntities = mapper.selectAll(); System.out.println(attributeEntities); System.out.println("Running..."); Thread.currentThread().join(); }
From source file:io.soabase.sql.attributes.SqlBundle.java
License:Apache License
@Override public void run(T configuration, Environment environment) throws Exception { SqlConfiguration sqlConfiguration = ComposedConfigurationAccessor.access(configuration, environment, SqlConfiguration.class); try {/*from w w w.ja v a 2 s . com*/ 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) { // TODO logging log.error("Could not initialize MyBatis", e); throw new RuntimeException(e); } }
From source file:mbg.test.mb3.dsql.AbstractTest.java
License:Apache License
@Before public void setUp() throws Exception { createDatabase();//from w ww . j a va2 s .c o m UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(AwfulTableMapper.class); config.addMapper(FieldsblobsMapper.class); config.addMapper(FieldsonlyMapper.class); config.addMapper(PkblobsMapper.class); config.addMapper(PkfieldsblobsMapper.class); config.addMapper(PkfieldsMapper.class); config.addMapper(PkonlyMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:mbg.test.mb3.dsql.miscellaneous.AbstractAnnotatedMiscellaneousTest.java
License:Apache License
@Before public void setUp() throws Exception { createDatabase();/*from www. jav a2 s.co m*/ UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(EnumtestMapper.class); config.addMapper(GeneratedalwaystestMapper.class); config.addMapper(GeneratedalwaystestnoupdatesMapper.class); config.addMapper(MyObjectMapper.class); config.addMapper(RegexrenameMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:net.landora.video.data.AbstractDataManager.java
License:Open Source License
private synchronized SqlSessionFactory getFactory() { if (factory == null) { TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("development", transactionFactory, DatabaseConnectionManager.getInstance().getDataSource()); Configuration configuration = new Configuration(environment); configuration.setCacheEnabled(true); configuration.setLazyLoadingEnabled(false); configuration.getTypeHandlerRegistry().register(Calendar.class, JdbcType.TIMESTAMP, new CalendarTypeHandler()); configuration.getTypeHandlerRegistry().register(Calendar.class, JdbcType.DATE, new DateCalendarTypeHandler()); for (Class<?> clazz : getAliasTypeClasses()) { String className = clazz.getSimpleName(); configuration.getTypeAliasRegistry().registerAlias(className, clazz); }/* w w w . j av a2 s . c o m*/ for (Class<?> clazz : getMapperClasses()) { configuration.addMapper(clazz); } factory = new SqlSessionFactoryBuilder().build(configuration); } return factory; }
From source file:org.activiti.engine.AbstractEngineConfiguration.java
License:Apache License
public void initCustomMybatisMappers(Configuration configuration) { if (getCustomMybatisMappers() != null) { for (Class<?> clazz : getCustomMybatisMappers()) { configuration.addMapper(clazz); }// w w w . j a v a2 s. co m } }
From source file:org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.java
License:Apache License
protected void initCustomMybatisMappers(Configuration configuration) { if (getCustomMybatisMappers() != null) { for (Class<?> clazz : getCustomMybatisMappers()) { configuration.addMapper(clazz); }//from ww w . j a va 2 s .co m } }
From source file:org.codehaus.griffon.runtime.mybatis.DefaultMybatisFactory.java
License:Apache License
@Nonnull @SuppressWarnings("ConstantConditions") private SqlSessionFactory createSqlSessionFactory(@Nonnull Map<String, Object> config, @Nonnull String dataSourceName) { DataSource dataSource = getDataSource(dataSourceName); Environment environment = new Environment(dataSourceName, new JdbcTransactionFactory(), dataSource); Configuration configuration = new Configuration(environment); Map<String, Object> copyOfConfig = new LinkedHashMap<>(config); copyOfConfig.remove("connect_on_startup"); GriffonClassUtils.setProperties(configuration, copyOfConfig); if (mappers.isEmpty()) { readMappers();// www . j a va2s . c o m } for (Class<?> mapper : mappers) { configuration.addMapper(mapper); } return new RecordingSqlSessionFactory(new SqlSessionFactoryBuilder().build(configuration)); }
From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java
License:Apache License
/** {@link SqlSessionFactory} */ private void buildSessionFactory() { synchronized (this) { if (sessionFactory == null) { try { Reader reader = Resources.getResourceAsReader(configFile); sessionFactory = new SqlSessionFactoryBuilder().build(reader, environment); if (GeneralHelper.isStrNotEmpty(pattern)) { Set<String> packages = PackageHelper.getPackages(pattern); for (String pkg : packages) { Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() { @Override public boolean accept(Class<?> clazz) { if (!BeanHelper.isPublicInterface(clazz)) return false; return true; }/*from w w w . j ava 2s . com*/ }); Configuration cfg = sessionFactory.getConfiguration(); for (Class<?> clazz : entities) { if (!cfg.hasMapper(clazz)) cfg.addMapper(clazz); } } } } catch (IOException e) { throw new SqlSessionException(e); } } } }
From source file:org.mybatis.guice.configuration.settings.MapperConfigurationSetting.java
License:Apache License
public void applyConfigurationSetting(Configuration configuration) { if (!configuration.hasMapper(mapperClass)) { configuration.addMapper(mapperClass); }//from www .j a v a 2s . c om }