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() {
if (mySearchEntity == null) {
reinitializeSearch();
}
}
mySearchEntity = new Search();
mySearchEntity.setUuid(UUID.randomUUID().toString());
mySearchEntity.setCreated(new Date());
mySearchEntity.setTotalCount(-1);
mySearchEntity.setPreferredPageSize(myParams.getCount());
mySearchEntity.setSearchType(myParams.getEverythingMode() != null ? SearchTypeEnum.EVERYTHING : SearchTypeEnum.SEARCH);
mySearchEntity.setLastUpdated(myParams.getLastUpdated());
private void reinitializeSearch() {
mySearchEntity = new Search();
mySearchEntity.setUuid(UUID.randomUUID().toString());
mySearchEntity.setCreated(new Date());
mySearchEntity.setTotalCount(-1);
mySearchEntity.setPreferredPageSize(myParams.getCount());
mySearchEntity.setSearchType(myParams.getEverythingMode() != null ? SearchTypeEnum.EVERYTHING : SearchTypeEnum.SEARCH);
mySearchEntity.setLastUpdated(myParams.getLastUpdated());
for (Include next : myParams.getIncludes()) {
mySearchEntity.getIncludes().add(new SearchInclude(mySearchEntity, next.getValue(), false, next.isRecurse()));
for (Include next : myParams.getIncludes()) {
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) {
if (myParams.isPersistResults()) {
mySearchResultDao.deleteForSearch(mySearchEntity.getId());
mySearchResultDao.flush();
if (mySearchEntity.getTotalCount() != null) {
reinitializeSearch();
}
LinkedHashSet<SearchResult> results = new LinkedHashSet<SearchResult>();
int index = 0;

View File

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