package de.example.mybatis.repository.mapper;
+import java.util.List;
import java.util.Set;
import de.example.mybatis.mapper.filter.MyBatisScanFilter;
public interface AdCustomMapper extends MyBatisScanFilter {
Set<Ad> selectAds();
+
+ List<Ad> selectAdsList();
+
+ void updateAdsBatch(List<Ad> ads);
}
logger.info("Starting application");
- final ExampleService exampleService = (ExampleService) SpringContextLocator
- .getInstance().getBean("exampleService");
-
- exampleService.insertNewAd();
-
- exampleService.getAdsByCriteria();
+// final ExampleService exampleService = (ExampleService) SpringContextLocator
+// .getInstance().getBean("exampleService");
+//
+// exampleService.insertNewAd();
+//
+// exampleService.getAdsByCriteria();
final ExampleCustomService exampleCustomService = (ExampleCustomService) SpringContextLocator
.getInstance().getBean("exampleCustomService");
exampleCustomService.getAds();
+
+ exampleCustomService.updateAds();
}
}
package de.example.mybatis.spring.service;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
logger.info("\n");
}
}
+
+ public void updateAds() {
+ logger.info("ExampleCustomService: updateAds");
+
+ final List<Ad> ads = this.adCustomMapper.selectAdsList();
+ final List<Ad> updateAds = new ArrayList<Ad>();
+
+ long companyId = 10;
+ long companyCategId = 20;
+ String mobileImage = "newimage.jpg";
+ for (final Ad ad : ads) {
+ ad.setCompanyCategId(companyCategId);
+ ad.setCompanyId(companyId);
+ ad.setAdMobileImage(mobileImage);
+
+ updateAds.add(ad);
+ companyId++;
+ companyCategId++;
+ }
+
+ this.adCustomMapper.updateAdsBatch(updateAds);
+ }
}
<select id="selectAds" resultType="de.example.mybatis.model.Ad" flushCache="false" useCache="true" timeout="10000" statementType="PREPARED">
select * FROM ad
</select>
+
+ <update id="updateAdsBatch" parameterType="List">
+ <!-- In order to make it work, the JDBC connection requires allowMultiQueries=true -->
+ <foreach collection="list" item="ad" separator=";">
+ UPDATE ad
+ <set>
+ company_id=#{ad.companyId},
+ company_categ_id=#{ad.companyCategId},
+ ad_mobile_image=#{ad.adMobileImage}
+ </set>
+ <where>
+ id=#{ad.id}
+ </where>
+ </foreach>
+ </update>
+
+ <select id="selectAdsList" resultType="de.example.mybatis.model.Ad" flushCache="false" useCache="true" timeout="10000" statementType="PREPARED">
+ select * FROM ad
+ </select>
+
</mapper>
\ No newline at end of file
The JVM tries to find out if IPV6 is available by means of opening a random
AF_INET6 POSIX socket.
-->
- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mybatis_example?autoReconnect=true&characterEncoding=UTF-8"/>
+ <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mybatis_example?allowMultiQueries=true&autoReconnect=true&characterEncoding=UTF-8"/>
<property name="initialPoolSize" value="5"/>
<property name="maxPoolSize" value="20"/>
<property name="minPoolSize" value="10"/>