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

Added adapter class for entityManager #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
*/
package com.github.tennaito.rsql.jpa;

import javax.persistence.EntityManager;

import com.github.tennaito.rsql.builder.BuilderTools;
import com.github.tennaito.rsql.builder.SimpleBuilderTools;
import com.github.tennaito.rsql.misc.EntityManagerAdapter;

import cz.jirutka.rsql.parser.ast.RSQLVisitor;

Expand All @@ -40,7 +39,7 @@
* @param <T> Result type
* @param <E> Entity type
*/
public abstract class AbstractJpaVisitor<T, E> implements RSQLVisitor<T, EntityManager> {
public abstract class AbstractJpaVisitor<T, E> implements RSQLVisitor<T, EntityManagerAdapter> {

protected Class<E> entityClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import com.github.tennaito.rsql.misc.EntityManagerAdapter;

import cz.jirutka.rsql.parser.ast.AndNode;
import cz.jirutka.rsql.parser.ast.ComparisonNode;
import cz.jirutka.rsql.parser.ast.OrNode;
Expand All @@ -45,7 +46,7 @@
*
* @param <T> Entity type
*/
public class JpaCriteriaCountQueryVisitor<T> extends AbstractJpaVisitor<CriteriaQuery<Long>, T> implements RSQLVisitor<CriteriaQuery<Long>, EntityManager> {
public class JpaCriteriaCountQueryVisitor<T> extends AbstractJpaVisitor<CriteriaQuery<Long>, T> implements RSQLVisitor<CriteriaQuery<Long>, EntityManagerAdapter> {

private static final Logger LOG = Logger.getLogger(JpaCriteriaCountQueryVisitor.class.getName());

Expand Down Expand Up @@ -77,7 +78,7 @@ protected JpaPredicateVisitor<T> getPredicateVisitor() {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.AndNode, java.lang.Object)
*/
public CriteriaQuery<Long> visit(AndNode node, EntityManager entityManager) {
public CriteriaQuery<Long> visit(AndNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for AndNode: {0}", node);

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expand All @@ -92,7 +93,7 @@ public CriteriaQuery<Long> visit(AndNode node, EntityManager entityManager) {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.OrNode, java.lang.Object)
*/
public CriteriaQuery<Long> visit(OrNode node, EntityManager entityManager) {
public CriteriaQuery<Long> visit(OrNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for OrNode: {0}", node);

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expand All @@ -107,7 +108,7 @@ public CriteriaQuery<Long> visit(OrNode node, EntityManager entityManager) {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.ComparisonNode, java.lang.Object)
*/
public CriteriaQuery<Long> visit(ComparisonNode node, EntityManager entityManager) {
public CriteriaQuery<Long> visit(ComparisonNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for ComparisonNode: {0}", node);

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expand All @@ -127,4 +128,4 @@ public void setRoot(Root<T> root) {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;

import com.github.tennaito.rsql.misc.EntityManagerAdapter;

import cz.jirutka.rsql.parser.ast.AndNode;
import cz.jirutka.rsql.parser.ast.ComparisonNode;
import cz.jirutka.rsql.parser.ast.OrNode;
Expand All @@ -44,7 +45,7 @@
*
* @param <T> Entity type
*/
public class JpaCriteriaQueryVisitor<T> extends AbstractJpaVisitor<CriteriaQuery<T>, T> implements RSQLVisitor<CriteriaQuery<T>, EntityManager> {
public class JpaCriteriaQueryVisitor<T> extends AbstractJpaVisitor<CriteriaQuery<T>, T> implements RSQLVisitor<CriteriaQuery<T>, EntityManagerAdapter> {

private static final Logger LOG = Logger.getLogger(JpaCriteriaQueryVisitor.class.getName());

Expand Down Expand Up @@ -73,7 +74,7 @@ protected JpaPredicateVisitor<T> getPredicateVisitor() {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.AndNode, java.lang.Object)
*/
public CriteriaQuery<T> visit(AndNode node, EntityManager entityManager) {
public CriteriaQuery<T> visit(AndNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for AndNode: {0}", node);
CriteriaQuery<T> criteria = entityManager.getCriteriaBuilder().createQuery(entityClass);
From root = criteria.from(entityClass);
Expand All @@ -83,7 +84,7 @@ public CriteriaQuery<T> visit(AndNode node, EntityManager entityManager) {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.OrNode, java.lang.Object)
*/
public CriteriaQuery<T> visit(OrNode node, EntityManager entityManager) {
public CriteriaQuery<T> visit(OrNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for OrNode: {0}", node);
CriteriaQuery<T> criteria = entityManager.getCriteriaBuilder().createQuery(entityClass);
From root = criteria.from(entityClass);
Expand All @@ -93,7 +94,7 @@ public CriteriaQuery<T> visit(OrNode node, EntityManager entityManager) {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.ComparisonNode, java.lang.Object)
*/
public CriteriaQuery<T> visit(ComparisonNode node, EntityManager entityManager) {
public CriteriaQuery<T> visit(ComparisonNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating CriteriaQuery for ComparisonNode: {0}", node);
CriteriaQuery<T> criteria = entityManager.getCriteriaBuilder().createQuery(entityClass);
From root = criteria.from(entityClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Predicate;

import com.github.tennaito.rsql.misc.EntityManagerAdapter;

import cz.jirutka.rsql.parser.ast.AndNode;
import cz.jirutka.rsql.parser.ast.ComparisonNode;
import cz.jirutka.rsql.parser.ast.OrNode;
Expand All @@ -44,7 +45,7 @@
*
* @param <T> Entity type
*/
public class JpaPredicateVisitor<T> extends AbstractJpaVisitor<Predicate, T> implements RSQLVisitor<Predicate, EntityManager> {
public class JpaPredicateVisitor<T> extends AbstractJpaVisitor<Predicate, T> implements RSQLVisitor<Predicate, EntityManagerAdapter> {

/**
* Logger.
Expand Down Expand Up @@ -78,23 +79,23 @@ public JpaPredicateVisitor<T> defineRoot(From root) {
/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.AndNode, java.lang.Object)
*/
public Predicate visit(AndNode node, EntityManager entityManager) {
public Predicate visit(AndNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating Predicate for AndNode: {0}", node);
return PredicateBuilder.<T>createPredicate(node, root, entityClass, entityManager, getBuilderTools());
}

/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.OrNode, java.lang.Object)
*/
public Predicate visit(OrNode node, EntityManager entityManager) {
public Predicate visit(OrNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating Predicate for OrNode: {0}", node);
return PredicateBuilder.<T>createPredicate(node, root, entityClass, entityManager, getBuilderTools());
}

/* (non-Javadoc)
* @see cz.jirutka.rsql.parser.ast.RSQLVisitor#visit(cz.jirutka.rsql.parser.ast.ComparisonNode, java.lang.Object)
*/
public Predicate visit(ComparisonNode node, EntityManager entityManager) {
public Predicate visit(ComparisonNode node, EntityManagerAdapter entityManager) {
LOG.log(Level.INFO, "Creating Predicate for ComparisonNode: {0}", node);
return PredicateBuilder.<T>createPredicate(node, root, entityClass, entityManager, getBuilderTools());
}
Expand Down
Loading