|
| 1 | +/* |
| 2 | + * Copyright 2025 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 | + * https://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 | +package org.springframework.data.jdbc.repository.query; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.*; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import org.junit.jupiter.api.BeforeEach; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import org.springframework.data.annotation.Id; |
| 26 | +import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; |
| 27 | +import org.springframework.data.jdbc.core.convert.JdbcTypeFactory; |
| 28 | +import org.springframework.data.jdbc.core.convert.MappingJdbcConverter; |
| 29 | +import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect; |
| 30 | +import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; |
| 31 | +import org.springframework.data.relational.core.mapping.Table; |
| 32 | +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
| 33 | + |
| 34 | +/** |
| 35 | + * Unit tests for {@link StatementFactory}. |
| 36 | + * |
| 37 | + * @author Mark Paluch |
| 38 | + */ |
| 39 | +class StatementFactoryUnitTests { |
| 40 | + |
| 41 | + JdbcMappingContext mappingContext = new JdbcMappingContext(); |
| 42 | + MappingJdbcConverter converter; |
| 43 | + |
| 44 | + @BeforeEach |
| 45 | + void setUp() { |
| 46 | + |
| 47 | + JdbcCustomConversions conversions = JdbcCustomConversions.of(JdbcH2Dialect.INSTANCE, List.of()); |
| 48 | + mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); |
| 49 | + mappingContext.afterPropertiesSet(); |
| 50 | + converter = new MappingJdbcConverter(mappingContext, (identifier, path) -> null, conversions, |
| 51 | + JdbcTypeFactory.unsupported()); |
| 52 | + } |
| 53 | + |
| 54 | + @Test // GH-2162 |
| 55 | + void statementFactoryConsidersQualifiedTableName() { |
| 56 | + |
| 57 | + MapSqlParameterSource parameterSource = new MapSqlParameterSource(); |
| 58 | + |
| 59 | + StatementFactory statementFactory = new StatementFactory(converter, JdbcH2Dialect.INSTANCE); |
| 60 | + StatementFactory.SelectionBuilder selection = statementFactory.select(Media.class); |
| 61 | + |
| 62 | + String sql = selection.build(parameterSource); |
| 63 | + assertThat(sql).contains("SELECT \"archive\".\"media\".").contains("ROM \"archive\".\"media\""); |
| 64 | + } |
| 65 | + |
| 66 | + @Table(schema = "archive", name = "media") |
| 67 | + public record Media(@Id Long id, String objectType, Long objectId) { |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments