Search in sources :

Example 31 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_dates.

@Test
// https://bitbucket.org/xerial/sqlite-jdbc/issue/133/prepstmtsetdate-int-date-calendar-seems
@ExcludeIn({ CUBRID, SQLITE })
public void insert_dates() {
    QDateTest dateTest = QDateTest.qDateTest;
    LocalDate localDate = new LocalDate(1978, 1, 2);
    Path<LocalDate> localDateProperty = ExpressionUtils.path(LocalDate.class, "DATE_TEST");
    Path<DateTime> dateTimeProperty = ExpressionUtils.path(DateTime.class, "DATE_TEST");
    SQLInsertClause insert = insert(dateTest);
    insert.set(localDateProperty, localDate);
    insert.execute();
    Tuple result = query().from(dateTest).select(dateTest.dateTest.year(), dateTest.dateTest.month(), dateTest.dateTest.dayOfMonth(), dateTimeProperty).fetchFirst();
    assertEquals(Integer.valueOf(1978), result.get(0, Integer.class));
    assertEquals(Integer.valueOf(1), result.get(1, Integer.class));
    assertEquals(Integer.valueOf(2), result.get(2, Integer.class));
    DateTime dateTime = result.get(dateTimeProperty);
    if (target == CUBRID) {
        // XXX Cubrid adds random milliseconds for some reason
        dateTime = dateTime.withMillisOfSecond(0);
    }
    assertEquals(localDate.toDateTimeAtStartOfDay(), dateTime);
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 32 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_nulls_in_batch.

@Test
@ExcludeIn(ORACLE)
public void insert_nulls_in_batch() {
    // QFoo f= QFoo.foo;
    // SQLInsertClause sic = new SQLInsertClause(c, new H2Templates(), f);
    // sic.columns(f.c1,f.c2).values(null,null).addBatch();
    // sic.columns(f.c1,f.c2).values(null,1).addBatch();
    // sic.execute();
    SQLInsertClause sic = insert(survey);
    sic.columns(survey.name, survey.name2).values(null, null).addBatch();
    sic.columns(survey.name, survey.name2).values(null, "X").addBatch();
    assertEquals(2, sic.execute());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 33 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_batch_Templates.

@Test
public void insert_batch_Templates() {
    SQLInsertClause insert = insert(survey).set(survey.id, 5).set(survey.name, Expressions.stringTemplate("'55'")).addBatch();
    insert.set(survey.id, 6).set(survey.name, Expressions.stringTemplate("'66'")).addBatch();
    assertEquals(2, insert.execute());
    assertEquals(1L, query().from(survey).where(survey.name.eq("55")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.eq("66")).fetchCount());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 34 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_nulls_in_batch2.

@Test
@Ignore
@ExcludeIn({ DERBY })
public void insert_nulls_in_batch2() {
    Mapper<Object> mapper = DefaultMapper.WITH_NULL_BINDINGS;
    // QFoo f= QFoo.foo;
    // SQLInsertClause sic = new SQLInsertClause(c, new H2Templates(), f);
    // Foo f1=new Foo();
    // sic.populate(f1).addBatch();
    // f1=new Foo();
    // f1.setC1(1);
    // sic.populate(f1).addBatch();
    // sic.execute();
    QEmployee employee = QEmployee.employee;
    SQLInsertClause sic = insert(employee);
    Employee e = new Employee();
    sic.populate(e, mapper).addBatch();
    e = new Employee();
    e.setFirstname("X");
    sic.populate(e, mapper).addBatch();
    assertEquals(0, sic.execute());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 35 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_batch_to_bulk.

@Test
public void insert_batch_to_bulk() {
    SQLInsertClause insert = insert(survey);
    insert.setBatchToBulk(true);
    insert.set(survey.id, 5).set(survey.name, "55").addBatch();
    assertEquals(1, insert.getBatchCount());
    insert.set(survey.id, 6).set(survey.name, "66").addBatch();
    assertEquals(2, insert.getBatchCount());
    assertEquals(2, insert.execute());
    assertEquals(1L, query().from(survey).where(survey.name.eq("55")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.eq("66")).fetchCount());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Aggregations

SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)52 Test (org.junit.Test)25 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)6 ColumnMetadata (com.querydsl.sql.ColumnMetadata)4 MAuditDelta (com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta)3 IncludeIn (com.querydsl.core.testutil.IncludeIn)3 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2 H2Templates (com.querydsl.sql.H2Templates)2 QGeneratedKeysEntity (com.querydsl.sql.QGeneratedKeysEntity)2 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 AuditEventRecordCustomColumnPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType)1 AuditEventRecordReferenceType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType)1 AuditEventRecordReferenceValueType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceValueType)1 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)1