Interpreting Quartz Scheduler job_data using java JPA. How to represent Bytea in JPA?

38 Views Asked by At

I'm creating a view over a few of the Quartz Scheduler tables. I will query this view to create an API in json format. I'm using Postgres for the tables. I'm having trouble retrieving job_data in the correct format. job_data is defined of type bytea when it's first declared in the tables.

The view is as follows:

create view sc_schedule_view as
(
    select qjd.job_name,qjd.job_class_name,qt.trigger_name,qct.cron_Expression,qjd.job_data
    from sc_scheduler.qrtz_job_details qjd,sc_scheduler.qrtz_triggers qt,sc_scheduler.qrtz_cron_triggers qct
    where qt.job_name=qjd.job_name
    and qt.job_group=qjd.job_group
    and qt.sched_name=qjd.sched_name
    and qt.sched_name =qct.sched_name
    and qt.trigger_name = qct.trigger_name
    and qt.trigger_group=qct.trigger_group
);

I created a class to hold the view in JPA:

@Entity
@Table(name = "sc_schedule_view")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ScheduleView implements Serializable {
    @Id
    @Column(length=200,nullable=false)
    private String jobName;

    @Column(length=250,nullable=false)
    private String job_class_name;

    @Column(length=200,nullable=false)
    private String triggerName;

    @Column(length=120,nullable=false)
    private String cronExpression;

    @Column(nullable=false)
    private byte[] jobData;
}

and the Repository:

@Repository
public interface ScheduleViewRepository extends PagingAndSortingRepository<ScheduleView, String> {
    Page<ScheduleView> findAll(Pageable pageable);

}

In my service class, I do the following:

public Page<ScheduleView> getAllSchedules(int pageNo, int pageSize){

    Pageable pageRequest = PageRequest.of(pageNo, pageSize);
    Page<ScheduleView> scheduleViews = scheduleViewRepository.findAll(pageRequest);
    List<ScheduleView> scheduleViewList = scheduleViews.stream().toList();

    byte[] jobData = scheduleViewList.get(0).getJobData();
    System.out.println(jobData);

    String string = new String(jobData, StandardCharsets.US_ASCII);
    System.out.println(string);

    return scheduleViews;
}

Which for the first print, prints out: [B@375ff3b5

And for the second, prints out:

�� sr org.quartz.JobDataMap�������� xr &org.quartz.utils.StringKeyDirtyFlagMap����]( Z allowsTransientDataxr org.quartz.utils.DirtyFlagMap�.�(v � Z dirtyL mapt Ljava/util/Map;xpsr java.util.HashMap���� F loadFactorI thresholdxp?@ t jobIdt myscheduledjobt payloadpt queryParamssr java.util.LinkedHashMap4�N\l�� Z accessOrderxq ~ ?@ q ~ t myscheduledjobx t urlt http://localhost:8888/dosomeworkx 2024-02-09T10:05:03.928

I want to get the job_data in JSON format, but i'm not sure how. I'm really new to Java/Jpa/Quartz so i'm a bit lost. Any help would be greatly appreciated.

Thankyou

0

There are 0 best solutions below