Package com.ateam.webstore.dao

Source Code of com.ateam.webstore.dao.PersonDAO

/**
*
*/
package com.ateam.webstore.dao;

import java.io.Serializable;
import java.util.HashMap;

import javax.jdo.Query;

import com.ateam.webstore.dao.common.GenericDAOImpl;
import com.ateam.webstore.model.Person;

/**
* @author Hendrix Tavarez
*
*/
public class PersonDAO extends GenericDAOImpl<Person, Serializable> {

  public Person getPersonByLogin(String email) {
   
    Person person = null;
   
    try {
      Query query = getPersistenceManager().newQuery(getPersistentClass(), "login == :email");
      query.setUnique(true);
      person = (Person) query.execute(email);
     
      return getPersistenceManager().detachCopy(person);
     
    } catch (RuntimeException re) {
      throw re;
    } finally {
      getPersistenceManager().close();
    }
  }
 
  public Person getPersonByLoginAndPassword(String email, String password) {
   
    Person person = null;
   
    try {
      Query query = getPersistenceManager().newQuery(getPersistentClass(), "login == :email && password == :password");
      query.setUnique(true);
      HashMap<String, String> params = new HashMap<String, String>();
      params.put("email", email);
      params.put("password", password);
      person = (Person) query.executeWithMap(params);
     
      return getPersistenceManager().detachCopy(person);
     
    } catch (RuntimeException re) {
      throw re;
    } finally {
      getPersistenceManager().close();
    }
  }
}
TOP

Related Classes of com.ateam.webstore.dao.PersonDAO

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.