Add support for Database Partition Mode
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
|
||||
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r5.model.Patient;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {Application.class}, properties =
|
||||
{
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr5_dbpm",
|
||||
"hapi.fhir.fhir_version=r5",
|
||||
"hapi.fhir.partitioning.database_partition_mode_enabled=true",
|
||||
"hapi.fhir.partitioning.patient_id_partitioning_mode=true"
|
||||
})
|
||||
public class ExampleServerDbpmR5IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private DataSource myDataSource;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager myTxManager;
|
||||
|
||||
|
||||
@Test
|
||||
void testCreateAndRead() {
|
||||
Patient pt = new Patient();
|
||||
pt.setId("A");
|
||||
pt.setActive(true);
|
||||
IIdType id = ourClient.update().resource(pt).execute().getId();
|
||||
|
||||
Patient pt2 = ourClient.read().resource(Patient.class).withId("Patient/A").execute();
|
||||
assertTrue(pt2.getActive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidateSchema() throws SQLException {
|
||||
TransactionTemplate tt = new TransactionTemplate(myTxManager);
|
||||
DriverTypeEnum.ConnectionProperties cp = new DriverTypeEnum.ConnectionProperties(myDataSource, tt, DriverTypeEnum.H2_EMBEDDED);
|
||||
Set<String> columns = JdbcUtils.getPrimaryKeyColumns(cp, "HFJ_RESOURCE");
|
||||
assertThat(columns).containsExactlyInAnyOrder("RES_ID", "PARTITION_ID");
|
||||
}
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forR5();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
}
|
||||
@@ -145,10 +145,27 @@ hapi:
|
||||
# local_base_urls:
|
||||
# - https://hapi.fhir.org/baseR4
|
||||
mdm_enabled: false
|
||||
|
||||
### Uncomment the following section, and any sub-properties you need in order to enable
|
||||
### partitioning support on this server.
|
||||
# partitioning:
|
||||
# allow_references_across_partitions: false
|
||||
# partitioning_include_in_search_hashes: false
|
||||
# partitioning_include_in_search_hashes
|
||||
# default_partition_id: 0
|
||||
# ### Enable the following setting to enable Database Partitioning Mode
|
||||
# ### See: https://hapifhir.io/hapi-fhir/docs/server_jpa_partitioning/db_partition_mode.html
|
||||
# database_partition_mode_enabled: false
|
||||
# ### Partition Style: Partitioning requires a partition interceptor which helps the server
|
||||
# ### select which partition(s) should be accessed for a given request. You can supply your
|
||||
# ### own interceptor (see https://hapifhir.io/hapi-fhir/docs/server_jpa_partitioning/partitioning.html#partition-interceptors )
|
||||
# ### but the following setting can also be used to use a built-in form.
|
||||
# ### Patient ID Partitioning Mode uses the patient/subject ID to determine the partition
|
||||
# patient_id_partitioning_mode: false
|
||||
# ### Request tenant mode can be used for a multi-tenancy setup where the request path is
|
||||
# ### expected to have an additional path element, e.g. GET http://example.com/fhir/TENANT-ID/Patient/A
|
||||
# request_tenant_partitioning_mode: false
|
||||
|
||||
|
||||
#cors:
|
||||
# allow_Credentials: true
|
||||
# These are allowed_origin patterns, see: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/cors/CorsConfiguration.html#setAllowedOriginPatterns-java.util.List-
|
||||
|
||||
Reference in New Issue
Block a user