Search in sources :

Example 66 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class MapBatchInsertBuilderTest method testNotEqualMapSize.

@SuppressWarnings("serial")
@Test
public void testNotEqualMapSize() {
    MapBatchInsertBuilder builder = MapBatchInsertBuilder.newInstance(new MockConfig(), "Emp");
    List<LinkedHashMap<String, Object>> employees = new ArrayList<LinkedHashMap<String, Object>>() {

        {
            add(new LinkedHashMap<String, Object>() {

                {
                    put("name", "SMITH");
                }
            });
            add(new LinkedHashMap<String, Object>() {

                {
                    put("name", "ALLEN");
                    put("salary", 2000);
                }
            });
        }
    };
    try {
        builder.execute(employees);
    } catch (JdbcException e) {
        assertEquals(Message.DOMA2231, e.getMessageResource());
        return;
    }
    fail();
}
Also used : ArrayList(java.util.ArrayList) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) JdbcException(org.seasar.doma.jdbc.JdbcException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 67 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class BatchDeleteExecutorTest method testChangeType.

@Test
public void testChangeType() {
    SqlBatchDeleteQuery query = mockQuery();
    BatchBuilder builder = BatchBuilder.newInstance(query);
    builder.sql("delete from Emp");
    builder.sql("where");
    builder.sql("name = ").param(String.class, "SMITH");
    builder.sql("and");
    builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
    builder = builder.fixSql();
    builder.sql("delete from Emp");
    builder.sql("where");
    builder.sql("name = ").param(String.class, "ALLEN");
    builder.sql("and");
    builder = builder.sql("salary = ");
    try {
        builder.param(int.class, 2000);
    } catch (JdbcException e) {
        assertEquals(Message.DOMA2229, e.getMessageResource());
        return;
    }
    fail();
}
Also used : SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) JdbcException(org.seasar.doma.jdbc.JdbcException) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 68 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class AutoInsertTest method testIdNotAssigned.

@Test
public void testIdNotAssigned(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentNo(99);
    department.setDepartmentName("hoge");
    try {
        dao.insert(department);
        fail();
    } catch (JdbcException expected) {
        assertEquals(Message.DOMA2020, expected.getMessageResource());
    }
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) CompKeyDepartmentDaoImpl(org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) CompKeyDepartment(org.seasar.doma.it.entity.CompKeyDepartment) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) JdbcException(org.seasar.doma.jdbc.JdbcException) Test(org.junit.jupiter.api.Test)

Example 69 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class AutoBatchDeleteTest method testNoId.

@Test
public void testNoId(Config config) throws Exception {
    NoIdDao dao = new NoIdDaoImpl(config);
    NoId entity = new NoId();
    entity.setValue1(1);
    entity.setValue2(2);
    NoId entity2 = new NoId();
    entity2.setValue1(1);
    entity2.setValue2(2);
    try {
        dao.delete(Arrays.asList(entity, entity2));
        fail();
    } catch (JdbcException expected) {
        assertEquals(Message.DOMA2022, expected.getMessageResource());
    }
}
Also used : NoIdDao(org.seasar.doma.it.dao.NoIdDao) NoId(org.seasar.doma.it.entity.NoId) NoIdDaoImpl(org.seasar.doma.it.dao.NoIdDaoImpl) JdbcException(org.seasar.doma.jdbc.JdbcException) Test(org.junit.jupiter.api.Test)

Aggregations

JdbcException (org.seasar.doma.jdbc.JdbcException)69 Test (org.junit.jupiter.api.Test)35 SqlNode (org.seasar.doma.jdbc.SqlNode)18 SQLException (java.sql.SQLException)15 BigDecimal (java.math.BigDecimal)9 Value (org.seasar.doma.internal.expr.Value)9 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)8 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)7 SelectOptions (org.seasar.doma.jdbc.SelectOptions)7 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)6 Connection (java.sql.Connection)5 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)5 PreparedStatement (java.sql.PreparedStatement)4 Savepoint (java.sql.Savepoint)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 DomaNullPointerException (org.seasar.doma.DomaNullPointerException)4 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)4 MockDataSource (org.seasar.doma.internal.jdbc.mock.MockDataSource)4 IfBlockNode (org.seasar.doma.internal.jdbc.sql.node.IfBlockNode)4