Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.Date;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;
import org.mapfish.print.Constants;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.processor.ExecutionStats;
Expand All @@ -25,13 +27,14 @@ public class HibernateAccountingEntry {
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateAccountingEntry.class);

@Id
@Column(name = "reference_id")
@Column(name = "reference_id", columnDefinition = "TEXT")
private String referenceId;

@Column(nullable = false, name = "app_id")
@Column(nullable = false, name = "app_id", columnDefinition = "TEXT")
private String appId;

@Column private String referrer;
@Column(columnDefinition = "TEXT")
private String referrer;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
Expand All @@ -46,16 +49,17 @@ public class HibernateAccountingEntry {
@Column(name = "total_time_ms", nullable = false)
private long totalTimeMS;

@Column(nullable = false, name = "output_format")
@Column(nullable = false, name = "output_format", columnDefinition = "TEXT")
private String outputFormat;

@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
private String layout;

@Column(name = "file_size")
private Long fileSize = null;

@Column(columnDefinition = "jsonb")
@JdbcTypeCode(SqlTypes.JSON)
private ObjectNode stats = null;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
@Embeddable
public class PrintJobEntry {

@Column(insertable = false, updatable = false)
@Column(insertable = false, updatable = false, columnDefinition = "TEXT")
private String referenceId;

@Column()
@Column(columnDefinition = "TEXT")
@Type(PJsonObjectUserType.class)
private PJsonObject requestData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@
@Table(name = "print_job_results")
public class PrintJobResultImpl implements PrintJobResult {

@Id private String reportURI;
@Id
@Column(columnDefinition = "TEXT")
private String reportURI;

@Column private String mimeType;
@Column(columnDefinition = "TEXT")
private String mimeType;

@Column private String fileExtension;
@Column(columnDefinition = "TEXT")
private String fileExtension;

@Column private String fileName;
@Column(columnDefinition = "TEXT")
private String fileName;

@OneToOne(targetEntity = PrintJobStatusImpl.class, fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "referenceId", insertable = false, updatable = false)
private PrintJobStatus status = null;

@Column(insertable = true, updatable = true)
@Column(insertable = true, updatable = true, columnDefinition = "TEXT")
private String referenceId;

/** Default Constructor. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class PrintJobStatusImpl implements PrintJobStatus {

@Embedded private PrintJobEntry entry;

@Id private String referenceId;
@Id
@Column(columnDefinition = "TEXT")
private String referenceId;

@Column
@Enumerated(EnumType.STRING)
Expand All @@ -33,7 +35,7 @@ public class PrintJobStatusImpl implements PrintJobStatus {

@Column private long requestCount;

@Column(length = 4096)
@Column(columnDefinition = "TEXT")
private String error;

@OneToOne(targetEntity = PrintJobResultImpl.class, cascade = CascadeType.ALL, mappedBy = "status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.annotation.Nullable;
import jakarta.annotation.PostConstruct;
import jakarta.persistence.PessimisticLockException;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
Expand All @@ -11,7 +10,6 @@
import jakarta.persistence.criteria.Root;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Session;
Expand Down Expand Up @@ -223,16 +221,11 @@ public final List<PrintJobStatusExtImpl> poll(final int size) {
criteria.orderBy(builder.asc(root.get("entry").get("startTime")));
final Query<PrintJobStatusExtImpl> query = getSession().createQuery(criteria);
query.setMaxResults(size);
// LOCK but don't wait for release (since this is run continuously
// anyway, no wait prevents deadlock)
query.setLockMode("pj", LockMode.PESSIMISTIC_WRITE);
// If the row is locked, it means that the row is already taken by some other worker.
// So, this row must not be returned as it's not in a WAITING state.
query.setLockMode("pj", LockMode.UPGRADE_SKIPLOCKED);
query.setHint("jakarta.persistence.lock.timeout", 0);
try {
return query.getResultList();
} catch (PessimisticLockException ex) {
// Another process was polling at the same time. We can ignore this error
return Collections.emptyList();
}
return query.getResultList();
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/mapfish-spring-hibernate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<property name="dataSource" ref="mfDataSource"/>
<property name="packagesToScan">
<array>
<value>org.mapfish.print.servlet.job</value>
<value>org.mapfish.print.servlet.job.impl</value>
<value>org.mapfish.print.servlet.job.impl.hibernate</value>
</array>
Expand Down
Loading