Package org.apache.ibatis.session

Examples of org.apache.ibatis.session.SqlSessionFactory.openSession()


    @SuppressWarnings("unchecked")
    @Test
    public void testRefCursor2() throws IOException {
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/refcursor/MapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
            Map<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("orderId", 1);
            mapper.getOrder2(parameter);
View Full Code Here


  @BeforeClass
  public static void setUpBeforeClass() {
    try {
      final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG));
      session = factory.openSession();
      Connection conn = session.getConnection();
      ScriptRunner runner = new ScriptRunner(conn);
      runner.setLogWriter(null);
      runner.setErrorLogWriter(null);
      Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/null_associations/create-schema-mysql.sql");
View Full Code Here

  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);

View Full Code Here

  public void shouldDemonstrateDuplicateResourceIssue() throws Exception {
    final String resource = "org/apache/ibatis/submitted/duplicate_resource_loaded/Config.xml";
    final Reader reader = Resources.getResourceAsReader(resource);
    final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
    final SqlSessionFactory factory = builder.build(reader);
    final SqlSession sqlSession = factory.openSession();
    try {
      final Mapper mapper = sqlSession.getMapper(Mapper.class);
      final List list = mapper.selectAllBlogs();
      Assert.assertEquals(2,list.size());
    } finally {
View Full Code Here

    Environment env = new Environment("test",new JdbcTransactionFactory(),ds);
    Configuration config = new Configuration(env);
    config.addMapper(NodeMapper.class);
    SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
    SqlSessionFactory sqlMapper = builder.build(config);
    SqlSession session = sqlMapper.openSession();
    try {
      NodeMapper mapper = session.getMapper(NodeMapper.class);

      try {
        mapper.selectNode(1);
View Full Code Here

    Configuration config = new Configuration(env);
    config.addMapper(JPetStoreMapper.class);

    SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
    SqlSessionFactory sqlMapper = builder.build(config);
    SqlSession session = sqlMapper.openSession();
    try {
      JPetStoreMapper mapper = session.getMapper(JPetStoreMapper.class);
      int n = mapper.insertCategory("MONKEYS",null,"Big hairy friendly (sometimes) mammals...");
      assertEquals(1,n);
      session.rollback();
View Full Code Here

    Configuration config = new Configuration(env);
    config.addMapper(BlogMapper.class);

    SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
    SqlSessionFactory sqlMapper = builder.build(config);
    SqlSession session = sqlMapper.openSession();
    try {
      BlogMapper mapper = session.getMapper(BlogMapper.class);
      int n = 0;
      try {
        n = mapper.insertAuthor(new Author(99999,"barney","******","barney@iloveyou.com",null, Section.NEWS));
View Full Code Here

    @Test
    public void testInsertAnnotated() throws Exception {
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
            Name name = new Name();
            name.setFirstName("Fred");
            name.setLastName("Flintstone");
View Full Code Here

    @Test
    public void testInsertMapped() throws Exception {
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
            Name name = new Name();
            name.setFirstName("Fred");
            name.setLastName("Flintstone");
View Full Code Here

                selectPerson.getResource());

        Connection conn = configuration.getEnvironment().getDataSource().getConnection();
        initDb(conn);

        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            Person person = (Person) sqlSession.selectOne("person namespace.select", 1);
            assertEquals((Integer)1, person.getId());
            assertEquals(2, person.getPets().size());
            assertEquals((Integer)2, person.getPets().get(1).getId());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.