use of org.eclipse.persistence.testing.models.jpa.inherited.Blue in project eclipselink by eclipse-ee4j.
the class CriteriaQueryCastTestSuite method testDowncastSingleTableQueryKey.
public void testDowncastSingleTableQueryKey() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("John");
em.persist(consumer);
Blue blue = new Blue();
blue.setAlcoholContent(5f);
blue.setUniqueKey(new BigInteger("4531"));
em.persist(blue);
BlueLight blueLight = new BlueLight();
blueLight.setDiscount(10);
blueLight.setUniqueKey(new BigInteger("4533"));
em.persist(blueLight);
consumer.addBlueBeerToConsume(blueLight);
blueLight.setBeerConsumer(consumer);
consumer.addBlueBeerToConsume(blue);
consumer.addBlueBeerToConsume(blueLight);
consumer = new BeerConsumer();
consumer.setName("Frank");
em.persist(consumer);
blueLight = new BlueLight();
blueLight.setDiscount(5);
blueLight.setUniqueKey(new BigInteger("4532"));
em.persist(blueLight);
consumer.addBlueBeerToConsume(blueLight);
blueLight.setBeerConsumer(consumer);
em.flush();
clearCache();
em.clear();
// Query query = em.createQuery("Select b from BeerConsumer b join treat(b.blueBeersToConsume as BlueLight) bl where bl.discount = 10");
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<BeerConsumer> cq = qb.createQuery(BeerConsumer.class);
Root<BeerConsumer> root = cq.from(BeerConsumer.class);
Join<Object, BlueLight> blueLightJoin = qb.treat(root.join("blueBeersToConsume"), BlueLight.class);
cq.where(qb.equal(blueLightJoin.get("discount"), 10));
List<BeerConsumer> resultList = em.createQuery(cq).getResultList();
assertTrue("Incorrect results returned", resultList.size() == 1);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Blue in project eclipselink by eclipse-ee4j.
the class CriteriaQueryCastTestSuite method testDowncastSingleTableQueryKey.
public void testDowncastSingleTableQueryKey() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("John");
em.persist(consumer);
Blue blue = new Blue();
blue.setAlcoholContent(5f);
blue.setUniqueKey(new BigInteger("4531"));
em.persist(blue);
BlueLight blueLight = new BlueLight();
blueLight.setDiscount(10);
blueLight.setUniqueKey(new BigInteger("4533"));
em.persist(blueLight);
consumer.addBlueBeerToConsume(blueLight);
blueLight.setBeerConsumer(consumer);
consumer.addBlueBeerToConsume(blue);
consumer.addBlueBeerToConsume(blueLight);
consumer = new BeerConsumer();
consumer.setName("Frank");
em.persist(consumer);
blueLight = new BlueLight();
blueLight.setDiscount(5);
blueLight.setUniqueKey(new BigInteger("4532"));
em.persist(blueLight);
consumer.addBlueBeerToConsume(blueLight);
blueLight.setBeerConsumer(consumer);
em.flush();
clearCache();
em.clear();
// Query query = em.createQuery("Select b from BeerConsumer b join treat(b.blueBeersToConsume as BlueLight) bl where bl.discount = 10");
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<BeerConsumer> cq = qb.createQuery(BeerConsumer.class);
Root<BeerConsumer> root = cq.from(BeerConsumer.class);
Join blueLightJoin = qb.treat(root.join("blueBeersToConsume"), BlueLight.class);
cq.where(qb.equal(blueLightJoin.get("discount"), 10));
List resultList = em.createQuery(cq).getResultList();
assertTrue("Incorrect results returned", resultList.size() == 1);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Blue in project eclipselink by eclipse-ee4j.
the class JUnitCriteriaSimpleTestSuiteBase method mapCastTest.
public void mapCastTest() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer bc1 = new BeerConsumer();
bc1.setName("George");
em.persist(bc1);
Blue blue = new Blue();
blue.setUniqueKey(new BigInteger("1"));
em.persist(blue);
bc1.addBlueBeerToConsume(blue);
blue.setBeerConsumer(bc1);
BeerConsumer bc2 = new BeerConsumer();
bc2.setName("Scott");
em.persist(bc2);
BlueLight blueLight = new BlueLight();
blueLight.setDiscount(10);
blueLight.setUniqueKey(new BigInteger("2"));
em.persist(blueLight);
blueLight.setBeerConsumer(bc2);
bc2.addBlueBeerToConsume(blueLight);
em.flush();
em.clear();
clearCache();
ReadAllQuery query = new ReadAllQuery();
Expression selectionCriteria = new ExpressionBuilder().anyOf("blueBeersToConsume").treat(BlueLight.class).get("discount").equal(10);
query.setSelectionCriteria(selectionCriteria);
query.setReferenceClass(BeerConsumer.class);
query.dontUseDistinct();
Query jpaQuery = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em.getDelegate()).createQuery(query);
List expectedResult = jpaQuery.getResultList();
clearCache();
em.clear();
// "SELECT e from Employee e join cast(e.project, LargeProject) p where p.budget = 1000
CriteriaBuilder qb1 = em.getCriteriaBuilder();
CriteriaQuery<BeerConsumer> cq1 = qb1.createQuery(BeerConsumer.class);
Root<BeerConsumer> root = wrapper.from(cq1, BeerConsumer.class);
Join<BeerConsumer, Blue> join = wrapper.join(root, BeerConsumer_blueBeersToConsume);
jakarta.persistence.criteria.Expression exp = wrapper.get((Path) join.as(BlueLight.class), BlueLight_discount);
cq1.where(qb1.equal(exp, 10));
List<BeerConsumer> result = em.createQuery(cq1).getResultList();
assertTrue("LargeProject cast failed.", comparer.compareObjects(result, expectedResult));
} finally {
if (isTransactionActive(em)) {
this.rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Blue in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method mapContainerPolicyMapValueInSelectionCriteriaTest.
public void mapContainerPolicyMapValueInSelectionCriteriaTest() {
// skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Marvin Monroe");
em.persist(consumer);
Blue blue = new Blue();
blue.setAlcoholContent(5.0f);
blue.setUniqueKey(BigInteger.ONE);
consumer.addBlueBeerToConsume(blue);
em.persist(blue);
BeerConsumer consumer2 = new BeerConsumer();
consumer2.setName("Marvin Monroe2");
em.persist(consumer2);
Blue blue2 = new Blue();
blue2.setAlcoholContent(5.0f);
blue2.setUniqueKey(BigInteger.valueOf(2));
consumer2.addBlueBeerToConsume(blue2);
em.persist(blue2);
em.flush();
Vector expectedResult = new Vector();
expectedResult.add(consumer);
clearCache();
String ejbqlString = "SELECT bc FROM BeerConsumer bc join bc.blueBeersToConsume b where VALUE(b).uniqueKey = 1";
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("mapContainerPolicyMapValueInSelectionCriteriaTest failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Blue in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method mapContainerPolicyMapKeyInSelectTest.
public void mapContainerPolicyMapKeyInSelectTest() {
// skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Marvin Monroe");
em.persist(consumer);
Blue blue = new Blue();
blue.setAlcoholContent(5.0f);
blue.setUniqueKey(BigInteger.ONE);
consumer.addBlueBeerToConsume(blue);
em.persist(blue);
BeerConsumer consumer2 = new BeerConsumer();
consumer2.setName("Marvin Monroe2");
em.persist(consumer2);
Blue blue2 = new Blue();
blue2.setAlcoholContent(5.0f);
blue2.setUniqueKey(BigInteger.valueOf(2));
consumer2.addBlueBeerToConsume(blue2);
em.persist(blue2);
em.flush();
Vector expectedResult = new Vector();
expectedResult.add(BigInteger.ONE);
clearCache();
String ejbqlString = "SELECT KEY(b) FROM BeerConsumer bc join bc.blueBeersToConsume b where bc.name = 'Marvin Monroe'";
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("mapContainerPolicyMapKeyInSelectTest failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
Aggregations