Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mp911de committed Jun 6, 2023
1 parent d23c0e2 commit 8cdc7be
Show file tree
Hide file tree
Showing 26 changed files with 1,605 additions and 789 deletions.
1 change: 0 additions & 1 deletion spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.mapping.schemasqlgeneration;

import org.springframework.data.relational.core.sql.SqlIdentifier;
package org.springframework.data.jdbc.core.mapping.schema;

import java.util.Objects;


/**
* Models a Column for generating SQL for Schema generation.
*
* @author Kurt Niemi
* @since 3.2
*/
public record ColumnModel(String name, String type, boolean nullable, boolean identityColumn) {
record Column(String name, String type, boolean nullable, boolean identity) {

public ColumnModel(String name, String type) {
this(name, type, false, false);
}
public Column(String name, String type) {
this(name, type, false, false);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ColumnModel that = (ColumnModel) o;
Column that = (Column) o;
return Objects.equals(name, that.name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.mapping.schema;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.UUID;

import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.util.ClassUtils;

/**
* Class that provides a default implementation of mapping Java type to a Database type. To customize the mapping an
* instance of a class implementing {@link SqlTypeMapping} interface can be set on the {@link Tables} class
*
* @author Kurt Niemi
* @since 3.2
*/
public class DefaultSqlTypeMapping implements SqlTypeMapping {

private final HashMap<Class<?>, String> typeMap = new HashMap<>();

public DefaultSqlTypeMapping() {

typeMap.put(String.class, "VARCHAR(255 BYTE)");
typeMap.put(Boolean.class, "TINYINT");
typeMap.put(Double.class, "DOUBLE");
typeMap.put(Float.class, "FLOAT");
typeMap.put(Integer.class, "INT");
typeMap.put(Long.class, "BIGINT");

typeMap.put(BigInteger.class, "BIGINT");
typeMap.put(BigDecimal.class, "NUMERIC");

typeMap.put(UUID.class, "UUID");

typeMap.put(LocalDate.class, "DATE");
typeMap.put(LocalTime.class, "TIME");
typeMap.put(LocalDateTime.class, "TIMESTAMP");

typeMap.put(ZonedDateTime.class, "TIMESTAMPTZ");
}

@Override
public String getColumnType(RelationalPersistentProperty property) {
return typeMap.get(ClassUtils.resolvePrimitiveIfNecessary(property.getActualType()));
}
}
Loading

0 comments on commit 8cdc7be

Please sign in to comment.