Search in sources :

Example 1 with GeneratedalwaystestMapper

use of mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper in project generator by mybatis.

the class GeneratedAlwaysTest method testUpdateByPrimaryKeyWithBlobs.

@Test
public void testUpdateByPrimaryKeyWithBlobs() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName("barney");
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.updateByPrimaryKey(gaTest);
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("barney", returnedRecord.getName());
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) Test(org.junit.jupiter.api.Test)

Example 2 with GeneratedalwaystestMapper

use of mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper in project generator by mybatis.

the class GeneratedAlwaysTest method testUpdateByPrimaryKey.

@Test
public void testUpdateByPrimaryKey() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName("barney");
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.updateByPrimaryKey(gaTest);
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("barney", returnedRecord.getName());
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) Test(org.junit.jupiter.api.Test)

Example 3 with GeneratedalwaystestMapper

use of mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper in project generator by mybatis.

the class GeneratedAlwaysTest method testUpdateByPrimaryKeySelective.

@Test
public void testUpdateByPrimaryKeySelective() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName(null);
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.updateByPrimaryKeySelective(gaTest);
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("fred", returnedRecord.getName());
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) Test(org.junit.jupiter.api.Test)

Example 4 with GeneratedalwaystestMapper

use of mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper in project generator by mybatis.

the class GeneratedAlwaysTest method testUpdateByExample.

@Test
public void testUpdateByExample() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName("barney");
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.update(dsl -> GeneratedalwaystestMapper.updateAllColumns(gaTest, dsl).where(idPlus1, isEqualTo(2)).and(idPlus2, isEqualTo(3)));
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(dsl -> dsl.where(idPlus1, isEqualTo(2)).and(idPlus2, isEqualTo(3)));
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("barney", returnedRecord.getName());
        // should not have update the BLOB in regular update by primary key
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Test(org.junit.jupiter.api.Test) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) List(java.util.List) GeneratedalwaystestDynamicSqlSupport(mbg.test.mb3.generated.dsql.miscellaneous.support.GeneratedalwaystestDynamicSqlSupport) SqlBuilder(org.mybatis.dynamic.sql.SqlBuilder) SelectDSLCompleter(org.mybatis.dynamic.sql.select.SelectDSLCompleter) Assertions(org.junit.jupiter.api.Assertions) Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) TestUtilities(mbg.test.common.util.TestUtilities) SqlSession(org.apache.ibatis.session.SqlSession) Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) Test(org.junit.jupiter.api.Test)

Example 5 with GeneratedalwaystestMapper

use of mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper in project generator by mybatis.

the class GeneratedAlwaysTest method testUpdateByExampleSelective.

@Test
public void testUpdateByExampleSelective() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        GeneratedalwaystestMapper mapper = sqlSession.getMapper(GeneratedalwaystestMapper.class);
        Generatedalwaystest gaTest = new Generatedalwaystest();
        gaTest.setId(1);
        gaTest.setName("fred");
        // should be ignored
        gaTest.setIdPlus1(55);
        // should be ignored
        gaTest.setIdPlus2(66);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        int rows = mapper.insert(gaTest);
        assertEquals(1, rows);
        gaTest.setName(null);
        // should be ignored
        gaTest.setIdPlus1(77);
        // should be ignored
        gaTest.setIdPlus2(88);
        gaTest.setBlob1(TestUtilities.generateRandomBlob());
        rows = mapper.update(dsl -> GeneratedalwaystestMapper.updateSelectiveColumns(gaTest, dsl).where(idPlus1, isEqualTo(2)).and(idPlus2, isEqualTo(3)));
        assertEquals(1, rows);
        List<Generatedalwaystest> returnedRecords = mapper.select(dsl -> dsl.where(idPlus1, isEqualTo(2)).and(idPlus2, isEqualTo(3)));
        assertEquals(1, returnedRecords.size());
        Generatedalwaystest returnedRecord = returnedRecords.get(0);
        assertEquals(1, returnedRecord.getId().intValue());
        assertEquals(2, returnedRecord.getIdPlus1().intValue());
        assertEquals(3, returnedRecord.getIdPlus2().intValue());
        assertEquals("fred", returnedRecord.getName());
        assertTrue(TestUtilities.blobsAreEqual(gaTest.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Test(org.junit.jupiter.api.Test) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) List(java.util.List) GeneratedalwaystestDynamicSqlSupport(mbg.test.mb3.generated.dsql.miscellaneous.support.GeneratedalwaystestDynamicSqlSupport) SqlBuilder(org.mybatis.dynamic.sql.SqlBuilder) SelectDSLCompleter(org.mybatis.dynamic.sql.select.SelectDSLCompleter) Assertions(org.junit.jupiter.api.Assertions) Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) TestUtilities(mbg.test.common.util.TestUtilities) SqlSession(org.apache.ibatis.session.SqlSession) Generatedalwaystest(mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest) SqlSession(org.apache.ibatis.session.SqlSession) GeneratedalwaystestMapper(mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)24 Test (org.junit.jupiter.api.Test)24 GeneratedalwaystestMapper (mbg.test.mb3.generated.annotated.miscellaneous.mapper.GeneratedalwaystestMapper)8 Generatedalwaystest (mbg.test.mb3.generated.annotated.miscellaneous.model.Generatedalwaystest)8 GeneratedalwaystestMapper (mbg.test.mb3.generated.dsql.miscellaneous.mapper.GeneratedalwaystestMapper)8 Generatedalwaystest (mbg.test.mb3.generated.dsql.miscellaneous.model.Generatedalwaystest)8 GeneratedalwaystestMapper (mbg.test.mb3.generated.miscellaneous.mapper.GeneratedalwaystestMapper)8 Generatedalwaystest (mbg.test.mb3.generated.miscellaneous.model.Generatedalwaystest)8 List (java.util.List)3 TestUtilities (mbg.test.common.util.TestUtilities)3 GeneratedalwaystestCriteria (mbg.test.mb3.generated.annotated.miscellaneous.model.GeneratedalwaystestCriteria)3 GeneratedalwaystestDynamicSqlSupport (mbg.test.mb3.generated.dsql.miscellaneous.support.GeneratedalwaystestDynamicSqlSupport)3 GeneratedalwaystestCriteria (mbg.test.mb3.generated.miscellaneous.model.GeneratedalwaystestCriteria)3 Assertions (org.junit.jupiter.api.Assertions)3 SqlBuilder (org.mybatis.dynamic.sql.SqlBuilder)3 SelectDSLCompleter (org.mybatis.dynamic.sql.select.SelectDSLCompleter)3