Coder Social home page Coder Social logo

openfeign / querydsl Goto Github PK

View Code? Open in Web Editor NEW
219.0 12.0 36.0 55.76 MB

Unified Queries for Java

Home Page: https://querydsl.com

License: Apache License 2.0

Shell 0.05% Ruby 0.01% Java 96.42% Scala 1.81% Clojure 0.03% Puppet 0.02% Kotlin 1.08% XSLT 0.48% CSS 0.05% Dockerfile 0.01% HTML 0.07%

querydsl's Introduction

Querydsl

Querydsl is a framework which enables the construction of type-safe SQL-like queries for multiple backends including JPA, MongoDB and SQL in Java.

Instead of writing queries as inline strings or externalizing them into XML files they are constructed via a fluent API.

Querydsl Maven Central

Why forking?

Querydsl is at best stale, at worse dead. By the time I made this fork, last commit was one year old and last release over 2 years old.

I reach out to the queryDSL team, but, honestly, they don't care.

Why forking under openfeign?

Well, openfeign is already stabilished and having querydsl under it gives a better idea on how committed I am on keeping the lights on.

What's next?

Initial goals accomplished.

We now have a stable fork with regular releases. Patches from community are happening and this project is moving idenpendently.

I'm here to help those who help themselves.

What does it mean?

  • If you send a PR, I will review, give an honest feedback, merge as soon I'm happy with it, and release as soon it's practical.
  • If you create an issue, well, I'm unlikely to get involved.

I dedicate some of my free time to this project, so I will favor people that are contributing to it.

What is the endgame?

Get a querydsl project active! May be as a fork, may be as a wake up call to present querydsl project. If querydsl team gets their act thogether and pick up maintaining the project, this fork will most likely be archived. If the want my help (which they don't at the present time) I can help.

I need feature X? Or bug Z fixed?

Well, you will need to get your hands dirty. I might fix bugs or create features, but mostly when they affect my day job. Sorry, just a single guy here doing free work on spare time.

Getting started

Use these tutorials to get started

Examples

Querydsl example projects

Support

Free support is provided in the Discussion Section and on StackOverflow. Please do not post questions as issue. Such issues will be closed immediately.

How to build

Querydsl provides releases via public Maven repositories, but you can also build the sources yourself like this

$ mvn -Pquickbuild,{projectname} clean install

Where projectname is one of the Maven profiles (e.g. jpa, sql, mongodb, etc. or all)

For more information visit the project homepage at https://querydsl.github.io.

Docker Compose setup

For running tests, a Docker Compose setup is provided. It comes with the following databases:

  • Oracle Express Edition 11g
  • PostgreSQL 16
  • MySQL 5.5.34
  • Cubrid 9.2

You will need to install Docker and docker-compose.

To launch the database containers:

$ docker-compose up -d

All of the databases' default ports are forwarded to the host machine.

How to contribute

GitHub pull requests are the way to contribute to Querydsl.

If you are unsure about the details of a contribution, ask on the Querydsl Google Group or create a ticket on GitHub.

Slack

If you want to join Slack workspace for Querydsl contributors join by following this link.

querydsl's People

Contributors

attila-kiss-it avatar balazs-zsoldos avatar bbakerman avatar borgiiri avatar capital5 avatar daniel-shuy avatar dependabot[bot] avatar dharaburda avatar f43nd1r avatar heniu20 avatar idosal avatar jendap avatar johnktims avatar jtsay362 avatar jwgmeligmeyling avatar khauser avatar lpandzic avatar mcuelenaere avatar mdiazf avatar mp911de avatar natros avatar plondrein avatar rdicroce avatar rdnetto4 avatar robertandrewbain avatar shredder121 avatar timowest avatar tuomaskiviaho avatar velo avatar viniciuspires avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

querydsl's Issues

No Q-Classes are generated since Spring Boot 3.0 Upgrade

May also see this issue in the main project:
querydsl/querydsl#3651

I am so happy that you guys forked the project.

So since I have loads of problems with querydsl since Spring 3.0 upgrade, I thought its may an good Idea to test it with your fork (6.0.0.M3). However when I add your fork, I come back to the problem, that the Q-Classes for my "QueryEntity" annotated classes are not generated.

Here some basics of my environment:

Spring Boot 3.0.13
Spring Cloud 2022.0.3
Java 17.0.7
Gradle 8.5 (gradle wrapper)

Querydsl version: 6.0.0.M3

Querydsl module: querydsl-mongodb

Database: mongodb

JDK: 17

I hope that someone here may could help me.

5.4 release

Hey, would it be possible to release new version from 5.0.0 branch? :)

On JDK 21, error: The reference to StringTemplate is ambiguous.

Problem Description:

In jdk21, if the following code snippet is used:

import com.querydsl.core.annotations.QueryDelegate;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.SimpleExpression;
import com.querydsl.core.types.dsl.StringTemplate;

public class QueryExtensions {

  @QueryDelegate(String.class)
  public static StringTemplate gc(SimpleExpression<String> expression) {
    return Expressions.stringTemplate("group_concat({0})", expression);
  }
}

