Search in sources :

Example 26 with Emp

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

the class EntityProviderTest method testGetEntity.

@Test
public void testGetEntity() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    metaData.columns.add(new ColumnMetaData("salary"));
    metaData.columns.add(new ColumnMetaData("version"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100));
    resultSet.next();
    _Emp entityType = _Emp.getSingletonInternal();
    EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
    Emp emp = provider.get(resultSet);
    assertEquals(1, emp.getId());
    assertEquals("aaa", emp.getName());
    assertEquals(new BigDecimal(10), emp.getSalary());
    assertEquals(100, emp.getVersion());
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 27 with Emp

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

the class EntityProviderTest method testGetEntity_UnknownColumnException.

@Test
public void testGetEntity_UnknownColumnException() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    metaData.columns.add(new ColumnMetaData("salary"));
    metaData.columns.add(new ColumnMetaData("version"));
    metaData.columns.add(new ColumnMetaData("unknown"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100, "bbb"));
    resultSet.next();
    _Emp entityType = _Emp.getSingletonInternal();
    EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
    try {
        provider.get(resultSet);
        fail();
    } catch (UnknownColumnException expected) {
    }
}
Also used : UnknownColumnException(org.seasar.doma.jdbc.UnknownColumnException) RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 28 with Emp

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

the class EntitySingleResultHandlerTest method testHandle.

@Test
public void testHandle() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa"));
    SqlFileSelectQuery query = new SqlFileSelectQuery();
    query.setConfig(runtimeConfig);
    query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setMethod(method);
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    EntitySingleResultHandler<Emp> handler = new EntitySingleResultHandler<>(_Emp.getSingletonInternal());
    Emp emp = handler.handle(resultSet, query, (i, next) -> {
    }).get();
    assertEquals(1, emp.getId());
    assertEquals("aaa", emp.getName());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) SqlFileUtil(org.seasar.doma.internal.jdbc.util.SqlFileUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) AssertionUtil.assertEquals(org.seasar.doma.internal.util.AssertionUtil.assertEquals) Emp(example.entity.Emp) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) NonUniqueResultException(org.seasar.doma.jdbc.NonUniqueResultException) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Method(java.lang.reflect.Method) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 29 with Emp

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

the class BatchInsertCommandTest method testExecute.

@Test
public void testExecute(TestInfo testInfo) {
    Emp emp1 = new Emp();
    emp1.setId(1);
    emp1.setName("hoge");
    emp1.setVersion(10);
    Emp emp2 = new Emp();
    emp2.setId(2);
    emp2.setName("foo");
    emp2.setVersion(20);
    AutoBatchInsertQuery<Emp> query = new AutoBatchInsertQuery<>(_Emp.getSingletonInternal());
    query.setMethod(testInfo.getTestMethod().get());
    query.setConfig(runtimeConfig);
    query.setEntities(Arrays.asList(emp1, emp2));
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    int[] rows = new BatchInsertCommand(query).execute();
    query.complete();
    assertEquals(2, rows.length);
    String sql = runtimeConfig.dataSource.connection.preparedStatement.sql;
    assertEquals("insert into EMP (ID, NAME, SALARY, VERSION) values (?, ?, ?, ?)", sql);
}
Also used : Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) AutoBatchInsertQuery(org.seasar.doma.jdbc.query.AutoBatchInsertQuery) Test(org.junit.jupiter.api.Test)

Example 30 with Emp

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

the class BatchUpdateCommandTest method testExecute_suppressesOptimisticLockException.

@Test
public void testExecute_suppressesOptimisticLockException() {
    Emp emp = new Emp();
    emp.setId(1);
    emp.setName("hoge");
    emp.setVersion(10);
    runtimeConfig.dataSource.connection.preparedStatement.updatedRows = 0;
    AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntities(Collections.singletonList(emp));
    query.setOptimisticLockExceptionSuppressed(true);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    new BatchUpdateCommand(query).execute();
    query.complete();
}
Also used : AutoBatchUpdateQuery(org.seasar.doma.jdbc.query.AutoBatchUpdateQuery) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) 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