Skip to content

Commit 8cdc7be

Browse files
committed
Polishing.
Reformat code, switch to tabs. Accept property in DatabaseTypeMapping to provide more context to the type mapping component. Rename LiquibaseChangeSetGenerator to …Writer as we're writing a changeset and computing the contents is a consequence of writing a changeset. Refine naming to express what we're actually doing. Introduce setters for enhanced configuration of predicates. Reduce visibility of types to avoid unwanted public API where public access is not needed. Remove usused code, move methods around for improved grouping of code. Rename package to schema as the schema is being created and updated and not generated. Rename …Model classes to just their name as types are package-private and not visible externally. Refactor SchemaDiff to Java record. Use different overloads to write schema changes to avoid LiquibaseException leaking into cases where no diff is being used. Introduce SchemaFilter to filter unwanted mapped entities. Move code to JDBC module. Introduce comparator strategy to customize how table and column names are compared. See #1478 Original pull request: #1520
1 parent d23c0e2 commit 8cdc7be

File tree

26 files changed

+1605
-789
lines changed

26 files changed

+1605
-789
lines changed

spring-data-jdbc/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@
226226
<groupId>org.liquibase</groupId>
227227
<artifactId>liquibase-core</artifactId>
228228
<version>${liquibase.version}</version>
229-
<scope>compile</scope>
230229
<optional>true</optional>
231230
</dependency>
232231

Original file line numberDiff line numberDiff line change
@@ -13,30 +13,27 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.relational.core.mapping.schemasqlgeneration;
17-
18-
import org.springframework.data.relational.core.sql.SqlIdentifier;
16+
package org.springframework.data.jdbc.core.mapping.schema;
1917

2018
import java.util.Objects;
2119

22-
2320
/**
2421
* Models a Column for generating SQL for Schema generation.
2522
*
2623
* @author Kurt Niemi
2724
* @since 3.2
2825
*/
29-
public record ColumnModel(String name, String type, boolean nullable, boolean identityColumn) {
26+
record Column(String name, String type, boolean nullable, boolean identity) {
3027

31-
public ColumnModel(String name, String type) {
32-
this(name, type, false, false);
33-
}
28+
public Column(String name, String type) {
29+
this(name, type, false, false);
30+
}
3431

3532
@Override
3633
public boolean equals(Object o) {
3734
if (this == o) return true;
3835
if (o == null || getClass() != o.getClass()) return false;
39-
ColumnModel that = (ColumnModel) o;
36+
Column that = (Column) o;
4037
return Objects.equals(name, that.name);
4138
}
4239

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2023 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.core.mapping.schema;
17+
18+
import java.math.BigDecimal;
19+
import java.math.BigInteger;
20+
import java.time.LocalDate;
21+
import java.time.LocalDateTime;
22+
import java.time.LocalTime;
23+
import java.time.ZonedDateTime;
24+
import java.util.HashMap;
25+
import java.util.UUID;
26+
27+
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
28+
import org.springframework.util.ClassUtils;
29+
30+
/**
31+
* Class that provides a default implementation of mapping Java type to a Database type. To customize the mapping an
32+
* instance of a class implementing {@link SqlTypeMapping} interface can be set on the {@link Tables} class
33+
*
34+
* @author Kurt Niemi
35+
* @since 3.2
36+
*/
37+
public class DefaultSqlTypeMapping implements SqlTypeMapping {
38+
39+
private final HashMap<Class<?>, String> typeMap = new HashMap<>();
40+
41+
public DefaultSqlTypeMapping() {
42+
43+
typeMap.put(String.class, "VARCHAR(255 BYTE)");
44+
typeMap.put(Boolean.class, "TINYINT");
45+
typeMap.put(Double.class, "DOUBLE");
46+
typeMap.put(Float.class, "FLOAT");
47+
typeMap.put(Integer.class, "INT");
48+
typeMap.put(Long.class, "BIGINT");
49+
50+
typeMap.put(BigInteger.class, "BIGINT");
51+
typeMap.put(BigDecimal.class, "NUMERIC");
52+
53+
typeMap.put(UUID.class, "UUID");
54+
55+
typeMap.put(LocalDate.class, "DATE");
56+
typeMap.put(LocalTime.class, "TIME");
57+
typeMap.put(LocalDateTime.class, "TIMESTAMP");
58+
59+
typeMap.put(ZonedDateTime.class, "TIMESTAMPTZ");
60+
}
61+
62+
@Override
63+
public String getColumnType(RelationalPersistentProperty property) {
64+
return typeMap.get(ClassUtils.resolvePrimitiveIfNecessary(property.getActualType()));
65+
}
66+
}

0 commit comments

Comments
 (0)