Skip to content

Commit a0b7560

Browse files
author
Jarvis
committed
add postgresql test case and passed
1 parent 4205110 commit a0b7560

File tree

15 files changed

+118
-43
lines changed

15 files changed

+118
-43
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Download the jar through Maven:
3131
<dependency>
3232
<groupId>com.ifrabbit</groupId>
3333
<artifactId>spring-data-mybatis</artifactId>
34-
<version>1.0.6.RELEASE</version>
34+
<version>1.0.7.RELEASE</version>
3535
</dependency>
3636
```
3737

@@ -125,7 +125,7 @@ add the jar through Maven:
125125
<dependency>
126126
<groupId>com.ifrabbit</groupId>
127127
<artifactId>spring-boot-starter-data-mybatis</artifactId>
128-
<version>1.0.6.RELEASE</version>
128+
<version>1.0.7.RELEASE</version>
129129
</dependency>
130130
```
131131

README_zh.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Spring Data 项目的主要目标是使构建使用数据访问技术的 Spring
3333
<dependency>
3434
<groupId>com.ifrabbit</groupId>
3535
<artifactId>spring-data-mybatis</artifactId>
36-
<version>1.0.6.RELEASE</version>
36+
<version>1.0.7.RELEASE</version>
3737
</dependency>
3838
```
3939
最简单的通过Java注解配置的Spring Data Mybatis 配置如下所示:
@@ -128,7 +128,7 @@ public class UserRepositoryIntegrationTest {
128128
<dependency>
129129
<groupId>com.ifrabbit</groupId>
130130
<artifactId>spring-boot-starter-data-mybatis</artifactId>
131-
<version>1.0.6.RELEASE</version>
131+
<version>1.0.7.RELEASE</version>
132132
</dependency>
133133
```
134134

pom.xml

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.ifrabbit</groupId>
1313
<artifactId>spring-data-mybatis</artifactId>
14-
<version>1.0.6.RELEASE</version>
14+
<version>1.0.7.RELEASE</version>
1515

1616
<name>Spring Data MyBatis</name>
1717
<description>The primary goal of the Spring Data project is to make it easier to build Spring-powered applications
@@ -150,17 +150,23 @@
150150
<scope>test</scope>
151151
</dependency>
152152
<!--<dependency>-->
153-
<!--<groupId>com.oracle</groupId>-->
154-
<!--<artifactId>ojdbc14</artifactId>-->
155-
<!--<version>10.2.0.4.0</version>-->
156-
<!--<scope>test</scope>-->
153+
<!--<groupId>com.oracle</groupId>-->
154+
<!--<artifactId>ojdbc14</artifactId>-->
155+
<!--<version>10.2.0.4.0</version>-->
156+
<!--<scope>test</scope>-->
157157
<!--</dependency>-->
158158
<dependency>
159159
<groupId>net.sourceforge.jtds</groupId>
160160
<artifactId>jtds</artifactId>
161161
<version>1.3.1</version>
162162
<scope>test</scope>
163163
</dependency>
164+
<dependency>
165+
<groupId>org.postgresql</groupId>
166+
<artifactId>postgresql</artifactId>
167+
<version>9.4.1212</version>
168+
<scope>test</scope>
169+
</dependency>
164170
</dependencies>
165171
<build>
166172
<plugins>

src/main/java/org/springframework/data/mybatis/repository/dialect/Dialect.java

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public String wrapTableName(String tableName) {
112112
return tableName;
113113
}
114114

115+
public String wrapColumnName(String columnName) {
116+
return columnName;
117+
}
118+
115119
public boolean supportsSequences() {
116120
return false;
117121
}

src/main/java/org/springframework/data/mybatis/repository/dialect/PostgreSQLDialect.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public String wrapTableName(String tableName) {
5757
return "\"" + tableName + "\"";
5858
}
5959

