Search in sources :

Example 6 with Employee

use of com.querydsl.sql.domain.Employee in project querydsl by querydsl.

the class AbstractMapperTest method setUp.

@Before
public void setUp() {
    employee = new Employee();
    employee.setDatefield(new Date(0));
    employee.setFirstname("A");
    employee.setLastname("B");
    employee.setSalary(new BigDecimal(1.0));
    employee.setSuperiorId(2);
    employee.setTimefield(new Time(0));
}
Also used : Employee(com.querydsl.sql.domain.Employee) Time(java.sql.Time) Date(java.sql.Date) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 7 with Employee

use of com.querydsl.sql.domain.Employee in project querydsl by querydsl.

the class QBeanTest method direct_to_custom_type.

@Test
public void direct_to_custom_type() {
    FactoryExpression<Employee> expr = Projections.bean(Employee.class, e.firstname, e.lastname);
    Employee e = expr.newInstance("John", "Smith");
    assertEquals("John", e.getFirstname());
    assertEquals("Smith", e.getLastname());
}
Also used : Employee(com.querydsl.sql.domain.Employee) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 8 with Employee

use of com.querydsl.sql.domain.Employee in project querydsl by querydsl.

the class QBeanTest method direct_to_managed_type.

@Test
public void direct_to_managed_type() {
    FactoryExpression<Employee> expr = Projections.bean(Employee.class, e.superiorId);
    Employee e = expr.newInstance(3);
    assertEquals(Integer.valueOf(3), e.getSuperiorId());
}
Also used : Employee(com.querydsl.sql.domain.Employee) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 9 with Employee

use of com.querydsl.sql.domain.Employee in project querydsl by querydsl.

the class BeanPopulationBase method custom_projection.

@Test
public void custom_projection() {
    // Insert
    Employee employee = new Employee();
    employee.setFirstname("John");
    Integer id = insert(e).populate(employee).executeWithKey(e.id);
    employee.setId(id);
    // Update
    employee.setLastname("S");
    assertEquals(1L, update(e).populate(employee).where(e.id.eq(employee.getId())).execute());
    // Query
    Employee smith = extQuery().from(e).where(e.lastname.eq("S")).limit(1).uniqueResult(Employee.class, e.lastname, e.firstname);
    assertEquals("John", smith.getFirstname());
    assertEquals("S", smith.getLastname());
    // Query with alias
    smith = extQuery().from(e).where(e.lastname.eq("S")).limit(1).uniqueResult(Employee.class, e.lastname.as("lastname"), e.firstname.as("firstname"));
    assertEquals("John", smith.getFirstname());
    assertEquals("S", smith.getLastname());
    // Query into custom type
    OtherEmployee other = extQuery().from(e).where(e.lastname.eq("S")).limit(1).uniqueResult(OtherEmployee.class, e.lastname, e.firstname);
    assertEquals("John", other.getFirstname());
    assertEquals("S", other.getLastname());
    // Delete (no changes needed)
    assertEquals(1L, delete(e).where(e.id.eq(employee.getId())).execute());
}
Also used : Employee(com.querydsl.sql.domain.Employee) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Example 10 with Employee

use of com.querydsl.sql.domain.Employee in project querydsl by querydsl.

the class BeanPopulationBase method insert_update_query_and_delete.

@Test
public void insert_update_query_and_delete() {
    // Insert
    Employee employee = new Employee();
    employee.setFirstname("John");
    Integer id = insert(e).populate(employee).executeWithKey(e.id);
    assertNotNull(id);
    employee.setId(id);
    // Update
    employee.setLastname("S");
    assertEquals(1L, update(e).populate(employee).where(e.id.eq(employee.getId())).execute());
    // Query
    Employee smith = query().from(e).where(e.lastname.eq("S")).limit(1).select(e).fetchFirst();
    assertEquals("John", smith.getFirstname());
    // Delete (no changes needed)
    assertEquals(1L, delete(e).where(e.id.eq(employee.getId())).execute());
}
Also used : Employee(com.querydsl.sql.domain.Employee) QEmployee(com.querydsl.sql.domain.QEmployee) Test(org.junit.Test)

Aggregations

Employee (com.querydsl.sql.domain.Employee)11 QEmployee (com.querydsl.sql.domain.QEmployee)10 Test (org.junit.Test)10 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)1 BeanMapper (com.querydsl.sql.dml.BeanMapper)1 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 Time (java.sql.Time)1 Before (org.junit.Before)1