Try to avoid deadlocks in complicated queries

This commit is contained in:
James Agnew 2016-03-27 09:38:01 -04:00
parent 1aebff9a43
commit bba9f5b584
2 changed files with 29 additions and 26 deletions

View File

@ -1322,29 +1322,31 @@ public class SearchBuilder {
private void doInitializeSearch() { private void doInitializeSearch() {
if (mySearchEntity == null) { if (mySearchEntity == null) {
reinitializeSearch();
}
}
mySearchEntity = new Search(); private void reinitializeSearch() {
mySearchEntity.setUuid(UUID.randomUUID().toString()); mySearchEntity = new Search();
mySearchEntity.setCreated(new Date()); mySearchEntity.setUuid(UUID.randomUUID().toString());
mySearchEntity.setTotalCount(-1); mySearchEntity.setCreated(new Date());
mySearchEntity.setPreferredPageSize(myParams.getCount()); mySearchEntity.setTotalCount(-1);
mySearchEntity.setSearchType(myParams.getEverythingMode() != null ? SearchTypeEnum.EVERYTHING : SearchTypeEnum.SEARCH); mySearchEntity.setPreferredPageSize(myParams.getCount());
mySearchEntity.setLastUpdated(myParams.getLastUpdated()); mySearchEntity.setSearchType(myParams.getEverythingMode() != null ? SearchTypeEnum.EVERYTHING : SearchTypeEnum.SEARCH);
mySearchEntity.setLastUpdated(myParams.getLastUpdated());
for (Include next : myParams.getIncludes()) { for (Include next : myParams.getIncludes()) {
mySearchEntity.getIncludes().add(new SearchInclude(mySearchEntity, next.getValue(), false, next.isRecurse())); mySearchEntity.getIncludes().add(new SearchInclude(mySearchEntity, next.getValue(), false, next.isRecurse()));
}
for (Include next : myParams.getRevIncludes()) {
mySearchEntity.getIncludes().add(new SearchInclude(mySearchEntity, next.getValue(), true, next.isRecurse()));
}
if (myParams.isPersistResults()) {
myEntityManager.persist(mySearchEntity);
for (SearchInclude next : mySearchEntity.getIncludes()) {
myEntityManager.persist(next);
} }
for (Include next : myParams.getRevIncludes()) {
mySearchEntity.getIncludes().add(new SearchInclude(mySearchEntity, next.getValue(), true, next.isRecurse()));
}
if (myParams.isPersistResults()) {
myEntityManager.persist(mySearchEntity);
for (SearchInclude next : mySearchEntity.getIncludes()) {
myEntityManager.persist(next);
}
}
} }
} }
@ -1362,8 +1364,9 @@ public class SearchBuilder {
private void doSetPids(Collection<Long> thePids) { private void doSetPids(Collection<Long> thePids) {
if (myParams.isPersistResults()) { if (myParams.isPersistResults()) {
mySearchResultDao.deleteForSearch(mySearchEntity.getId()); if (mySearchEntity.getTotalCount() != null) {
mySearchResultDao.flush(); reinitializeSearch();
}
LinkedHashSet<SearchResult> results = new LinkedHashSet<SearchResult>(); LinkedHashSet<SearchResult> results = new LinkedHashSet<SearchResult>();
int index = 0; int index = 0;

View File

@ -95,8 +95,8 @@ public class Search implements Serializable {
@Column(name="SEARCH_TYPE", nullable=false) @Column(name="SEARCH_TYPE", nullable=false)
private SearchTypeEnum mySearchType; private SearchTypeEnum mySearchType;
@Column(name="TOTAL_COUNT") @Column(name="TOTAL_COUNT", nullable=false)
private int myTotalCount; private Integer myTotalCount;
@Column(name="SEARCH_UUID", length=40, nullable=false, updatable=false) @Column(name="SEARCH_UUID", length=40, nullable=false, updatable=false)
private String myUuid; private String myUuid;
@ -145,7 +145,7 @@ public class Search implements Serializable {
} }
public int getTotalCount() { public Integer getTotalCount() {
return myTotalCount; return myTotalCount;
} }
@ -188,7 +188,7 @@ public class Search implements Serializable {
mySearchType = theSearchType; mySearchType = theSearchType;
} }
public void setTotalCount(int theTotalCount) { public void setTotalCount(Integer theTotalCount) {
myTotalCount = theTotalCount; myTotalCount = theTotalCount;
} }