Skip to content

Instantly share code, notes, and snippets.

@MirkoRossini
Created September 28, 2016 19:23
Show Gist options
  • Save MirkoRossini/647e4e8f4aefd913bcd664fce75b8685 to your computer and use it in GitHub Desktop.
Save MirkoRossini/647e4e8f4aefd913bcd664fce75b8685 to your computer and use it in GitHub Desktop.
package com.mirkorossini.transactionaltest.services;
import com.mirkorossini.transactionaltest.mappers.DummyMapper;
import org.apache.ibatis.session.SqlSessionManager;
import org.mybatis.guice.transactional.Transactional;
import javax.inject.Inject;
public class DummyService implements DummyServiceInt {
private final DummyMapper dummyMapper;
private final SqlSessionManager sqlSessionManager;
@Inject
public DummyService(final DummyMapper dummyMapper,
final SqlSessionManager sqlSessionManager) {
this.dummyMapper = dummyMapper;
this.sqlSessionManager = sqlSessionManager;
}
@Override
@Transactional
public void insertValue(int value) {
assert sqlSessionManager.isManagedSessionStarted();
}
public void insertValueCallingPublicMethod(int value) {
insertValue(value);
}
public void insertValueCallingPrivateMethod(int value) {
insertValuePrivate(value);
}
@Transactional
private void insertValuePrivate(int value) {
assert sqlSessionManager.isManagedSessionStarted();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment