</if>
</sql>
- <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <sql id="insertSql">
INSERT INTO projects (kee, deprecated_kee, uuid, project_uuid, module_uuid, module_uuid_path, name, long_name,
qualifier, scope, language, description, root_id, path, copy_resource_id, person_id, enabled,
created_at, authorization_updated_at)
#{developerId,jdbcType=BIGINT},
#{enabled,jdbcType=BOOLEAN},
#{createdAt,jdbcType=TIMESTAMP}, #{authorizationUpdatedAt,jdbcType=BIGINT})
+ </sql>
+
+ <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <include refid="insertSql"/>
+ </insert>
+
+ <insert id="insertBatch" parameterType="Component" useGeneratedKeys="false">
+ <include refid="insertSql"/>
</insert>
<update id="update" parameterType="Component" useGeneratedKeys="false">
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
-import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
db.prepareDbUnit(getClass(), "empty.xml");
ComponentDto componentDto = new ComponentDto()
- .setId(1L)
.setUuid("GHIJ")
.setProjectUuid("ABCD")
.setModuleUuid("EFGH")
db.assertDbUnit(getClass(), "insert-result.xml", "projects");
}
+ @Test
+ public void insertBatch() {
+ try (DbSession batchSession = db.myBatis().openSession(true)) {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ ComponentDto componentDto = new ComponentDto()
+ .setUuid("GHIJ")
+ .setProjectUuid("ABCD")
+ .setModuleUuid("EFGH")
+ .setModuleUuidPath(".ABCD.EFGH.")
+ .setKey("org.struts:struts-core:src/org/struts/RequestContext.java")
+ .setDeprecatedKey("org.struts:struts-core:src/org/struts/RequestContext.java")
+ .setName("RequestContext.java")
+ .setLongName("org.struts.RequestContext")
+ .setQualifier("FIL")
+ .setScope("FIL")
+ .setLanguage("java")
+ .setDescription("description")
+ .setPath("src/org/struts/RequestContext.java")
+ .setParentProjectId(3L)
+ .setCopyResourceId(5L)
+ .setDeveloperId(7L)
+ .setEnabled(true)
+ .setCreatedAt(DateUtils.parseDate("2014-06-18"))
+ .setAuthorizationUpdatedAt(123456789L);
+
+ underTest.insertBatch(batchSession, componentDto);
+ batchSession.commit();
+
+ assertThat(componentDto.getId()).isNull();
+ db.assertDbUnit(getClass(), "insert-result.xml", "projects");
+ }
+ }
+
@Test
public void insert_disabled_component() {
db.prepareDbUnit(getClass(), "empty.xml");