package org.ph.txex.mapper;


import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Param;

import org.apache.ibatis.annotations.Update;


public interface TxExMapper {


@Insert("insert into tbl_tx1 (num, codevalue) values (seq_tx.nextval, #{codeValue})")

public void insertMain(String codeValue)throws Exception;

@Insert("insert into tbl_tx2 (num, strValue) values (seq_tx.nextval, #{strValue})")

public void insertSub(String strValue)throws Exception;

@Update("update tbl_tx2 set strvalue = strvalue||#{appendValue} where num = #{num} ")

public void update1(@Param("num") Integer num,  @Param("appendValue")String appendValue)throws Exception;

}







package org.ph.txex.service;


import javax.inject.Inject;


import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Isolation;

import org.springframework.transaction.annotation.Propagation;

import org.springframework.transaction.annotation.Transactional;

import org.ph.txex.mapper.TxExMapper;


@Service

@Transactional

public class TxExService {

@Inject

TxExMapper mapper;

@Transactional(propagation = Propagation.REQUIRED)

public void addData(String codeValue, String strValue) throws Exception {

mapper.insertMain(codeValue);

mapper.insertSub(strValue);

}

public void updateData(Integer num, String value) throws Exception {

mapper.insertMain(value);

mapper.update1(num, value);

}

}







package org.ph.txex.test;


import static org.junit.Assert.fail;


import javax.inject.Inject;


import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.ph.txex.service.TxExService;


@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations ={"file:src/main/webapp/WEB-INF/spring/**/*.xml"})


public class TxExServiceTest {

@Inject

TxExService service;

@Test

public void testInsert() throws Exception{

String codeValue = "이이이3";

String strValue = "이이이3"; 

service.addData(codeValue, strValue);

}

@Test

public void testUpdate() throws Exception{

Integer num = 2;

String strValue = "zzz"; 

service.updateData(num, strValue);

}

}



Posted by 타다키치
,