Search in sources :

Example 1 with Emp

use of example.entity.Emp in project doma by domaframework.

the class AutoDeleteQueryTest method testPrepare.

@Test
public void testPrepare() {
    Emp emp = new Emp();
    AutoDeleteQuery<Emp> query = new AutoDeleteQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    assertNotNull(((DeleteQuery) query).getSql());
}
Also used : Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 2 with Emp

use of example.entity.Emp in project doma by domaframework.

the class AutoDeleteQueryTest method testOption_default.

@Test
public void testOption_default() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setVersion(100);
    AutoDeleteQuery<Emp> query = new AutoDeleteQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("delete from EMP where ID = ? and VERSION = ?", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(2, parameters.size());
    assertEquals(10, parameters.get(0).getWrapper().get());
    assertEquals(100, parameters.get(1).getWrapper().get());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 3 with Emp

use of example.entity.Emp in project doma by domaframework.

the class AutoDeleteQueryTest method testOption_ignoreVersion.

@Test
public void testOption_ignoreVersion() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setVersion(100);
    AutoDeleteQuery<Emp> query = new AutoDeleteQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setVersionIgnored(true);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("delete from EMP where ID = ?", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(1, parameters.size());
    assertEquals(10, parameters.get(0).getWrapper().get());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 4 with Emp

use of example.entity.Emp in project doma by domaframework.

the class AutoInsertQueryTest method testOption_excludeNull.

@Test
public void testOption_excludeNull() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    AutoInsertQuery<Emp> query = new AutoInsertQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setNullExcluded(true);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("insert into EMP (ID, NAME, VERSION) values (?, ?, ?)", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(3, parameters.size());
    assertEquals(10, parameters.get(0).getWrapper().get());
    assertEquals("aaa", parameters.get(1).getWrapper().get());
    assertEquals(1, parameters.get(2).getWrapper().get());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 5 with Emp

use of example.entity.Emp in project doma by domaframework.

the class AutoInsertQueryTest method testOption_exclude.

@Test
public void testOption_exclude() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setSalary(new BigDecimal(200));
    AutoInsertQuery<Emp> query = new AutoInsertQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setExcludedPropertyNames("name");
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("insert into EMP (ID, SALARY, VERSION) values (?, ?, ?)", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(3, parameters.size());
    assertEquals(10, parameters.get(0).getWrapper().get());
    assertEquals(new BigDecimal(200), parameters.get(1).getWrapper().get());
    assertEquals(1, parameters.get(2).getWrapper().get());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

Emp (example.entity.Emp)80 example.entity._Emp (example.entity._Emp)73 Test (org.junit.jupiter.api.Test)73 PreparedSql (org.seasar.doma.jdbc.PreparedSql)29 InParameter (org.seasar.doma.jdbc.InParameter)27 BigDecimal (java.math.BigDecimal)25 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)13 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)12 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)12 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)12 RowData (org.seasar.doma.internal.jdbc.mock.RowData)11 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)9 BindValue (org.seasar.doma.internal.jdbc.mock.BindValue)8 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)5 MockPreparedStatement (org.seasar.doma.internal.jdbc.mock.MockPreparedStatement)5 Method (java.lang.reflect.Method)4 List (java.util.List)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 TestInfo (org.junit.jupiter.api.TestInfo)4 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)4