MyBatis:code improvements/java.net.preferIPv4Stack
authorGustavo Martin Morcuende <gustavo@supergusarapo.(none)>
Tue, 27 Aug 2013 22:01:48 +0000 (00:01 +0200)
committerGustavo Martin Morcuende <gustavo@supergusarapo.(none)>
Tue, 27 Aug 2013 22:01:48 +0000 (00:01 +0200)
MyBatis/README.txt
MyBatis/src/main/java/de/example/mybatis/TestMain.java
MyBatis/src/main/resources/generator/generatorConfig.xml
MyBatis/src/main/resources/mybatis-sql-maps-config.xml

index 8291f62..3511f09 100644 (file)
@@ -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
 
index c383502..bffa47f 100644 (file)
@@ -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();
index 9f1442a..a020fcc 100644 (file)
             <property name="suppressDate" value="true" />
         </commentGenerator>
         
+        <!--
+        If you are dropping like me (by means of some firewall) IPV6 connections and you feel
+        during the first MySLQ connection as if there is a huge lag and you are using
+        *NIX, you could use this system property -Djava.net.preferIPv4Stack=true
+        in order to stop using IPV6 from JVM.
+         -->
         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
             connectionURL="jdbc:mysql://localhost:3306/mybatis_example?characterEncoding=UTF-8" userId="root" password="root">
         </jdbcConnection>
index 982dc10..ff80a44 100644 (file)
       <transactionManager type="JDBC"/>
       <dataSource type="UNPOOLED">
         <property name="driver" value="com.mysql.jdbc.Driver"/>
+        <!--
+        If you are dropping like me (by means of some firewall) IPV6 connections and you feel
+        during the first MySLQ connection as if there is a huge lag and you are using
+        *NIX, you could use this system property -Djava.net.preferIPv4Stack=true
+        in order to stop using IPV6 from JVM.
+         -->
         <property name="url" value="jdbc:mysql://localhost:3306/mybatis_example?characterEncoding=UTF-8"/>
         <property name="username" value="root"/>
         <property name="password" value="root"/>