例
mvn -P !profile
select flg, count(*) from test group by flg;
flg | count
-----+---------
0 | 1000000
1 | 1
(2 rows)
#EXPLAIN select * from test where flg = '1';
QUERY PLAN
----------------------------------------------------------------------
Index Scan using test_idx on test (cost=0.42..4.44 rows=1 width=17)
Index Cond: (flg = '1'::bpchar)
(2 rows)
# EXPLAIN select * from test where flg = '0';
QUERY PLAN
---------------------------------------------------------------
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17)
Filter: (flg = '0'::bpchar)
(2 rows)
try (Connection connection = dataSource.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("load 'auto_explain'");
statement.execute("set auto_explain.log_min_duration = 0");
statement.execute("set auto_explain.log_analyze = true");
}
try (PreparedStatement statement = connection.prepareStatement("select * from test where flg = ?")) {
for (int i = 0; i < 10; i++) {
statement.setString(1, "0");
statement.executeQuery();
}
}
try (PreparedStatement statement = connection.prepareStatement("select * from test where flg = ?")) {
statement.setString(1, "1");
statement.executeQuery();
}
}
LOG: duration: 880.555 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.011..250.647 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 965.254 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.013..263.084 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 713.326 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.015..216.970 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 603.937 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.010..189.935 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 565.579 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.008..175.277 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 582.891 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.007..183.025 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 604.002 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.010..187.921 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 590.842 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.007..185.131 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 589.730 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.007..183.538 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 610.742 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.009..192.248 rows=1000000 loops=1)
Filter: (flg = ($1)::bpchar)
Rows Removed by Filter: 1
LOG: duration: 114.769 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=114.755..114.756 rows=1 loops=1)
Filter: (flg = ($1)::bpchar)
Rows Removed by Filter: 1000000
G: duration: 813.314 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.011..248.204 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 769.790 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.013..236.008 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 663.801 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.013..198.553 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 562.532 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.009..177.537 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 599.577 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.009..188.422 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 611.355 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.008..192.423 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 626.638 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.010..197.469 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 639.909 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.012..200.366 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 590.332 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.007..187.930 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 587.067 ms plan:
Query Text: select * from test where flg = $1
Seq Scan on test (cost=0.00..18860.01 rows=1000001 width=17) (actual time=0.012..185.482 rows=1000000 loops=1)
Filter: (flg = '0'::bpchar)
Rows Removed by Filter: 1
LOG: duration: 0.018 ms plan:
Query Text: select * from test where flg = $1
Index Scan using test_idx on test (cost=0.42..4.44 rows=1 width=17) (actual time=0.014..0.014 rows=1 loops=1)
Index Cond: (flg = '1'::bpchar)
<script src="//cdnjs.cloudflare.com/ajax/libs/semantic-ui-calendar/0.0.8/calendar.min.js"
type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui-calendar/0.0.8/calendar.min.css"/>
<div class="field ui calendar required">
<label>日付</label>
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" name="date" placeholder="日付">
</div>
</div>
$('.ui.calendar').calendar({
type: 'date'
})
$('.ui.calendar').calendar({
type: 'date',
formatter: {
date: function (date) {
var day = ('0' + date.getDate()).slice(-2);
var month = ('0' + (date.getMonth() + 1)).slice(-2);
var year = date.getFullYear();
return year + '/' + month + '/' + day;
}
}
})
plugins {
id "com.github.opengl-BOBO.assertjGen" version "1.1.8"
}
// assertj-gen
ext {
assertjGenPreConfig = [
'assertjGenerator': 'org.assertj:assertj-assertions-generator:2.1.0',
'sourceSets': ['main]
]
}
sourceSets.test.java.srcDirs += 'src-gen/test/java'
assertjGen {
// test.Hogeがアサーションを生成するクラス。
// パッケージ指定もできる
classOrPackageNames = ['test.Hoge']
outputDir = 'src-gen/test/java'
}
package test;
public class Hoge {
public final int hoge;
public Hoge(final int hoge) {
this.hoge = hoge;
}
public String getFuga() {
return "fuga";
}
}
$ ./gradlew assertjGen
> Task :assertjGen
07:22:13.289 INFO o.a.a.g.c.AssertionGeneratorLauncher - Generating assertions for classes [class test.Hoge]
07:22:13.310 INFO o.a.a.g.c.AssertionGeneratorLauncher - Generating assertions for class : test.Hoge
07:22:13.326 INFO o.a.a.g.c.AssertionGeneratorLauncher - Generated Hoge assertions file -> /home/hoge/IdeaProjects/test-pj/src-gen/test/java/./test/HogeAssert.java
@Test
void test() {
final Hoge hoge = new Hoge(100);
HogeAssert.assertThat(hoge)
.hasHoge(10);
}
Expecting hoge of:
<test.Hoge@3c72f59f>
to be:
<10>
but was:
<100>
alter system flush buffer_cache;
SQL> select * from person where id = 1;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1167617095
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 17 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| PERSON | 1 | 17 | 3 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0013811 | 1 | | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
469 bytes sent via SQL*Net to client
540 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> alter system flush buffer_cache;
System altered.
SQL> select * from person where id=1;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1167617095
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 17 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| PERSON | 1 | 17 | 3 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0013811 | 1 | | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
24 physical reads
0 redo size
469 bytes sent via SQL*Net to client
540 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
otn_user=hoge
otn_password=fuga
maven {
url "https://www.oracle.com/content/secure/maven/content"
credentials {
username otn_user
password otn_password
}
}
compile 'com.oracle.jdbc:ojdbc8:12.2.0.1'
\--- com.oracle.jdbc:ojdbc8:12.2.0.1
\--- com.oracle.jdbc:ucp:12.2.0.1
\--- com.oracle.jdbc:ojdbc8:12.2.0.1 (*)
sqlplus hoge@pdb1/hoge@orcl
compile 'org.thymeleaf.extras:thymeleaf-extras-java8time:2.1.0.RELEASE'
<span th:text="${#temporals.format(nowDateTime, 'yyyy/MM/dd HH:mm:ss')}"></span>
<div th:attr="data-sample=${sample.name}"></div>
<div th:attr="data-sample=${sample.name},data-sample2=${sample.name2}"></div>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>/opt/java/jdk1.6.0_45/bin/java</jvm>
</configuration>
</plugin>
public class HogeTest {
@Test
public void name() throws Exception {
System.out.println("System.getProperty(\"java.version\") = " + System.getProperty("java.version"));
}
}
$ export JAVA_HOME=/opt/java/jdk1.8.0_141
$ mvn test
********** 省略 **********
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HogeTest
System.getProperty("java.version") = 1.6.0_45
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.955 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
dependencies {
testCompile 'org.jmockit:jmockit:1.33'
testCompile 'junit:junit:4.12'
}
Caused by: java.lang.IllegalStateException: Running on JDK 9 requires
-javaagent:/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf
test {
jvmArgs "-Djdk.attach.allowAttachSelf"
}
➜ java9 ./gradlew clean test
BUILD SUCCESSFUL in 2s
3 actionable tasks: 3 executed
➜ java9 ./gradlew clean test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<!-- specify the dependent jdbc driver here -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.3</version>
</dependency>
</dependencies>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/test_db</url>
<username>test</username>
<password>test</password>
<srcFiles>
<srcFile>src/test/resources/test.sql</srcFile>
</srcFiles>
</configuration>
</plugin>
</plugins>
</build>
$ mvn sql:execute
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sql-maven-plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (default-cli) @ sql-maven-plugin ---
[INFO] Executing file: /tmp/test.838893334sql
[INFO] 1 of 1 SQL statements executed successfully
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.428 s
[INFO] Finished at: 2017-07-29T06:59:17+09:00
[INFO] Final Memory: 9M/238M
[INFO] ------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="access" suffix=".log" pattern="%h %l %u %t "%r" %s %b" />
</Context>
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
final String docBase = new File("src/main/webapp").getAbsolutePath();
final StandardContext context = (StandardContext) tomcat.addWebapp("/", docBase);
final File additionWebInfClasses = new File("build/classes/main");
final StandardRoot resources = new StandardRoot(context);
resources.addPreResources(
new DirResourceSet(resources, "/WEB-INF/classes",
additionWebInfClasses.getAbsolutePath(), "/"));
context.setResources(resources);
tomcat.start();
tomcat.getServer().await();
➜ tomcat-embedded-example cat tomcat.8080/logs/access.2017-07-15.log
127.0.0.1 - - [15/Jul/2017:15:36:39 +0900] "GET / HTTP/1.1" 200 89
127.0.0.1 - - [15/Jul/2017:15:36:43 +0900] "GET /hoge HTTP/1.1" 404 1002
testCompile 'org.assertj:assertj-db:1.2.0'
ID,NAME 1,name 2,name_2
final OracleDataSource source = new OracleDataSource(); // 接続先情報は省略 final Table.Order order = Table.Order.asc("id"); final Table table = new Table(source, "test_table", new Table.Order[] {order}); assertThat(table) .column("id") .value().isEqualTo(1L) .value().isEqualTo(2L) .column("name") .value().isEqualTo("name") .value().isEqualTo("name_2");
final Request request = new Request(source, "select name from test_table where id = 2"); assertThat(request).column(0).value().isEqualTo("name_2");
final Table table = new Table(source, "test_table"); final Changes changes = new Changes(table); changes.setStartPointNow(); try (final Connection connection = source.getConnection(); final PreparedStatement statement = connection.prepareStatement( "update test_table set name = ? where id = 2")) { statement.setString(1, "へんこうご"); statement.execute(); } changes.setEndPointNow(); assertThat(changes) .hasNumberOfChanges(1) // 1レコード変更されている .ofModification().hasNumberOfChanges(1) // 変更内容は更新 .change() .columnAmongTheModifiedOnes() .hasColumnName("name") .hasValues("name_2", "へんこうご"); // name_2からへんこうごに変更されていること
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); final LocalDate localDate = LocalDate.parse("2017/04/13", formatter);
org.jmockit jmockit 1.30 test
new MockUp<ArrayList<String>>() { @Mock void $init(int initialCapacity) { System.out.println("initialCapacity = " + initialCapacity); } @Mock boolean add(String s) { System.out.println("s = " + s); return true; } }; final List<String> strings = new ArrayList<>(10); strings.add("hoge");
initialCapacity = 10 s = hoge