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

Require native queries to be executed from native expressions #251

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractSQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.querydsl.jpa.domain.Cat;
import com.querydsl.jpa.domain.Color;
import com.querydsl.jpa.domain.QCat;
import com.querydsl.jpa.domain.QCompany;
import com.querydsl.jpa.domain.sql.SAnimal_;
import com.querydsl.jpa.domain.sql.SCompany_;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -111,8 +111,14 @@ public void entityQueries2() {

@Test
public void entityQueries3() {
QCat catEntity = new QCat("animal_");
assertThat(query().from(catEntity).select(catEntity.toes.max()).fetchFirst().intValue())
SAnimal_ catEntity = new SAnimal_("animal_");
assertThat(
query()
.from(catEntity)
.select(catEntity.toes.max())
.where(catEntity.dtype.eq("C"))
.fetchFirst()
.intValue())
.isEqualTo(0);
}

Expand Down Expand Up @@ -163,7 +169,7 @@ public void entityQueries6() {

@Test
public void entityQueries7() {
QCompany company = QCompany.company;
SCompany_ company = SCompany_.company_;
assertThat(query().from(company).select(company.officialName).fetch())
.isEqualTo(Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.querydsl.jpa.domain.QAnimal;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.querydsl.sql.SQLExpressions;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import java.util.Date;
Expand Down Expand Up @@ -156,7 +155,7 @@ public void insert4() {
.insert(QAnimal.animal)
.columns(QAnimal.animal.id, QAnimal.animal.birthdate)
.select(
SQLExpressions.select(QAnimal.animal.id, QAnimal.animal.birthdate)
JPAExpressions.select(QAnimal.animal.id, QAnimal.animal.birthdate)
.from(QAnimal.animal));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait SQL extends SQLHelpers {

def query() = new SQLQuery(connection, templates)

def from(expr: Expression[_]*) = query.from(expr:_*)
def from(expr: RelationalPath[_]*) = query.from(expr:_*)

def insert(path: RelationalPath[_]) = new SQLInsertClause(connection, templates, path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public final SQLDeleteClause delete(RelationalPath<?> path) {

@SuppressWarnings("unchecked")
@Override
public final Q from(Expression<?> from) {
public final Q from(RelationalPath<?> from) {
return (Q) query().from(from);
}

@SuppressWarnings("unchecked")
@Override
public final Q from(Expression<?>... args) {
public final Q from(RelationalPath<?>... args) {
return (Q) query().from(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,21 @@ public long fetchCount() {
return ((Number) fetchOne()).longValue();
}

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

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

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

@Override
public Q from(Expression<?>... args) {
public Q from(RelationalPath<?>... args) {
return queryMixin.from(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public interface SQLCommonQuery<Q extends SQLCommonQuery<Q>> extends Query<Q> {
* @param o from
* @return the current object
*/
Q from(Expression<?>... o);
Q from(RelationalPath<?>... o);

/**
* Adds a sub query source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.querydsl.sql;

import com.querydsl.core.QueryFactory;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.SubQueryExpression;
import com.querydsl.sql.dml.SQLDeleteClause;
Expand Down Expand Up @@ -57,15 +56,15 @@ public interface SQLCommonQueryFactory<
* @param from query source
* @return query
*/
Q from(Expression<?> from);
Q from(RelationalPath<?> from);

/**
* Create a new SELECT query
*
* @param from query sources
* @return query
*/
Q from(Expression<?>... from);
Q from(RelationalPath<?>... from);

/**
* Create a new SELECT query
Expand Down
Loading