package com.nobodyiam.impl;

import com.nobodyiam.annotation.RestrictBatchSize;
import com.nobodyiam.api.GreetingService;
import com.nobodyiam.dto.Greeting;
import com.nobodyiam.mapper.GreetingMapper;
import com.nobodyiam.util.ConstantsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Created by Jason on 7/5/15.
 */
@Service("greetingService")
public class GreetingServiceImpl implements GreetingService {

    @Autowired
    private GreetingMapper greetingMapper;

    @Override
    public Greeting getGreeting(long greetingId) {
        return greetingMapper.getGreeting(greetingId);
    }

    @Override
    @RestrictBatchSize(paramIndex = 0)
    public List<Greeting> getGreetings(int limit, int offset) {
        checkArgument(limit > 0, "Limit must be positive");
        checkArgument(offset >= 0, "Offset must be equal to or greater than 0");

        return greetingMapper.getGreetings(limit, offset);
    }

    @Override
    public int insertGreeting(Greeting greeting) {
        checkNotNull(greeting, "Greeting cannot be null");

        return greetingMapper.insertGreeting(greeting);
    }

    @Override
    public int updateGreeting(Greeting greeting) {
        checkNotNull(greeting, "Greeting cannot be null");

        return greetingMapper.updateGreeting(greeting);
    }
}
@@ -198,49 +198,8 @@
 er;%0A
-import com.nobodyiam.util.ConstantsUtil;%0A
 impo
@@ -303,16 +303,205 @@
 Service;
+%0Aimport org.springframework.transaction.annotation.Isolation;%0Aimport org.springframework.transaction.annotation.Propagation;%0Aimport org.springframework.transaction.annotation.Transactional;
 %0A%0Aimport
@@ -717,16 +717,122 @@
 rvice%22)%0A
+@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)%0A
 public c
@@ -1403,32 +1403,105 @@
 %0A%0A    @Override%0A
+    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)%0A
     public int i
@@ -1664,32 +1664,105 @@
 %0A%0A    @Override%0A
+    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)%0A
     public int u

add transaction annotation