From: Gustavo Martin Morcuende Date: Tue, 27 Aug 2013 15:16:08 +0000 (+0200) Subject: MyBatis: log4j.xml, improving maps-config.xml X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=5ddefe8cbf292692a14957354344bbb590cea22b;p=JavaForFun MyBatis: log4j.xml, improving maps-config.xml --- diff --git a/MyBatis/pom.xml b/MyBatis/pom.xml index a38961e..0c7e15e 100644 --- a/MyBatis/pom.xml +++ b/MyBatis/pom.xml @@ -93,9 +93,29 @@ 5.1.9 - log4j - log4j - 1.2.17 + org.slf4j + slf4j-api + 1.7.5 + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + log4j + log4j + 1.2.17 + + + commons-logging + commons-logging + 1.1.1 + + + cglib + cglib + 2.2.2 diff --git a/MyBatis/src/main/java/de/example/mybatis/TestMain.java b/MyBatis/src/main/java/de/example/mybatis/TestMain.java index 2db41c4..9e14d0c 100644 --- a/MyBatis/src/main/java/de/example/mybatis/TestMain.java +++ b/MyBatis/src/main/java/de/example/mybatis/TestMain.java @@ -11,9 +11,6 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder; import de.example.mybatis.model.Ad; import de.example.mybatis.repository.mapper.AdMapper; -//import de.example.ibatis.demo.dao.UserDao; -//import de.example.ibatis.demo.dao.UserDaoIbatis; -//import de.example.ibatis.dto.UserTEO; public class TestMain { @@ -79,7 +76,7 @@ public class TestMain { // EN EL CLASSPATH: final SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder() .build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/ - Resources.getResourceAsStream("mybatis-sql-maps-config.xml")); + Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample"); final SqlSession session = sqlSessionFactory.openSession(); // EN MYBATIS HAY UNA FORMA MEJOR QUE ESTA // try { @@ -88,60 +85,21 @@ public class TestMain { // session.close(); // } // ESTA FORMA ES MUCHO MEJOR :) + try { final AdMapper mapper = session.getMapper(AdMapper.class); final Ad adprueba = new Ad(); + adprueba.setAdMobileImage("lol"); adprueba.setCompanyCategId(200L); adprueba.setCreatedAt(new Date()); adprueba.setCompanyId(2L); adprueba.setUpdatedAt(new Date()); mapper.insert(adprueba); + session.commit(); // Ad ad = mapper.selectByPrimaryKey(1000L); } finally { session.close(); } - - // De esa forma consigo que el encoding dependa del valor puesto en la cabecera del xml :) - - // SqlSession session = sqlSessionFactory.openSession(); - // try { - // Blog blog = session.selectOne("org.mybatis.example.BlogMapper.selectBlog", 101); - // } finally { - // session.close(); - // } - // - // SqlSession session = sqlSessionFactory.openSession(); - // try { - // BlogMapper mapper = session.getMapper(BlogMapper.class); - // Blog blog = mapper.selectBlog(101); - // } finally { - // session.close(); - // } - // SqlMapClient sqlmapClient = SqlMapClientBuilder.buildSqlMapClient (reader); - // - // //Create a new user to persist - // UserTEO user = new UserTEO(); - // user.setId(1); - // user.setName("Demo User"); - // user.setPassword("password"); - // user.setEmail("demo-user@howtodoinjava.com"); - // user.setStatus(1); - // - // //Add the user - // manager.addUser(user,sqlmapClient); - // - // //Fetch the user detail - // UserTEO createdUser = manager.getUserById(4, sqlmapClient); - // System.out.println(createdUser.getEmail()); - // - // //Lets delete the user - // manager.deleteUserById(1, sqlmapClient); - // try { - // Thread.sleep(100000); - // } catch (InterruptedException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } } } diff --git a/MyBatis/src/main/resources/log4j.xml b/MyBatis/src/main/resources/log4j.xml new file mode 100644 index 0000000..7c75361 --- /dev/null +++ b/MyBatis/src/main/resources/log4j.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyBatis/src/main/resources/mybatis-sql-maps-config.xml b/MyBatis/src/main/resources/mybatis-sql-maps-config.xml index 5ec8c90..982dc10 100644 --- a/MyBatis/src/main/resources/mybatis-sql-maps-config.xml +++ b/MyBatis/src/main/resources/mybatis-sql-maps-config.xml @@ -2,13 +2,33 @@ + - - + + + + + + + + + + + + + + + + + + + + + - + - +