This commit is contained in:
James Agnew 2019-10-18 07:13:11 -04:00
parent e6ae368424
commit 13b80a294a
3 changed files with 28 additions and 17 deletions

View File

@ -302,6 +302,11 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test {
* 20 should be prefetched since that's the initial page size * 20 should be prefetched since that's the initial page size
*/ */
await().until(()-> runInTransaction(()->{
Search search = mySearchEntityDao.findByUuidAndFetchIncludes(uuid).orElseThrow(() -> new InternalErrorException(""));
return search.getNumFound() >= 200;
}));
runInTransaction(() -> { runInTransaction(() -> {
Search search = mySearchEntityDao.findByUuidAndFetchIncludes(uuid).orElseThrow(() -> new InternalErrorException("")); Search search = mySearchEntityDao.findByUuidAndFetchIncludes(uuid).orElseThrow(() -> new InternalErrorException(""));
assertEquals(200, search.getNumFound()); assertEquals(200, search.getNumFound());

View File

@ -26,8 +26,8 @@ import org.apache.commons.lang3.Validate;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public class DropIndexTask extends BaseTableTask<DropIndexTask> { public class DropIndexTask extends BaseTableTask<DropIndexTask> {
@ -56,18 +56,27 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
boolean isUnique = JdbcUtils.isIndexUnique(getConnectionProperties(), getTableName(), myIndexName); boolean isUnique = JdbcUtils.isIndexUnique(getConnectionProperties(), getTableName(), myIndexName);
String uniquenessString = isUnique ? "unique" : "non-unique"; String uniquenessString = isUnique ? "unique" : "non-unique";
ourLog.info("Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName());
String sql = createDropIndexSql(getConnectionProperties(), getTableName(), myIndexName, getDriverType());
executeSql(getTableName(), sql);
Optional<String> sql = createDropIndexSql(getConnectionProperties(), getTableName(), myIndexName, getDriverType());
if (sql.isPresent()) {
ourLog.info("Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName());
executeSql(getTableName(), sql.get());
}
} }
@Nonnull public DropIndexTask setIndexName(String theIndexName) {
static String createDropIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName, DriverTypeEnum theDriverType) throws SQLException { myIndexName = theIndexName;
return this;
}
static Optional<String> createDropIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName, DriverTypeEnum theDriverType) throws SQLException {
Validate.notBlank(theIndexName, "theIndexName must not be blank"); Validate.notBlank(theIndexName, "theIndexName must not be blank");
Validate.notBlank(theTableName, "theTableName must not be blank"); Validate.notBlank(theTableName, "theTableName must not be blank");
if (!JdbcUtils.getIndexNames(theConnectionProperties, theTableName).contains(theIndexName)) {
return Optional.empty();
}
boolean isUnique = JdbcUtils.isIndexUnique(theConnectionProperties, theTableName, theIndexName); boolean isUnique = JdbcUtils.isIndexUnique(theConnectionProperties, theTableName, theIndexName);
String sql = null; String sql = null;
@ -109,12 +118,6 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
break; break;
} }
} }
return sql; return Optional.of(sql);
}
public DropIndexTask setIndexName(String theIndexName) {
myIndexName = theIndexName;
return this;
} }
} }

View File

@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public class DropTableTask extends BaseTableTask<DropTableTask> { public class DropTableTask extends BaseTableTask<DropTableTask> {
@ -53,9 +54,11 @@ public class DropTableTask extends BaseTableTask<DropTableTask> {
} }
for (String nextIndex : indexNames) { for (String nextIndex : indexNames) {
String sql = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType()); Optional<String> sql = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType());
ourLog.info("Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName()); if (sql.isPresent()) {
executeSql(getTableName(), sql); ourLog.info("Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName());
executeSql(getTableName(), sql.get());
}
} }
ourLog.info("Dropping table: {}", getTableName()); ourLog.info("Dropping table: {}", getTableName());