Search in sources :

Example 11 with SQLInsertClause

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

the class InsertBase method complex1.

@Test
public void complex1() {
    // related to #584795
    QSurvey survey = new QSurvey("survey");
    QEmployee emp1 = new QEmployee("emp1");
    QEmployee emp2 = new QEmployee("emp2");
    SQLInsertClause insert = insert(survey);
    insert.columns(survey.id, survey.name);
    insert.select(select(survey.id, emp2.firstname).from(survey).innerJoin(emp1).on(survey.id.eq(emp1.id)).innerJoin(emp2).on(emp1.superiorId.eq(emp2.superiorId), emp1.firstname.eq(emp2.firstname)));
    assertEquals(0, insert.execute());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 12 with SQLInsertClause

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

the class InsertBase method insert_with_keys_listener.

@Test
@ExcludeIn({ CUBRID, SQLSERVER })
public void insert_with_keys_listener() throws SQLException {
    final AtomicBoolean result = new AtomicBoolean();
    SQLListener listener = new SQLBaseListener() {

        @Override
        public void end(SQLListenerContext context) {
            result.set(true);
        }
    };
    SQLInsertClause clause = insert(survey).set(survey.name, "Hello World");
    clause.addListener(listener);
    ResultSet rs = clause.executeWithKeys();
    assertFalse(result.get());
    assertTrue(rs.next());
    assertTrue(rs.getObject(1) != null);
    rs.close();
    assertTrue(result.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) ResultSet(java.sql.ResultSet) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 13 with SQLInsertClause

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

the class InsertBase method replace.

@Test
@IncludeIn(MYSQL)
@SkipForQuoted
public void replace() {
    SQLInsertClause clause = mysqlReplace(survey);
    clause.columns(survey.id, survey.name).values(3, "Hello");
    assertEquals("replace into SURVEY (ID, NAME) values (?, ?)", clause.toString());
    clause.execute();
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test) IncludeIn(com.querydsl.core.testutil.IncludeIn)

Example 14 with SQLInsertClause

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

the class InsertBase method like_with_escape.

@Test
public void like_with_escape() {
    SQLInsertClause insert = insert(survey);
    insert.set(survey.id, 5).set(survey.name, "aaa").addBatch();
    insert.set(survey.id, 6).set(survey.name, "a_").addBatch();
    insert.set(survey.id, 7).set(survey.name, "a%").addBatch();
    assertEquals(3, insert.execute());
    assertEquals(1L, query().from(survey).where(survey.name.like("a|%", '|')).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.like("a|_", '|')).fetchCount());
    assertEquals(3L, query().from(survey).where(survey.name.like("a%")).fetchCount());
    assertEquals(2L, query().from(survey).where(survey.name.like("a_")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.startsWith("a_")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.startsWith("a%")).fetchCount());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 15 with SQLInsertClause

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

the class InsertBase method insert_with_subQuery_Via_Constructor.

@Test
// too slow
@ExcludeIn(FIREBIRD)
public void insert_with_subQuery_Via_Constructor() {
    int count = (int) query().from(survey).fetchCount();
    SQLInsertClause insert = insert(survey, query().from(survey2));
    insert.set(survey.id, survey2.id.add(20));
    insert.set(survey.name, survey2.name);
    assertEquals(count, insert.execute());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

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