001/*-
002 * #%L
003 * HAPI FHIR Server - SQL Migration
004 * %%
005 * Copyright (C) 2014 - 2026 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.migrate.taskdef;
021
022import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
023import jakarta.annotation.Nonnull;
024
025import java.util.Objects;
026import java.util.StringJoiner;
027
028/**
029 * Capture a single SQL column type text override to the logic in {@link ColumnDriverMappingOverride}, namely,
030 * by column type and driver type.
031 * <p/>
032 * Several overrides can be passed down together at the same time to override said logic.
033 */
034public class ColumnDriverMappingOverride {
035        private final ColumnTypeEnum myColumnType;
036        private final DriverTypeEnum myDriverType;
037
038        private final String myColumnTypeSql;
039
040        public ColumnDriverMappingOverride(
041                        @Nonnull ColumnTypeEnum theColumnType,
042                        @Nonnull DriverTypeEnum theDriverType,
043                        @Nonnull String theColumnTypeSql) {
044                myColumnType = theColumnType;
045                myDriverType = theDriverType;
046                myColumnTypeSql = theColumnTypeSql;
047        }
048
049        public ColumnTypeEnum getColumnType() {
050                return myColumnType;
051        }
052
053        public DriverTypeEnum getDriverType() {
054                return myDriverType;
055        }
056
057        public String getColumnTypeSql() {
058                return myColumnTypeSql;
059        }
060
061        @Override
062        public boolean equals(Object theO) {
063                if (this == theO) {
064                        return true;
065                }
066                if (theO == null || getClass() != theO.getClass()) {
067                        return false;
068                }
069                ColumnDriverMappingOverride that = (ColumnDriverMappingOverride) theO;
070                return myColumnType == that.myColumnType
071                                && myDriverType == that.myDriverType
072                                && Objects.equals(myColumnTypeSql, that.myColumnTypeSql);
073        }
074
075        @Override
076        public int hashCode() {
077                return Objects.hash(myColumnType, myDriverType, myColumnTypeSql);
078        }
079
080        @Override
081        public String toString() {
082                return new StringJoiner(", ", ColumnDriverMappingOverride.class.getSimpleName() + "[", "]")
083                                .add("myColumnType=" + myColumnType)
084                                .add("myDriverType=" + myDriverType)
085                                .add("myColumnTypeSql='" + myColumnTypeSql + "'")
086                                .toString();
087        }
088}