Search in sources :

Example 16 with AwfulTableKey

use of mbg.test.ib2j2.generated.hierarchical.model.AwfulTableKey in project generator by mybatis.

the class HierarchicalJava5Test method testAwfulTableUpdateByPrimaryKeySelective.

@Test
public void testAwfulTableUpdateByPrimaryKeySelective() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        Integer generatedCustomerId = record.getCustomerId();
        AwfulTable newRecord = new AwfulTable();
        newRecord.setCustomerId(generatedCustomerId);
        newRecord.setId1(11);
        newRecord.setId2(22);
        int rows = mapper.updateByPrimaryKeySelective(newRecord);
        assertEquals(1, rows);
        AwfulTableKey key = new AwfulTableKey();
        key.setCustomerId(generatedCustomerId);
        AwfulTable returnedRecord = mapper.selectByPrimaryKey(key);
        assertEquals(generatedCustomerId, returnedRecord.getCustomerId());
        assertEquals(record.geteMail(), returnedRecord.geteMail());
        assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
        assertEquals(record.getFirstFirstName(), returnedRecord.getFirstFirstName());
        assertEquals(record.getFrom(), returnedRecord.getFrom());
        assertEquals(newRecord.getId1(), returnedRecord.getId1());
        assertEquals(newRecord.getId2(), returnedRecord.getId2());
        assertEquals(record.getId5(), returnedRecord.getId5());
        assertEquals(record.getId6(), returnedRecord.getId6());
        assertEquals(record.getId7(), returnedRecord.getId7());
        assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
        assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.hierarchical.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.hierarchical.model.AwfulTable) AwfulTableKey(mbg.test.mb3.generated.hierarchical.model.AwfulTableKey) Test(org.junit.Test)

Example 17 with AwfulTableKey

use of mbg.test.ib2j2.generated.hierarchical.model.AwfulTableKey in project generator by mybatis.

the class HierarchicalJava5Test method testAwfulTableInsertSelective.

@Test
public void testAwfulTableInsertSelective() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        int count = mapper.insertSelective(record);
        assertEquals(1, count);
        Integer generatedCustomerId = record.getCustomerId();
        assertEquals(57, generatedCustomerId.intValue());
        AwfulTableKey key = new AwfulTableKey();
        key.setCustomerId(generatedCustomerId);
        AwfulTable returnedRecord = mapper.selectByPrimaryKey(key);
        assertEquals(generatedCustomerId, returnedRecord.getCustomerId());
        assertEquals(record.geteMail(), returnedRecord.geteMail());
        assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
        assertEquals("Mabel", returnedRecord.getFirstFirstName());
        assertEquals(record.getFrom(), returnedRecord.getFrom());
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(record.getId5(), returnedRecord.getId5());
        assertEquals(record.getId6(), returnedRecord.getId6());
        assertEquals(record.getId7(), returnedRecord.getId7());
        assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
        assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.hierarchical.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.hierarchical.model.AwfulTable) AwfulTableKey(mbg.test.mb3.generated.hierarchical.model.AwfulTableKey) Test(org.junit.Test)

Example 18 with AwfulTableKey

use of mbg.test.ib2j2.generated.hierarchical.model.AwfulTableKey in project generator by mybatis.

the class HierarchicalJava5Test method testAwfulTableSelectByPrimaryKey.

@Test
public void testAwfulTableSelectByPrimaryKey() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AwfulTableMapper mapper = sqlSession.getMapper(AwfulTableMapper.class);
        AwfulTable record = new AwfulTable();
        record.seteMail("fred@fred.com");
        record.setEmailaddress("alsofred@fred.com");
        record.setFirstFirstName("fred1");
        record.setFrom("from field");
        record.setId1(1);
        record.setId2(2);
        record.setId5(5);
        record.setId6(6);
        record.setId7(7);
        record.setSecondFirstName("fred2");
        record.setThirdFirstName("fred3");
        mapper.insert(record);
        record = new AwfulTable();
        record.seteMail("fred2@fred.com");
        record.setEmailaddress("alsofred2@fred.com");
        record.setFirstFirstName("fred11");
        record.setFrom("from from field");
        record.setId1(11);
        record.setId2(22);
        record.setId5(55);
        record.setId6(66);
        record.setId7(77);
        record.setSecondFirstName("fred22");
        record.setThirdFirstName("fred33");
        mapper.insert(record);
        Integer generatedKey = record.getCustomerId();
        AwfulTableKey key = new AwfulTableKey();
        key.setCustomerId(generatedKey);
        AwfulTable returnedRecord = mapper.selectByPrimaryKey(key);
        assertNotNull(returnedRecord);
        assertEquals(record.getCustomerId(), returnedRecord.getCustomerId());
        assertEquals(record.geteMail(), returnedRecord.geteMail());
        assertEquals(record.getEmailaddress(), returnedRecord.getEmailaddress());
        assertEquals(record.getFirstFirstName(), returnedRecord.getFirstFirstName());
        assertEquals(record.getFrom(), returnedRecord.getFrom());
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(record.getId5(), returnedRecord.getId5());
        assertEquals(record.getId6(), returnedRecord.getId6());
        assertEquals(record.getId7(), returnedRecord.getId7());
        assertEquals(record.getSecondFirstName(), returnedRecord.getSecondFirstName());
        assertEquals(record.getThirdFirstName(), returnedRecord.getThirdFirstName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.hierarchical.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.hierarchical.model.AwfulTable) AwfulTableKey(mbg.test.mb3.generated.hierarchical.model.AwfulTableKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 SQLException (java.sql.SQLException)6 AwfulTableDAO (mbg.test.ib2j2.generated.hierarchical.dao.AwfulTableDAO)6 AwfulTable (mbg.test.ib2j2.generated.hierarchical.model.AwfulTable)6 AwfulTableKey (mbg.test.ib2j2.generated.hierarchical.model.AwfulTableKey)6 AwfulTableDAO (mbg.test.ib2j5.generated.hierarchical.dao.AwfulTableDAO)6 AwfulTable (mbg.test.ib2j5.generated.hierarchical.model.AwfulTable)6 AwfulTableKey (mbg.test.ib2j5.generated.hierarchical.model.AwfulTableKey)6 AwfulTableMapper (mbg.test.mb3.generated.hierarchical.mapper.AwfulTableMapper)6 AwfulTable (mbg.test.mb3.generated.hierarchical.model.AwfulTable)6 AwfulTableKey (mbg.test.mb3.generated.hierarchical.model.AwfulTableKey)6 SqlSession (org.apache.ibatis.session.SqlSession)6 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AwfulTableExample (mbg.test.ib2j2.generated.hierarchical.model.AwfulTableExample)1 AwfulTableExample (mbg.test.ib2j5.generated.hierarchical.model.AwfulTableExample)1 AwfulTableExample (mbg.test.mb3.generated.hierarchical.model.AwfulTableExample)1