infobip/infobip-spring-data-querydsl

Want to support the Embedded.Empty(Nullable) annotation

Closed this issue · 6 comments

I forked the project and found that the configuration of the Embedded annotation is upstream, and since the upstream does not handle data-jdbc, this needs to be handled by infobip-querydsl-apt. I'm not sure at the moment how the appropriate modification is, so wanted to discuss it.

I can provide PR if you want to add such a feature.

So basically Q class support for embedded classes? Sure, feel free to create a PR.

@Embedded(onEmpty = OnEmpty.USE_EMPTY) = @Embedded.Empty

@Embedded(onEmpty = OnEmpty.USE_NULL) = @Embedded.Nullable

What I mean by this is that the correct Q class is generated when the entity uses a convenience annotation.

Due to time zone issues I may not be able to reply to you in time, I plan to implement the following logic.
(Since Embedded is nestable, prefix must be continuously appended, just like what data-jdbc itself implements.)
Can you give me some guidance?

public class Inventory {
    @Embedded.Empty(prefix = "prefix_")
    private EarlyWarningRange earlyWarningRange;
}
public record EarlyWarningRange(
        int averageSalesDays,
        int earlyWarningMaxLimitDays,
        int earlyWarningMinLimitDays
) {}

public class QInventory extends com.querydsl.sql.RelationalPathBase<Inventory> {
    public final NumberPath<Integer> averageSalesDays = createNumber("averageSalesDays", Integer.class);
    public final NumberPath<Integer> earlyWarningMaxLimitDays = createNumber("earlyWarningMaxLimitDays", Integer.class);
    public final NumberPath<Integer> earlyWarningMinLimitDays = createNumber("earlyWarningMinLimitDays", Integer.class);

    public void addMetadata() {
        addMetadata(averageSalesDays, ColumnMetadata.named("prefix_average_sales_days").withIndex(0));
        addMetadata(earlyWarningMaxLimitDays, ColumnMetadata.named("prefix_early_warning_max_limit_days").withIndex(1));
        addMetadata(earlyWarningMinLimitDays, ColumnMetadata.named("prefix_early_warning_min_limit_days").withIndex(2));
    }
}

Can you give me some guidance?

Basic case is here - Embedded.
I'd first start with a test like this one - https://github.com/infobip/infobip-spring-data-querydsl/blob/master/infobip-spring-data-jdbc-annotation-processor/src/test/java/com/infobip/spring/data/jdbc/annotation/processor/SpringDataJdbcAnnotationProcessorTest.java#L155

So basically write the test and what you expect Querydsl to generate here and then go on from there. You can debug the annotation processor and figure out what is going on.

Sorry I haven't given feedback for a long time. Due to work reasons, I don't have time to contribute to this feature.

Here's my solution to my current work dilemma and my apologies for not keeping my end of the bargain.

Currently, dynamic query is implemented through the Query mechanism in spring data jdbc's own JdbcAggregateOperations.

In terms of query only, JdbcClient is used to integrate RelationalConverter to realize dynamic query and integration with the converter part of data-jdbc. It is a lightweight mechanism using native SQL.

Sorry I haven't given feedback for a long time. Due to work reasons, I don't have time to contribute to this feature.

Here's my solution to my current work dilemma and my apologies for not keeping my end of the bargain.

Currently, dynamic query is implemented through the Query mechanism in spring data jdbc's own JdbcAggregateOperations.

In terms of query only, JdbcClient is used to integrate RelationalConverter to realize dynamic query and integration with the converter part of data-jdbc. It is a lightweight mechanism using native SQL.

Understandable, it's similar for everyone working on open source projects on the side.
Thank you for sharing your solution.