Skip to content
Snippets Groups Projects
Commit e79607cc authored by zyq's avatar zyq Committed by Wei
Browse files

test relation and view

parent 9483d60d
No related branches found
No related tags found
Loading
......@@ -15,7 +15,7 @@ public class RelationshipDO {
private String name;
private Long view_id;
private Long viewId;
private Long firstEntityId;
......
package com.ic.er.service;
import com.ic.er.bean.dto.ViewDTO;
import com.ic.er.bean.vo.ViewVO;
import com.ic.er.common.ResultState;
import java.util.List;
public interface ViewService {
ViewVO createView(ViewDTO view);
//todo deleteById
ResultState deleteView(ViewDTO view);
List<ViewVO> queryAllView();
ViewVO queryView(ViewDTO view);
ResultState updateView(ViewDTO view);
}
......@@ -7,7 +7,7 @@
<resultMap id="BaseResultMap" type="com.ic.er.bean.entity.RelationshipDO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="view_id" property="view_id"/>
<result column="view_id" property="viewId"/>
<result column="first_entity_id" property="firstEntityId"/>
<result column="second_entity_id" property="secondEntityId"/>
<result column="first_attribute_id" property="firstAttributeId"/>
......@@ -33,42 +33,41 @@
select
id,name,view_id,first_entity_id,second_entity_id,first_attribute_id,second_attribute_id,cardinality,is_delete,gmt_create,gmt_modified
from relationship
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
and id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="viewId != null">
view_id = #{viewId,jdbcType=BIGINT},
and view_id = #{viewId,jdbcType=BIGINT}
</if>
<if test="firstEntityId != null">
first_entity_id = #{firstEntityId,jdbcType=BIGINT},
and first_entity_id = #{firstEntityId,jdbcType=BIGINT}
</if>
<if test="secondEntityId != null">
second_entity_id = #{secondEntityId,jdbcType=BIGINT},
and second_entity_id = #{secondEntityId,jdbcType=BIGINT}
</if>
<if test="firstAttributeId != null">
first_attribute_id = #{firstAttributeId,jdbcType=BIGINT},
and first_attribute_id = #{firstAttributeId,jdbcType=BIGINT}
</if>
<if test="secondAttributeId != null">
second_attribute_id = #{secondAttributeId,jdbcType=BIGINT},
and second_attribute_id = #{secondAttributeId,jdbcType=BIGINT}
</if>
<if test="cardinality != null">
cardinality = #{cardinality,jdbcType=SMALLINT},
and cardinality = #{cardinality,jdbcType=SMALLINT}
</if>
<if test="is_delete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
<if test="isDelete != null">
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<insert id="insert" parameterType="com.ic.er.bean.entity.RelationshipDO">
......
......@@ -28,30 +28,29 @@
select
id,name,creator,parent_id,is_delete,gmt_create,gmt_modified
from view
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="creator != null">
creator = #{creator,jdbcType=VARCHAR},
and creator = #{creator,jdbcType=VARCHAR}
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=BIGINT},
and parent_id = #{parentId,jdbcType=BIGINT}
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<select id="selectById" parameterType="java.lang.Long" resultMap="BaseResultMap">
......
package com.ic.er;
import com.ic.er.bean.entity.RelationshipDO;
import com.ic.er.dao.RelationshipMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Date;
import java.util.List;
public class testRelationMapper {
public static SqlSession sqlSession;
public static Connection connection;
public static RelationshipMapper relationMapper;
@Before
public void init() throws IOException {
InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
sqlSession = sqlSessionFactory.openSession(true);
connection = sqlSession.getConnection();
System.out.println(connection);
relationMapper = sqlSession.getMapper(RelationshipMapper.class);
}
@Test
public void testQueryRelation() {
Assert.assertNotNull(sqlSession);
RelationshipDO relationshipDO = relationMapper.selectById(Long.valueOf(3));
System.out.println(relationshipDO);
}
@Test
public void testQueryRelationByRelation(){
Assert.assertNotNull(sqlSession);
RelationshipDO relationshipDO = new RelationshipDO(null,"relation4",
null,null,null,null,null,
0,0,null,null);
List<RelationshipDO> res = relationMapper.selectByRelationship(relationshipDO);
System.out.println(res);
}
@Test
public void testCreateRelation(){
Assert.assertNotNull(sqlSession);
RelationshipDO relationshipDO = new RelationshipDO(Long.valueOf(4),"relation4",
Long.valueOf(3),Long.valueOf(4),Long.valueOf(3),Long.valueOf(4),Long.valueOf(4),
0,0,new Date(),new Date());
Assert.assertEquals(relationMapper.insert(relationshipDO),1);
}
@Test
public void testDeleteRelation(){
Assert.assertNotNull(sqlSession);
Assert.assertEquals(relationMapper.deleteById(Long.valueOf(3)),1);
}
@Test
public void testUpdateRelation(){
Assert.assertNotNull(sqlSession);
RelationshipDO relationshipDO = new RelationshipDO(Long.valueOf(4),"relation4update",
Long.valueOf(3),Long.valueOf(4),Long.valueOf(3),Long.valueOf(4),Long.valueOf(4),
0,0,new Date(),new Date());
Assert.assertEquals(relationMapper.updateById(relationshipDO),1);
}
}
......@@ -11,9 +11,12 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import javax.swing.text.View;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
public class testViewMapper {
......@@ -36,7 +39,42 @@ public class testViewMapper {
public void testQueryAllViews() {
Assert.assertNotNull(sqlSession);
List<ViewDO> viewDOList = viewMapper.selectAll();
Assert.assertEquals(viewDOList.size(), 0);
Assert.assertEquals(viewDOList.size(), 1);
}
@Test
public void testQueryById(){
Assert.assertNotNull(sqlSession);
ViewDO viewDO = viewMapper.selectById(Long.valueOf(3));
System.out.println(viewDO);
}
@Test
public void testCreateView(){
Assert.assertNotNull(sqlSession);
ViewDO viewDO = new ViewDO(Long.valueOf(3),"view3","creator3", Long.valueOf(1),0, new Date(),new Date());
Assert.assertEquals(viewMapper.insert(viewDO),1);
}
@Test
public void testDeleteView(){
Assert.assertNotNull(sqlSession);
Assert.assertEquals(viewMapper.deleteById(Long.valueOf(2)),1);
}
@Test
public void testQueryView(){
Assert.assertNotNull(sqlSession);
ViewDO viewDO = new ViewDO(null,"view1",null, null,0, null,null);
List<ViewDO> res = viewMapper.selectByView(viewDO);
System.out.println(res);
}
@Test
public void testUpdateView(){
Assert.assertNotNull(sqlSession);
ViewDO viewDO = new ViewDO(Long.valueOf(3),"view3update","creator3update", Long.valueOf(1),0, new Date(),new Date());
Assert.assertEquals(viewMapper.updateById(viewDO),1);
}
}
......@@ -7,7 +7,7 @@
<resultMap id="BaseResultMap" type="com.ic.er.bean.entity.RelationshipDO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="view_id" property="view_id"/>
<result column="view_id" property="viewId"/>
<result column="first_entity_id" property="firstEntityId"/>
<result column="second_entity_id" property="secondEntityId"/>
<result column="first_attribute_id" property="firstAttributeId"/>
......@@ -33,42 +33,41 @@
select
id,name,view_id,first_entity_id,second_entity_id,first_attribute_id,second_attribute_id,cardinality,is_delete,gmt_create,gmt_modified
from relationship
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
and id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="viewId != null">
view_id = #{viewId,jdbcType=BIGINT},
and view_id = #{viewId,jdbcType=BIGINT}
</if>
<if test="firstEntityId != null">
first_entity_id = #{firstEntityId,jdbcType=BIGINT},
and first_entity_id = #{firstEntityId,jdbcType=BIGINT}
</if>
<if test="secondEntityId != null">
second_entity_id = #{secondEntityId,jdbcType=BIGINT},
and second_entity_id = #{secondEntityId,jdbcType=BIGINT}
</if>
<if test="firstAttributeId != null">
first_attribute_id = #{firstAttributeId,jdbcType=BIGINT},
and first_attribute_id = #{firstAttributeId,jdbcType=BIGINT}
</if>
<if test="secondAttributeId != null">
second_attribute_id = #{secondAttributeId,jdbcType=BIGINT},
and second_attribute_id = #{secondAttributeId,jdbcType=BIGINT}
</if>
<if test="cardinality != null">
cardinality = #{cardinality,jdbcType=SMALLINT},
and cardinality = #{cardinality,jdbcType=SMALLINT}
</if>
<if test="is_delete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
<if test="isDelete != null">
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<insert id="insert" parameterType="com.ic.er.bean.entity.RelationshipDO">
......
......@@ -28,30 +28,29 @@
select
id,name,creator,parent_id,is_delete,gmt_create,gmt_modified
from view
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="creator != null">
creator = #{creator,jdbcType=VARCHAR},
and creator = #{creator,jdbcType=VARCHAR}
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=BIGINT},
and parent_id = #{parentId,jdbcType=BIGINT}
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<select id="selectById" parameterType="java.lang.Long" resultMap="BaseResultMap">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment