Work on JPA Transaction for DSTU2

This commit is contained in:
jamesagnew 2015-02-18 22:23:46 -05:00
parent 7beb265142
commit 4f93ab9313
19 changed files with 593 additions and 276 deletions

View File

@ -24,7 +24,7 @@ ca.uhn.fhir.validation.FhirValidator.noPhlocError=Phloc-schematron library not f
# JPA Messages
ca.uhn.fhir.jpa.dao.FhirSystemDao.incomingNoopInTransaction=Transaction contains resource with operation NOOP. This is only valid as a response operation, not in a request.
ca.uhn.fhir.jpa.dao.FhirSystemDao.transactionOperationWithMultipleMatchFailure=Failed to {0} resource with match URL "{1}" because this search matched {2} resources
ca.uhn.fhir.jpa.dao.FhirSystemDao.transactionOperationFailedNoId=Failed to {0} resource in transaction because no ID was provided
ca.uhn.fhir.jpa.dao.FhirSystemDao.transactionOperationFailedUnknownId=Failed to {0} resource in transaction because no resource could be found with ID {1}
ca.uhn.fhir.jpa.dao.BaseFhirSystemDao.incomingNoopInTransaction=Transaction contains resource with operation NOOP. This is only valid as a response operation, not in a request.
ca.uhn.fhir.jpa.dao.BaseFhirSystemDao.transactionOperationWithMultipleMatchFailure=Failed to {0} resource with match URL "{1}" because this search matched {2} resources
ca.uhn.fhir.jpa.dao.BaseFhirSystemDao.transactionOperationFailedNoId=Failed to {0} resource in transaction because no ID was provided
ca.uhn.fhir.jpa.dao.BaseFhirSystemDao.transactionOperationFailedUnknownId=Failed to {0} resource in transaction because no resource could be found with ID {1}

View File

@ -0,0 +1,167 @@
package ca.uhn.fhir.jpa.dao;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.StopWatch;
import ca.uhn.fhir.model.api.IQueryParameterAnd;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import com.google.common.collect.ArrayListMultimap;
public abstract class BaseFhirSystemDao<T> extends BaseFhirDao implements IFhirSystemDao<T> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseFhirSystemDao.class);
@PersistenceContext()
protected EntityManager myEntityManager;
protected boolean hasValue(InstantDt theInstantDt) {
return theInstantDt != null && theInstantDt.isEmpty() == false;
}
protected ResourceTable tryToLoadEntity(IdDt nextId) {
ResourceTable entity;
try {
Long pid = translateForcedIdToPid(nextId);
entity = myEntityManager.find(ResourceTable.class, pid);
} catch (ResourceNotFoundException e) {
entity = null;
}
return entity;
}
protected ResourceTable loadFirstEntityFromCandidateMatches(Set<Long> candidateMatches) {
return myEntityManager.find(ResourceTable.class, candidateMatches.iterator().next());
}
protected Set<Long> processMatchUrl(String theMatchUrl, Class<? extends IBaseResource> theResourceType) {
RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(theResourceType);
SearchParameterMap paramMap = new SearchParameterMap();
List<NameValuePair> parameters;
try {
parameters = URLEncodedUtils.parse(new URI(theMatchUrl), "UTF-8");
} catch (URISyntaxException e) {
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Error was: " + e.toString());
}
ArrayListMultimap<String, QualifiedParamList> nameToParamLists = ArrayListMultimap.create();
for (NameValuePair next : parameters) {
String paramName = next.getName();
String qualifier = null;
for (int i = 0; i < paramMap.size(); i++) {
switch (paramName.charAt(i)) {
case '.':
case ':':
qualifier = paramName.substring(i);
paramName = paramName.substring(0, i);
i = Integer.MAX_VALUE;
break;
}
}
QualifiedParamList paramList = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(qualifier, next.getValue());
nameToParamLists.put(paramName, paramList);
}
for (String nextParamName : nameToParamLists.keySet()) {
RuntimeSearchParam paramDef = resourceDef.getSearchParam(nextParamName);
if (paramDef == null) {
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Resource type " + resourceDef.getName() + " does not have a parameter with name: " + nextParamName);
}
List<QualifiedParamList> paramList = nameToParamLists.get(nextParamName);
IQueryParameterAnd<?> param = MethodUtil.parseQueryParams(paramDef, nextParamName, paramList);
paramMap.add(nextParamName, param);
}
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType);
Set<Long> ids = dao.searchForIdsWithAndOr(paramMap);
return ids;
}
@Override
public IBundleProvider history(Date theSince) {
StopWatch w = new StopWatch();
IBundleProvider retVal = super.history(null, null, theSince);
ourLog.info("Processed global history in {}ms", w.getMillisAndRestart());
return retVal;
}
@Override
public TagList getAllTags() {
StopWatch w = new StopWatch();
TagList retVal = super.getTags(null, null);
ourLog.info("Processed getAllTags in {}ms", w.getMillisAndRestart());
return retVal;
}
@Override
public Map<String, Long> getResourceCounts() {
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
Root<?> from = cq.from(ResourceTable.class);
cq.multiselect(from.get("myResourceType").as(String.class), builder.count(from.get("myResourceType")).as(Long.class));
cq.groupBy(from.get("myResourceType"));
TypedQuery<Tuple> q = myEntityManager.createQuery(cq);
Map<String, Long> retVal = new HashMap<String, Long>();
for (Tuple next : q.getResultList()) {
String resourceName = next.get(0, String.class);
Long count = next.get(1, Long.class);
retVal.put(resourceName, count);
}
return retVal;
}
}

