From 724f400cad72dc3ab8f90feb3247d10278716f4c Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 28 Aug 2013 00:01:48 +0200 Subject: [PATCH] MyBatis:code improvements/java.net.preferIPv4Stack --- MyBatis/README.txt | 2 ++ .../src/main/java/de/example/mybatis/TestMain.java | 31 +++++++++++++++++----- .../main/resources/generator/generatorConfig.xml | 6 +++++ .../src/main/resources/mybatis-sql-maps-config.xml | 6 +++++ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/MyBatis/README.txt b/MyBatis/README.txt index 8291f62..3511f09 100644 --- a/MyBatis/README.txt +++ b/MyBatis/README.txt @@ -1,3 +1,5 @@ +Create database with createdatabase.sh script. + export M2_HOME=/opt/maven/apache-maven-2.2.1 PATH=$M2_HOME/bin:$PATH diff --git a/MyBatis/src/main/java/de/example/mybatis/TestMain.java b/MyBatis/src/main/java/de/example/mybatis/TestMain.java index c383502..bffa47f 100644 --- a/MyBatis/src/main/java/de/example/mybatis/TestMain.java +++ b/MyBatis/src/main/java/de/example/mybatis/TestMain.java @@ -15,7 +15,7 @@ import de.example.mybatis.repository.mapper.AdMapper; public class TestMain { - static Logger logger = Logger.getLogger(TestMain.class); + private static final Logger logger = Logger.getLogger(TestMain.class); public static void main(final String[] args) throws IOException { @@ -39,12 +39,12 @@ public class TestMain { .build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/ Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample"); - final SqlSession session = sqlSessionFactory.openSession(); + SqlSession session = sqlSessionFactory.openSession(); try { final AdMapper adMapper = session.getMapper(AdMapper.class); final Ad adTest = new Ad(); - adTest.setAdMobileImage("lol"); + adTest.setAdMobileImage("mobileImage.jpg"); adTest.setCompanyCategId(200L); adTest.setCreatedAt(new Date()); adTest.setCompanyId(2L); @@ -59,12 +59,29 @@ public class TestMain { logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8")); } logger.info("Ad mobileImage: " + ad.getAdMobileImage()); - logger.info("Ad mobileImage: " + ad.getCompanyCategId()); - logger.info("Ad id: " + ad.getCompanyId()); - logger.info("Ad id: " + ad.getCreatedAt()); - logger.info("Ad id: " + ad.getUpdatedAt()); + logger.info("Ad companyCategId: " + ad.getCompanyCategId()); + logger.info("Ad companyId: " + ad.getCompanyId()); + logger.info("Ad createdAt: " + ad.getCreatedAt()); + logger.info("Ad updatedAt: " + ad.getUpdatedAt()); logger.info("\n"); } + } finally { + session.close(); + } + + session = sqlSessionFactory.openSession(); + + try { + logger.info("Last insert"); + final AdMapper adMapper = session.getMapper(AdMapper.class); + final Ad adTest = new Ad(); + adTest.setAdMobileImage("mobileImage.jpg"); + adTest.setCompanyCategId(200L); + adTest.setCreatedAt(new Date()); + adTest.setCompanyId(2L); + adTest.setUpdatedAt(new Date()); + adMapper.insert(adTest); + session.commit(); } finally { session.close(); diff --git a/MyBatis/src/main/resources/generator/generatorConfig.xml b/MyBatis/src/main/resources/generator/generatorConfig.xml index 9f1442a..a020fcc 100644 --- a/MyBatis/src/main/resources/generator/generatorConfig.xml +++ b/MyBatis/src/main/resources/generator/generatorConfig.xml @@ -16,6 +16,12 @@ + diff --git a/MyBatis/src/main/resources/mybatis-sql-maps-config.xml b/MyBatis/src/main/resources/mybatis-sql-maps-config.xml index 982dc10..ff80a44 100644 --- a/MyBatis/src/main/resources/mybatis-sql-maps-config.xml +++ b/MyBatis/src/main/resources/mybatis-sql-maps-config.xml @@ -28,6 +28,12 @@ + -- 2.1.4