An error will occur: Ambiguous reference to StringTemplate

Source code analysis:

The location of the relevant source code to generate the Q class is:

protected void introImports(CodeWriter writer, SerializerConfig config, EntityType model)
throws IOException {
writer.staticimports(PathMetadataFactory.class);
// import package of query type
Type queryType = typeMappings.getPathType(model, model, true);
if (!model.getPackageName().isEmpty()
&& !queryType.getPackageName().equals(model.getPackageName())
&& !queryType.getSimpleName().equals(model.getSimpleName())) {
String fullName = model.getFullName();
String packageName = model.getPackageName();
if (fullName.substring(packageName.length() + 1).contains(".")) {
fullName = fullName.substring(0, fullName.lastIndexOf('.'));
}
writer.importClasses(fullName);
}
// delegate packages
introDelegatePackages(writer, model);
// other packages
writer.imports(SimpleExpression.class.getPackage());
// other classes
List<Class<?>> classes = new ArrayList<>();
classes.add(PathMetadata.class);
classes.add(generatedAnnotationClass);
if (!getUsedClassNames(model).contains("Path")) {
classes.add(Path.class);
}
if (!model.getConstructors().isEmpty()) {
classes.add(ConstructorExpression.class);
classes.add(Projections.class);
classes.add(Expression.class);
}
boolean inits = false;
if (model.hasEntityFields() || model.hasInits()) {
inits = true;
} else {
Set<TypeCategory> collections =
EnumSet.of(TypeCategory.COLLECTION, TypeCategory.LIST, TypeCategory.SET);
for (Property property : model.getProperties()) {
if (!property.isInherited() && collections.contains(property.getType().getCategory())) {
inits = true;
break;
}
}
}
if (inits) {
classes.add(PathInits.class);
}
writer.imports(classes.toArray(new Class<?>[0]));
}
private Set<String> getUsedClassNames(EntityType model) {
Set<String> result = new HashSet<>();
result.add(model.getSimpleName());
for (Property property : model.getProperties()) {
result.add(property.getType().getSimpleName());
for (Type type : property.getType().getParameters()) {
if (type != null) {
result.add(type.getSimpleName());
}
}
}
return result;
}

Especially this line of code:

// other packages
writer.imports(SimpleExpression.class.getPackage());

The code it generates is:

import com.querydsl.core.types.dsl.*;

but missing com.querydsl.core.types.dsl.StringTemplate

Possible solutions:

Add after line 488:

// com.querydsl.core.types.dsl.StringTemplate
writer.importClasses("com.querydsl.core.types.dsl.StringTemplate");

The generated code will be:

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.dsl.StringTemplate;

Missing META-INF/services/javax.annotation.processing.Processor in 6.0 apt jar file

The file META-INF/services/javax.annotation.processing.Processor is missing from the jar files in querydsl-apt-6.0.0.M3.jar it is there in version 5.1.1. In 5.1.1 and earlier versions the annotation processor was auto detected by the maven compiler plugin but now it has to be specified with

<annotationProcessors>
  <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</annotationProcessors>

Gradle working example

Hello,

I spent a few hours trying to get a project running with this version of QueryDSL. My project basically works with queryDsl v4. I'd like to update it, but I've tried everything I can't found on the Internet but and I can't get my Q classes generated with V5 and grandle. The examples on the repo are in Maven only unfortunately.

Is it possible to get help to have a minimal project that generates Q classes with Gradle?

I think it will help other people. Thanks for everything!

Could give an example for multi data source for query dsl sql codegen?

I want to use query dsl sql in spring, but we using multi data source in application.

<configuration>
    <jdbcDriver>org.apache.derby.jdbc.EmbeddedDriver</jdbcDriver>
    <jdbcUrl>jdbc:derby:target/demoDB;create=true</jdbcUrl>
    <packageName>com.myproject.domain</packageName>
    <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
</configuration>

So this example not suitable for me, I want to generator multi data source in application like mybatis generator.

About this fork!

First, thanks you for maintaining this great library.

Can you please, if possible, create this project as a fork to the official querydsl project? This makes this project more discoverable. It also help in comparing changes and finding open issues. (Maybe, this requires to delete or rename it, and create a fork, than push your changes again.)

In the readme, you say, that the querydsl project is not interested in your maintenance. Do you have any links?

R2DBC connection not released back to the pool

Existing implementation of AbstractR2DBCQuery.fetch() and unsafeCount() takes an existing connection from the connection provider and uses it, in case if a connection pool is used, the connections are never closed

return getConnection() .flatMapMany( conn -> { ...});

A way to handle the close connection (returning it to the pool)

return Flux.usingWhen(getConnection(), conn -> { ...}, Connection::close);

Is there a way to close the connection from the connection provider in case if a connection pool is used?

JPA + custom type + Number + NumberExpression throws IllegalArgument Unsupported target type

Observed vs. expected behavior