60+
@Override
61+
public String wrapColumnName(String columnName) {
62+
return "\"" + columnName + "\"";
63+
}
64+
6065
@Override
6166
public String getDatabaseId() {
6267
return "postgresql";
@@ -75,6 +80,6 @@ public IdentityColumnSupport getIdentityColumnSupport() {
7580

7681
@Override
7782
public boolean supportsDeleteAlias() {
78-
return true;
83+
return false;
7984
}
8085
}

src/main/java/org/springframework/data/mybatis/repository/dialect/identity/PostgreSQLIdentityColumnSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public boolean supportsIdentityColumns() {
2828

2929
@Override
3030
public String getIdentitySelectString(String table, String column, int type) {
31-
return "select currval('" + table + '_' + column + "_seq')";
31+
return "select currval('\"" + table + '_' + column + "_seq\"')";
3232
}
3333

3434
@Override

src/main/java/org/springframework/data/mybatis/repository/query/PartTreeMybatisQuery.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private String buildQueryCondition(boolean basic) {
120120
throw new MybatisQueryException("can not find property: " + part.getProperty().getSegment() + " from entity: " + persistentEntity.getName());
121121
}
122122
if (!property.isEntity()) {
123-
columnName = quota(persistentEntity.getEntityName()) + "." + property.getColumnName();
123+
columnName = quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(property.getColumnName());
124124
} else if (!basic) {
125125
if (property.isAssociation()) {
126126
Association<MybatisPersistentProperty> ass = property.getAssociation();
@@ -130,9 +130,9 @@ private String buildQueryCondition(boolean basic) {
130130
if (null == leafProperty) {
131131
throw new MybatisQueryException("can not find property: " + part.getProperty().getLeafProperty().getSegment() + " from entity: " + association.getObversePersistentEntity().getName());
132132
}
133-
columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + leafProperty.getColumnName();
133+
columnName = quota(persistentEntity.getEntityName() + "." + part.getProperty().getSegment()) + "." + dialect.wrapColumnName(leafProperty.getColumnName());
134134
} else if (ass instanceof MybatisEmbeddedAssociation) {
135-
columnName = quota(persistentEntity.getEntityName()) + "." + ass.getObverse().getColumnName();
135+
columnName = quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(ass.getObverse().getColumnName());
136136
}
137137
}
138138
}

src/main/java/org/springframework/data/mybatis/repository/support/MybatisMapperGenerator.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public String buildSelectColumns(final boolean basic) {
168168
@Override
169169
public void doWithPersistentProperty(PersistentProperty<?> pp) {
170170
MybatisPersistentProperty property = (MybatisPersistentProperty) pp;
171-
builder.append(quota(persistentEntity.getEntityName()) + "." + property.getColumnName()).append(" as ").append(quota(property.getName())).append(",");
171+
builder.append(quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(property.getColumnName())).append(" as ").append(quota(property.getName())).append(",");
172172
}
173173
});
174174

@@ -183,7 +183,7 @@ public void doWithAssociation(Association<? extends PersistentProperty<?>> ass)
183183
@Override
184184
public void doWithPersistentProperty(PersistentProperty<?> pp) {
185185
MybatisPersistentProperty property = (MybatisPersistentProperty) pp;
186-
builder.append(quota(persistentEntity.getEntityName()) + "." + property.getColumnName()).append(" as ").append(quota(association.getInverse().getName() + "." + property.getName())).append(",");
186+
builder.append(quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(property.getColumnName())).append(" as ").append(quota(association.getInverse().getName() + "." + property.getName())).append(",");
187187
}
188188
});
189189
}
@@ -193,7 +193,7 @@ public void doWithPersistentProperty(PersistentProperty<?> pp) {
193193
if ((ass instanceof MybatisManyToOneAssociation)) {
194194
final MybatisManyToOneAssociation association = (MybatisManyToOneAssociation) ass;
195195
if (basic) {
196-
builder.append(quota(persistentEntity.getEntityName()) + "." + association.getJoinColumnName()).append(" as ").append(quota(association.getInverse().getName() + "." + association.getObverse().getName())).append(",");
196+
builder.append(quota(persistentEntity.getEntityName()) + "." + dialect.wrapColumnName(association.getJoinColumnName())).append(" as ").append(quota(association.getInverse().getName() + "." + association.getObverse().getName())).append(",");
197197
return;
198198
} else {
199199
MybatisPersistentEntity<?> obversePersistentEntity = association.getObversePersistentEntity();
@@ -202,7 +202,7 @@ public void doWithPersistentProperty(PersistentProperty<?> pp) {
202202
@Override
203203
public void doWithPersistentProperty(PersistentProperty<?> pp) {
204204
MybatisPersistentProperty property = (MybatisPersistentProperty) pp;
205-
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + property.getColumnName())
205+
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(property.getColumnName()))
206206
.append(" as ").append(quota(association.getInverse().getName() + "." + property.getName())).append(",");
207207
}
208208
});
@@ -217,7 +217,7 @@ public void doWithAssociation(Association<? extends PersistentProperty<?>> ass)
217217
@Override
218218
public void doWithPersistentProperty(PersistentProperty<?> pp) {
219219
MybatisPersistentProperty property = (MybatisPersistentProperty) pp;
220-
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + property.getColumnName())
220+
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(property.getColumnName()))
221221
.append(" as ").append(quota(association.getInverse().getName() + "." + association1.getInverse().getName() + "." + property.getName())).append(",");
222222
}
223223
});
@@ -227,7 +227,7 @@ public void doWithPersistentProperty(PersistentProperty<?> pp) {
227227

228228
if ((ass instanceof MybatisManyToOneAssociation)) {
229229
final MybatisManyToOneAssociation association1 = (MybatisManyToOneAssociation) ass;
230-
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + association1.getJoinColumnName())
230+
builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(association1.getJoinColumnName()))
231231
.append(" as ").append(quota(association.getInverse().getName() + "." + association1.getInverse().getName() + "." + association1.getObverse().getName())).append(",");
232232

233233
}
@@ -269,8 +269,8 @@ public void doWithAssociation(Association<? extends PersistentProperty<?>> ass)
269269
if ((ass instanceof MybatisManyToOneAssociation)) {
270270
final MybatisManyToOneAssociation association = (MybatisManyToOneAssociation) ass;
271271
builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()))
272-
.append(" on ").append(quota(persistentEntity.getEntityName())).append(".").append(association.getJoinColumnName())
273-
.append("=").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(association.getJoinReferencedColumnName());
272+
.append(" on ").append(quota(persistentEntity.getEntityName())).append(".").append(dialect.wrapColumnName(association.getJoinColumnName()))
273+
.append("=").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(dialect.wrapColumnName(association.getJoinReferencedColumnName()));
274274
}
275275
}
276276
});

0 commit comments

Comments
 (0)