Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit 8d1d704

Browse files
author
Thomas Risberg
committed
DATAJDBC-51 Upgrading to Querydsl version 3.3.0
- Adding GeneratorApp to re-generate test classes for Querydsl
1 parent f8cb1dc commit 8d1d704

File tree

8 files changed

+137
-34
lines changed

8 files changed

+137
-34
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
slf4jVersion=1.6.6
22
junitVersion=4.10
33
springRetryVersion=1.0.0.RELEASE
4-
querydslVersion=2.8.2
4+
querydslVersion=3.3.0
55
aspectjVersion=1.6.11.RELEASE
66
springVersion=3.0.7.RELEASE
77
log4jVersion=1.2.16

spring-data-jdbc-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ dependencies {
44

55
// Querydsl
66
compile "com.mysema.querydsl:querydsl-sql:$querydslVersion", optional
7-
7+
testCompile "com.mysema.querydsl:querydsl-sql-codegen:$querydslVersion"
88
}

spring-data-jdbc-core/src/main/java/org/springframework/data/jdbc/query/QueryDslJdbcTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.mysema.query.sql.PostgresTemplates;
4747
import com.mysema.query.sql.RelationalPath;
4848
import com.mysema.query.sql.SQLQuery;
49-
import com.mysema.query.sql.SQLQueryImpl;
5049
import com.mysema.query.sql.SQLServerTemplates;
5150
import com.mysema.query.sql.SQLTemplates;
5251
import com.mysema.query.sql.dml.SQLDeleteClause;
@@ -120,7 +119,7 @@ public JdbcOperations getJdbcOperations() {
120119
}
121120

122121
public SQLQuery newSqlQuery() {
123-
return new SQLQueryImpl(this.dialect);
122+
return new SQLQuery(this.dialect);
124123
}
125124

