001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2025 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.tasks; 021 022import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; 023import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; 024import ca.uhn.fhir.jpa.util.PartitionedIdModeVerificationSvc; 025import org.apache.commons.lang3.builder.EqualsBuilder; 026import org.apache.commons.lang3.builder.HashCodeBuilder; 027 028import java.sql.SQLException; 029 030/** 031 * This task verifies that the in-place schema is appropriate for 032 * Database Partition Mode (if that mode is enabled), or is appropriate 033 * for legacy mode otherwise. 034 */ 035public class VerifyDatabasePartitioningModeMigrationTask extends BaseTask { 036 private final boolean myExpectDatabasePartitionMode; 037 038 public VerifyDatabasePartitioningModeMigrationTask( 039 String theProductVersion, String theSchemaVersion, boolean theExpectDatabasePartitionMode) { 040 super(theProductVersion, theSchemaVersion); 041 myExpectDatabasePartitionMode = theExpectDatabasePartitionMode; 042 } 043 044 @Override 045 public void validate() { 046 // nothing 047 } 048 049 @Override 050 protected void doExecute() throws SQLException { 051 DriverTypeEnum.ConnectionProperties cp = getConnectionProperties(); 052 PartitionedIdModeVerificationSvc.verifySchemaIsAppropriateForDatabasePartitionMode( 053 cp, myExpectDatabasePartitionMode); 054 } 055 056 /** 057 * Nothing added other than the class name, just to give some kind 058 * of meaningful value. There is one bit of interesting state in this class, 059 * in the {@link #myExpectDatabasePartitionMode} field. But we actually want 060 * this task to keep working even if the wrong flag is passed in, so we 061 * don't include it here. 062 */ 063 @Override 064 protected void generateHashCode(HashCodeBuilder theBuilder) { 065 theBuilder.append(getClass().getSimpleName()); 066 } 067 068 @Override 069 protected void generateEquals(EqualsBuilder theBuilder, BaseTask theOtherObject) { 070 theBuilder.append(getClass().getSimpleName(), theOtherObject.getClass().getSimpleName()); 071 } 072}