Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit 1b08ad9

Browse files
committed
Created pom.xml files to allow projects to be built using Maven.
1 parent 9a2ba39 commit 1b08ad9

File tree

42 files changed

+928
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+928
-303
lines changed

jdbc/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ task codegen << {
1313
ant.codegen(jdbcDriverClass: 'org.hsqldb.jdbc.JDBCDriver',
1414
dbUrl: 'jdbc:hsqldb:hsql://localhost:9001/test',
1515
dbUserName: 'sa', schemaPattern: 'PUBLIC',
16-
targetSourceFolder: 'src/generated/java',
17-
targetPackage: 'com.oreilly.springdata.jdbc.domain')
16+
targetSourceFolder: 'src/main/java',
17+
targetPackage: 'com.oreilly.springdata.jdbc.domain.generated')
1818
}
1919

2020
dependencies {

jdbc/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
5+
<artifactId>spring-data-book-jdbc</artifactId>
6+
7+
<name>Spring Data Book - JDBC</name>
8+
9+
<parent>
10+
<groupId>com.oreilly.springdata</groupId>
11+
<artifactId>spring-data-book</artifactId>
12+
<version>1.0.0.BUILD-SNAPSHOT</version>
13+
<relativePath>../pom.xml</relativePath>
14+
</parent>
15+
16+
<properties>
17+
<querydsl.version>2.7.0</querydsl.version>
18+
</properties>
19+
20+
<dependencies>
21+
22+
<dependency>
23+
<groupId>org.springframework.data</groupId>
24+
<artifactId>spring-data-jdbc-core</artifactId>
25+
<version>1.0.0.RC3</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>com.mysema.querydsl</groupId>
30+
<artifactId>querydsl-sql</artifactId>
31+
<version>${querydsl.version}</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.hsqldb</groupId>
36+
<artifactId>hsqldb</artifactId>
37+
<version>2.2.8</version>
38+
<scope>runtime</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework</groupId>
43+
<artifactId>spring-jdbc</artifactId>
44+
<version>${spring.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.springframework</groupId>
49+
<artifactId>spring-tx</artifactId>
50+
<version>${spring.version}</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>commons-dbcp</groupId>
55+
<artifactId>commons-dbcp</artifactId>
56+
<version>1.4</version>
57+
</dependency>
58+
59+
</dependencies>
60+
61+
<build>
62+
63+
<plugins>
64+
65+
<plugin>
66+
<groupId>com.mysema.querydsl</groupId>
67+
<artifactId>querydsl-maven-plugin</artifactId>
68+
<version>${querydsl.version}</version>
69+
<configuration>
70+
<jdbcDriver>org.hsqldb.jdbc.JDBCDriver</jdbcDriver>
71+
<jdbcUrl>jdbc:hsqldb:hsql://localhost:9001/test</jdbcUrl>
72+
<jdbcUser>sa</jdbcUser>
73+
<schemaPattern>PUBLIC</schemaPattern>
74+
<packageName>com.oreilly.springdata.jdbc.domain.generated</packageName>
75+
<targetFolder>${project.basedir}/src/main/java</targetFolder>
76+
</configuration>
77+
<dependencies>
78+
<dependency>
79+
<groupId>org.hsqldb</groupId>
80+
<artifactId>hsqldb</artifactId>
81+
<version>2.2.8</version>
82+
</dependency>
83+
</dependencies>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
88+
</project>

jdbc/src/main/java/com/oreilly/springdata/jdbc/ApplicationConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.oreilly.springdata.jdbc;
22

3-
import com.oreilly.springdata.jdbc.repository.CustomerRepository;
3+
import javax.sql.DataSource;
4+
45
import org.apache.commons.dbcp.BasicDataSource;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.context.annotation.Bean;
@@ -12,17 +13,17 @@
1213
import org.springframework.transaction.PlatformTransactionManager;
1314
import org.springframework.transaction.annotation.EnableTransactionManagement;
1415

15-
import javax.sql.DataSource;
16+
import com.oreilly.springdata.jdbc.repository.CustomerRepository;
1617

1718
/**
18-
*
1919
* @author Thomas Risberg
2020
*/
2121
@Configuration
2222
@EnableTransactionManagement
2323
@ComponentScan(basePackageClasses = CustomerRepository.class)
2424
@PropertySource("classpath:jdbc.properties")
2525
public class ApplicationConfig {
26+
2627
@Autowired
2728
Environment env;
2829

jdbc/src/generated/java/com/oreilly/springdata/jdbc/domain/QAddress.java renamed to jdbc/src/main/java/com/oreilly/springdata/jdbc/domain/generated/QAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oreilly.springdata.jdbc.domain;
1+
package com.oreilly.springdata.jdbc.domain.generated;
22

33
import static com.mysema.query.types.PathMetadataFactory.*;
44

jdbc/src/generated/java/com/oreilly/springdata/jdbc/domain/QCustomer.java renamed to jdbc/src/main/java/com/oreilly/springdata/jdbc/domain/generated/QCustomer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oreilly.springdata.jdbc.domain;
1+
package com.oreilly.springdata.jdbc.domain.generated;
22

33
import static com.mysema.query.types.PathMetadataFactory.*;
44

jdbc/src/main/java/com/oreilly/springdata/jdbc/package-info.java

Whitespace-only changes.

jdbc/src/main/java/com/oreilly/springdata/jdbc/repository/QueryDslCustomerRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import com.oreilly.springdata.jdbc.domain.Address;
1010
import com.oreilly.springdata.jdbc.domain.Customer;
1111
import com.oreilly.springdata.jdbc.domain.EmailAddress;
12-
import com.oreilly.springdata.jdbc.domain.QAddress;
13-
import com.oreilly.springdata.jdbc.domain.QCustomer;
12+
import com.oreilly.springdata.jdbc.domain.generated.QAddress;
13+
import com.oreilly.springdata.jdbc.domain.generated.QCustomer;
14+
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.dao.DataAccessException;
1617
import org.springframework.data.jdbc.core.OneToManyResultSetExtractor;
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
11
package com.oreilly.springdata.jdbc;
22

3-
import com.oreilly.springdata.jdbc.repository.CustomerRepository;
3+
import javax.sql.DataSource;
4+
45
import org.springframework.context.annotation.Bean;
5-
import org.springframework.context.annotation.ComponentScan;
66
import org.springframework.context.annotation.Configuration;
7-
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
87
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
98
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
10-
import org.springframework.transaction.PlatformTransactionManager;
119
import org.springframework.transaction.annotation.EnableTransactionManagement;
1210

13-
import javax.sql.DataSource;
14-
1511
/**
16-
*
12+
* Additional configuration for integration tests. Overriding the bean definition for the {@link DataSource}.
13+
*
1714
* @author Thomas Risberg
15+
* @author Oliver Gierke
1816
*/
1917
@Configuration
2018
@EnableTransactionManagement
21-
@ComponentScan(basePackageClasses = CustomerRepository.class)
22-
public class TestConfig {
19+
public class TestConfig extends ApplicationConfig {
2320

21+
/*
22+
* (non-Javadoc)
23+
* @see com.oreilly.springdata.jdbc.ApplicationConfig#dataSource()
24+
*/
2425
@Bean
26+
@Override
2527
public DataSource dataSource() {
26-
return new EmbeddedDatabaseBuilder()
27-
.setType(EmbeddedDatabaseType.HSQL)
28-
.addScript("classpath:sql/schema.sql")
29-
.addScript("classpath:sql/test-data.sql")
30-
.build();
31-
}
32-
33-
@Bean
34-
public PlatformTransactionManager transactionManager() {
35-
DataSourceTransactionManager txManager = new DataSourceTransactionManager();
36-
txManager.setDataSource(dataSource());
37-
return txManager;
28+
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).addScript("classpath:sql/schema.sql")
29+
.addScript("classpath:sql/test-data.sql").build();
3830
}
3931
}

jdbc/src/test/java/com/oreilly/springdata/jdbc/package-info.java

Whitespace-only changes.

jdbc/src/test/java/com/oreilly/springdata/jdbc/repository/QueryDslCustomerRepositoryTests.java renamed to jdbc/src/test/java/com/oreilly/springdata/jdbc/repository/QueryDslCustomerRepositoryTest.java

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package com.oreilly.springdata.jdbc.repository;
22

3-
import com.mysema.query.Tuple;
4-
import com.mysema.query.sql.HSQLDBTemplates;
5-
import com.mysema.query.sql.SQLQuery;
6-
import com.mysema.query.sql.SQLQueryImpl;
7-
import com.mysema.query.sql.SQLTemplates;
8-
import com.mysema.query.types.MappingProjection;
9-
import com.mysema.query.types.QBean;
10-
import com.oreilly.springdata.jdbc.TestConfig;
11-
import com.oreilly.springdata.jdbc.domain.Address;
12-
import com.oreilly.springdata.jdbc.domain.Customer;
13-
import com.oreilly.springdata.jdbc.domain.EmailAddress;
14-
import com.oreilly.springdata.jdbc.domain.QAddress;
15-
import com.oreilly.springdata.jdbc.domain.QCustomer;
3+
import static org.hamcrest.Matchers.*;
4+
import static org.junit.Assert.*;
5+
6+
import java.sql.Connection;
7+
import java.sql.ResultSet;
8+
import java.sql.SQLException;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
import javax.sql.DataSource;
13+
1614
import org.junit.Test;
1715
import org.junit.runner.RunWith;
1816
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,28 +23,28 @@
2523
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2624
import org.springframework.transaction.annotation.Transactional;
2725

28-
import javax.sql.DataSource;
29-
import java.sql.Connection;
30-
import java.sql.ResultSet;
31-
import java.sql.SQLException;
32-
import java.util.ArrayList;
33-
import java.util.List;
34-
35-
import static org.hamcrest.Matchers.hasSize;
36-
import static org.hamcrest.Matchers.is;
37-
import static org.hamcrest.Matchers.notNullValue;
38-
import static org.hamcrest.Matchers.nullValue;
39-
import static org.junit.Assert.assertThat;
26+
import com.mysema.query.Tuple;
27+
import com.mysema.query.sql.HSQLDBTemplates;
28+
import com.mysema.query.sql.SQLQuery;
29+
import com.mysema.query.sql.SQLQueryImpl;
30+
import com.mysema.query.sql.SQLTemplates;
31+
import com.mysema.query.types.MappingProjection;
32+
import com.mysema.query.types.QBean;
33+
import com.oreilly.springdata.jdbc.TestConfig;
34+
import com.oreilly.springdata.jdbc.domain.Address;
35+
import com.oreilly.springdata.jdbc.domain.Customer;
36+
import com.oreilly.springdata.jdbc.domain.EmailAddress;
37+
import com.oreilly.springdata.jdbc.domain.generated.QAddress;
38+
import com.oreilly.springdata.jdbc.domain.generated.QCustomer;
4039

4140
/**
42-
*
4341
* @author Thomas Risberg
4442
*/
4543
@RunWith(SpringJUnit4ClassRunner.class)
46-
@ContextConfiguration(classes={TestConfig.class})
44+
@ContextConfiguration(classes = { TestConfig.class })
4745
@Transactional
4846
@DirtiesContext
49-
public class QueryDslCustomerRepositoryTests {
47+
public class QueryDslCustomerRepositoryTest {
5048

5149
@Autowired
5250
CustomerRepository repository;
@@ -109,7 +107,7 @@ public void saveNewCustomerWithoutEmail() {
109107
assertThat(result.getEmailAddress(), is(nullValue()));
110108
}
111109

112-
@Test(expected=DuplicateKeyException.class)
110+
@Test(expected = DuplicateKeyException.class)
113111
public void saveNewCustomerWithDuplicateEmail() {
114112
Customer c = new Customer();
115113
c.setFirstName("Bob");
@@ -134,12 +132,9 @@ public void directQueryDslUseExtractingList() {
134132
Connection connection = DataSourceUtils.getConnection(dataSource);
135133
QAddress qAddress = QAddress.address;
136134
SQLTemplates dialect = new HSQLDBTemplates();
137-
SQLQuery query = new SQLQueryImpl(connection, dialect)
138-
.from(qAddress)
139-
.where(qAddress.city.eq("London"));
140-
List<Address> results = query.list(
141-
new QBean<Address>(Address.class, qAddress.street,
142-
qAddress.city, qAddress.country));
135+
SQLQuery query = new SQLQueryImpl(connection, dialect).from(qAddress).where(qAddress.city.eq("London"));
136+
List<Address> results = query.list(new QBean<Address>(Address.class, qAddress.street, qAddress.city,
137+
qAddress.country));
143138
DataSourceUtils.releaseConnection(connection, dataSource);
144139
assertThat(results, is(notNullValue()));
145140
assertThat(results, hasSize(1));
@@ -154,15 +149,12 @@ public void directQueryDslUseExtractingResultSet() throws SQLException {
154149
final QAddress qAddress = QAddress.address;
155150
SQLTemplates dialect = new HSQLDBTemplates();
156151
SQLQuery query = new SQLQueryImpl(connection, dialect);
157-
ResultSet rs = query.from(qAddress)
158-
.where(qAddress.city.eq("London"))
159-
.getResults(qAddress.street, qAddress.city, qAddress.country);
152+
ResultSet rs = query.from(qAddress).where(qAddress.city.eq("London"))
153+
.getResults(qAddress.street, qAddress.city, qAddress.country);
160154
List<Address> results = new ArrayList<Address>();
161155
while (rs.next()) {
162-
results.add(new Address(
163-
rs.getString(qAddress.street.toString()),
164-
rs.getString(qAddress.city.toString()),
165-
rs.getString(qAddress.country.toString())));
156+
results.add(new Address(rs.getString(qAddress.street.toString()), rs.getString(qAddress.city.toString()), rs
157+
.getString(qAddress.country.toString())));
166158
}
167159
DataSourceUtils.releaseConnection(connection, dataSource);
168160
assertThat(results, is(notNullValue()));
@@ -175,12 +167,8 @@ public void directQueryDslUseExtractingResultSet() throws SQLException {
175167
public void templateWithMappingExample() {
176168
QueryDslJdbcTemplate qdslTemplate = new QueryDslJdbcTemplate(dataSource);
177169
final QAddress qAddress = QAddress.address;
178-
SQLQuery addressQuery = qdslTemplate.newSqlQuery()
179-
.from(qAddress)
180-
.where(qAddress.city.eq("London"));
181-
List<Address> results = qdslTemplate.query(
182-
addressQuery,
183-
BeanPropertyRowMapper.newInstance(Address.class),
170+
SQLQuery addressQuery = qdslTemplate.newSqlQuery().from(qAddress).where(qAddress.city.eq("London"));
171+
List<Address> results = qdslTemplate.query(addressQuery, BeanPropertyRowMapper.newInstance(Address.class),
184172
qAddress.street, qAddress.city, qAddress.country);
185173
assertThat(results, is(notNullValue()));
186174
assertThat(results, hasSize(1));
@@ -193,10 +181,7 @@ public void templateWithMappingProjectionExample() {
193181
final QCustomer customer = new QCustomer("c");
194182

195183
QueryDslJdbcTemplate template = new QueryDslJdbcTemplate(dataSource);
196-
List<Customer> results = template.query(
197-
template.newSqlQuery()
198-
.from(customer)
199-
.where(customer.id.eq(100L)),
184+
List<Customer> results = template.query(template.newSqlQuery().from(customer).where(customer.id.eq(100L)),
200185
new MappingProjection<Customer>(Customer.class, customer.all()) {
201186
@Override
202187
protected Customer map(Tuple row) {

jdbc/src/test/resources/logback.xml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<configuration>
23

3-
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
4-
<encoder>
5-
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
6-
</encoder>
7-
</appender>
4+
<!-- <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
5+
<resetJUL>true</resetJUL> </contextListener> -->
86

9-
<logger name="com.oreilly.springdata" level="debug"/>
10-
<logger name="org.springframework.data" level="debug"/>
11-
<logger name="org.springframework" level="info"/>
7+
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
8+
<encoder>
9+
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
10+
</encoder>
11+
</appender>
1212

13-
<root level="info">
14-
<appender-ref ref="stdout"/>
15-
</root>
13+
<logger name="org.springframework.data" level="debug" />
14+
<logger name="com.oreilly.springdata" level="debug" />
1615

17-
</configuration>
16+
<root level="info">
17+
<appender-ref ref="console" />
18+
</root>
19+
20+
</configuration>

0 commit comments

Comments
 (0)