Search in sources :

Example 1 with QUser

use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.

the class QueryDSLIntegrationTest method whenUsingOrderBy_thenResultsShouldBeOrdered.

@Test
public void whenUsingOrderBy_thenResultsShouldBeOrdered() {
    QUser user = QUser.user;
    List<User> users = queryFactory.selectFrom(user).orderBy(user.login.asc()).fetch();
    assertEquals(users.size(), 4);
    assertEquals(users.get(0).getLogin(), "Ash");
    assertEquals(users.get(1).getLogin(), "Bishop");
    assertEquals(users.get(2).getLogin(), "Call");
    assertEquals(users.get(3).getLogin(), "David");
}
Also used : QUser(org.baeldung.querydsl.intro.entities.QUser) QUser(org.baeldung.querydsl.intro.entities.QUser) User(org.baeldung.querydsl.intro.entities.User)

Example 2 with QUser

use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.

the class QueryDSLIntegrationTest method whenUpdating_thenTheRecordShouldChange.

@Test
public void whenUpdating_thenTheRecordShouldChange() {
    QUser user = QUser.user;
    queryFactory.update(user).where(user.login.eq("Ash")).set(user.login, "Ash2").set(user.disabled, true).execute();
    em.getTransaction().commit();
    em.getTransaction().begin();
    assertEquals(Boolean.TRUE, queryFactory.select(user.disabled).from(user).where(user.login.eq("Ash2")).fetchOne());
}
Also used : QUser(org.baeldung.querydsl.intro.entities.QUser)

Example 3 with QUser

use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.

the class QueryDSLIntegrationTest method whenFindByLogin_thenShouldReturnUser.

@Test
public void whenFindByLogin_thenShouldReturnUser() {
    QUser user = QUser.user;
    User aUser = queryFactory.selectFrom(user).where(user.login.eq("David")).fetchOne();
    assertNotNull(aUser);
    assertEquals(aUser.getLogin(), "David");
}
Also used : QUser(org.baeldung.querydsl.intro.entities.QUser) QUser(org.baeldung.querydsl.intro.entities.QUser) User(org.baeldung.querydsl.intro.entities.User)

Example 4 with QUser

use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.

the class QueryDSLIntegrationTest method whenDeleting_thenTheRecordShouldBeAbsent.

@Test
public void whenDeleting_thenTheRecordShouldBeAbsent() {
    QUser user = QUser.user;
    queryFactory.delete(user).where(user.login.eq("Bishop")).execute();
    em.getTransaction().commit();
    em.getTransaction().begin();
    assertNull(queryFactory.selectFrom(user).where(user.login.eq("Bishop")).fetchOne());
}
Also used : QUser(org.baeldung.querydsl.intro.entities.QUser)

Example 5 with QUser

use of org.baeldung.querydsl.intro.entities.QUser in project tutorials by eugenp.

the class QueryDSLIntegrationTest method whenJoiningWithCondition_thenResultCountShouldMatch.

@Test
public void whenJoiningWithCondition_thenResultCountShouldMatch() {
    QUser user = QUser.user;
    QBlogPost blogPost = QBlogPost.blogPost;
    List<User> users = queryFactory.selectFrom(user).innerJoin(user.blogPosts, blogPost).on(blogPost.title.eq("Hello World!")).fetch();
    assertEquals(2, users.size());
}
Also used : QUser(org.baeldung.querydsl.intro.entities.QUser) QBlogPost(org.baeldung.querydsl.intro.entities.QBlogPost) QUser(org.baeldung.querydsl.intro.entities.QUser) User(org.baeldung.querydsl.intro.entities.User)

Aggregations

QUser (org.baeldung.querydsl.intro.entities.QUser)6 User (org.baeldung.querydsl.intro.entities.User)4 QBlogPost (org.baeldung.querydsl.intro.entities.QBlogPost)2