|
16 | 16 | package org.springframework.data.r2dbc.repository.query; |
17 | 17 |
|
18 | 18 | import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
19 | 20 | import java.util.List; |
20 | 21 | import java.util.stream.Collectors; |
21 | 22 |
|
|
27 | 28 | import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; |
28 | 29 | import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; |
29 | 30 | import org.springframework.data.relational.core.query.Criteria; |
30 | | -import org.springframework.data.relational.core.sql.SqlIdentifier; |
| 31 | +import org.springframework.data.relational.core.sql.*; |
31 | 32 | import org.springframework.data.relational.repository.query.RelationalEntityMetadata; |
32 | 33 | import org.springframework.data.relational.repository.query.RelationalParameterAccessor; |
33 | 34 | import org.springframework.data.relational.repository.query.RelationalQueryCreator; |
|
41 | 42 | * @author Roman Chigvintsev |
42 | 43 | * @author Mark Paluch |
43 | 44 | * @author Mingyuan Wu |
| 45 | + * @author Myeonghyeon Lee |
44 | 46 | * @since 1.1 |
45 | 47 | */ |
46 | 48 | class R2dbcQueryCreator extends RelationalQueryCreator<PreparedOperation<?>> { |
@@ -132,28 +134,39 @@ private PreparedOperation<?> select(@Nullable Criteria criteria, Sort sort, Stat |
132 | 134 | return statementMapper.getMappedObject(selectSpec); |
133 | 135 | } |
134 | 136 |
|
135 | | -private SqlIdentifier[] getSelectProjection() { |
| 137 | +private Expression[] getSelectProjection() { |
136 | 138 |
|
137 | | -List<SqlIdentifier> columnNames; |
| 139 | +List<Expression> expressions; |
138 | 140 |
|
| 141 | +Table table = Table.create(entityMetadata.getTableName()); |
139 | 142 | if (!projectedProperties.isEmpty()) { |
140 | 143 |
|
141 | 144 | RelationalPersistentEntity<?> entity = entityMetadata.getTableEntity(); |
142 | | -columnNames = new ArrayList<>(projectedProperties.size()); |
| 145 | +expressions = new ArrayList<>(projectedProperties.size()); |
143 | 146 |
|
144 | 147 | for (String projectedProperty : projectedProperties) { |
145 | 148 |
|
146 | 149 | RelationalPersistentProperty property = entity.getPersistentProperty(projectedProperty); |
147 | | -columnNames.add(property != null ? property.getColumnName() : SqlIdentifier.unquoted(projectedProperty)); |
| 150 | +Column column = table.column(property != null ? property.getColumnName() : SqlIdentifier.unquoted(projectedProperty)); |
| 151 | +expressions.add(column); |
148 | 152 | } |
149 | 153 |
|
150 | 154 | } else if (tree.isExistsProjection()) { |
151 | | -columnNames = dataAccessStrategy.getIdentifierColumns(entityMetadata.getJavaType()); |
| 155 | + |
| 156 | +expressions = dataAccessStrategy.getIdentifierColumns(entityMetadata.getJavaType()).stream() |
| 157 | +.map(table::column) |
| 158 | +.collect(Collectors.toList()); |
| 159 | +} else if (tree.isCountProjection()) { |
| 160 | + |
| 161 | +SqlIdentifier idColumn = entityMetadata.getTableEntity().getRequiredIdProperty().getColumnName(); |
| 162 | +expressions = Collections.singletonList(Functions.count(table.column(idColumn))); |
152 | 163 | } else { |
153 | | -columnNames = dataAccessStrategy.getAllColumns(entityMetadata.getJavaType()); |
| 164 | +expressions = dataAccessStrategy.getAllColumns(entityMetadata.getJavaType()).stream() |
| 165 | +.map(table::column) |
| 166 | +.collect(Collectors.toList()); |
154 | 167 | } |
155 | 168 |
|
156 | | -return columnNames.toArray(new SqlIdentifier[0]); |
| 169 | +return expressions.toArray(new Expression[0]); |
157 | 170 | } |
158 | 171 |
|
159 | 172 | private Sort getSort(Sort sort) { |
|
0 commit comments