126125
public long count(final SQLQuery sqlQuery) {
@@ -142,8 +141,9 @@ public long countDistinct(final SQLQuery sqlQuery) {
142141
public Long doInConnection(Connection con) throws SQLException,
143142
DataAccessException {
144143
SQLQuery liveQuery = sqlQuery.clone(con);
144+
liveQuery.distinct();
145145
try {
146-
return liveQuery.countDistinct();
146+
return liveQuery.count();
147147
} catch (QueryException qe) {
148148
throw translateQueryException(qe, "SQLQuery", liveQuery.toString());
149149
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2008-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.jdbc.query.generated;
18+
19+
import com.mysema.query.sql.codegen.MetaDataExporter;
20+
import org.springframework.context.ConfigurableApplicationContext;
21+
import org.springframework.context.support.ClassPathXmlApplicationContext;
22+
23+
import javax.sql.DataSource;
24+
import java.io.File;
25+
import java.sql.Connection;
26+
import java.sql.SQLException;
27+
28+
/**
29+
* App to generate the Querydsl query classes.
30+
*
31+
* Run this app as needed, usually when yhe Querydsl version
32+
* is upgraded to a new version. The generated classes are
33+
* written to build/generated-sources/java
34+
*
35+
* It's easiest to run this class from an IDE since the classpath
36+
* is already set.
37+
*
38+
* Copy new QCustomer.java and QCustomerNames.java classes to the
39+
* src/test/java directory
40+
*
41+
* Make a duplicate of QCustomer.java called QBadCustomer.java and
42+
* remove underscores from FIRST_NAME and LAST_NAME field name
43+
* metadata. Copy this class to src/text/java
44+
*
45+
* @author Thomas Risberg
46+
* @since 1.0.1
47+
*/
48+
public class GeneratorApp {
49+
public static void main(String[] args) {
50+
System.out.println("Generating Querydsl classes for the tests");
51+
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("query-dsl-context.xml");
52+
DataSource ds = ctx.getBean(DataSource.class);
53+
Connection conn = null;
54+
try {
55+
conn = ds.getConnection();
56+
MetaDataExporter exporter = new MetaDataExporter();
57+
exporter.setPackageName("org.springframework.data.jdbc.query.generated");
58+
exporter.setTargetFolder(new File("build/generated-sources/java"));
59+
exporter.export(conn.getMetaData());
60+
} catch (SQLException e) {
61+
e.printStackTrace();
62+
} finally {
63+
try {
64+
conn.close();
65+
} catch (SQLException ignore) {}
66+
}
67+
ctx.close();
68+
}
69+
}

spring-data-jdbc-core/src/test/java/org/springframework/data/jdbc/query/generated/QBadCustomer.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,52 @@
22

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

5-
import com.mysema.query.types.*;
65
import com.mysema.query.types.path.*;
76

7+
import com.mysema.query.types.PathMetadata;
88
import javax.annotation.Generated;
9+
import com.mysema.query.types.Path;
10+
11+
import com.mysema.query.sql.ColumnMetadata;
912

1013

1114
/**
12-
* QCustomer is a Querydsl query type for QCustomer
15+
* QBadCustomer is a Querydsl query type for QBadCustomer
1316
*/
1417
@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
1518
public class QBadCustomer extends com.mysema.query.sql.RelationalPathBase<QBadCustomer> {
1619

17-
private static final long serialVersionUID = -409565065;
20+
private static final long serialVersionUID = 676296244;
1821

1922
public static final QBadCustomer customer = new QBadCustomer("CUSTOMER");
2023

21-
public final StringPath firstName = createString("FIRSTNAME");
24+
public final StringPath firstName = createString("firstName");
2225

23-
public final NumberPath<Long> id = createNumber("ID", Long.class);
26+
public final NumberPath<Long> id = createNumber("id", Long.class);
2427

25-
public final StringPath lastName = createString("LASTNAME");
28+
public final StringPath lastName = createString("lastName");
2629

27-
public final com.mysema.query.sql.PrimaryKey<QBadCustomer> primary = createPrimaryKey(id);
30+
public final com.mysema.query.sql.PrimaryKey<QBadCustomer> sysPk10025 = createPrimaryKey(id);
2831

2932
public QBadCustomer(String variable) {
30-
super(QBadCustomer.class, forVariable(variable), "PUBLIC", "CUSTOMER");
33+
super(QBadCustomer.class, forVariable(variable), "PUBLIC", "CUSTOMER");
34+
addMetadata();
3135
}
3236

33-
public QBadCustomer(Path<? extends QBadCustomer> entity) {
34-
super(entity.getType(), entity.getMetadata(), "PUBLIC", "CUSTOMER");
37+
public QBadCustomer(Path<? extends QBadCustomer> path) {
38+
super(path.getType(), path.getMetadata(), "PUBLIC", "CUSTOMER");
39+
addMetadata();
3540
}
3641

3742
public QBadCustomer(PathMetadata<?> metadata) {
38-
super(QBadCustomer.class, metadata, "PUBLIC", "CUSTOMER");
43+
super(QBadCustomer.class, metadata, "PUBLIC", "CUSTOMER");
44+
addMetadata();
45+
}
46+
47+
public void addMetadata() {
48+
addMetadata(firstName, ColumnMetadata.named("FIRSTNAME").ofType(12).withSize(255));
49+
addMetadata(id, ColumnMetadata.named("ID").ofType(-5).withSize(0).notNull());
50+
addMetadata(lastName, ColumnMetadata.named("LASTNAME").ofType(12).withSize(255));
3951
}
4052

4153
}

spring-data-jdbc-core/src/test/java/org/springframework/data/jdbc/query/generated/QCustomer.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

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

5-
import com.mysema.query.types.*;
65
import com.mysema.query.types.path.*;
76

7+
import com.mysema.query.types.PathMetadata;
88
import javax.annotation.Generated;
9+
import com.mysema.query.types.Path;
10+
11+
import com.mysema.query.sql.ColumnMetadata;
912

1013

1114
/**
@@ -14,28 +17,37 @@
1417
@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
1518
public class QCustomer extends com.mysema.query.sql.RelationalPathBase<QCustomer> {
1619

17-
private static final long serialVersionUID = -409565065;
20+
private static final long serialVersionUID = 676296244;
1821

1922
public static final QCustomer customer = new QCustomer("CUSTOMER");
2023

21-
public final StringPath firstName = createString("FIRST_NAME");
24+
public final StringPath firstName = createString("firstName");
2225

23-
public final NumberPath<Long> id = createNumber("ID", Long.class);
26+
public final NumberPath<Long> id = createNumber("id", Long.class);
2427

25-
public final StringPath lastName = createString("LAST_NAME");
28+
public final StringPath lastName = createString("lastName");
2629

27-
public final com.mysema.query.sql.PrimaryKey<QCustomer> primary = createPrimaryKey(id);
30+
public final com.mysema.query.sql.PrimaryKey<QCustomer> sysPk10025 = createPrimaryKey(id);
2831

2932
public QCustomer(String variable) {
30-
super(QCustomer.class, forVariable(variable), "PUBLIC", "CUSTOMER");
33+
super(QCustomer.class, forVariable(variable), "PUBLIC", "CUSTOMER");
34+
addMetadata();
3135
}
3236

33-
public QCustomer(Path<? extends QCustomer> entity) {
34-
super(entity.getType(), entity.getMetadata(), "PUBLIC", "CUSTOMER");
37+
public QCustomer(Path<? extends QCustomer> path) {
38+
super(path.getType(), path.getMetadata(), "PUBLIC", "CUSTOMER");
39+
addMetadata();
3540
}
3641

3742
public QCustomer(PathMetadata<?> metadata) {
38-
super(QCustomer.class, metadata, "PUBLIC", "CUSTOMER");
43+
super(QCustomer.class, metadata, "PUBLIC", "CUSTOMER");
44+
addMetadata();
45+
}
46+
47+
public void addMetadata() {
48+
addMetadata(firstName, ColumnMetadata.named("FIRST_NAME").ofType(12).withSize(255));
49+
addMetadata(id, ColumnMetadata.named("ID").ofType(-5).withSize(0).notNull());
50+
addMetadata(lastName, ColumnMetadata.named("LAST_NAME").ofType(12).withSize(255));
3951
}
4052

4153
}

spring-data-jdbc-core/src/test/java/org/springframework/data/jdbc/query/generated/QCustomerNames.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

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

5-
import com.mysema.query.types.*;
65
import com.mysema.query.types.path.*;
76

7+
import com.mysema.query.types.PathMetadata;
88
import javax.annotation.Generated;
9+
import com.mysema.query.types.Path;
10+
11+
import com.mysema.query.sql.ColumnMetadata;
912

1013

1114
/**
@@ -14,22 +17,29 @@
1417
@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
1518
public class QCustomerNames extends com.mysema.query.sql.RelationalPathBase<QCustomerNames> {
1619

17-
private static final long serialVersionUID = 1221071121;
20+
private static final long serialVersionUID = 1780429172;
1821

1922
public static final QCustomerNames customerNames = new QCustomerNames("CUSTOMER_NAMES");
2023

21-
public final StringPath name = createString("NAME");
24+
public final StringPath name = createString("name");
2225

2326
public QCustomerNames(String variable) {
24-
super(QCustomerNames.class, forVariable(variable), "PUBLIC", "CUSTOMER_NAMES");
27+
super(QCustomerNames.class, forVariable(variable), "PUBLIC", "CUSTOMER_NAMES");
28+
addMetadata();
2529
}
2630

27-
public QCustomerNames(Path<? extends QCustomerNames> entity) {
28-
super(entity.getType(), entity.getMetadata(), "PUBLIC", "CUSTOMER_NAMES");
31+
public QCustomerNames(Path<? extends QCustomerNames> path) {
32+
super(path.getType(), path.getMetadata(), "PUBLIC", "CUSTOMER_NAMES");
33+
addMetadata();
2934
}
3035

3136
public QCustomerNames(PathMetadata<?> metadata) {
32-
super(QCustomerNames.class, metadata, "PUBLIC", "CUSTOMER_NAMES");
37+
super(QCustomerNames.class, metadata, "PUBLIC", "CUSTOMER_NAMES");
38+
addMetadata();
39+
}
40+
41+
public void addMetadata() {
42+
addMetadata(name, ColumnMetadata.named("NAME").ofType(12).withSize(255));
3343
}
3444

3545
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create table customer(id IDENTITY, first_name VARCHAR(255), last_name VARCHAR(255));
1+
create table customer(id BIGINT IDENTITY, first_name VARCHAR(255), last_name VARCHAR(255));
22
create view customer_names as select last_name as name from customer;
33
insert into customer(first_name, last_name) values('Thomas', 'Risberg');
44
insert into customer(first_name, last_name) values('Mark', 'Pollack');

0 commit comments

Comments
 (0)