Skip to content

Add Unique Constraint to the Inquiry Table #102

@alexanderkiel

Description

@alexanderkiel

I had the following exception:

DEBUG [SamplyShareScheduler_Worker-5] de.samply.share.client.job.CollectInquiriesJob - No specific entity requested
[SamplyShareScheduler_Worker-5] ERROR org.quartz.core.JobRunShell - Job DecentralSearchGroup.CollectInquiriesJob threw an unhandled Exception: 
org.jooq.exception.TooManyRowsException: Cursor returned more than one result
        at org.jooq.impl.Tools.fetchOne(Tools.java:1816)
        at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:545)
        at org.jooq.impl.AbstractResultQuery.fetchOneInto(AbstractResultQuery.java:568)
        at org.jooq.impl.SelectImpl.fetchOneInto(SelectImpl.java:2899)
        at de.samply.share.client.util.db.InquiryUtil.fetchInquiryBySourceIdAndBrokerId(InquiryUtil.java:89)
        at de.samply.share.client.job.CollectInquiriesJob.addInquiryDetails(CollectInquiriesJob.java:225)
        at de.samply.share.client.job.CollectInquiriesJob.loadAndPersistInquiries(CollectInquiriesJob.java:117)
        at de.samply.share.client.job.CollectInquiriesJob.execute(CollectInquiriesJob.java:77)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

The fetchInquiryBySourceIdAndBrokerId method looks like this:

public static Inquiry fetchInquiryBySourceIdAndBrokerId`(int sourceId, int brokerId) {
    DSLContext dslContext = ResourceManager.getDslContext();
    return dslContext
        .selectFrom(Tables.INQUIRY)
        .where(
            Tables.INQUIRY.SOURCE_ID.equal(sourceId)
                .and(Tables.INQUIRY.BROKER_ID.equal(brokerId))
        )
        .fetchOneInto(Inquiry.class);
  }

I had one result regarding this query:

select source_id, broker_id, count(*)
from samply.inquiry group by source_id, broker_id having count(*) > 1;

So we need a unique constraint over the columns source_id and broker_id in order to guaranty uniqueness for the query in fetchInquiryBySourceIdAndBrokerId.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions