Package ua.ck.geekhub

Source Code of ua.ck.geekhub.GroupService

package ua.ck.geekhub;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import ua.ck.geekhub.entity.Group;

import javax.transaction.Transactional;
import java.util.List;

@Repository
@Transactional
public class GroupService {

    @Autowired
    SessionFactory sessionFactory;

    public void saveGroup(Group group) {
        sessionFactory.getCurrentSession().saveOrUpdate(group);
    }

    public Group getGroup(Integer id) {
        return (Group) sessionFactory.getCurrentSession().get(Group.class, id);
    }

    public void deleteGroup(Group group) {
        sessionFactory.getCurrentSession().delete(group);
    }

    public void createGroup(String name) {
        Group group = new Group();
        group.setName(name);
        saveGroup(group);
    }

    public List<Group> getGroups() {
        return sessionFactory.getCurrentSession().createCriteria(Group.class).list();
    }
}
TOP

Related Classes of ua.ck.geekhub.GroupService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.