Created
March 27, 2017 16:26
-
-
Save lynas/b8a591077a036e01ebaea8ae3abfd169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 com.lynas.service.impl; | |
import com.lynas.model.AppUser; | |
import com.lynas.service.AppUserService; | |
import org.hibernate.SessionFactory; | |
import org.hibernate.criterion.Restrictions; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import org.springframework.transaction.annotation.Transactional; | |
@Service(value = "appUserService") | |
public class AppUserServiceImpl implements AppUserService { | |
private final SessionFactory sessionFactory; | |
@Autowired | |
public AppUserServiceImpl(SessionFactory sessionFactory) { | |
this.sessionFactory = sessionFactory; | |
} | |
@Override | |
@Transactional | |
public AppUser loadUserByUsername(String username) { | |
return (AppUser) sessionFactory.getCurrentSession() | |
.createCriteria(AppUser.class) | |
.add(Restrictions.eq("username", username)) | |
.uniqueResult(); | |
} | |
@Transactional | |
@Override | |
public long post(AppUser appUser) { | |
return (long) sessionFactory.getCurrentSession().save(appUser); | |
} | |
@Transactional | |
@Override | |
public AppUser get(long id) { | |
return sessionFactory.getCurrentSession().get(AppUser.class, id); | |
} | |
@Transactional | |
@Override | |
public AppUser patch(AppUser appUser) { | |
sessionFactory.getCurrentSession().update(appUser); | |
return get(appUser.getId()); | |
} | |
@Transactional | |
@Override | |
public boolean delete(long id) { | |
sessionFactory.getCurrentSession().delete(get(id)); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment