mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
66 lines
2.1 KiB
Java
66 lines
2.1 KiB
Java
/*
|
|
* Copyright (c) 2010 Mysema Ltd.
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
package com.mysema.query.jpa;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import org.junit.Test;
|
|
|
|
import com.mysema.query.BooleanBuilder;
|
|
|
|
public class BooleanOperationsTest extends AbstractQueryTest {
|
|
|
|
@Test
|
|
public void BooleanOperations() {
|
|
assertToString("cust is null or cat is null", cust.isNull().or(cat.isNull()));
|
|
assertToString("cust is null and cat is null", cust.isNull().and(cat.isNull()));
|
|
assertToString("not (cust is null)", cust.isNull().not());
|
|
cat.name.eq(cust.name.firstName).and(cat.bodyWeight.eq(kitten.bodyWeight));
|
|
cat.name.eq(cust.name.firstName).or(cat.bodyWeight.eq(kitten.bodyWeight));
|
|
}
|
|
|
|
@Test
|
|
public void LogicalOperations() {
|
|
// logical operations and, or, not
|
|
assertToString("cat = kitten or kitten = cat", cat.eq(kitten).or(kitten.eq(cat)));
|
|
assertToString("cat = kitten and kitten = cat", cat.eq(kitten).and(kitten.eq(cat)));
|
|
assertToString("cat is null and (kitten is null or kitten.bodyWeight > :a1)",
|
|
cat.isNull().and(kitten.isNull().or(kitten.bodyWeight.gt(10))));
|
|
}
|
|
|
|
@Test
|
|
public void BooleanBuilder1(){
|
|
BooleanBuilder bb1 = new BooleanBuilder();
|
|
bb1.and(cat.eq(cat));
|
|
|
|
BooleanBuilder bb2 = new BooleanBuilder();
|
|
bb2.or(cat.eq(cat));
|
|
bb2.or(cat.eq(cat));
|
|
|
|
assertToString("cat = cat and (cat = cat or cat = cat)", bb1.and(bb2));
|
|
}
|
|
|
|
@Test
|
|
public void BooleanBuilder2(){
|
|
BooleanBuilder bb1 = new BooleanBuilder();
|
|
bb1.and(cat.eq(cat));
|
|
|
|
BooleanBuilder bb2 = new BooleanBuilder();
|
|
bb2.or(cat.eq(cat));
|
|
bb2.or(cat.eq(cat));
|
|
|
|
assertToString("cat = cat and (cat = cat or cat = cat)", bb1.and(bb2.getValue()));
|
|
}
|
|
|
|
@Test
|
|
public void BooleanBuilderWithNull(){
|
|
assertEquals("from Cat cat", sub().from(cat).where(new BooleanBuilder()).toString());
|
|
assertEquals("from Cat cat\ngroup by cat.name",
|
|
sub().from(cat).groupBy(cat.name).having(new BooleanBuilder()).toString());
|
|
}
|
|
|
|
}
|