Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.overhead.markeugie.manager; import com.overhead.markeugie.entity.Accounts; import com.overhead.markeugie.services.AccountsService; import com.overhead.markeugie.util.RegistrationHibernateUtil; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.criterion.Restrictions; /** * * @author markeugie */ public class AccountsManager extends UnicastRemoteObject implements AccountsService { public AccountsManager() throws RemoteException { } @Override public Accounts add(Accounts account) throws RemoteException { Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.save(account); session.getTransaction().commit(); session.close(); return account; } @Override public void edit() throws RemoteException { } @Override public void delete() throws RemoteException { } @Override public void getAll() throws RemoteException { } @Override public String getPasswordByUsername(Accounts account) throws RemoteException { String password = null; Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Accounts.class); criteria.add(Restrictions.eq("username", account.getUsername())); Accounts checkedAccount = (Accounts) criteria.uniqueResult(); password = checkedAccount.getPassword(); session.getTransaction().commit(); session.close(); return password; } @Override public Accounts getByName(String username) throws RemoteException { Accounts loginAccount = null; Session session = RegistrationHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Accounts.class); criteria.add(Restrictions.eq("username", username)); criteria.setMaxResults(1); loginAccount = (Accounts) criteria.uniqueResult(); session.getTransaction().commit(); session.close(); return loginAccount; } }