Skip to content

Commit 17ff572

Browse files
spring-boot-starter for jdbc-perf-logger
1 parent 608163a commit 17ff572

File tree

19 files changed

+1350
-0
lines changed

19 files changed

+1350
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Although other tools already exist around JDBC performance monitoring ([log4jdbc
2525
- Displays the `queryTimeout` of each statement (no value means 0 or no timeout) (since 0.5.0)
2626
- Displays the `autoCommit` status of each statement (since 0.6.0)
2727
- Supports new java 8 methods like `executeLargeUpdate` (since 0.6.2)
28+
- Auto configuration for [Spring Boot](http://projects.spring.io/spring-boot/) (since 0.7.2)
2829

2930
## Requirements
3031
- java 6 or later for the driver
@@ -44,6 +45,7 @@ Although other tools already exist around JDBC performance monitoring ([log4jdbc
4445
```
4546

4647
## How to setup the JDBC Driver
48+
- If using Spring-Boot see [README.md](jdbc-perf-logger-spring-boot-starter/README.md)
4749
- If using maven, add the `<dependency>` snippet above (replacing the version with the latest one) to your `pom.xml`
4850
- If NOT using maven, add one (and only one) of the following set of files to the classpath of the JDBC-client application (the files can be found in the `lib` directory of the binary distribution)
4951
- `jdbc-perf-logger-driver` and `slf4j-api` jar files
@@ -68,6 +70,24 @@ Although other tools already exist around JDBC performance monitoring ([log4jdbc
6870
- No DataSource nor XADataSource class provided
6971
- Only the first ResultSet of queries is logged (`Statement.getMoreResults()` works but no effort has been put to log the fetching of those ResultSets)
7072

73+
## Potential ClassLoader issues
74+
Here are the rules to observe :
75+
- The jdbc-perf-logger must be able to use your bare JDBC driver
76+
- The DataSource you use must be able to use the jdbc-perf-logger driver classes
77+
78+
Here are the most common cases with Tomcat :
79+
- Tomcat _shared.loader_ includes
80+
- the DataSource implementation (which is by default for tomcat 7 DataSource)
81+
- the bare JDBC driver
82+
- the jdbc-perf-logger driver
83+
This is the case if you place your JDBC driver and jdbc-perf-logger driver in the `lib` directory of `CATALINA_BASE` or `CATALINA_HOME`.
84+
This can also be done by configuring the `catalina.properties` file.
85+
- your WAR file embeds the jars for
86+
- the DataSource implementation
87+
- the bare JDBC driver
88+
- the jdbc-perf-logger driver
89+
- the JVM classpath includes the bare JDBC driver and the jdbc-perf-logger driver and the Tomcat _shared.loader_ includes the DataSource implementation.
90+
7191
## Source code
7292
The source code is available on GitHub : https://github.com/sylvainlaurent/JDBC-Performance-Logger
7393

jdbc-perf-logger-spring-boot-starter-test/.settings/org.eclipse.jdt.core.prefs

Lines changed: 379 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
cleanup.add_default_serial_version_id=true
2+
cleanup.add_generated_serial_version_id=false
3+
cleanup.add_missing_annotations=true
4+
cleanup.add_missing_deprecated_annotations=true
5+
cleanup.add_missing_methods=false
6+
cleanup.add_missing_nls_tags=false
7+
cleanup.add_missing_override_annotations=true
8+
cleanup.add_missing_override_annotations_interface_methods=true
9+
cleanup.add_serial_version_id=true
10+
cleanup.always_use_blocks=true
11+
cleanup.always_use_parentheses_in_expressions=false
12+
cleanup.always_use_this_for_non_static_field_access=false
13+
cleanup.always_use_this_for_non_static_method_access=false
14+
cleanup.convert_to_enhanced_for_loop=false
15+
cleanup.correct_indentation=true
16+
cleanup.format_source_code=true
17+
cleanup.format_source_code_changes_only=false
18+
cleanup.make_local_variable_final=true
19+
cleanup.make_parameters_final=false
20+
cleanup.make_private_fields_final=true
21+
cleanup.make_type_abstract_if_missing_method=false
22+
cleanup.make_variable_declarations_final=true
23+
cleanup.never_use_blocks=false
24+
cleanup.never_use_parentheses_in_expressions=true
25+
cleanup.organize_imports=true
26+
cleanup.qualify_static_field_accesses_with_declaring_class=false
27+
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
28+
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
29+
cleanup.qualify_static_member_accesses_with_declaring_class=true
30+
cleanup.qualify_static_method_accesses_with_declaring_class=false
31+
cleanup.remove_private_constructors=true
32+
cleanup.remove_trailing_whitespaces=true
33+
cleanup.remove_trailing_whitespaces_all=true
34+
cleanup.remove_trailing_whitespaces_ignore_empty=false
35+
cleanup.remove_unnecessary_casts=true
36+
cleanup.remove_unnecessary_nls_tags=true
37+
cleanup.remove_unused_imports=true
38+
cleanup.remove_unused_local_variables=false
39+
cleanup.remove_unused_private_fields=true
40+
cleanup.remove_unused_private_members=false
41+
cleanup.remove_unused_private_methods=true
42+
cleanup.remove_unused_private_types=true
43+
cleanup.sort_members=false
44+
cleanup.sort_members_all=false
45+
cleanup.use_blocks=true
46+
cleanup.use_blocks_only_for_return_and_throw=false
47+
cleanup.use_parentheses_in_expressions=false
48+
cleanup.use_this_for_non_static_field_access=false
49+
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
50+
cleanup.use_this_for_non_static_method_access=false
51+
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
52+
cleanup_profile=_PerfLogger code style
53+
cleanup_settings_version=2
54+
eclipse.preferences.version=1
55+
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
56+
formatter_profile=_PerfLogger code style
57+
formatter_settings_version=12
58+
org.eclipse.jdt.ui.javadoc=false
59+
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/* \n * Copyright 2013 Sylvain LAURENT\n * \n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http\://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
60+
sp_cleanup.add_default_serial_version_id=true
61+
sp_cleanup.add_generated_serial_version_id=false
62+
sp_cleanup.add_missing_annotations=true
63+
sp_cleanup.add_missing_deprecated_annotations=true
64+
sp_cleanup.add_missing_methods=false
65+
sp_cleanup.add_missing_nls_tags=false
66+
sp_cleanup.add_missing_override_annotations=true
67+
sp_cleanup.add_missing_override_annotations_interface_methods=true
68+
sp_cleanup.add_serial_version_id=false
69+
sp_cleanup.always_use_blocks=true
70+
sp_cleanup.always_use_parentheses_in_expressions=false
71+
sp_cleanup.always_use_this_for_non_static_field_access=false
72+
sp_cleanup.always_use_this_for_non_static_method_access=false
73+
sp_cleanup.convert_to_enhanced_for_loop=false
74+
sp_cleanup.correct_indentation=true
75+
sp_cleanup.format_source_code=true
76+
sp_cleanup.format_source_code_changes_only=false
77+
sp_cleanup.make_local_variable_final=true
78+
sp_cleanup.make_parameters_final=true
79+
sp_cleanup.make_private_fields_final=true
80+
sp_cleanup.make_type_abstract_if_missing_method=false
81+
sp_cleanup.make_variable_declarations_final=true
82+
sp_cleanup.never_use_blocks=false
83+
sp_cleanup.never_use_parentheses_in_expressions=true
84+
sp_cleanup.on_save_use_additional_actions=true
85+
sp_cleanup.organize_imports=true
86+
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
87+
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
88+
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
89+
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
90+
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
91+
sp_cleanup.remove_private_constructors=true
92+
sp_cleanup.remove_trailing_whitespaces=true
93+
sp_cleanup.remove_trailing_whitespaces_all=true
94+
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
95+
sp_cleanup.remove_unnecessary_casts=true
96+
sp_cleanup.remove_unnecessary_nls_tags=false
97+
sp_cleanup.remove_unused_imports=true
98+
sp_cleanup.remove_unused_local_variables=false
99+
sp_cleanup.remove_unused_private_fields=true
100+
sp_cleanup.remove_unused_private_members=false
101+
sp_cleanup.remove_unused_private_methods=true
102+
sp_cleanup.remove_unused_private_types=true
103+
sp_cleanup.sort_members=false
104+
sp_cleanup.sort_members_all=false
105+
sp_cleanup.use_blocks=true
106+
sp_cleanup.use_blocks_only_for_return_and_throw=false
107+
sp_cleanup.use_parentheses_in_expressions=false
108+
sp_cleanup.use_this_for_non_static_field_access=true
109+
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
110+
sp_cleanup.use_this_for_non_static_method_access=false
111+
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.github.sylvainlaurent.jdbcperflogger</groupId>
6+
<artifactId>jdbc-perf-logger</artifactId>
7+
<version>0.7.2-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>jdbc-perf-logger-spring-boot-starter-test</artifactId>
10+
11+
12+
<dependencyManagement>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-dependencies</artifactId>
17+
<version>${spring-boot.version}</version>
18+
<type>pom</type>
19+
<scope>import</scope>
20+
</dependency>
21+
</dependencies>
22+
</dependencyManagement>
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.github.sylvainlaurent.jdbcperflogger</groupId>
26+
<artifactId>jdbc-perf-logger-spring-boot-starter</artifactId>
27+
<version>${project.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-data-jpa</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.h2database</groupId>
40+
<artifactId>h2</artifactId>
41+
<!-- <scope>test</scope> -->
42+
</dependency>
43+
<dependency>
44+
<groupId>org.flywaydb</groupId>
45+
<artifactId>flyway-core</artifactId>
46+
</dependency>
47+
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-release-plugin</artifactId>
55+
<configuration>
56+
<skip>true</skip>
57+
</configuration>
58+
</plugin>
59+
<plugin>
60+
<groupId>org.sonatype.plugins</groupId>
61+
<artifactId>nexus-staging-maven-plugin</artifactId>
62+
<configuration>
63+
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ch.sla.jdbcperflogger.spring.test;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.CommandLineRunner;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
@Configuration
11+
@ComponentScan
12+
@EnableAutoConfiguration
13+
public class MyApplication implements CommandLineRunner {
14+
@Autowired
15+
private PersonRepository repository;
16+
17+
@Override
18+
public void run(String... args) throws Exception {
19+
System.err.println(this.repository.findAll());
20+
}
21+
22+
public static void main(String[] args) throws Exception {
23+
SpringApplication.run(MyApplication.class, args);
24+
}
25+
26+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ch.sla.jdbcperflogger.spring.test;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.Id;
6+
7+
@Entity
8+
class Person {
9+
@Id
10+
@GeneratedValue
11+
private Long id;
12+
private String firstName;
13+
private String lastName;
14+
15+
public String getFirstName() {
16+
return this.firstName;
17+
}
18+
19+
public void setFirstName(String firstName) {
20+
this.firstName = firstName;
21+
}
22+
23+
public String getLastName() {
24+
return this.lastName;
25+
}
26+
27+
public void setLastName(String lastname) {
28+
this.lastName = lastname;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName + "]";
34+
}
35+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ch.sla.jdbcperflogger.spring.test;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
import org.springframework.stereotype.Repository;
5+
6+
@Repository
7+
interface PersonRepository extends CrudRepository<Person, Long> {
8+
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.jpa.hibernate.ddl-auto: validate
2+
jdbcperflogger.enable=true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE PERSON (
2+
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
3+
first_name varchar(255) not null,
4+
last_name varchar(255) not null
5+
);
6+
7+
insert into PERSON (first_name, last_name) values ('Dave', 'Syer');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ch.sla.jdbcperflogger.spring.test;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.SpringApplicationConfiguration;
9+
import org.springframework.jdbc.core.JdbcTemplate;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
12+
@RunWith(SpringJUnit4ClassRunner.class)
13+
@SpringApplicationConfiguration(classes = MyApplication.class)
14+
public class MyApplicationTest {
15+
@Autowired
16+
private JdbcTemplate template;
17+
18+
@Test
19+
public void testDefaultSettings() throws Exception {
20+
assertEquals(new Integer(1), this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class));
21+
}
22+
}

0 commit comments

Comments
 (0)