List of usage examples for org.apache.ibatis.session SqlSessionManager newInstance
public static SqlSessionManager newInstance(SqlSessionFactory sqlSessionFactory)
From source file:cn.com.bricks.mybatis.rbac.DynamicRbacInterceptorNGTest.java
/** * intercept (DynamicRbacInterceptor)/*from w ww . ja v a 2 s.com*/ */ @Test public void testIntercept() throws Throwable { System.out.println("intercept"); InputStream inputStream = null; try { inputStream = Resources.getResourceAsStream("cn/com/bricks/mybatis/test/MapperConfig.xml"); SqlSessionManager sqlSession = SqlSessionManager.newInstance(inputStream); int count = sqlSession.openSession() .selectOne("org.apache.ibatis.domain.blog.mappers.BlogMapper.selectCountOfPosts"); System.out.println(count); } catch (IOException ex) { Logger.getLogger(DynamicRbacInterceptorNGTest.class.getName()).log(Level.SEVERE, null, ex); } finally { try { inputStream.close(); } catch (IOException ex) { Logger.getLogger(DynamicRbacInterceptorNGTest.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.mirth.connect.server.util.SqlConfig.java
License:Open Source License
/** * This method loads the MyBatis SQL config file for the database in use, * then appends sqlMap entries from any installed plugins *//*www . jav a 2 s . c o m*/ public static void init() { try { LogFactory.useLog4JLogging(); System.setProperty("derby.stream.error.method", "com.mirth.connect.server.Mirth.getNullOutputStream"); DatabaseSettings databaseSettings = ControllerFactory.getFactory().createConfigurationController() .getDatabaseSettings(); BufferedReader br = new BufferedReader(Resources.getResourceAsReader("SqlMapConfig.xml")); // parse the SqlMapConfig (ignoring the DTD) DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document document = factory.newDocumentBuilder().parse(new InputSource(br)); addPluginSqlMaps(databaseSettings.getDatabase(), new DonkeyElement(document.getDocumentElement()).getChildElement("mappers")); DocumentSerializer docSerializer = new DocumentSerializer(); Reader reader = new StringReader(docSerializer.toXML(document)); sqlSessionfactory = new SqlSessionFactoryBuilder().build(reader, databaseSettings.getProperties()); sqlSessionManager = SqlSessionManager.newInstance(sqlSessionfactory); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.pivotal.kr.load_gen.GemfireXDClient.java
License:Open Source License
public GemfireXDClient(String type, String sqlMapConfigXMLPath) throws FileNotFoundException { this.type = type; this.sqlSessionManager = SqlSessionManager.newInstance(new FileReader(new File(sqlMapConfigXMLPath))); }
From source file:org.glassfish.jersey.examples.helloworld.App.java
License:Open Source License
public static ResourceConfig createSessionInViewConfig() throws IOException { String resource = "mybatis.xml"; final Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); final SqlSessionManager sqlSessionManager = SqlSessionManager.newInstance(sqlSessionFactory); final KlassRepository klassRepository = sqlSessionManager.getMapper(KlassRepository.class); final ResourceConfig config = new ResourceConfig().packages(" org.glassfish.jersey.examples.helloworld") .register(new AbstractBinder() { @Override//from w w w. j ava 2 s. c o m protected void configure() { bind(klassRepository).to(KlassRepository.class); } }); return config; }
From source file:org.mybatis.cdi.ManagerProducers.java
License:Apache License
@ApplicationScoped @Produces// w w w . j ava 2 s . co m @Named("unmanaged") public SqlSession createNonCdiManagedSession() throws IOException { return SqlSessionManager.newInstance(createSessionManager(4)); }
From source file:org.mybatis.cdi.SqlSessionManagerRegistry.java
License:Apache License
/** * Inits the SqlSessionManagerRegistry./*ww w .ja v a2 s .com*/ */ @PostConstruct public void init() { if (this.factories.isUnsatisfied()) { throw new MybatisCdiConfigurationException( "There are no SqlSessionFactory producers properly configured."); } Map<SqlSessionFactory, SqlSessionManager> m = new HashMap<SqlSessionFactory, SqlSessionManager>(); for (SqlSessionFactory factory : this.factories) { SqlSessionManager manager = SqlSessionManager.newInstance(factory); m.put(factory, manager); } this.managers = Collections.unmodifiableMap(m); }
From source file:org.nanoframework.orm.mybatis.MultiDataSourceModule.java
License:Apache License
@Override protected void configure() { Reader reader = null;/*from w w w . j a v a 2s . c om*/ try { InputStream input; try { Resource resource = new ClassPathResource(mybatisConfigPath); input = resource.getInputStream(); if (input == null) input = new FileInputStream(ResourceUtils.getFile(mybatisConfigPath)); } catch (IOException e) { throw new LoaderException(": " + e.getMessage()); } reader = new InputStreamReader(input); SqlSessionFactory sessionFactory; SqlSessionManager sessionManager = SqlSessionManager .newInstance(sessionFactory = new SqlSessionFactoryBuilder().build(reader, envId, jdbc)); GlobalSqlSession.set(envId, sessionManager); Configuration configuration = sessionFactory.getConfiguration(); MapperRegistry registry = configuration.getMapperRegistry(); for (String pkg : mapperPackageName) { Set<Class<?>> classes = getClasses(pkg); if (!CollectionUtils.isEmpty(classes)) { for (Class<?> cls : classes) { if (!registry.hasMapper(cls)) registry.addMapper(cls); } } } // bind mappers Collection<Class<?>> mapperClasses = registry.getMappers(); for (Class<?> mapperType : mapperClasses) { bindMapper(mapperType, sessionManager); } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } }