Search in sources :

Example 86 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class DynamicSqlTest method testPKBlobsSelectByPrimaryKey.

@Test
public void testPKBlobsSelectByPrimaryKey() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkblobsMapper mapper = sqlSession.getMapper(PkblobsMapper.class);
        Pkblobs record = new Pkblobs();
        record.setId(3);
        record.setBlob1(generateRandomBlob());
        record.setBlob2(generateRandomBlob());
        mapper.insert(record);
        Pkblobs record1 = new Pkblobs();
        record1.setId(6);
        record1.setBlob1(generateRandomBlob());
        record1.setBlob2(generateRandomBlob());
        mapper.insert(record1);
        Optional<Pkblobs> newRecord = mapper.selectByPrimaryKey(6);
        assertThat(newRecord).hasValueSatisfying(nr -> {
            assertEquals(record1.getId(), nr.getId());
            assertTrue(blobsAreEqual(record1.getBlob1(), nr.getBlob1()));
            assertTrue(blobsAreEqual(record1.getBlob2(), nr.getBlob2()));
        });
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkblobsMapper(mbg.test.mb3.generated.dsql.mapper.PkblobsMapper) Pkblobs(mbg.test.mb3.generated.dsql.model.Pkblobs) Test(org.junit.jupiter.api.Test)

Example 87 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class DynamicSqlTest method testFieldsOnlySelectByExampleNoCriteria.

@Test
public void testFieldsOnlySelectByExampleNoCriteria() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        FieldsonlyMapper mapper = sqlSession.getMapper(FieldsonlyMapper.class);
        Fieldsonly record = new Fieldsonly();
        record.setDoublefield(11.22);
        record.setFloatfield(33.44);
        record.setIntegerfield(5);
        mapper.insert(record);
        record = new Fieldsonly();
        record.setDoublefield(44.55);
        record.setFloatfield(66.77);
        record.setIntegerfield(8);
        mapper.insert(record);
        record = new Fieldsonly();
        record.setDoublefield(88.99);
        record.setFloatfield(100.111);
        record.setIntegerfield(9);
        mapper.insert(record);
        List<Fieldsonly> answer = mapper.select(SelectDSLCompleter.allRows());
        assertThat(answer.size()).isEqualTo(3);
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) FieldsonlyMapper(mbg.test.mb3.generated.dsql.mapper.FieldsonlyMapper) Fieldsonly(mbg.test.mb3.generated.dsql.model.Fieldsonly) Test(org.junit.jupiter.api.Test)

Example 88 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class DynamicSqlTest method testPKFieldsBlobsSelectByPrimaryKey.

@Test
public void testPKFieldsBlobsSelectByPrimaryKey() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
        Pkfieldsblobs record = new Pkfieldsblobs();
        record.setId1(3);
        record.setId2(4);
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        mapper.insert(record);
        Pkfieldsblobs record1 = new Pkfieldsblobs();
        record1.setId1(5);
        record1.setId2(6);
        record1.setFirstname("Scott");
        record1.setLastname("Jones");
        record1.setBlob1(generateRandomBlob());
        mapper.insert(record1);
        List<Pkfieldsblobs> answer = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(2, answer.size());
        Optional<Pkfieldsblobs> newRecord = mapper.selectByPrimaryKey(5, 6);
        assertThat(newRecord).hasValueSatisfying(nr -> {
            assertEquals(record1.getId1(), nr.getId1());
            assertEquals(record1.getId2(), nr.getId2());
            assertEquals(record1.getFirstname(), nr.getFirstname());
            assertEquals(record1.getLastname(), nr.getLastname());
            assertTrue(blobsAreEqual(record1.getBlob1(), nr.getBlob1()));
        });
    }
}
Also used : Pkfieldsblobs(mbg.test.mb3.generated.dsql.model.Pkfieldsblobs) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsblobsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsblobsMapper) Test(org.junit.jupiter.api.Test)

Example 89 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class DynamicSqlTest method testPKFieldsBlobsInsert.

@Test
public void testPKFieldsBlobsInsert() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        PkfieldsblobsMapper mapper = sqlSession.getMapper(PkfieldsblobsMapper.class);
        Pkfieldsblobs record = new Pkfieldsblobs();
        record.setId1(3);
        record.setId2(4);
        record.setFirstname("Jeff");
        record.setLastname("Smith");
        record.setBlob1(generateRandomBlob());
        mapper.insert(record);
        List<Pkfieldsblobs> answer = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(1, answer.size());
        Pkfieldsblobs returnedRecord = answer.get(0);
        assertEquals(record.getId1(), returnedRecord.getId1());
        assertEquals(record.getId2(), returnedRecord.getId2());
        assertEquals(record.getFirstname(), returnedRecord.getFirstname());
        assertEquals(record.getLastname(), returnedRecord.getLastname());
        assertTrue(blobsAreEqual(record.getBlob1(), returnedRecord.getBlob1()));
    }
}
Also used : Pkfieldsblobs(mbg.test.mb3.generated.dsql.model.Pkfieldsblobs) SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsblobsMapper(mbg.test.mb3.generated.dsql.mapper.PkfieldsblobsMapper) Test(org.junit.jupiter.api.Test)

Example 90 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class DynamicSqlTest method testAwfulTableDeleteByPrimaryKey.

@Test
public void testAwfulTableDeleteByPrimaryKey() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        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();
        int rows = mapper.deleteByPrimaryKey(generatedCustomerId);
        assertEquals(1, rows);
        List<AwfulTable> answer = mapper.select(SelectDSLCompleter.allRows());
        assertEquals(0, answer.size());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) AwfulTableMapper(mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper) AwfulTable(mbg.test.mb3.generated.dsql.model.AwfulTable) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)2117 Test (org.junit.jupiter.api.Test)1845 BaseDataTest (org.apache.ibatis.BaseDataTest)593 Test (org.junit.Test)127 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)104 Reader (java.io.Reader)97 User (com.github.pagehelper.model.User)87 ArrayList (java.util.ArrayList)84 UserMapper (com.github.pagehelper.mapper.UserMapper)75 Connection (java.sql.Connection)68 FirstName (mbg.test.common.FirstName)60 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)60 HashMap (java.util.HashMap)59 BeforeClass (org.junit.BeforeClass)56 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)54 RowBounds (org.apache.ibatis.session.RowBounds)36 Map (java.util.Map)34 Date (java.util.Date)33 List (java.util.List)24 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)23