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
package com.thanglequoc.decorator.starbuzz; | |
public enum BeverageSize { | |
SMALL("Small"), | |
MEDIUM("Medium"), | |
LARGE("Large"); | |
private String literal; | |
BeverageSize(String literal){ |
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
{"lastUpload":"2018-03-20T15:38:12.734Z","extensionVersion":"v2.9.0"} |
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
{ | |
CriteriaBuilder qb = entityManager.getCriteriaBuilder(); | |
CriteriaQuery<Long> cq = qb.createQuery(Long.class); | |
cq.select(qb.count(cq.from(MyEntity.class))); | |
cq.where(/*your stuff*/); | |
return entityManager.createQuery(cq).getSingleResult(); | |
} |
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
/*SELECT e | |
FROM Employee e | |
WHERE e.id IN (SELECT emp.id | |
FROM Project p JOIN p.employees emp | |
WHERE p.name = :project) | |
*/ | |
CriteriaBuilder cb = em.getCriteriaBuilder(); | |
CriteriaQuery<Employee> c = cb.createQuery(Employee.class); | |
Root<Employee> emp = c.from(Employee.class); |
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
//SELECT a FROM A a, B b WHERE a.someField = b.otherField ORDER BY b.anotherField | |
CriteriaBuilder cb = emf.getCriteriaBuilder(); | |
CriteriaQuery<A> crit = cb.createQuery(A.class); | |
Root<A> aRoot = crit.from(A.class); | |
Root<B> bRoot = crit.from(B.class); | |
aRoot.alias("a"); | |
bRoot.alias("b"); | |
crit.select(aRoot); |
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
Something simple like this can be done using subqueries in the select clause: | |
select ((select sum(hours) from resource) + | |
(select sum(hours) from projects-time) | |
) as totalHours | |
For such a simple query as this, such a subselect is reasonable. | |
In some databases, you might have to add from dual for the query to compile. | |
If you want to output each individually: |
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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.function.Function; | |
import java.util.function.Predicate; | |
//www . ja va 2 s .c om | |
public class Main { | |
public static void main(String[] args) { | |
List<Student> employees = Arrays.asList( | |
new Student(1, 3, "John"), |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.github.thanglequoc.junit5</groupId> | |
<artifactId>junit5</artifactId> | |
<version>0.0.1-SNAPSHOT</version> |
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
public void doReflectionMagic() { | |
Method method = ldapUserCache.getClass().getDeclaredMethod("initActiveUsers", Long.TYPE); | |
method.setAccessible(true); | |
method.invoke(ldapUserCache, 3600L); | |
} |
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
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | |
CriteriaQuery<Employee> q = cb.createQuery(Employee.class); | |
Root<Employee> root = q.from(Employee.class); | |
q.select(root); | |
List<String> parentList = Arrays.asList(new String[]{"John", "Raj"}); | |
Expression<String> parentExpression = root.get(Employee_.Parent); |
OlderNewer