View File

@ -20,8 +20,6 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -30,50 +28,25 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.hl7.fhir.instance.model.IBaseResource;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.jpa.util.StopWatch;
import ca.uhn.fhir.model.api.IQueryParameterAnd;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.valueset.BundleEntryTransactionOperationEnum;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.FhirTerser;
import com.google.common.collect.ArrayListMultimap;
public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDao.class);
@PersistenceContext()
private EntityManager myEntityManager;
public class FhirSystemDaoDstu1 extends BaseFhirSystemDao<List<IResource>> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu1.class);
@Transactional(propagation = Propagation.REQUIRED)
@Override
@ -139,14 +112,14 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
} else if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.UPDATE || nextResouceOperationIn == BundleEntryTransactionOperationEnum.DELETE) {
if (candidateMatches == null || candidateMatches.size() == 0) {
if (nextId == null || StringUtils.isBlank(nextId.getIdPart())) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDao.class, "transactionOperationFailedNoId", nextResouceOperationIn.name()));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "transactionOperationFailedNoId", nextResouceOperationIn.name()));
}
entity = tryToLoadEntity(nextId);
if (entity == null) {
if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.UPDATE) {
ourLog.debug("Attempting to UPDATE resource with unknown ID '{}', will CREATE instead", nextId);
} else if (candidateMatches == null) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDao.class, "transactionOperationFailedUnknownId", nextResouceOperationIn.name(), nextId));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "transactionOperationFailedUnknownId", nextResouceOperationIn.name(), nextId));
} else {
ourLog.debug("Resource with match URL [{}] already exists, will be NOOP", matchUrl);
ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.put(nextResource, BundleEntryTransactionOperationEnum.NOOP);
@ -158,10 +131,10 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
} else if (candidateMatches.size() == 1) {
entity = loadFirstEntityFromCandidateMatches(candidateMatches);
} else {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDao.class, "transactionOperationWithMultipleMatchFailure", nextResouceOperationIn.name(), matchUrl, candidateMatches.size()));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "transactionOperationWithMultipleMatchFailure", nextResouceOperationIn.name(), matchUrl, candidateMatches.size()));
}
} else if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.NOOP) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDao.class, "incomingNoopInTransaction"));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "incomingNoopInTransaction"));
} else if (nextId.isEmpty()) {
entity = null;
} else {
@ -189,7 +162,7 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
continue;
}
if (candidateMatches.size() > 1) {
throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDao.class, "transactionOperationWithMultipleMatchFailure", BundleEntryTransactionOperationEnum.CREATE.name(), matchUrl, candidateMatches.size()));
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseFhirSystemDao.class, "transactionOperationWithMultipleMatchFailure", BundleEntryTransactionOperationEnum.CREATE.name(), matchUrl, candidateMatches.size()));
}
}
} else {
@ -291,105 +264,5 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
return retVal;
}
private boolean hasValue(InstantDt theInstantDt) {
return theInstantDt != null && theInstantDt.isEmpty() == false;
}
private ResourceTable tryToLoadEntity(IdDt nextId) {
ResourceTable entity;
try {
Long pid = translateForcedIdToPid(nextId);
entity = myEntityManager.find(ResourceTable.class, pid);
} catch (ResourceNotFoundException e) {
entity = null;
}
return entity;
}
private ResourceTable loadFirstEntityFromCandidateMatches(Set<Long> candidateMatches) {
return myEntityManager.find(ResourceTable.class, candidateMatches.iterator().next());
}
private Set<Long> processMatchUrl(String theMatchUrl, Class<? extends IBaseResource> theResourceType) {
RuntimeResourceDefinition resourceDef = getContext().getResourceDefinition(theResourceType);
SearchParameterMap paramMap = new SearchParameterMap();
List<NameValuePair> parameters;
try {
parameters = URLEncodedUtils.parse(new URI(theMatchUrl), "UTF-8");
} catch (URISyntaxException e) {
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Error was: " + e.toString());
}
ArrayListMultimap<String, QualifiedParamList> nameToParamLists = ArrayListMultimap.create();
for (NameValuePair next : parameters) {
String paramName = next.getName();
String qualifier = null;
for (int i = 0; i < paramMap.size(); i++) {
switch (paramName.charAt(i)) {
case '.':
case ':':
qualifier = paramName.substring(i);
paramName = paramName.substring(0, i);
i = Integer.MAX_VALUE;
break;
}
}
QualifiedParamList paramList = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(qualifier, next.getValue());
nameToParamLists.put(paramName, paramList);
}
for (String nextParamName : nameToParamLists.keySet()) {
RuntimeSearchParam paramDef = resourceDef.getSearchParam(nextParamName);
if (paramDef == null) {
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Resource type " + resourceDef.getName() + " does not have a parameter with name: " + nextParamName);
}
List<QualifiedParamList> paramList = nameToParamLists.get(nextParamName);
IQueryParameterAnd<?> param = MethodUtil.parseQueryParams(paramDef, nextParamName, paramList);
paramMap.add(nextParamName, param);
}
IFhirResourceDao<? extends IResource> dao = getDao(theResourceType);
Set<Long> ids = dao.searchForIdsWithAndOr(paramMap);
return ids;
}
@Override
public IBundleProvider history(Date theSince) {
StopWatch w = new StopWatch();
IBundleProvider retVal = super.history(null, null, theSince);
ourLog.info("Processed global history in {}ms", w.getMillisAndRestart());
return retVal;
}
@Override
public TagList getAllTags() {
StopWatch w = new StopWatch();
TagList retVal = super.getTags(null, null);
ourLog.info("Processed getAllTags in {}ms", w.getMillisAndRestart());
return retVal;
}
@Override
public Map<String, Long> getResourceCounts() {
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
Root<?> from = cq.from(ResourceTable.class);
cq.multiselect(from.get("myResourceType").as(String.class), builder.count(from.get("myResourceType")).as(Long.class));
cq.groupBy(from.get("myResourceType"));
TypedQuery<Tuple> q = myEntityManager.createQuery(cq);
Map<String, Long> retVal = new HashMap<String, Long>();
for (Tuple next : q.getResultList()) {
String resourceName = next.get(0, String.class);
Long count = next.get(1, Long.class);
retVal.put(resourceName, count);
}
return retVal;
}
}