(This is a continuation from the original QueryDSL issue #3550)

When using the following Combination

  • a custom type extending Number (imho this seems to trigger the strange behavior)
  • a custom @Converter/AttributeConverter (also happens with all other Hibernate custom types like UserType)
  • a NumberExpression in the JPAQuery: sumAggregate() (formerly: sum())

Example:

var result = new JPAQuery<>(em)
		.select(myEntity.myCustomNumber.sumAggregate())
		.from(myEntity)
		.fetchOne();

Actual outcome:

java.lang.IllegalArgumentException: Unsupported target type : MyCustomNumber is thrown instead of a valid result.

Expected outcome:

The query-result.

Steps to reproduce

I created a reproducer with unit tests showing what works and what doesn't:
https://github.com/dvbern/bug-reproducers-querydsl-jpa-hibernate6/tree/openfeign

Environment

Querydsl version: 6.0.0.RC1

Querydsl module: querydsl-jpa

Database: any (e.g. hsqldb, postgresql)

JDK: 17 (but the stacktrace indicates this is not a JDK-problem)

[Question] Why the APT Code generation process is needed ?

Hello,
I've been studying Querydsl's source code for a few days, and I've come to a question and I'd like to ask you a question!

Currently, Querydsl relies on Hibernate's Query interface and also includes the creation of QClass files at build time.
(A rough look at other similar libraries also showed that there must be an additional build-time code generation process.)

However, looking at ORMs such as Kotlin's Exposed, I found that there are technologies that do not include the code generation process separately and rely on JPA EntityManager's create query method rather than Hibernate.

In Querydsl, I thought that it would be easier to process without the code generation process if I used the create query method by reading and parsing the information of the entity and its fields using the Reflection API.

Is there something I'm missing?
(maybe it's because of the fundamental difference between java and kotlin that I don't know...?)

I'd like you to tell me why the APT code generation process is necessary in Querydsl ! ๐Ÿ˜ƒ

new Spring Data Scrolling API support

Will You guys support the new Spring Data Scrolling API with QueryDsl?
Something like:

Window<Resource> findAllBy(Predicate predicate, ScrollPosition position, Limit limit, Sort sort);

Re-open method SqlQuery#Q from(Expression<?> arg) as public

I used to be able to set FROM with basic "Expression<?>" objects.

In ProjectableSQLQuery

public Q from(Expression<?> arg) {
  return queryMixin.from(arg);
}

But with the fix from issue #251 this signature has been made protected.
My main usage is calling it with Template expressions with Oracle's procedure call, generating an sql like SELECT ... FROM TABLE(PROCEDURE(...)) a by passing Expression.template(Tuple.class, "TABLE(PROCEDURE(...)") to the method.

Maybe i'm missing something and this can translated to a RelationalPath ? (because is see that from(RelationalPath<?> arg) is supposed to be the new way of setting the from expression)

I'm using QueryDSL SQL without JPA BTW

update morphia version

the latest morphia lib is 2.4.x , but querydsl still using a very old version 1.3.2 , seven years old.

the new morphia library has change a lot , and all the example of MorphiaQuery usage is outdated.

old version:

<dependency>
    <groupId>org.mongodb.morphia</groupId>
    <artifactId>morphia</artifactId>
    <version>1.3.2</version>
</dependency>

new version:

<dependency>
    <groupId>dev.morphia.morphia</groupId>
    <artifactId>morphia-core</artifactId>
    <version>2.4.14</version>
</dependency>

Support query delegates on collection classes

Originally filed as querydsl/querydsl#3327

@QueryDelegate is a powerful feature that does not work properly with collections. QueryDSL creates Q-classes, but they extend BeanPath. As a result, one can't use expressions already available in these classes and can't pass appropriately typed Path parameters to custom extensions.

Actual:

public class QSet extends BeanPath<Set<?>> {
  ...
}

Expected:

public class QSet<V, E extends SimpleExpression<V>> extends SetPath<V, E> {
  ...
} 

public class QEntity extends BeanPath<Entity> {
  public final QSet<String, ext.java.lang.QString> s = 
    new QSet<String, ext.java.lang.QString>(forProperty("s"));
}

I tried to tinker around the annotation processor, but it does not look like it generally supports the generation of parameterized classes.

Avoid depending on Spring Data and Spring Boot

Querydsl is an upstream dependency of both Spring Data and Spring Boot. Therefore, introducing a dependency back on released versions of either of the two constitutes a cyclic dependency between the projects that is very likely to create versioning and compatibility problems for users going forward.

It would be nice if those dependencies would be removed and integration โ€“ if needed and feasible โ€“ was moved to the downstream projects.

Querydsl generates classes that throw compiler warnings since JDK 21

As mentioned in querydsl/querydsl#3606 (comment):

Observed vs. expected behavior
If I compile generates by QueryDSL 5.0 classes I see JDK 21 compiler throw a lot of warnings like:

QAuditableEntity.java:[32,70] possible 'this' escape before subclass is fully initialized
All of them come from new Xlint option called this-escape, so I would propose either fix that by not calling overridable methods from constructors or adding @SuppressWarnings("this-escape") to all generated constructors.

Steps to reproduce
Have a project with any JPA entity and generate QueryDSL code for it.
Use JDK 21 compiler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.