--- /dev/null
+Create database with createdatabase.sh script.
+
+export M2_HOME=/opt/maven/apache-maven-2.2.1
+PATH=$M2_HOME/bin:$PATH
+
+mvn clean install -Dmaven.test.skip=true
+mvn dependency:sources
+mvn dependency:resolve -Dclassifier=javadoc
--- /dev/null
+#!/bin/bash
+mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8"
+
+mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci"
+
+# Por alguna extraña razon no pude poner el id de esta tabla como serial y no tiene ahora este id autoincrement
+# Daba un error raro diciendo que no podia haber 2 claves con autoincrement en la misma tabla. Pero sí se puede...
+# debo estar haciendo algo mal... :(
+mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id BIGINT(20) UNSIGNED NOT NULL, laguage_id BIGINT NOT NULL, ad_id SERIAL NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci"
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>de.example.mybatis</groupId>
+ <artifactId>mybatisexample</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>mybatisexample</name>
+ <url>http://gumartinm.name</url>
+ <properties>
+ <mybatis.generator.outputdirectory>${project.build.directory}/generated-sources/mybatis-generator/</mybatis.generator.outputdirectory>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mybatis.generator</groupId>
+ <artifactId>mybatis-generator-maven-plugin</artifactId>
+ <version>1.3.2</version>
+ <executions>
+ <execution>
+ <id>Generate MyBatis Artifacts</id>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
+ <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
+ <jdbcPassword>root</jdbcPassword>
+ <jdbcURL>jdbc:mysql://localhost:3306/mybatis_example</jdbcURL>
+ <jdbcUserId>root</jdbcUserId>
+ <outputDirectory>${mybatis.generator.outputdirectory}</outputDirectory>
+ <overwrite>true</overwrite>
+ <verbose>true</verbose>
+ </configuration>
+ </plugin>
+ <!-- Required to work with m2e plugin for Eclipse (there is an available connector for this plugin but no for mybatis-generator-maven-plugin) -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${mybatis.generator.outputdirectory}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis</groupId>
+ <artifactId>mybatis</artifactId>
+ <version>3.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+package de.example.mybatis;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.log4j.Logger;
+
+import de.example.mybatis.model.Ad;
+import de.example.mybatis.model.AdCriteria;
+import de.example.mybatis.repository.mapper.AdMapper;
+
+
+public class TestMain {
+ private static final Logger logger = Logger.getLogger(TestMain.class);
+
+ public static void main(final String[] args) throws IOException {
+
+ // From org.xml.sax.InputSource Javadoc:
+ // The SAX parser will use the InputSource object to determine how to
+ // read XML input. If there is a character stream available, the parser
+ // will read that stream directly, disregarding any text encoding
+ // declaration found in that stream. If there is no character stream,
+ // but there is a byte stream, the parser will use that byte stream,
+ // using the encoding specified in the InputSource or else (if no
+ // encoding is specified) autodetecting the character encoding using an
+ // algorithm such as the one in the XML specification. If neither a
+ // character stream nor a byte stream is available, the parser will
+ // attempt to open a URI connection to the resource identified by the
+ // system identifier.
+
+ // Then if we use an InputStream (it is not a character stream) and
+ // we do not specify the encoding, the encoding should be autodetected
+ // reading the XML header. :) That is what I want. :)
+ final SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
+ .build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/
+ Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample");
+
+ SqlSession session = sqlSessionFactory.openSession();
+
+ try {
+ 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();
+
+ final List<Ad> adLists = adMapper.selectByExample(null);
+ for (final Ad ad : adLists) {
+ logger.info("Ad id: " + ad.getId());
+ if (ad.getAdGps() != null) {
+ logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
+ }
+ logger.info("Ad mobileImage: " + ad.getAdMobileImage());
+ 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();
+ }
+
+ session = sqlSessionFactory.openSession();
+
+ try {
+ logger.info("Using criteria");
+
+ final AdCriteria adCriteria = new AdCriteria();
+
+ adCriteria.or().andAdMobileImageEqualTo("mobileImage.jpg")
+ .andCreatedAtNotEqualTo(new Date());
+
+ adCriteria.or().andAdMobileImageNotEqualTo("noMobileImage.jpg")
+ .andAdMobileImageIsNotNull();
+
+ // where (ad_mobile_image = "mobileImage.jpg" and created_at <> Now())
+ // or (ad_mobile_image <> "noMobileImage.jpg" and ad_mobile_image is not null)
+
+ final AdMapper adMapper = session.getMapper(AdMapper.class);
+ final List<Ad> adLists = adMapper.selectByExampleWithBLOBs(adCriteria);
+ for (final Ad ad : adLists) {
+ logger.info("Ad id: " + ad.getId());
+ if (ad.getAdGps() != null) {
+ logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
+ }
+ logger.info("Ad mobileImage: " + ad.getAdMobileImage());
+ 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();
+ }
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE generatorConfiguration
+ PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+
+<generatorConfiguration>
+ <!--
+ user.home property is not working with maven 2.2.1
+ <classPathEntry location="${user.home}/.m2/repository/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar" />
+ -->
+ <classPathEntry location="/home/gustavo/.m2/repository/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar" />
+
+ <context id="MySQLTables" targetRuntime="MyBatis3">
+
+ <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
+ <property name="searchString" value="Example$"/>
+ <property name="replaceString" value="Criteria"/>
+ </plugin>
+
+ <!-- This can be useful in paging applications -->
+ <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin">
+ </plugin>
+
+ <commentGenerator>
+ <property name="suppressAllComments" value="false" />
+ <property name="suppressDate" value="false" />
+ </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>
+
+ <javaTypeResolver>
+ <property name="forceBigDecimals" value="false" />
+ </javaTypeResolver>
+
+ <javaModelGenerator targetPackage="de.example.mybatis.model" targetProject="MAVEN">
+ <!--property name="constructorBased" value="true" />
+ <property name="immutable" value="true" /-->
+ <property name="enableSubPackages" value="true" />
+ <property name="trimStrings" value="false" />
+ </javaModelGenerator>
+
+ <sqlMapGenerator targetPackage="de.example.mybatis.repository.mapper" targetProject="MAVEN">
+ <property name="enableSubPackages" value="true" />
+ </sqlMapGenerator>
+
+ <javaClientGenerator type="XMLMAPPER" targetPackage="de.example.mybatis.repository.mapper"
+ targetProject="MAVEN">
+ <property name="enableSubPackages" value="true" />
+ </javaClientGenerator>
+
+ <table schema="mybatis_example" tableName="ad" domainObjectName="Ad">
+ <property name="useActualColumnNames" value="false" />
+ <property name="ignoreQualifiersAtRuntime" value="true" />
+ <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
+ </table>
+ <table schema="mybatis_example" tableName="ad_description" domainObjectName="AdDescription">
+ <property name="useActualColumnNames" value="false" />
+ <property name="ignoreQualifiersAtRuntime" value="true" />
+ <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
+ </table>
+ </context>
+</generatorConfiguration>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
+<log4j:configuration>
+ <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L %m%n"/>
+ </layout>
+ </appender>
+ <root>
+ <priority value="debug"></priority>
+ <appender-ref ref="stdout"/>
+ </root>
+</log4j:configuration>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration
+ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-config.dtd">
+
+<configuration>
+<settings>
+ <setting name="cacheEnabled" value="false"/>
+ <setting name="lazyLoadingEnabled" value="false"/>
+ <setting name="aggressiveLazyLoading" value="false"/>
+ <setting name="multipleResultSetsEnabled" value="true"/>
+ <setting name="useColumnLabel" value="false"/>
+ <setting name="useGeneratedKeys" value="false"/>
+ <setting name="autoMappingBehavior" value="PARTIAL"/>
+ <setting name="defaultExecutorType" value="SIMPLE"/>
+ <setting name="defaultStatementTimeout" value="5"/>
+ <setting name="safeRowBoundsEnabled" value="false"/>
+ <setting name="mapUnderscoreToCamelCase" value="false"/>
+ <setting name="localCacheScope" value="SESSION"/>
+ <setting name="jdbcTypeForNull" value="OTHER"/>
+ <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
+ <setting name="logPrefix" value="mybatislogger"/>
+ <setting name="logImpl" value="LOG4J"/>
+ <setting name="proxyFactory" value="CGLIB"/>
+ </settings>
+ <environments default="mybatisexample">
+ <environment id="mybatisexample">
+ <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"/>
+ </dataSource>
+ </environment>
+ </environments>
+ <mappers>
+ <mapper resource="de/example/mybatis/repository/mapper/AdDescriptionMapper.xml"/>
+ <mapper resource="de/example/mybatis/repository/mapper/AdMapper.xml"/>
+ </mappers>
+</configuration>
\ No newline at end of file
+++ /dev/null
-Create database with createdatabase.sh script.
-
-export M2_HOME=/opt/maven/apache-maven-2.2.1
-PATH=$M2_HOME/bin:$PATH
-
-mvn clean install -Dmaven.test.skip=true
-mvn dependency:sources
-mvn dependency:resolve -Dclassifier=javadoc
+++ /dev/null
-#!/bin/bash
-mysql -uroot -proot -e "CREATE DATABASE mybatis_example DEFAULT CHARACTER SET utf8"
-
-mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad (id SERIAL, company_id BIGINT, company_categ_id BIGINT, ad_gps BLOB, ad_mobile_image varchar(255), created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci"
-
-# Por alguna extraña razon no pude poner el id de esta tabla como serial y no tiene ahora este id autoincrement
-# Daba un error raro diciendo que no podia haber 2 claves con autoincrement en la misma tabla. Pero sí se puede...
-# debo estar haciendo algo mal... :(
-mysql -uroot -proot -e "USE mybatis_example; CREATE TABLE ad_description (id BIGINT(20) UNSIGNED NOT NULL, laguage_id BIGINT NOT NULL, ad_id SERIAL NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description LONGTEXT, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY (id), INDEX(ad_id), FOREIGN KEY (ad_id) REFERENCES ad (id) ON DELETE CASCADE) ENGINE=InnoDB, DEFAULT CHARSET=utf8, COLLATE=utf8_unicode_ci"
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>de.example.mybatis</groupId>
- <artifactId>mybatisexample</artifactId>
- <packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
- <name>mybatisexample</name>
- <url>http://gumartinm.name</url>
- <properties>
- <mybatis.generator.outputdirectory>${project.build.directory}/generated-sources/mybatis-generator/</mybatis.generator.outputdirectory>
- </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>${project.build.sourceEncoding}</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
- <configuration>
- <encoding>${project.build.sourceEncoding}</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.2</version>
- <executions>
- <execution>
- <id>Generate MyBatis Artifacts</id>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
- <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
- <jdbcPassword>root</jdbcPassword>
- <jdbcURL>jdbc:mysql://localhost:3306/mybatis_example</jdbcURL>
- <jdbcUserId>root</jdbcUserId>
- <outputDirectory>${mybatis.generator.outputdirectory}</outputDirectory>
- <overwrite>true</overwrite>
- <verbose>true</verbose>
- </configuration>
- </plugin>
- <!-- Required to work with m2e plugin for Eclipse (there is an available connector for this plugin but no for mybatis-generator-maven-plugin) -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.8</version>
- <executions>
- <execution>
- <id>add-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${mybatis.generator.outputdirectory}</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.2.2</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.9</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.5</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.5</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.17</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- <version>2.2.2</version>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-package de.example.mybatis;
-
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.ibatis.io.Resources;
-import org.apache.ibatis.session.SqlSession;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
-import org.apache.log4j.Logger;
-
-import de.example.mybatis.model.Ad;
-import de.example.mybatis.model.AdCriteria;
-import de.example.mybatis.repository.mapper.AdMapper;
-
-
-public class TestMain {
- private static final Logger logger = Logger.getLogger(TestMain.class);
-
- public static void main(final String[] args) throws IOException {
-
- // From org.xml.sax.InputSource Javadoc:
- // The SAX parser will use the InputSource object to determine how to
- // read XML input. If there is a character stream available, the parser
- // will read that stream directly, disregarding any text encoding
- // declaration found in that stream. If there is no character stream,
- // but there is a byte stream, the parser will use that byte stream,
- // using the encoding specified in the InputSource or else (if no
- // encoding is specified) autodetecting the character encoding using an
- // algorithm such as the one in the XML specification. If neither a
- // character stream nor a byte stream is available, the parser will
- // attempt to open a URI connection to the resource identified by the
- // system identifier.
-
- // Then if we use an InputStream (it is not a character stream) and
- // we do not specify the encoding, the encoding should be autodetected
- // reading the XML header. :) That is what I want. :)
- final SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
- .build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/
- Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample");
-
- SqlSession session = sqlSessionFactory.openSession();
-
- try {
- 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();
-
- final List<Ad> adLists = adMapper.selectByExample(null);
- for (final Ad ad : adLists) {
- logger.info("Ad id: " + ad.getId());
- if (ad.getAdGps() != null) {
- logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
- }
- logger.info("Ad mobileImage: " + ad.getAdMobileImage());
- 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();
- }
-
- session = sqlSessionFactory.openSession();
-
- try {
- logger.info("Using criteria");
-
- final AdCriteria adCriteria = new AdCriteria();
-
- adCriteria.or().andAdMobileImageEqualTo("mobileImage.jpg")
- .andCreatedAtNotEqualTo(new Date());
-
- adCriteria.or().andAdMobileImageNotEqualTo("noMobileImage.jpg")
- .andAdMobileImageIsNotNull();
-
- // where (ad_mobile_image = "mobileImage.jpg" and created_at <> Now())
- // or (ad_mobile_image <> "noMobileImage.jpg" and ad_mobile_image is not null)
-
- final AdMapper adMapper = session.getMapper(AdMapper.class);
- final List<Ad> adLists = adMapper.selectByExampleWithBLOBs(adCriteria);
- for (final Ad ad : adLists) {
- logger.info("Ad id: " + ad.getId());
- if (ad.getAdGps() != null) {
- logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
- }
- logger.info("Ad mobileImage: " + ad.getAdMobileImage());
- 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();
- }
- }
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE generatorConfiguration
- PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
- "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
-
-<generatorConfiguration>
- <!--
- user.home property is not working with maven 2.2.1
- <classPathEntry location="${user.home}/.m2/repository/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar" />
- -->
- <classPathEntry location="/home/gustavo/.m2/repository/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar" />
-
- <context id="MySQLTables" targetRuntime="MyBatis3">
-
- <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
- <property name="searchString" value="Example$"/>
- <property name="replaceString" value="Criteria"/>
- </plugin>
-
- <!-- This can be useful in paging applications -->
- <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin">
- </plugin>
-
- <commentGenerator>
- <property name="suppressAllComments" value="false" />
- <property name="suppressDate" value="false" />
- </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>
-
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
-
- <javaModelGenerator targetPackage="de.example.mybatis.model" targetProject="MAVEN">
- <!--property name="constructorBased" value="true" />
- <property name="immutable" value="true" /-->
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="false" />
- </javaModelGenerator>
-
- <sqlMapGenerator targetPackage="de.example.mybatis.repository.mapper" targetProject="MAVEN">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
-
- <javaClientGenerator type="XMLMAPPER" targetPackage="de.example.mybatis.repository.mapper"
- targetProject="MAVEN">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
-
- <table schema="mybatis_example" tableName="ad" domainObjectName="Ad">
- <property name="useActualColumnNames" value="false" />
- <property name="ignoreQualifiersAtRuntime" value="true" />
- <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
- </table>
- <table schema="mybatis_example" tableName="ad_description" domainObjectName="AdDescription">
- <property name="useActualColumnNames" value="false" />
- <property name="ignoreQualifiersAtRuntime" value="true" />
- <generatedKey column="id" sqlStatement="MySql" identity="false" type="pre" />
- </table>
- </context>
-</generatorConfiguration>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
-<log4j:configuration>
- <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L %m%n"/>
- </layout>
- </appender>
- <root>
- <priority value="debug"></priority>
- <appender-ref ref="stdout"/>
- </root>
-</log4j:configuration>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
-
-<configuration>
-<settings>
- <setting name="cacheEnabled" value="false"/>
- <setting name="lazyLoadingEnabled" value="false"/>
- <setting name="aggressiveLazyLoading" value="false"/>
- <setting name="multipleResultSetsEnabled" value="true"/>
- <setting name="useColumnLabel" value="false"/>
- <setting name="useGeneratedKeys" value="false"/>
- <setting name="autoMappingBehavior" value="PARTIAL"/>
- <setting name="defaultExecutorType" value="SIMPLE"/>
- <setting name="defaultStatementTimeout" value="5"/>
- <setting name="safeRowBoundsEnabled" value="false"/>
- <setting name="mapUnderscoreToCamelCase" value="false"/>
- <setting name="localCacheScope" value="SESSION"/>
- <setting name="jdbcTypeForNull" value="OTHER"/>
- <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
- <setting name="logPrefix" value="mybatislogger"/>
- <setting name="logImpl" value="LOG4J"/>
- <setting name="proxyFactory" value="CGLIB"/>
- </settings>
- <environments default="mybatisexample">
- <environment id="mybatisexample">
- <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"/>
- </dataSource>
- </environment>
- </environments>
- <mappers>
- <mapper resource="de/example/mybatis/repository/mapper/AdDescriptionMapper.xml"/>
- <mapper resource="de/example/mybatis/repository/mapper/AdMapper.xml"/>
- </mappers>
-</configuration>
\ No newline at end of file