Search in sources :

Example 1 with StringPath

use of com.querydsl.core.types.dsl.StringPath in project querydsl by querydsl.

the class ProjectionsTest method nestedSkipNulls2.

@Test
public void nestedSkipNulls2() {
    StringPath str1 = Expressions.stringPath("str1");
    StringPath str2 = Expressions.stringPath("str2");
    StringPath str3 = Expressions.stringPath("str3");
    FactoryExpression<Entity1> entity = Projections.constructor(Entity1.class, str1, str2).skipNulls();
    FactoryExpression<Entity2> wrapper = Projections.constructor(Entity2.class, str3, entity).skipNulls();
    FactoryExpression<Entity2> wrapped = FactoryExpressionUtils.wrap(wrapper);
    Entity2 w = wrapped.newInstance("a", "b", "c");
    assertEquals("a", w.arg1);
    assertEquals("b", w.entity.arg1);
    assertEquals("c", w.entity.arg2);
    w = wrapped.newInstance("a", null, null);
    assertEquals("a", w.arg1);
    assertNull(w.entity);
    w = wrapped.newInstance(null, null, null);
    assertNull(w);
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 2 with StringPath

use of com.querydsl.core.types.dsl.StringPath in project querydsl by querydsl.

the class ExpressionUtilsTest method regexToLike.

@Test
public void regexToLike() {
    assertEquals("%", like(ConstantImpl.create(".*")));
    assertEquals("_", like(ConstantImpl.create(".")));
    assertEquals(".", like(ConstantImpl.create("\\.")));
    StringPath path = Expressions.stringPath("path");
    assertEquals("path + %", like(path.append(".*")));
    assertEquals("% + path", like(path.prepend(".*")));
    assertEquals("path + _", like(path.append(".")));
    assertEquals("_ + path", like(path.prepend(".")));
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 3 with StringPath

use of com.querydsl.core.types.dsl.StringPath in project querydsl by querydsl.

the class ExpressionUtilsTest method likeToRegexSpeed.

@Test
@Ignore
public void likeToRegexSpeed() {
    // 4570
    StringPath path = Expressions.stringPath("path");
    final int iterations = 1000000;
    long start = System.currentTimeMillis();
    for (int i = 0; i < iterations; i++) {
        regex(ConstantImpl.create("%"));
        regex(ConstantImpl.create("abc%"));
        regex(ConstantImpl.create("%abc"));
        regex(ConstantImpl.create("_"));
        regex(path.append("%"));
        regex(path.prepend("%"));
        regex(path.append("_"));
        regex(path.prepend("_"));
    }
    long duration = System.currentTimeMillis() - start;
    System.err.println(duration);
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with StringPath

use of com.querydsl.core.types.dsl.StringPath in project querydsl by querydsl.

the class ExpressionUtilsTest method likeToRegex.

@Test
public void likeToRegex() {
    assertEquals(".*", regex(ConstantImpl.create("%")));
    assertEquals("^abc.*", regex(ConstantImpl.create("abc%")));
    assertEquals(".*abc$", regex(ConstantImpl.create("%abc")));
    assertEquals("^.$", regex(ConstantImpl.create("_")));
    StringPath path = Expressions.stringPath("path");
    assertEquals("path + .*", regex(path.append("%")));
    assertEquals(".* + path", regex(path.prepend("%")));
    assertEquals("path + .", regex(path.append("_")));
    assertEquals(". + path", regex(path.prepend("_")));
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 5 with StringPath

use of com.querydsl.core.types.dsl.StringPath in project querydsl by querydsl.

the class ExpressionUtilsTest method regexToLikeSpeed.

@Test
@Ignore
public void regexToLikeSpeed() {
    // 3255
    StringPath path = Expressions.stringPath("path");
    final int iterations = 1000000;
    long start = System.currentTimeMillis();
    for (int i = 0; i < iterations; i++) {
        like(ConstantImpl.create(".*"));
        like(ConstantImpl.create("."));
        like(path.append(".*"));
        like(path.prepend(".*"));
        like(path.append("."));
        like(path.prepend("."));
    }
    long duration = System.currentTimeMillis() - start;
    System.err.println(duration);
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StringPath (com.querydsl.core.types.dsl.StringPath)33 Test (org.junit.Test)33 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)6 QueryMetadata (com.querydsl.core.QueryMetadata)6 Tuple (com.querydsl.core.Tuple)4 QTuple (com.querydsl.core.types.QTuple)2 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 Ignore (org.junit.Ignore)2 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)1 JavaTemplates (com.querydsl.core.types.JavaTemplates)1 Predicate (com.querydsl.core.types.Predicate)1 BooleanExpression (com.querydsl.core.types.dsl.BooleanExpression)1 PhraseElement (com.querydsl.lucene5.PhraseElement)1 TermElement (com.querydsl.lucene5.TermElement)1 BigDecimal (java.math.BigDecimal)1