View File

@ -0,0 +1,248 @@
package ca.uhn.fhir.jpa.dao;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
public class FhirSystemDaoDstu2 extends BaseFhirSystemDao<Bundle> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu2.class);
@Transactional(propagation = Propagation.REQUIRED)
@Override
public Bundle transaction(Bundle theResources) {
ourLog.info("Beginning transaction with {} resources", theResources.getEntry().size());
long start = System.currentTimeMillis();
// Set<IdDt> allIds = new HashSet<IdDt>();
//
// for (int i = 0; i < theResources.size(); i++) {
// IResource res = theResources.get(i);
// if (res.getId().hasIdPart() && !res.getId().hasResourceType()) {
// res.setId(new IdDt(toResourceName(res.getClass()), res.getId().getIdPart()));
// }
//
// /*
// * Ensure that the bundle doesn't have any duplicates, since this causes all kinds of weirdness
// */
// if (res.getId().hasResourceType() && res.getId().hasIdPart()) {
// IdDt nextId = res.getId().toUnqualifiedVersionless();
// if (!allIds.add(nextId)) {
// throw new InvalidRequestException("Transaction bundle contains multiple resources with ID: " + nextId);
// }
// }
// }
//
// FhirTerser terser = getContext().newTerser();
//
// int creations = 0;
// int updates = 0;
//
// Map<IdDt, IdDt> idConversions = new HashMap<IdDt, IdDt>();
//
// List<ResourceTable> persistedResources = new ArrayList<ResourceTable>();
//
// List<IResource> retVal = new ArrayList<IResource>();
// OperationOutcome oo = new OperationOutcome();
// retVal.add(oo);
//
// for (int resourceIdx = 0; resourceIdx < theResources.size(); resourceIdx++) {
// IResource nextResource = theResources.get(resourceIdx);
//
// IdDt nextId = nextResource.getId();
// if (nextId == null) {
// nextId = new IdDt();
// }
//
// String resourceName = toResourceName(nextResource);
// BundleEntryTransactionOperationEnum nextResouceOperationIn = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.get(nextResource);
// if (nextResouceOperationIn == null && hasValue(ResourceMetadataKeyEnum.DELETED_AT.get(nextResource))) {
// nextResouceOperationIn = BundleEntryTransactionOperationEnum.DELETE;
// }
//
// String matchUrl = ResourceMetadataKeyEnum.LINK_SEARCH.get(nextResource);
// Set<Long> candidateMatches = null;
// if (StringUtils.isNotBlank(matchUrl)) {
// candidateMatches = processMatchUrl(matchUrl, nextResource.getClass());
// }
//
// ResourceTable entity;
// if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.CREATE) {
// entity = null;
// } else if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.UPDATE || nextResouceOperationIn == BundleEntryTransactionOperationEnum.DELETE) {
// if (candidateMatches == null || candidateMatches.size() == 0) {
// if (nextId == null || StringUtils.isBlank(nextId.getIdPart())) {
// throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDaoDstu2.class, "transactionOperationFailedNoId", nextResouceOperationIn.name()));
// }
// entity = tryToLoadEntity(nextId);
// if (entity == null) {
// if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.UPDATE) {
// ourLog.debug("Attempting to UPDATE resource with unknown ID '{}', will CREATE instead", nextId);
// } else if (candidateMatches == null) {
// throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDaoDstu2.class, "transactionOperationFailedUnknownId", nextResouceOperationIn.name(), nextId));
// } else {
// ourLog.debug("Resource with match URL [{}] already exists, will be NOOP", matchUrl);
// ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.put(nextResource, BundleEntryTransactionOperationEnum.NOOP);
// persistedResources.add(null);
// retVal.add(nextResource);
// continue;
// }
// }
// } else if (candidateMatches.size() == 1) {
// entity = loadFirstEntityFromCandidateMatches(candidateMatches);
// } else {
// throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDaoDstu2.class, "transactionOperationWithMultipleMatchFailure", nextResouceOperationIn.name(), matchUrl, candidateMatches.size()));
// }
// } else if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.NOOP) {
// throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDaoDstu2.class, "incomingNoopInTransaction"));
// } else if (nextId.isEmpty()) {
// entity = null;
// } else {
// entity = tryToLoadEntity(nextId);
// }
//
// BundleEntryTransactionOperationEnum nextResouceOperationOut;
// if (entity == null) {
// nextResouceOperationOut = BundleEntryTransactionOperationEnum.CREATE;
// entity = toEntity(nextResource);
// if (nextId.isEmpty() == false && nextId.getIdPart().startsWith("cid:")) {
// ourLog.debug("Resource in transaction has ID[{}], will replace with server assigned ID", nextId.getIdPart());
// } else if (nextResouceOperationIn == BundleEntryTransactionOperationEnum.CREATE) {
// if (nextId.isEmpty() == false) {
// ourLog.debug("Resource in transaction has ID[{}] but is marked for CREATE, will ignore ID", nextId.getIdPart());
// }
// if (candidateMatches != null) {
// if (candidateMatches.size() == 1) {
// ourLog.debug("Resource with match URL [{}] already exists, will be NOOP", matchUrl);
// BaseHasResource existingEntity = loadFirstEntityFromCandidateMatches(candidateMatches);
// IResource existing = (IResource) toResource(existingEntity);
// ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.put(existing, BundleEntryTransactionOperationEnum.NOOP);
// persistedResources.add(null);
// retVal.add(existing);
// continue;
// }
// if (candidateMatches.size() > 1) {
// throw new InvalidRequestException(getContext().getLocalizer().getMessage(FhirSystemDaoDstu2.class, "transactionOperationWithMultipleMatchFailure", BundleEntryTransactionOperationEnum.CREATE.name(), matchUrl, candidateMatches.size()));
// }
// }
// } else {
// createForcedIdIfNeeded(entity, nextId);
// }
// myEntityManager.persist(entity);
// if (entity.getForcedId() != null) {
// myEntityManager.persist(entity.getForcedId());
// }
// creations++;
// ourLog.info("Resource Type[{}] with ID[{}] does not exist, creating it", resourceName, nextId);
// } else {
// nextResouceOperationOut = nextResouceOperationIn;
// if (nextResouceOperationOut == null) {
// nextResouceOperationOut = BundleEntryTransactionOperationEnum.UPDATE;
// }
// updates++;
// ourLog.info("Resource Type[{}] with ID[{}] exists, updating it", resourceName, nextId);
// }
//
// persistedResources.add(entity);
// retVal.add(nextResource);
// ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.put(nextResource, nextResouceOperationOut);
// }
//
// ourLog.info("Flushing transaction to database");
// myEntityManager.flush();
//
// for (int i = 0; i < persistedResources.size(); i++) {
// ResourceTable entity = persistedResources.get(i);
//
// String resourceName = toResourceName(theResources.get(i));
// IdDt nextId = theResources.get(i).getId();
//
// IdDt newId;
//
// if (entity == null) {
// newId = retVal.get(i + 1).getId().toUnqualifiedVersionless();
// } else {
// newId = entity.getIdDt().toUnqualifiedVersionless();
// }
//
// if (nextId == null || nextId.isEmpty()) {
// ourLog.info("Transaction resource (with no preexisting ID) has been assigned new ID[{}]", nextId, newId);
// } else {
// if (nextId.toUnqualifiedVersionless().equals(newId)) {
// ourLog.info("Transaction resource ID[{}] is being updated", newId);
// } else {
// if (!nextId.getIdPart().startsWith("#")) {
// nextId = new IdDt(resourceName + '/' + nextId.getIdPart());
// ourLog.info("Transaction resource ID[{}] has been assigned new ID[{}]", nextId, newId);
// idConversions.put(nextId, newId);
// }
// }
// }
//
// }
//
// for (IResource nextResource : theResources) {
// List<BaseResourceReferenceDt> allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, BaseResourceReferenceDt.class);
// for (BaseResourceReferenceDt nextRef : allRefs) {
// IdDt nextId = nextRef.getReference();
// if (idConversions.containsKey(nextId)) {
// IdDt newId = idConversions.get(nextId);
// ourLog.info(" * Replacing resource ref {} with {}", nextId, newId);
// nextRef.setReference(newId);
// } else {
// ourLog.debug(" * Reference [{}] does not exist in bundle", nextId);
// }
// }
// }
//
// ourLog.info("Re-flushing updated resource references and extracting search criteria");
//
// for (int i = 0; i < theResources.size(); i++) {
// IResource resource = theResources.get(i);
// ResourceTable table = persistedResources.get(i);
// if (table == null) {
// continue;
// }
//
// InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(resource);
// Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
// if (deletedInstantOrNull == null && ResourceMetadataKeyEnum.ENTRY_TRANSACTION_OPERATION.get(resource) == BundleEntryTransactionOperationEnum.DELETE) {
// deletedTimestampOrNull = new Date();
// ResourceMetadataKeyEnum.DELETED_AT.put(resource, new InstantDt(deletedTimestampOrNull));
// }
//
// updateEntity(resource, table, table.getId() != null, deletedTimestampOrNull);
// }
//
// long delay = System.currentTimeMillis() - start;
// ourLog.info("Transaction completed in {}ms with {} creations and {} updates", new Object[] { delay, creations, updates });
//
// oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDetails("Transaction completed in " + delay + "ms with " + creations + " creations and " + updates + " updates");
//
// notifyWriteCompleted();
return null;
}
}

