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

Querydsl support #222

Open
easybest opened this issue Sep 1, 2020 · 3 comments
Open

Querydsl support #222

easybest opened this issue Sep 1, 2020 · 3 comments
Assignees
Labels
Milestone

Comments

@easybest
Copy link
Owner

easybest commented Sep 1, 2020

Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API.

Spring Data Mybatis offer integration with Querydsl through QuerydslPredicateExecutor, as shown in the following example:

public interface QuerydslPredicateExecutor<T> {

  Optional<T> findById(Predicate predicate);  

  Iterable<T> findAll(Predicate predicate);   

  long count(Predicate predicate);            

  boolean exists(Predicate predicate);        

  // … more functionality omitted.
}

To make use of Querydsl support, extend QuerydslPredicateExecutor on your repository interface, as shown in the following example

interface UserRepository extends CrudRepository<User, Long>, QuerydslPredicateExecutor<User> {
}

The preceding example lets you write typesafe queries using Querydsl Predicate instances, as shown in the following example:

Predicate predicate = user.firstname.equalsIgnoreCase("dave")
	.and(user.lastname.startsWithIgnoreCase("mathews"));

userRepository.findAll(predicate);

How to use?

Add dependencies to you pom.xml

                <dependency>
			<groupId>io.easybest</groupId>
			<artifactId>spring-data-mybatis-querydsl</artifactId>
			<version>${revision}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.querydsl</groupId>
			<artifactId>querydsl-sql</artifactId>
			<version>${querydsl}</version>
			<optional>true</optional>
		</dependency>

spring-data-mybatis-querydsl use APT to generate query code

@easybest easybest self-assigned this Sep 1, 2020
@easybest easybest added this to the 2.0.2 milestone Sep 1, 2020
@kopax
Copy link

kopax commented Sep 3, 2020

Good afternoon @easybest,

I wanted to take your attention on #189 (comment) , from what I have learn in v1, it is not possible to migrate to v2 without any further notices.

We use a lot of @conditions coupled with XML before mappers in our spring-data-mybatis 1 application and so far, the example does not use before mappers (nor can execute all entities without errors).

I also take your attention on #215 (comment) , with a v2 documentation or v2 migration guide, this will solve #189, is there an estimated time of arrival for v2 documentation ?

Or before mappers completely removed ?

  • my definition of before mappers: part XML statement for mybatis where statement will be injected after the WHERE condition.

@easybest
Copy link
Owner Author

easybest commented Sep 5, 2020

before mapper just marked the mapper files been executed before spring data mybatis automatic generate mappers.
But in v2, it used mybatis starter from mybatis official, so you can define any mapper files if you want, and it will be added to the mybatis context before spring data mybatis, so theoretically, before mappers still can be used in a more reasonable way.
If you want, you can show me some part of your project, and let me see that how to migrate it from V1.

@conditions was marked as @Deprecated, it is not a good(normative) way to condition query. Instead of it, in v2, there's new ways to resolve the probleam.

  1. use spring data example query;
  2. use mybatis example query;
  3. use querydsl
    detail document is writing and it will be published in https://sdm.easybest.io/

@easybest
Copy link
Owner Author

easybest commented Sep 5, 2020

and in my roadmap, I will maintain the v1 version after v2 features completed, and v1 will migrate all new features from v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants