001/*- 002 * #%L 003 * HAPI FHIR Server - SQL Migration 004 * %% 005 * Copyright (C) 2014 - 2023 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.JdbcUtils; 023import ca.uhn.fhir.util.VersionEnum; 024 025import java.sql.SQLException; 026import java.util.Set; 027 028public class CalculateHashesTask extends BaseColumnCalculatorTask { 029 030 /** 031 * Constructor 032 */ 033 public CalculateHashesTask(VersionEnum theRelease, String theVersion) { 034 super(theRelease, theVersion); 035 setDescription("Calculate resource search parameter index hashes"); 036 setPidColumnName("SP_ID"); 037 } 038 039 @Override 040 protected boolean shouldSkipTask() { 041 try { 042 Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties()); 043 boolean shouldSkip = tableNames.contains("HFJ_RES_REINDEX_JOB"); 044 // This table was added shortly after hash indexes were added, so it is a reasonable indicator for whether 045 // this 046 // migration has already been run 047 if (shouldSkip) { 048 logInfo(ourLog, "The table HFJ_RES_REINDEX_JOB already exists. Skipping calculate hashes task."); 049 } 050 return shouldSkip; 051 } catch (SQLException e) { 052 logInfo(ourLog, "Error retrieving table names, skipping task"); 053 return true; 054 } 055 } 056}