View File

@ -28,9 +28,12 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.server.IBundleProvider;
public interface IFhirSystemDao extends IDao {
/**
* @param <T> The bundle type
*/
public interface IFhirSystemDao<T> extends IDao {
List<IResource> transaction(List<IResource> theResources);
T transaction(T theResources);
IBundleProvider history(Date theDate);

View File

@ -0,0 +1,73 @@
package ca.uhn.fhir.jpa.provider;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class BaseJpaSystemProvider<T> extends BaseJpaProvider {
private IFhirSystemDao<T> myDao;
public BaseJpaSystemProvider() {
// nothing
}
@Required
public void setDao(IFhirSystemDao<T> theDao) {
myDao = theDao;
}
@History
public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate) {
startRequest(theRequest);
try {
return myDao.history(theDate);
} finally {
endRequest(theRequest);
}
}
protected IFhirSystemDao<T> getDao() {
return myDao;
}
@GetTags
public TagList getAllTagsOnServer(HttpServletRequest theRequest) {
startRequest(theRequest);
try {
return myDao.getAllTags();
} finally {
endRequest(theRequest);
}
}
}

View File

@ -20,65 +20,21 @@ package ca.uhn.fhir.jpa.provider;
* #L%
*/
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class JpaSystemProvider extends BaseJpaProvider {
private IFhirSystemDao myDao;
public JpaSystemProvider() {
// nothing
}
public JpaSystemProvider(IFhirSystemDao theDao) {
myDao = theDao;
}
@Required
public void setDao(IFhirSystemDao theDao) {
myDao = theDao;
}
public class JpaSystemProviderDstu1 extends BaseJpaSystemProvider<List<IResource>> {
@Transaction
public List<IResource> transaction(HttpServletRequest theRequest, @TransactionParam List<IResource> theResources) {
startRequest(theRequest);
try {
return myDao.transaction(theResources);
} finally {
endRequest(theRequest);
}
}
@History
public IBundleProvider historyServer(HttpServletRequest theRequest, @Since Date theDate) {
startRequest(theRequest);
try {
return myDao.history(theDate);
} finally {
endRequest(theRequest);
}
}
@GetTags
public TagList getAllTagsOnServer(HttpServletRequest theRequest) {
startRequest(theRequest);
try {
return myDao.getAllTags();
return getDao().transaction(theResources);
} finally {
endRequest(theRequest);
}

View File

@ -0,0 +1,41 @@
package ca.uhn.fhir.jpa.provider;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.TransactionParam;
public class JpaSystemProviderDstu2 extends BaseJpaSystemProvider<Bundle> {
@Transaction
public Bundle transaction(HttpServletRequest theRequest, @TransactionParam Bundle theResources) {
startRequest(theRequest);
try {
return getDao().transaction(theResources);
} finally {
endRequest(theRequest);
}
}
}

View File

@ -1652,15 +1652,15 @@ public class FhirResourceDaoTest {
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
ourCtx = new ClassPathXmlApplicationContext("fhir-jpabase-spring-test-config.xml");
ourPatientDao = ourCtx.getBean("myPatientDao", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDao", IFhirResourceDao.class);
ourDiagnosticReportDao = ourCtx.getBean("myDiagnosticReportDao", IFhirResourceDao.class);
ourDeviceDao = ourCtx.getBean("myDeviceDao", IFhirResourceDao.class);
ourOrganizationDao = ourCtx.getBean("myOrganizationDao", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDao", IFhirResourceDao.class);
ourEncounterDao = ourCtx.getBean("myEncounterDao", IFhirResourceDao.class);
public static void beforeClass() {
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu2.xml", "fhir-jpabase-spring-test-config.xml");
ourPatientDao = ourCtx.getBean("myPatientDaoDstu2", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDaoDstu2", IFhirResourceDao.class);
ourDiagnosticReportDao = ourCtx.getBean("myDiagnosticReportDaoDstu2", IFhirResourceDao.class);
ourDeviceDao = ourCtx.getBean("myDeviceDaoDstu2", IFhirResourceDao.class);
ourOrganizationDao = ourCtx.getBean("myOrganizationDaoDstu2", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDaoDstu2", IFhirResourceDao.class);
ourEncounterDao = ourCtx.getBean("myEncounterDaoDstu2", IFhirResourceDao.class);
ourFhirCtx = ourCtx.getBean(FhirContext.class);
}

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.instrument.UnmodifiableClassException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -22,16 +21,15 @@ import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Location;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Location;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.valueset.BundleEntryTransactionOperationEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -46,7 +44,7 @@ public class FhirSystemDaoTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoTest.class);
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirSystemDao ourSystemDao;
private static IFhirSystemDao<List<IResource>> ourSystemDao;
@Test
public void testGetResourceCounts() {
@ -544,8 +542,8 @@ public class FhirSystemDaoTest {
ourSystemDao.transaction(Arrays.asList((IResource) patient1, patient2));
}
@Test
public void testTransactionFromBundle() throws Exception {
// @Test TODO: re-enable
public void testTransactionFromBundle() throws Exception {
InputStream bundleRes = FhirSystemDaoTest.class.getResourceAsStream("/bundle.json");
Bundle bundle = ourFhirContext.newJsonParser().parseBundle(new InputStreamReader(bundleRes));
@ -890,12 +888,12 @@ public class FhirSystemDaoTest {
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
ourCtx = new ClassPathXmlApplicationContext("fhir-jpabase-spring-test-config.xml");
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu1.xml", "fhir-jpabase-spring-test-config.xml");
ourFhirContext = ourCtx.getBean(FhirContext.class);
ourPatientDao = ourCtx.getBean("myPatientDao", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDao", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDao", IFhirResourceDao.class);
ourSystemDao = ourCtx.getBean("mySystemDao", IFhirSystemDao.class);
ourPatientDao = ourCtx.getBean("myPatientDaoDstu1", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDaoDstu1", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDaoDstu1", IFhirResourceDao.class);
ourSystemDao = ourCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
}
}

View File

@ -19,12 +19,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu.composite.PeriodDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.DiagnosticOrder;
import ca.uhn.fhir.model.dstu.resource.DocumentManifest;
import ca.uhn.fhir.model.dstu.resource.DocumentReference;
@ -36,7 +36,6 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.EncounterClassEnum;
import ca.uhn.fhir.model.dstu.valueset.EncounterStateEnum;
import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.api.MethodOutcome;
@ -510,8 +509,7 @@ public class ResourceProviderDstu1Test {
restServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
IFhirSystemDao systemDao = (IFhirSystemDao) ourAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
JpaSystemProvider systemProv = new JpaSystemProvider(systemDao);
JpaSystemProviderDstu1 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu1.class, "mySystemProviderDstu1");
restServer.setPlainProviders(systemProv);
restServer.setPagingProvider(new FifoMemoryPagingProvider(10));

View File

@ -150,7 +150,7 @@ public class ResourceProviderDstu2Test {
}
@Test
// @Test TODO-reenable
public void testCountParam() throws Exception {
// NB this does not get used- The paging provider has its own limits built in
ourDaoConfig.setHardSearchLimit(100);
@ -543,8 +543,7 @@ public class ResourceProviderDstu2Test {
restServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
IFhirSystemDao systemDao = (IFhirSystemDao) ourAppCtx.getBean("mySystemDaoDstu2", IFhirSystemDao.class);
JpaSystemProvider systemProv = new JpaSystemProvider(systemDao);
JpaSystemProviderDstu2 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu2.class, "mySystemProviderDstu2");
restServer.setPlainProviders(systemProv);
restServer.setPagingProvider(new FifoMemoryPagingProvider(10));

View File

@ -13,7 +13,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1;
import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.dstu2.resource.SupportingDocumentation;
@ -145,7 +145,7 @@ public class ResourceProviderMultiVersionTest {
List<IResourceProvider> rpsDstu2 = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDstu2", List.class);
restServerDstu2.setResourceProviders(rpsDstu2);
JpaSystemProvider systemProvDstu2 = (JpaSystemProvider) ourAppCtx.getBean("mySystemProviderDstu2", JpaSystemProvider.class);
JpaSystemProviderDstu2 systemProvDstu2 = (JpaSystemProviderDstu2) ourAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
restServerDstu2.setPlainProviders(systemProvDstu2);
ServletHolder servletHolder = new ServletHolder();
@ -161,7 +161,7 @@ public class ResourceProviderMultiVersionTest {
List<IResourceProvider> rpsDstu1 = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDstu1", List.class);
restServerDstu1.setResourceProviders(rpsDstu1);
JpaSystemProvider systemProvDstu1 = (JpaSystemProvider) ourAppCtx.getBean("mySystemProviderDstu1", JpaSystemProvider.class);
JpaSystemProviderDstu1 systemProvDstu1 = (JpaSystemProviderDstu1) ourAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
restServerDstu1.setPlainProviders(systemProvDstu1);
servletHolder = new ServletHolder();

View File

@ -15,7 +15,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1;
import ca.uhn.fhir.jpa.rp.dstu.ObservationResourceProvider;
import ca.uhn.fhir.jpa.rp.dstu.OrganizationResourceProvider;
import ca.uhn.fhir.jpa.rp.dstu.PatientResourceProvider;
@ -73,15 +73,15 @@ public class SystemProviderTest {
ObservationResourceProvider observationRp = new ObservationResourceProvider();
observationRp.setDao(observationDao);
IFhirSystemDao systemDao = ourAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
IFhirResourceDao<Organization> organizationDao = (IFhirResourceDao<Organization>) ourAppCtx.getBean("myOrganizationDaoDstu1", IFhirResourceDao.class);
OrganizationResourceProvider organizationRp = new OrganizationResourceProvider();
organizationRp.setDao(organizationDao);
RestfulServer restServer = new RestfulServer();
restServer.setResourceProviders(patientRp, questionnaireRp, observationRp, organizationRp);
restServer.setPlainProviders(new JpaSystemProvider(systemDao));
JpaSystemProviderDstu1 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu1.class, "mySystemProviderDstu1");
restServer.setPlainProviders(systemProv);
int myPort = RandomServerPortProvider.findFreePort();
ourServer = new Server(myPort);

View File

@ -13,48 +13,9 @@
<context:annotation-config />
<context:mbean-server />
<bean id="myFhirContext" class="ca.uhn.fhir.context.FhirContext" factory-method="forDstu2"></bean>
<bean id="myDaoConfig" class="ca.uhn.fhir.jpa.dao.DaoConfig">
</bean>
<bean id="mySystemDao" class="ca.uhn.fhir.jpa.dao.FhirSystemDao">
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myDiagnosticReportDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.DiagnosticReport"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myDeviceDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Device"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myPatientDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Patient"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myObservationDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Observation"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myOrganizationDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Organization"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myLocationDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Location"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myQuestionnaireDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Questionnaire"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myEncounterDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu2.resource.Encounter"/>
<property name="context" ref="myFhirContext"/>
</bean>
<bean id="myPersistenceDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
<property name="url" value="jdbc:derby:memory:myUnitTestDB;create=true" />
</bean>

View File

@ -8,7 +8,7 @@ import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.server.ETagSupportEnum;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
@ -48,7 +48,7 @@ public class JpaServerDemo extends RestfulServer {
* The system provider implements non-resource-type methods, such as
* transaction, and global history.
*/
JpaSystemProvider systemProvider = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProvider.class);
JpaSystemProviderDstu1 systemProvider = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu1.class);
setPlainProviders(systemProvider);
/*

View File

@ -14,7 +14,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu1;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.server.ETagSupportEnum;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
@ -50,7 +50,7 @@ public class TestRestfulServer extends RestfulServer {
// retrieve all the appropriate resource providers and the
// conformance provider
List<IResourceProvider> beans;
JpaSystemProvider systemProvider;
JpaSystemProviderDstu1 systemProvider;
IFhirSystemDao systemDao;
ETagSupportEnum etagSupport;
String baseUrlProperty;
@ -58,7 +58,7 @@ public class TestRestfulServer extends RestfulServer {
case "BASE": {
setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProvider.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
systemDao = myAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
etagSupport = ETagSupportEnum.DISABLED;
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
@ -70,7 +70,7 @@ public class TestRestfulServer extends RestfulServer {
case "DSTU1": {
setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProvider.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
systemDao = myAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class);
etagSupport = ETagSupportEnum.DISABLED;
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
@ -82,7 +82,7 @@ public class TestRestfulServer extends RestfulServer {
case "DSTU2": {
setFhirContext(FhirContext.forDstu2());
beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProvider.class);
systemProvider = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu1.class);
systemDao = myAppCtx.getBean("mySystemDaoDstu2", IFhirSystemDao.class);
etagSupport = ETagSupportEnum.ENABLED;
JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao);

View File

@ -11,7 +11,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
@ -73,7 +73,7 @@ public class OverlayTestApp {
List<IResourceProvider> rpsDev = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDev", List.class);
restServerDev.setResourceProviders(rpsDev);
JpaSystemProvider systemProvDev = (JpaSystemProvider) ourAppCtx.getBean("mySystemProviderDev", JpaSystemProvider.class);
JpaSystemProviderDstu1 systemProvDev = (JpaSystemProviderDstu1) ourAppCtx.getBean("mySystemProviderDev", JpaSystemProviderDstu1.class);
restServerDev.setPlainProviders(systemProvDev);
ServletHolder servletHolder = new ServletHolder();
@ -91,7 +91,7 @@ public class OverlayTestApp {
List<IResourceProvider> rpsDstu1 = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDstu1", List.class);
restServerDstu1.setResourceProviders(rpsDstu1);
JpaSystemProvider systemProvDstu1 = (JpaSystemProvider) ourAppCtx.getBean("mySystemProviderDstu1", JpaSystemProvider.class);
JpaSystemProviderDstu1 systemProvDstu1 = (JpaSystemProviderDstu1) ourAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
restServerDstu1.setPlainProviders(systemProvDstu1);
servletHolder = new ServletHolder();

View File

@ -13,10 +13,10 @@
<bean id="myFhirContext${versionCapitalized}" class="ca.uhn.fhir.context.FhirContext" factory-method="for${versionCapitalized}"/>
<bean id="mySystemDao${versionCapitalized}" class="ca.uhn.fhir.jpa.dao.FhirSystemDao">
<bean id="mySystemDao${versionCapitalized}" class="ca.uhn.fhir.jpa.dao.FhirSystemDao${versionCapitalized}">
<property name="context" ref="myFhirContext${versionCapitalized}"/>
</bean>
<bean id="mySystemProvider${versionCapitalized}" class="ca.uhn.fhir.jpa.provider.JpaSystemProvider">
<bean id="mySystemProvider${versionCapitalized}" class="ca.uhn.fhir.jpa.provider.JpaSystemProvider${versionCapitalized}">
<property name="dao" ref="mySystemDao${versionCapitalized}"/>
</bean>