
com.aspectran.jpa.querydsl.EntityQuery Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2025 The Aspectran Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aspectran.jpa.querydsl;
import com.aspectran.core.component.bean.annotation.Advisable;
import com.aspectran.jpa.EntityManagerAgent;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.EntityPath;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPQLQueryFactory;
import com.querydsl.jpa.JPQLTemplates;
import com.querydsl.jpa.impl.JPADeleteClause;
import com.querydsl.jpa.impl.JPAInsertClause;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAUpdateClause;
/**
* A unified implementation of the EntityManager and JPQLQueryFactory interfaces.
*
* Created: 2025-04-24
*/
public class EntityQuery extends EntityManagerAgent implements JPQLQueryFactory {
private JPQLTemplates templates;
public EntityQuery(String relevantAspectId) {
super(relevantAspectId);
}
public void setTemplates(JPQLTemplates templates) {
this.templates = templates;
}
@Advisable
@Override
public JPADeleteClause delete(EntityPath> path) {
getEntityManagerAdvice().transactional();
if (templates != null) {
return new JPADeleteClause(getEntityManager(), path, templates);
} else {
return new JPADeleteClause(getEntityManager(), path);
}
}
@Advisable
@Override
public JPAQuery select(Expression expr) {
return query().select(expr);
}
@Advisable
@Override
public JPAQuery select(Expression>... exprs) {
return query().select(exprs);
}
@Advisable
@Override
public JPAQuery selectDistinct(Expression expr) {
return select(expr).distinct();
}
@Advisable
@Override
public JPAQuery selectDistinct(Expression>... exprs) {
return select(exprs).distinct();
}
@Advisable
@Override
public JPAQuery selectOne() {
return select(Expressions.ONE);
}
@Advisable
@Override
public JPAQuery selectZero() {
return select(Expressions.ZERO);
}
@Advisable
@Override
public JPAQuery selectFrom(EntityPath from) {
return select(from).from(from);
}
@Advisable
@Override
public JPAQuery> from(EntityPath> from) {
return query().from(from);
}
@Advisable
@Override
public JPAQuery> from(EntityPath>... from) {
return query().from(from);
}
@Advisable
@Override
public JPAUpdateClause update(EntityPath> path) {
getEntityManagerAdvice().transactional();
if (templates != null) {
return new JPAUpdateClause(getEntityManager(), path, templates);
} else {
return new JPAUpdateClause(getEntityManager(), path);
}
}
@Advisable
@Override
public JPAInsertClause insert(EntityPath> path) {
getEntityManagerAdvice().transactional();
if (templates != null) {
return new JPAInsertClause(getEntityManager(), path, templates);
} else {
return new JPAInsertClause(getEntityManager(), path);
}
}
@Advisable
@Override
public JPAQuery> query() {
if (templates != null) {
return new JPAQuery(getEntityManager(), templates);
} else {
return new JPAQuery(getEntityManager());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy