Created
November 30, 2012 00:24
-
-
Save martinlau/4172872 to your computer and use it in GitHub Desktop.
A simple service using spring's @transactional and dependency injection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.com.permeance.service; | |
public interface FakeService { | |
void doStuff() throws Exception; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.com.permeance.service.impl; | |
import au.com.permeance.service.FakeService; | |
import com.liferay.portal.service.UserLocalService; | |
import com.liferay.portal.util.Portal; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import org.springframework.transaction.annotation.Transactional; | |
@Service | |
public class FakeServiceImpl implements FakeService { | |
private final Portal portal; | |
private final UserLocalService userLocalService; | |
@Autowired | |
public FakeServiceImpl(Portal portal, | |
UserLocalService userLocalService) { | |
this.portal = portal; | |
this.userLocalService = userLocalService; | |
} | |
@Override | |
@Transactional(rollbackFor = Exception.class) | |
public void doStuff() throws Exception { | |
userLocalService.getDefaultUser(portal.getDefaultCompanyId()); | |
throw new RuntimeException("Don't really delete that user"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment