Search in sources :

Example 21 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class DynamicSqlTest method testPKOnlySelectByExampleWithMultiInsert.

@Test
public void testPKOnlySelectByExampleWithMultiInsert() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        mapper.insertMultiple(Arrays.asList(new Pkonly(1, 3), new Pkonly(5, 6), new Pkonly(7, 8)));
        List<Pkonly> answer = mapper.select(dsl -> dsl.where(pkonly.id, isGreaterThan(4)).orderBy(pkonly.id));
        assertThat(answer.size()).isEqualTo(2);
        assertThat(answer.get(0).getId().intValue()).isEqualTo(5);
        assertThat(answer.get(0).getSeqNum().intValue()).isEqualTo(6);
        assertThat(answer.get(1).getId().intValue()).isEqualTo(7);
        assertThat(answer.get(1).getSeqNum().intValue()).isEqualTo(8);
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.dsql.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) Pkonly(mbg.test.mb3.generated.dsql.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 22 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class DynamicSqlTest method testPKOnlySelectByExampleNoCriteria.

@Test
public void testPKOnlySelectByExampleNoCriteria() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly(1, 3);
        mapper.insert(key);
        key = new Pkonly(5, 6);
        mapper.insert(key);
        key = new Pkonly(7, 8);
        mapper.insert(key);
        List<Pkonly> answer = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(3, answer.size());
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.dsql.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) Pkonly(mbg.test.mb3.generated.dsql.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 23 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class SimpleTest method testPkonly.

@Test
public void testPkonly() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly record = new Pkonly();
        record.setId(1);
        record.setSeqNum(1);
        mapper.insert(record);
        record = new Pkonly();
        record.setId(1);
        record.setSeqNum(2);
        mapper.insert(record);
        record = new Pkonly();
        record.setId(2);
        record.setSeqNum(1);
        mapper.insert(record);
        record = new Pkonly();
        record.setId(2);
        record.setSeqNum(2);
        mapper.insert(record);
        List<Pkonly> records = mapper.selectAll();
        assertEquals(4, records.size());
        mapper.deleteByPrimaryKey(record.getId(), record.getSeqNum());
        records = mapper.selectAll();
        assertEquals(3, records.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.simple.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) Pkonly(mbg.test.mb3.generated.simple.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 24 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlySelectByExample.

@Test
public void testPKOnlySelectByExample() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(5);
        key.setSeqNum(6);
        mapper.insert(key);
        key = new Pkonly();
        key.setId(7);
        key.setSeqNum(8);
        mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        example.createCriteria().andIdGreaterThan(4);
        List<Pkonly> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.annotated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.annotated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.annotated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Example 25 with Pkonly

use of mbg.test.mb3.generated.dsql.model.Pkonly in project generator by mybatis.

the class FlatJava5Test method testPKOnlyDeleteByPrimaryKey.

@Test
public void testPKOnlyDeleteByPrimaryKey() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkonlyMapper mapper = sqlSession.getMapper(PkonlyMapper.class);
        Pkonly key = new Pkonly();
        key.setId(1);
        key.setSeqNum(3);
        int rows = mapper.insert(key);
        key = new Pkonly();
        key.setId(5);
        key.setSeqNum(6);
        rows = mapper.insert(key);
        PkonlyExample example = new PkonlyExample();
        List<Pkonly> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
        rows = mapper.deleteByPrimaryKey(5, 6);
        assertEquals(1, rows);
        answer = mapper.selectByExample(example);
        assertEquals(1, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : PkonlyMapper(mbg.test.mb3.generated.flat.mapper.PkonlyMapper) SqlSession(org.apache.ibatis.session.SqlSession) PkonlyExample(mbg.test.mb3.generated.flat.model.PkonlyExample) Pkonly(mbg.test.mb3.generated.flat.model.Pkonly) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)37 Test (org.junit.jupiter.api.Test)37 PkonlyMapper (mbg.test.mb3.generated.dsql.mapper.PkonlyMapper)11 Pkonly (mbg.test.mb3.generated.dsql.model.Pkonly)11 PkonlyMapper (mbg.test.mb3.generated.annotated.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.annotated.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.annotated.flat.model.PkonlyExample)8 PkonlyMapper (mbg.test.mb3.generated.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.flat.model.PkonlyExample)8 PkonlyMapper (mbg.test.mb3.generated.mixed.flat.mapper.PkonlyMapper)8 Pkonly (mbg.test.mb3.generated.mixed.flat.model.Pkonly)8 PkonlyExample (mbg.test.mb3.generated.mixed.flat.model.PkonlyExample)8 List (java.util.List)2 TestUtilities.blobsAreEqual (mbg.test.common.util.TestUtilities.blobsAreEqual)2 TestUtilities.generateRandomBlob (mbg.test.common.util.TestUtilities.generateRandomBlob)2 AwfulTableDynamicSqlSupport.awfulTable (mbg.test.mb3.generated.dsql.mapper.AwfulTableDynamicSqlSupport.awfulTable)2 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)2 FieldsblobsDynamicSqlSupport.fieldsblobs (mbg.test.mb3.generated.dsql.mapper.FieldsblobsDynamicSqlSupport.fieldsblobs)2 FieldsblobsMapper (mbg.test.mb3.generated.dsql.mapper.FieldsblobsMapper)2