Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server/springboot: alter "list tickets" SQL query on the fly #408

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

srenatus
Copy link
Member

@srenatus srenatus commented Nov 5, 2024

One learning is that we cannot rely on the "method name to SQL query" magic that JPA supports -- rewriting queries using QueryRewriter only works for JPQL1 or "native" (= dialect of the database) queries.

Omitted:

  1. get conditions from OPA, after feeding it query and user information
  2. convert conditions to SQL WHERE clause

SQL logging uncovered a lot of queries happening for "list tickets". I'd assume that they're done automatically by Spring Data JPA, to ensure relationships etc; but it also means they are under the radar of this rewriter.
However, I'd envision that there's one rewriter that would be used with all the repositories, so maybe we would end up covering call queries after all.

Footnotes

  1. JPQL (Java Persistence Query Language) is a query language used to perform database operations on entities defined in JPA (Java Persistence API). It is similar to SQL but operates on the entity objects instead of the database tables.

@Repository
public interface TicketRepository extends JpaRepository<Ticket, Integer> {
List<Ticket> findByTenant(Tenant tenant);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Before, we've let JPA figure out what SQL should be used just from the method signature.

👇 Now, we'll have to spell out the query ourselves.

One learning is that we cannot rely on the "method name to SQL query"
magic that JPA supports -- rewriting queries using QueryRewriter only
works for JPQL or "native" (=dialect of the database) queries.

lmgty:
JPQL (Java Persistence Query Language) is a query language used to perform
database operations on entities defined in JPA (Java Persistence API). It
is similar to SQL but operates on the entity objects instead of the
database tables.

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus srenatus force-pushed the sr/experiment/springboot-altering-raw-sql branch from b00f7e4 to c867614 Compare November 5, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant