Skip to content

Commit

Permalink
Replace QueryDSL by JPA Criteria API dcm4che#1806
Browse files Browse the repository at this point in the history
  • Loading branch information
vrindanayak committed Mar 20, 2019
1 parent 7071103 commit 7140ce4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

package org.dcm4chee.arc.diff.rs;

import com.querydsl.core.types.Predicate;
import org.dcm4che3.conf.json.JsonReader;
import org.dcm4che3.json.JSONWriter;
import org.dcm4che3.net.Device;
Expand All @@ -55,7 +54,6 @@
import org.dcm4chee.arc.event.QueueMessageEvent;
import org.dcm4chee.arc.event.QueueMessageOperation;
import org.dcm4chee.arc.qmgt.IllegalTaskStateException;
import org.dcm4chee.arc.query.util.MatchTask;
import org.dcm4chee.arc.query.util.TaskQueryParam;
import org.dcm4chee.arc.rs.client.RSClient;
import org.jboss.resteasy.annotations.cache.NoCache;
Expand Down Expand Up @@ -383,8 +381,8 @@ public String deleteTasks() {
int deleteTasksFetchSize = queueTasksFetchSize();
do {
count = diffService.deleteTasks(
matchQueueMessage(status(), deviceName, null),
matchDiffTask(updatedTime),
queueTaskQueryParam(deviceName, status()),
diffTaskQueryParam(updatedTime),
deleteTasksFetchSize);
deleted += count;
} while (count >= deleteTasksFetchSize);
Expand Down Expand Up @@ -541,16 +539,6 @@ private String exceptionAsString(Exception e) {
return sw.toString();
}

private Predicate matchDiffTask(String updatedTime) {
return MatchTask.matchDiffTask(
localAET, primaryAET, secondaryAET, checkDifferent, checkMissing, comparefields, createdTime, updatedTime);
}

private Predicate matchQueueMessage(QueueMessage.Status status, String devName, String updatedTime) {
return MatchTask.matchQueueMessage(
null, devName, status, batchID, null, null, updatedTime, null);
}

private int queueTasksFetchSize() {
return arcDev().getQueueTasksFetchSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

package org.dcm4chee.arc.diff;

import com.querydsl.core.types.Predicate;
import org.dcm4chee.arc.entity.AttributesBlob;
import org.dcm4chee.arc.entity.DiffTask;
import org.dcm4chee.arc.event.QueueMessageEvent;
Expand Down Expand Up @@ -90,7 +89,7 @@ long cancelDiffTasks(TaskQueryParam queueTaskQueryParam, TaskQueryParam diffTask

boolean deleteDiffTask(Long pk, QueueMessageEvent queueEvent);

int deleteTasks(Predicate matchQueueMessage, Predicate matchDiffTask, int deleteTasksFetchSize);
int deleteTasks(TaskQueryParam queueTaskQueryParam, TaskQueryParam diffTaskQueryParam, int deleteTasksFetchSize);

List<String> listDistinctDeviceNames(TaskQueryParam queueTaskQueryParam, TaskQueryParam diffTaskQueryParam);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ public boolean deleteDiffTask(Long pk, QueueMessageEvent queueEvent) {
return true;
}

public int deleteTasks(Predicate matchQueueMessage, Predicate matchDiffTask, int deleteTasksFetchSize) {
List<String> referencedQueueMsgIDs = createQuery(matchQueueMessage, matchDiffTask)
.select(QDiffTask.diffTask.queueMessage.messageID)
.limit(deleteTasksFetchSize)
.fetch();
public int deleteTasks(
TaskQueryParam queueTaskQueryParam, TaskQueryParam diffTaskQueryParam, int deleteTasksFetchSize) {
List<String> referencedQueueMsgIDs = em.createQuery(createQuery(queueTaskQueryParam, diffTaskQueryParam)
.select(queueMsg.get(QueueMessage_.messageID)))
.setMaxResults(deleteTasksFetchSize)
.getResultList();

for (String queueMsgID : referencedQueueMsgIDs)
queueManager.deleteTask(queueMsgID, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

package org.dcm4chee.arc.diff.impl;

import com.querydsl.core.types.Predicate;
import org.dcm4che3.conf.api.ConfigurationException;
import org.dcm4che3.conf.api.IApplicationEntityCache;
import org.dcm4che3.data.Attributes;
Expand Down Expand Up @@ -213,8 +212,8 @@ public boolean deleteDiffTask(Long pk, QueueMessageEvent queueEvent) {
}

@Override
public int deleteTasks(Predicate matchQueueMessage, Predicate matchDiffTask, int deleteTasksFetchSize) {
return ejb.deleteTasks(matchQueueMessage, matchDiffTask, deleteTasksFetchSize);
public int deleteTasks(TaskQueryParam queueTaskQueryParam, TaskQueryParam diffTaskQueryParam, int deleteTasksFetchSize) {
return ejb.deleteTasks(queueTaskQueryParam, diffTaskQueryParam, deleteTasksFetchSize);
}

private QueueMessage.Status check(String prompt, int failures, QueueMessage.Status status, StringBuilder sb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ public static Predicate range(StringPath field, String range, FormatDate dt) {
return range(field, parseDateRange(range), dt);
}

public static Predicate range(DateTimePath field, String range, FormatDate dt) {
return range(field, parseDateRange(range), dt);
}

public static Predicate range(DateTimePath field, DateRange range, FormatDate dt) {
Date startDate = range.getStartDate();
Date endDate = range.getEndDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

package org.dcm4chee.arc.query.util;

import com.querydsl.core.BooleanBuilder;
import javax.persistence.criteria.Predicate;
import org.dcm4chee.arc.entity.*;

Expand All @@ -63,31 +62,6 @@ public MatchTask(CriteriaBuilder cb) {
this.cb = Objects.requireNonNull(cb);
}

public static com.querydsl.core.types.Predicate matchQueueMessage(
String queueName, String deviceName, QueueMessage.Status status, String batchID, String jmsMessageID,
String createdTime, String updatedTime, Date updatedBefore) {
BooleanBuilder predicate = new BooleanBuilder();
if (queueName != null)
predicate.and(QQueueMessage.queueMessage.queueName.eq(queueName));
if (status != null && status != QueueMessage.Status.TO_SCHEDULE)
predicate.and(QQueueMessage.queueMessage.status.eq(status));
if (deviceName != null)
predicate.and(QQueueMessage.queueMessage.deviceName.eq(deviceName));
if (batchID != null)
predicate.and(QQueueMessage.queueMessage.batchID.eq(batchID));
if (jmsMessageID != null)
predicate.and(QQueueMessage.queueMessage.messageID.eq(jmsMessageID));
if (createdTime != null)
predicate.and(MatchDateTimeRange.range(
QQueueMessage.queueMessage.createdTime, createdTime, MatchDateTimeRange.FormatDate.DT));
if (updatedTime != null)
predicate.and(MatchDateTimeRange.range(
QQueueMessage.queueMessage.updatedTime, updatedTime, MatchDateTimeRange.FormatDate.DT));
if (updatedBefore != null)
predicate.and(QQueueMessage.queueMessage.updatedTime.before(updatedBefore));
return predicate;
}

public List<Predicate> queueMsgPredicates(
Root<QueueMessage> queueMsg, TaskQueryParam queueTaskQueryParam) {
List<Predicate> predicates = new ArrayList<>();
Expand Down Expand Up @@ -257,31 +231,6 @@ private void matchStgVerTask(
cb, stgVerTask.get(StorageVerificationTask_.updatedTime), taskQueryParam.getUpdatedTime()));
}

public static com.querydsl.core.types.Predicate matchDiffTask(
String localAET, String primaryAET, String secondaryAET, String checkDifferent,
String checkMissing, String comparefields, String createdTime, String updatedTime) {
BooleanBuilder predicate = new BooleanBuilder();
if (localAET != null)
predicate.and(QDiffTask.diffTask.localAET.eq(localAET));
if (primaryAET != null)
predicate.and(QDiffTask.diffTask.primaryAET.eq(primaryAET));
if (secondaryAET != null)
predicate.and(QDiffTask.diffTask.secondaryAET.eq(secondaryAET));
if (checkDifferent != null)
predicate.and(QDiffTask.diffTask.checkDifferent.eq(Boolean.parseBoolean(checkDifferent)));
if (checkMissing != null)
predicate.and(QDiffTask.diffTask.checkMissing.eq(Boolean.parseBoolean(checkMissing)));
if (comparefields != null)
predicate.and(QDiffTask.diffTask.compareFields.eq(comparefields));
if (createdTime != null)
predicate.and(MatchDateTimeRange.range(
QDiffTask.diffTask.createdTime, createdTime, MatchDateTimeRange.FormatDate.DT));
if (updatedTime != null)
predicate.and(MatchDateTimeRange.range(
QDiffTask.diffTask.updatedTime, updatedTime, MatchDateTimeRange.FormatDate.DT));
return predicate;
}

public Order exportTaskOrder(String orderby, Path<ExportTask> exportTask) {
return taskOrder(orderby,
exportTask.get(ExportTask_.createdTime),
Expand Down

0 comments on commit 7140ce4

Please sign in to comment.