-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from axelsean/master
Added BigDecimal and Date support (from fstn), also embedded mapping
- Loading branch information
Showing
22 changed files
with
474 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
src/main/java/com/github/tennaito/rsql/builder/BuilderTools.java
100644 → 100755
Empty file.
Empty file modified
0
src/main/java/com/github/tennaito/rsql/builder/SimpleBuilderTools.java
100644 → 100755
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/main/java/com/github/tennaito/rsql/jpa/JpaCriteriaCountQueryVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2015 Antonio Rabelo. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.github.tennaito.rsql.jpa; | ||
|
||
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 cz.jirutka.rsql.parser.ast.AndNode; | ||
import cz.jirutka.rsql.parser.ast.ComparisonNode; | ||
import cz.jirutka.rsql.parser.ast.OrNode; | ||
import cz.jirutka.rsql.parser.ast.RSQLVisitor; | ||
|
||
/** | ||
* JpaCriteriaQueryVisitor | ||
* | ||
* Visitor class for Criteria Query count creation from RSQL AST Nodes. | ||
* | ||
* @author sza | ||
* | ||
* @param <T> Entity type | ||
*/ | ||
public class JpaCriteriaCountQueryVisitor<T> extends AbstractJpaVisitor<CriteriaQuery<Long>, T> implements RSQLVisitor<CriteriaQuery<Long>, EntityManager> { | ||
|
||
private static final Logger LOG = Logger.getLogger(JpaCriteriaCountQueryVisitor.class.getName()); | ||
|
||
private final JpaPredicateVisitor<T> predicateVisitor; | ||
|
||
private Root<T> root; | ||
|
||
/** | ||
* Construtor with template varargs for entityClass discovery. | ||
* | ||
* @param t not for usage | ||
*/ | ||
@SafeVarargs | ||
public JpaCriteriaCountQueryVisitor(T... t) { | ||
super(t); | ||
this.predicateVisitor = new JpaPredicateVisitor<T>(t); | ||
} | ||
|
||
/** | ||
* Get the Predicate Visitor instance. | ||
* | ||
* @return Return the Predicate Visitor. | ||
*/ | ||
protected JpaPredicateVisitor<T> getPredicateVisitor() { | ||
this.predicateVisitor.setBuilderTools(this.getBuilderTools()); | ||
return this.predicateVisitor; | ||
} | ||
|
||
/* (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) { | ||
LOG.log(Level.INFO, "Creating CriteriaQuery for AndNode: {0}", node); | ||
|
||
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Long> cq = cb.createQuery(Long.class); | ||
root = cq.from(entityClass); | ||
cq.select(cb.countDistinct(root)); | ||
cq.where(this.getPredicateVisitor().defineRoot(root).visit(node, entityManager)); | ||
|
||
return cq; | ||
} | ||
|
||
/* (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) { | ||
LOG.log(Level.INFO, "Creating CriteriaQuery for OrNode: {0}", node); | ||
|
||
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Long> cq = cb.createQuery(Long.class); | ||
root = cq.from(entityClass); | ||
cq.select(cb.countDistinct(root)); | ||
root = cq.from(entityClass); | ||
cq.where(this.getPredicateVisitor().defineRoot(root).visit(node, entityManager)); | ||
return cq; | ||
} | ||
|
||
/* (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) { | ||
LOG.log(Level.INFO, "Creating CriteriaQuery for ComparisonNode: {0}", node); | ||
|
||
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Long> cq = cb.createQuery(Long.class); | ||
root = cq.from(entityClass); | ||
cq.select(cb.countDistinct(root)); | ||
cq.where(this.getPredicateVisitor().defineRoot(root).visit(node, entityManager)); | ||
return cq; | ||
} | ||
|
||
public Root<T> getRoot() { | ||
return root; | ||
} | ||
|
||
public void setRoot(Root<T> root) { | ||
this.root = root; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
src/main/java/com/github/tennaito/rsql/jpa/JpaPredicateVisitor.java
100644 → 100755
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilderStrategy.java
100644 → 100755
Empty file.
Empty file modified
0
src/main/java/com/github/tennaito/rsql/misc/ArgumentFormatException.java
100644 → 100755
Empty file.
Empty file modified
0
src/main/java/com/github/tennaito/rsql/misc/ArgumentParser.java
100644 → 100755
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
src/main/java/com/github/tennaito/rsql/parser/ast/ComparisonOperatorProxy.java
100644 → 100755
Empty file.
Oops, something went wrong.