Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jul 1, 2017
1 parent 6e181b1 commit dd7b1b2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ public void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, Stri
TagDefinition def = getTagOrNull(TagTypeEnum.TAG, theScheme, theTerm, theLabel);
if (def != null) {
BaseTag newEntity = entity.addTag(def);

myEntityManager.persist(newEntity);
myEntityManager.merge(entity);
if (newEntity.getTagId() == null) {
myEntityManager.persist(newEntity);
myEntityManager.merge(entity);
}
}

ourLog.info("Processed addTag {}/{} on {} in {}ms", new Object[] { theScheme, theTerm, theId, w.getMillisAndRestart() });
Expand Down Expand Up @@ -450,7 +451,9 @@ private <MT extends IBaseMetaType> void doMetaAdd(MT theMetaAdd, BaseHasResource
TagDefinition def = getTagOrNull(nextDef.getTagType(), nextDef.getSystem(), nextDef.getCode(), nextDef.getDisplay());
if (def != null) {
BaseTag newEntity = entity.addTag(def);
myEntityManager.persist(newEntity);
if (newEntity.getTagId() == null) {
myEntityManager.persist(newEntity);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.*;

import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.primitive.IdDt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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
* 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,
Expand All @@ -32,20 +32,23 @@ public class BaseTag implements Serializable {

private static final long serialVersionUID = 1L;

@ManyToOne(cascade= {})
@JoinColumn(name="TAG_ID", nullable=false)
@ManyToOne(cascade = {})
@JoinColumn(name = "TAG_ID", nullable = false)
private TagDefinition myTag;

@Column(name="TAG_ID", insertable=false,updatable=false)
@Column(name = "TAG_ID", insertable = false, updatable = false)
private Long myTagId;

public Long getTagId() {
return myTagId;
}

public TagDefinition getTag() {
return myTag;
}

public void setTag(TagDefinition theTag) {
myTag = theTag;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ public void addTag(ResourceTag theTag) {
}

@Override
public BaseTag addTag(TagDefinition theDef) {
ResourceHistoryTag historyTag = new ResourceHistoryTag(this, theDef);
public ResourceHistoryTag addTag(TagDefinition theTag) {
for (ResourceHistoryTag next : getTags()) {
if (next.getTag().equals(theTag)) {
return next;
}
}
ResourceHistoryTag historyTag = new ResourceHistoryTag(this, theTag);
getTags().add(historyTag);
return historyTag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ public class ResourceTable extends BaseHasResource implements Serializable {

@Override
public ResourceTag addTag(TagDefinition theTag) {
ResourceTag tag = new ResourceTag(this, theTag);
if (!getTags().contains(tag)) {
getTags().add(tag);
for (ResourceTag next : getTags()) {
if (next.getTag().equals(theTag)) {
return next;
}
}
ResourceTag tag = new ResourceTag(this, theTag);
getTags().add(tag);
return tag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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
* 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,
Expand Down Expand Up @@ -45,8 +45,8 @@

//@formatter:on
@Entity
@Table(name = "HFJ_TAG_DEF", uniqueConstraints = {
@UniqueConstraint(name="IDX_TAGDEF_TYPESYSCODE", columnNames = { "TAG_TYPE", "TAG_SYSTEM", "TAG_CODE" })
@Table(name = "HFJ_TAG_DEF", uniqueConstraints = {
@UniqueConstraint(name = "IDX_TAGDEF_TYPESYSCODE", columnNames = { "TAG_TYPE", "TAG_SYSTEM", "TAG_CODE" })
})
//@formatter:off
public class TagDefinition implements Serializable {
Expand Down Expand Up @@ -78,6 +78,8 @@ public class TagDefinition implements Serializable {
@Enumerated(EnumType.ORDINAL)
private TagTypeEnum myTagType;

private Integer myHashCode;

public TagDefinition() {
}

Expand Down Expand Up @@ -110,6 +112,7 @@ public TagTypeEnum getTagType() {

public void setCode(String theCode) {
myCode = theCode;
myHashCode = null;
}

public void setDisplay(String theDisplay) {
Expand All @@ -118,10 +121,12 @@ public void setDisplay(String theDisplay) {

public void setSystem(String theSystem) {
mySystem = theSystem;
myHashCode = null;
}

public void setTagType(TagTypeEnum theTagType) {
myTagType = theTagType;
myHashCode = null;
}

public Tag toTag() {
Expand Down Expand Up @@ -155,15 +160,14 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
HashCodeBuilder b = new HashCodeBuilder();
if (myId != null) {
b.append(myId);
} else {
if (myHashCode == null) {
HashCodeBuilder b = new HashCodeBuilder();
b.append(myTagType);
b.append(mySystem);
b.append(myCode);
myHashCode = b.toHashCode();
}
return b.toHashCode();
return myHashCode;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
</action>
<action type="fix">
Fix a regression in HAPI FHIR 2.5 JPA server where executing a search in a
transaction or batch operation caused an exception.
transaction or batch operation caused an exception. Thanks to Ravi Kuchi for
reporting!
</action>
<action type="fix">
Correct an issue when processing transactions in JPA server where updates and
Expand Down

0 comments on commit dd7b1b2

Please sign in to comment.