Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sl-eng committed Dec 21, 2012
1 parent 496cdcc commit 917ebfd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Expand Up @@ -25,6 +25,7 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
Expand All @@ -46,6 +47,8 @@ public class HPersonEmailValidationKey implements Serializable
{
private static final long serialVersionUID = 1L;

private Long id;

private String keyHash;

private HPerson person;
Expand All @@ -62,7 +65,14 @@ public HPersonEmailValidationKey(HPerson person, String email, String keyHash, D
this.email = email;
}

@Column(unique = true, nullable = false)
@Id
@GeneratedValue
public Long getId()
{
return id;
}

@Column(nullable = false, unique = true)
public String getKeyHash()
{
return keyHash;
Expand All @@ -75,9 +85,9 @@ public Date getCreationDate()
return creationDate;
}

@Id

@ManyToOne(optional = false)
@JoinColumn(name = "personId", nullable = false)
@JoinColumn(name = "personId", nullable = false, unique = true)
public HPerson getPerson()
{
return person;
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.model.HPerson;
import org.zanata.model.HPersonEmailValidationKey;


Expand All @@ -45,12 +46,22 @@ public PersonEmailValidationKeyDAO(Session session)
super(HPersonEmailValidationKey.class, session);
}


public HPersonEmailValidationKey findByKeyHash(String keyHash)
{
Query query = getSession().createQuery("from HPersonEmailValidationKey as key where key.keyHash= :keyHash");
query.setParameter("keyHash", keyHash);
query.setCacheable(false);
query.setComment("PersonEmailValidationKeyDAO.findByKeyHashId");
return (HPersonEmailValidationKey) query.uniqueResult();
Query query = getSession().createQuery("from HPersonEmailValidationKey as key where key.keyHash= :keyHash");
query.setParameter("keyHash", keyHash);
query.setCacheable(false);
query.setComment("PersonEmailValidationKeyDAO.findByKeyHash");
return (HPersonEmailValidationKey) query.uniqueResult();
}

public HPersonEmailValidationKey findByPersonId(Long personId)
{
Query query = getSession().createQuery("from HPersonEmailValidationKey as key where key.person.id= :personId");
query.setLong("personId", personId);
query.setCacheable(false);
query.setComment("PersonEmailValidationKeyDAO.findByPersonId");
return (HPersonEmailValidationKey) query.uniqueResult();
}
}
Expand Up @@ -76,7 +76,7 @@ public String generateActivationKey(HPerson person, String email)
String var = person.getId() + email + System.currentTimeMillis();
String hash = HashUtil.generateHash(var);

HPersonEmailValidationKey entry = personEmailValidationKeyDAO.findById(person.getId(), false);
HPersonEmailValidationKey entry = personEmailValidationKeyDAO.findByPersonId(person.getId());
if (entry == null)
{
entry = new HPersonEmailValidationKey(person, email, hash, new Date());
Expand Down
Expand Up @@ -52,11 +52,14 @@
<changeSet id="4" author="aeng@redhat.com">
<comment>Add HPersonEmailValidationKey table</comment>
<createTable tableName="HPersonEmailValidationKey">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="keyHash" type="varchar(32)">
<constraints nullable="false" unique="true" />
<constraints nullable="false" unique="true"/>
</column>
<column name="personId" type="bigint">
<constraints primaryKey="true" nullable="false" />
<constraints nullable="false" unique="true" />
</column>
<column name="email" type="varchar(255)">
<constraints nullable="false" />
Expand Down

0 comments on commit 917ebfd

Please sign in to comment.