Search in sources :

Example 26 with ExcludeIn

use of com.querydsl.core.testutil.ExcludeIn in project querydsl by querydsl.

the class AbstractSQLTest method union3.

@SuppressWarnings("unchecked")
@Test
@ExcludeIn(Target.DERBY)
// FIXME
@Ignore
public void union3() {
    SAnimal cat2 = new SAnimal("cat2");
    List<Tuple> rows = query().union(select(cat.id, cat2.id).from(cat).innerJoin(cat2).on(cat2.id.eq(cat.id)), select(cat.id, null).from(cat)).list();
    assertEquals(12, rows.size());
    int nulls = 0;
    for (Tuple row : rows) {
        System.err.println(Arrays.asList(row));
        if (row.get(1, Object.class) == null) {
            nulls++;
        }
    }
    assertEquals(6, nulls);
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 27 with ExcludeIn

use of com.querydsl.core.testutil.ExcludeIn in project querydsl by querydsl.

the class AbstractSQLTest method union2.

@SuppressWarnings("unchecked")
@Test
@ExcludeIn({ Target.DERBY, Target.POSTGRESQL })
// FIXME
@Ignore
public void union2() {
    List<Tuple> rows = query().union(select(cat.name, cat.id).from(cat).where(cat.name.eq("Beck")).distinct(), select(cat.name, null).from(cat).where(cat.name.eq("Kate")).distinct()).list();
    assertEquals(2, rows.size());
    for (Tuple row : rows) {
        System.err.println(row);
    }
}
Also used : Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 28 with ExcludeIn

use of com.querydsl.core.testutil.ExcludeIn in project querydsl by querydsl.

the class DeleteBase method batch_templates.

@Test
@ExcludeIn({ CUBRID, SQLITE })
public void batch_templates() throws SQLException {
    insert(survey).values(2, "A", "B").execute();
    insert(survey).values(3, "B", "C").execute();
    SQLDeleteClause delete = delete(survey);
    delete.where(survey.name.eq(Expressions.stringTemplate("'A'"))).addBatch();
    delete.where(survey.name.eq(Expressions.stringTemplate("'B'"))).addBatch();
    assertEquals(2, delete.execute());
}
Also used : SQLDeleteClause(com.querydsl.sql.dml.SQLDeleteClause) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 29 with ExcludeIn

use of com.querydsl.core.testutil.ExcludeIn in project querydsl by querydsl.

the class SelectBase method dates.

@Test
@ExcludeIn({ CUBRID, DB2, DERBY, HSQLDB, POSTGRESQL, SQLITE, TERADATA })
public void dates() {
    long ts = ((long) Math.floor(System.currentTimeMillis() / 1000)) * 1000;
    long tsDate = new org.joda.time.LocalDate(ts).toDateMidnight().getMillis();
    long tsTime = new org.joda.time.LocalTime(ts).getMillisOfDay();
    List<Object> data = Lists.newArrayList();
    data.add(Constants.date);
    data.add(Constants.time);
    data.add(new java.util.Date(ts));
    data.add(new java.util.Date(tsDate));
    data.add(new java.util.Date(tsTime));
    data.add(new java.sql.Timestamp(ts));
    data.add(new java.sql.Timestamp(tsDate));
    data.add(new java.sql.Date(110, 0, 1));
    data.add(new java.sql.Date(tsDate));
    data.add(new java.sql.Time(0, 0, 0));
    data.add(new java.sql.Time(12, 30, 0));
    data.add(new java.sql.Time(23, 59, 59));
    //data.add(new java.sql.Time(tsTime));
    data.add(new DateTime(ts));
    data.add(new DateTime(tsDate));
    data.add(new DateTime(tsTime));
    data.add(new LocalDateTime(ts));
    data.add(new LocalDateTime(tsDate));
    data.add(new LocalDateTime(2014, 3, 30, 2, 0));
    data.add(new LocalDate(2010, 1, 1));
    data.add(new LocalDate(ts));
    data.add(new LocalDate(tsDate));
    data.add(new LocalTime(0, 0, 0));
    data.add(new LocalTime(12, 30, 0));
    data.add(new LocalTime(23, 59, 59));
    data.add(new LocalTime(ts));
    data.add(new LocalTime(tsTime));
    java.time.Instant javaInstant = java.time.Instant.now().truncatedTo(java.time.temporal.ChronoUnit.SECONDS);
    java.time.LocalDateTime javaDateTime = java.time.LocalDateTime.ofInstant(javaInstant, java.time.ZoneId.of("Z"));
    java.time.LocalDate javaDate = javaDateTime.toLocalDate();
    java.time.LocalTime javaTime = javaDateTime.toLocalTime();
    //java.time.Instant
    data.add(javaInstant);
    //java.time.LocalDateTime
    data.add(javaDateTime);
    //java.time.LocalDate
    data.add(javaDate);
    //java.time.LocalTime
    data.add(javaTime);
    //java.time.OffsetDateTime
    data.add(javaDateTime.atOffset(java.time.ZoneOffset.UTC));
    //java.time.OffsetTime
    data.add(javaTime.atOffset(java.time.ZoneOffset.UTC));
    //java.time.ZonedDateTime
    data.add(javaDateTime.atZone(java.time.ZoneId.of("Z")));
    Map<Object, Object> failures = Maps.newIdentityHashMap();
    for (Object dt : data) {
        Object dt2 = firstResult(Expressions.constant(dt));
        if (!dt.equals(dt2)) {
            failures.put(dt, dt2);
        }
    }
    if (!failures.isEmpty()) {
        for (Map.Entry<Object, Object> entry : failures.entrySet()) {
            System.out.println(entry.getKey().getClass().getName() + ": " + entry.getKey() + " != " + entry.getValue());
        }
        Assert.fail("Failed with " + failures);
    }
}
Also used : Date(java.sql.Date) java.util(java.util) org.joda.time(org.joda.time) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 30 with ExcludeIn

use of com.querydsl.core.testutil.ExcludeIn in project querydsl by querydsl.

the class SelectBase method date_diff2.

// TDO Date_diff with timestamps
@Test
@ExcludeIn({ DB2, HSQLDB, SQLITE, TERADATA })
public void date_diff2() {
    SQLQuery<?> query = query().from(employee).orderBy(employee.id.asc());
    LocalDate localDate = new LocalDate(1970, 1, 10);
    Date date = new Date(localDate.toDateMidnight().getMillis());
    int years = query.select(SQLExpressions.datediff(DatePart.year, date, employee.datefield)).fetchFirst();
    int months = query.select(SQLExpressions.datediff(DatePart.month, date, employee.datefield)).fetchFirst();
    // weeks
    int days = query.select(SQLExpressions.datediff(DatePart.day, date, employee.datefield)).fetchFirst();
    int hours = query.select(SQLExpressions.datediff(DatePart.hour, date, employee.datefield)).fetchFirst();
    int minutes = query.select(SQLExpressions.datediff(DatePart.minute, date, employee.datefield)).fetchFirst();
    int seconds = query.select(SQLExpressions.datediff(DatePart.second, date, employee.datefield)).fetchFirst();
    assertEquals(949363200, seconds);
    assertEquals(15822720, minutes);
    assertEquals(263712, hours);
    assertEquals(10988, days);
    assertEquals(361, months);
    assertEquals(30, years);
}
Also used : Date(java.sql.Date) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Aggregations

ExcludeIn (com.querydsl.core.testutil.ExcludeIn)40 Test (org.junit.Test)38 Tuple (com.querydsl.core.Tuple)9 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)6 ResultSet (java.sql.ResultSet)6 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)4 QEmployee (com.querydsl.sql.domain.QEmployee)4 BigDecimal (java.math.BigDecimal)4 Date (java.sql.Date)4 Ignore (org.junit.Ignore)4 AbstractBaseTest (com.querydsl.sql.AbstractBaseTest)3 Group (com.querydsl.core.group.Group)2 IncludeIn (com.querydsl.core.testutil.IncludeIn)2 QCat (com.querydsl.jpa.domain.QCat)2 BigInteger (java.math.BigInteger)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ImmutableList (com.google.common.collect.ImmutableList)1 MockTuple (com.querydsl.core.group.MockTuple)1 StringPath (com.querydsl.core.types.dsl.StringPath)1 QBookMark (com.querydsl.jpa.domain4.QBookMark)1