From a71da926e381b1e880d342420325f07712a71fb6 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 10 Apr 2016 14:15:42 +0200 Subject: [PATCH] mend --- .../de/example/date/parsing/DateFormatUtils.java | 2 ++ .../de/example/date/parsing/MainDateFormat.java | 10 +++++++ .../de/test/thread/executor/future/ThreadMain.java | 13 ++++++-- .../mybatis/executor/ReuseBatchExecutor.java | 35 ++++++++++++++++++++++ .../java/de/example/mybatis/spring/TestMain.java | 34 ++++++++------------- .../spring/service/BatchAndSimpleSameTrx.java | 19 +++++++++--- .../src/main/resources/config/mybatis-config.xml | 8 ++++- RemoteAgents/remote-agents-batchapp/pom.xml | 9 ++++++ 8 files changed, 100 insertions(+), 30 deletions(-) diff --git a/Allgemeines/DateParsingJava8/src/de/example/date/parsing/DateFormatUtils.java b/Allgemeines/DateParsingJava8/src/de/example/date/parsing/DateFormatUtils.java index 334a216..a690b19 100644 --- a/Allgemeines/DateParsingJava8/src/de/example/date/parsing/DateFormatUtils.java +++ b/Allgemeines/DateParsingJava8/src/de/example/date/parsing/DateFormatUtils.java @@ -8,6 +8,8 @@ import java.util.Date; public class DateFormatUtils { + private static final String TEST1 = "Gustavo"; + private final String TEST2 = "Martin"; public static String format(Date date, String format) { final ZoneId timeZone = ZoneId.of("America/Los_Angeles"); diff --git a/Allgemeines/DateParsingJava8/src/de/example/date/parsing/MainDateFormat.java b/Allgemeines/DateParsingJava8/src/de/example/date/parsing/MainDateFormat.java index 6abb385..60ae0be 100644 --- a/Allgemeines/DateParsingJava8/src/de/example/date/parsing/MainDateFormat.java +++ b/Allgemeines/DateParsingJava8/src/de/example/date/parsing/MainDateFormat.java @@ -32,6 +32,16 @@ public class MainDateFormat { Date dateCurrentTimeFormatter = DateHourFormatter.parseToDate("12/05/2014 18:40"); + + + LocalDate nowTomcat = LocalDate.now(ZoneId.of("America/New_York")); + + Date joer = Date.from(nowTomcat.atStartOfDay().atZone(ZoneId.of("America/New_York")).toInstant()); + + System.out.println(nowTomcat); + + System.out.println(joer); + } } diff --git a/Allgemeines/Threads/Executor/ExecutorwithFuture/src/de/test/thread/executor/future/ThreadMain.java b/Allgemeines/Threads/Executor/ExecutorwithFuture/src/de/test/thread/executor/future/ThreadMain.java index b85f5d7..aab53b8 100644 --- a/Allgemeines/Threads/Executor/ExecutorwithFuture/src/de/test/thread/executor/future/ThreadMain.java +++ b/Allgemeines/Threads/Executor/ExecutorwithFuture/src/de/test/thread/executor/future/ThreadMain.java @@ -1,11 +1,18 @@ package de.test.thread.executor.future; +import de.test.thread.executor.future.FutureTaskExample.Car; + public class ThreadMain { public static void main(String[] args) { - ThreadTest test = new ThreadTest(); - - test.start(); +// ThreadTest test = new ThreadTest(); +// +// test.start(); + + FutureTaskExample lol = new FutureTaskExample(); + Car jeje = lol.test(); + + System.out.println(jeje.getId()); } } diff --git a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/java/de/example/mybatis/executor/ReuseBatchExecutor.java b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/java/de/example/mybatis/executor/ReuseBatchExecutor.java index c5d543c..bec632d 100644 --- a/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/java/de/example/mybatis/executor/ReuseBatchExecutor.java +++ b/MyBatis/MyBatis-Spring-ReuseBatchExecutor/src/main/java/de/example/mybatis/executor/ReuseBatchExecutor.java @@ -25,6 +25,41 @@ import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.transaction.Transaction; +/** + * This class tries to give some kind of solution to this problem: + * Why MyBatis implementation only checks for last SQL string? + * If the implementation uses map of sql strings then it can reuse the statements even for the multiple queries. + * http://mybatis-user.963551.n3.nabble.com/Unexpected-multiple-prepared-statements-when-using-batch-executor-type-td4027708.html + * + */ + +// But be careful when using this Executor: +// If you write this: +// for (1000 records) { +// insert into table A +// update into table B +// } +// +// you will probably expect the execution to be: +// insert into A +// insert into B +// insert into A +// ... +// +// And not +// 1000 inserts into A +// 1000 inserts into B +// +// Breaking that expectation sounds like a bad idea. +// +// The BatchExecutor can indeed reuse more than it does at a cost of making it more difficult to understand and control. +// +// Right now you need to understand how it works for sure, but its behaviour is simple and once you get it you can just +// get the same result by changing a bit your code +// +// for (1000 records) insert into table A +// for (1000 records) update into table B + public class ReuseBatchExecutor extends BaseExecutor { public static final int BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002; diff --git a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java index 13ebde1..2208b3b 100644 --- a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java +++ b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java @@ -26,12 +26,7 @@ public class TestMain { // exampleService.getAdsByCriteria(); // // -// final ExampleCustomService exampleCustomService = (ExampleCustomService) SpringContextLocator -// .getInstance().getBean("exampleCustomService"); -// -// exampleCustomService.getAds(); -// -// exampleCustomService.updateAds(); + // final ExampleBatchService exampleBatchService = (ExampleBatchService) SpringContextLocator @@ -42,23 +37,18 @@ public class TestMain { // exampleBatchService.insertBatchNewAd(); -// final BatchAndSimpleSameTrx batchAndSimpleSameTrx = (BatchAndSimpleSameTrx) SpringContextLocator -// .getInstance().getBean("batchAndSimpleSameTrx"); -// -// try { -// batchAndSimpleSameTrx.insertNewAd(); -// } catch (CannotGetJdbcConnectionException e) { -// logger.error("Error exception: ", e); -// } catch (SQLException e) { -// logger.error("Error exception: ", e); -// } + final BatchAndSimpleSameTrx batchAndSimpleSameTrx = (BatchAndSimpleSameTrx) SpringContextLocator + .getInstance().getBean("batchAndSimpleSameTrx"); + + try { + batchAndSimpleSameTrx.insertNewAd(); + } catch (CannotGetJdbcConnectionException e) { + logger.error("Error exception: ", e); + } catch (SQLException e) { + logger.error("Error exception: ", e); + } - final ExampleInheritanceService exampleBatchService = (ExampleInheritanceService) SpringContextLocator - .getInstance().getBean("exampleInheritanceService"); - - exampleBatchService.selectAdsParent(); - - exampleBatchService.selectAdsChild(); + } } diff --git a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/BatchAndSimpleSameTrx.java b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/BatchAndSimpleSameTrx.java index 7a15a89..3123ee0 100644 --- a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/BatchAndSimpleSameTrx.java +++ b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/BatchAndSimpleSameTrx.java @@ -38,10 +38,7 @@ public class BatchAndSimpleSameTrx { adTest.setCompanyId(2L); adTest.setUpdatedAt(new Date()); - /** - * No batched inserts will be sent to data base just in this very moment. - */ - this.adMapper.insert(adTest); + /** * We want to use SIMPLE and BATCH operations but MyBatis complains with this exception: @@ -75,6 +72,20 @@ public class BatchAndSimpleSameTrx { preparedStatement.addBatch(); } + + final Ad adTest = new Ad(); + adTest.setAdMobileImage("bild.jpg"); + adTest.setCompanyCategId(200L); + adTest.setCreatedAt(new Date()); + adTest.setCompanyId(2L); + adTest.setUpdatedAt(new Date()); + + /** + * No batched inserts will be sent to data base just in this very moment. + */ + this.adMapper.insert(adTest); + + /** * RIGHT HERE THE BATCH STATEMENTS WILL BE SENT TO THE DATA BASE. */ diff --git a/MyBatis/MyBatis-Spring/src/main/resources/config/mybatis-config.xml b/MyBatis/MyBatis-Spring/src/main/resources/config/mybatis-config.xml index 5ee3309..8959895 100644 --- a/MyBatis/MyBatis-Spring/src/main/resources/config/mybatis-config.xml +++ b/MyBatis/MyBatis-Spring/src/main/resources/config/mybatis-config.xml @@ -23,7 +23,13 @@ to the same objects which are stored in the local cache. Any modification of returned object (lists etc.) influences the local cache contents and subsequently the values which are returned from the cache in the lifetime of the session. - Therefore, as best practice, do not to modify the objects returned by MyBatis. --> + Therefore, as best practice, do not to modify the objects returned by MyBatis. + + SI SE MODIFICAN, CUANDO HAGA UNA BÚSQUEDA EN LA CACHE POR ESE OBJETO, YA NO LO ENCONTRARÉ, + SERÁ COMO SI NUNCA HUBIERA SIDO CACHEADO, Y ENTONCES LA CACHE NO SIRVE PARA NADA. + + VER CachingExecutor. + --> diff --git a/RemoteAgents/remote-agents-batchapp/pom.xml b/RemoteAgents/remote-agents-batchapp/pom.xml index 64df0fe..25d44ce 100644 --- a/RemoteAgents/remote-agents-batchapp/pom.xml +++ b/RemoteAgents/remote-agents-batchapp/pom.xml @@ -44,6 +44,15 @@ + org.apache.maven.plugins + maven-war-plugin + + ${basedir}/src/main/webapp + ${warTarget} + ${project.artifactId} + + + org.eclipse.jetty jetty-maven-plugin ${jetty.version} -- 2.1.4