Search in sources :

Example 26 with Pkfields

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

the class HierarchicalJava5Test method testPKFieldsSelectByPrimaryKey.

@Test
public void testPKFieldsSelectByPrimaryKey() {
    PkfieldsDAO dao = getPkfieldsDAO();
    try {
        Pkfields record = new Pkfields();
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setId1(1);
        record.setId2(2);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Bob");
        record.setLastname("Jones");
        record.setId1(3);
        record.setId2(4);
        dao.insert(record);
        PkfieldsKey key = new PkfieldsKey();
        key.setId1(3);
        key.setId2(4);
        Pkfields newRecord = dao.selectByPrimaryKey(key);
        assertNotNull(newRecord);
        assertEquals(record.getFirstname(), newRecord.getFirstname());
        assertEquals(record.getLastname(), newRecord.getLastname());
        assertEquals(record.getId1(), newRecord.getId1());
        assertEquals(record.getId2(), newRecord.getId2());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pkfields(mbg.test.ib2j5.generated.hierarchical.model.Pkfields) PkfieldsKey(mbg.test.ib2j5.generated.hierarchical.model.PkfieldsKey) PkfieldsDAO(mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO) Test(org.junit.Test)

Example 27 with Pkfields

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

the class HierarchicalJava5Test method testPKFieldsSelectByExampleComplexLike.

@Test
public void testPKFieldsSelectByExampleComplexLike() {
    PkfieldsDAO dao = getPkfieldsDAO();
    try {
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        dao.insert(record);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andFirstnameLike("B%").andId2EqualTo(3);
        example.or(example.createCriteria().andFirstnameLike("Wi%"));
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = dao.selectByExample(example);
        assertEquals(2, answer.size());
        Pkfields returnedRecord = answer.get(0);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(2, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pkfields(mbg.test.ib2j5.generated.hierarchical.model.Pkfields) PkfieldsExample(mbg.test.ib2j5.generated.hierarchical.model.PkfieldsExample) PkfieldsDAO(mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO) Test(org.junit.Test)

Example 28 with Pkfields

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

the class HierarchicalJava5Test method testPKFieldsInsert.

@Test
public void testPKFieldsInsert() {
    PkfieldsDAO dao = getPkfieldsDAO();
    try {
        Pkfields record = new Pkfields();
        record.setDatefield(new Date());
        record.setDecimal100field(10L);
        record.setDecimal155field(new BigDecimal("15.12345"));
        record.setDecimal30field((short) 3);
        record.setDecimal60field(6);
        record.setFirstname("Jeff");
        record.setId1(1);
        record.setId2(2);
        record.setLastname("Butler");
        record.setTimefield(new Date());
        record.setTimestampfield(new Date());
        dao.insert(record);
        PkfieldsKey key = new PkfieldsKey();
        key.setId1(1);
        key.setId2(2);
        Pkfields returnedRecord = dao.selectByPrimaryKey(key);
        assertNotNull(returnedRecord);
        assertTrue(datesAreEqual(record.getDatefield(), returnedRecord.getDatefield()));
        assertEquals(record.getDecimal100field(), returnedRecord.getDecimal100field());
        assertEquals(record.getDecimal155field(), returnedRecord.getDecimal155field());
        assertEquals(record.getDecimal30field(), returnedRecord.getDecimal30field());
        assertEquals(record.getDecimal60field(), returnedRecord.getDecimal60field());
        assertEquals(record.getFirstname(), returnedRecord.getFirstname());
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(record.getLastname(), returnedRecord.getLastname());
        assertTrue(timesAreEqual(record.getTimefield(), returnedRecord.getTimefield()));
        assertEquals(record.getTimestampfield(), returnedRecord.getTimestampfield());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pkfields(mbg.test.ib2j5.generated.hierarchical.model.Pkfields) PkfieldsKey(mbg.test.ib2j5.generated.hierarchical.model.PkfieldsKey) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PkfieldsDAO(mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO) Test(org.junit.Test)

Example 29 with Pkfields

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

the class HierarchicalJava5Test method testPKFieldsSelectByExampleIn.

@Test
public void testPKFieldsSelectByExampleIn() {
    PkfieldsDAO dao = getPkfieldsDAO();
    try {
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        dao.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        dao.insert(record);
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(3);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andId2In(ids);
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = dao.selectByExample(example);
        assertEquals(4, answer.size());
        Pkfields returnedRecord = answer.get(0);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(3);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) Pkfields(mbg.test.ib2j5.generated.hierarchical.model.Pkfields) PkfieldsExample(mbg.test.ib2j5.generated.hierarchical.model.PkfieldsExample) PkfieldsDAO(mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO) Test(org.junit.Test)

Example 30 with Pkfields

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

the class HierarchicalJava5Test method testPKFieldsSelectByExampleIn.

@Test
public void testPKFieldsSelectByExampleIn() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        mapper.insert(record);
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(3);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andId2In(ids);
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(4, answer.size());
        Pkfields returnedRecord = answer.get(0);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(1);
        assertEquals(1, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(2);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(1, returnedRecord.getId2().intValue());
        returnedRecord = answer.get(3);
        assertEquals(2, returnedRecord.getId1().intValue());
        assertEquals(3, returnedRecord.getId2().intValue());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.hierarchical.mapper.PkfieldsMapper) ArrayList(java.util.ArrayList) Pkfields(mbg.test.mb3.generated.hierarchical.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.hierarchical.model.PkfieldsExample) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)32 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)29 List (java.util.List)27 PkfieldsDAO (mbg.test.ib2j2.generated.conditional.dao.PkfieldsDAO)16 Pkfields (mbg.test.ib2j2.generated.conditional.model.Pkfields)16 PkfieldsDAO (mbg.test.ib2j2.generated.flat.dao.PkfieldsDAO)16 Pkfields (mbg.test.ib2j2.generated.flat.model.Pkfields)16 PkfieldsDAO (mbg.test.ib2j2.generated.hierarchical.dao.PkfieldsDAO)16 Pkfields (mbg.test.ib2j2.generated.hierarchical.model.Pkfields)16 PkfieldsDAO (mbg.test.ib2j5.generated.hierarchical.dao.PkfieldsDAO)16 Pkfields (mbg.test.ib2j5.generated.hierarchical.model.Pkfields)16 PkfieldsMapper (mbg.test.mb3.generated.hierarchical.mapper.PkfieldsMapper)16 Pkfields (mbg.test.mb3.generated.hierarchical.model.Pkfields)16 SqlSession (org.apache.ibatis.session.SqlSession)16 PkfieldsExample (mbg.test.ib2j2.generated.conditional.model.PkfieldsExample)12 PkfieldsExample (mbg.test.ib2j2.generated.flat.model.PkfieldsExample)12 PkfieldsExample (mbg.test.ib2j2.generated.hierarchical.model.PkfieldsExample)12 PkfieldsExample (mbg.test.ib2j5.generated.hierarchical.model.PkfieldsExample)12 PkfieldsExample (mbg.test.mb3.generated.hierarchical.model.PkfieldsExample)12