// Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
//    @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )  
//  , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//       
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Long id;
//     
//     @NotBlank
//     @Column(nullable = false , unique = true)
//     private String name;
//     
//     @ManyToOne(optional = false)
//     private EquipmentType equipmentType;
//     
//     public EquipmentModel() {    }
//     
//     public EquipmentModel(Long id) {
//         this.id = id;
//     }
//     
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((id == null) ? 0 : id.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (obj == null)
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         EquipmentModel other = (EquipmentModel) obj;
//         if (id == null) {
//             if (other.id != null)
//                 return false;
//         } else if (!id.equals(other.id))
//             return false;
//         return true;
//     }
// 
// 
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public EquipmentType getEquipmentType() {
//         return equipmentType;
//     }
// 
//     public void setEquipmentType(EquipmentType equipmentType) {
//         this.equipmentType = equipmentType;
//     }
//     
// }
// 
// Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
//     @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
// 	
// 	@Id
// 	@GeneratedValue(strategy = GenerationType.IDENTITY)
// 	private Long id;
// 	
// 	@NotBlank
// 	private String name;
// 	
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((id == null) ? 0 : id.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		EquipmentType other = (EquipmentType) obj;
// 		if (id == null) {
// 			if (other.id != null)
// 				return false;
// 		} else if (!id.equals(other.id))
// 			return false;
// 		return true;
// 	}
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	
// }


import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.EquipmentType;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.bean;



@Stateless
public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
    
    @PersistenceContext
    private EntityManager entityManager;
    
    public EquipmentModelBean() {
        super(EquipmentModel.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public boolean isNameAvailable(String name){
        TypedQuery<EquipmentModel> query = getEntityManager()
                    .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
        query.setParameter("name", name);
        return query.getResultList().isEmpty();
    }
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
//    @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )  
//  , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//       
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Long id;
//     
//     @NotBlank
//     @Column(nullable = false , unique = true)
//     private String name;
//     
//     @ManyToOne(optional = false)
//     private EquipmentType equipmentType;
//     
//     public EquipmentModel() {    }
//     
//     public EquipmentModel(Long id) {
//         this.id = id;
//     }
//     
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((id == null) ? 0 : id.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (obj == null)
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         EquipmentModel other = (EquipmentModel) obj;
//         if (id == null) {
//             if (other.id != null)
//                 return false;
//         } else if (!id.equals(other.id))
//             return false;
//         return true;
//     }
// 
// 
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public EquipmentType getEquipmentType() {
//         return equipmentType;
//     }
// 
//     public void setEquipmentType(EquipmentType equipmentType) {
//         this.equipmentType = equipmentType;
//     }
//     
// }
// 
// Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
//     @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
// 	
// 	@Id
// 	@GeneratedValue(strategy = GenerationType.IDENTITY)
// 	private Long id;
// 	
// 	@NotBlank
// 	private String name;
// 	
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((id == null) ? 0 : id.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		EquipmentType other = (EquipmentType) obj;
// 		if (id == null) {
// 			if (other.id != null)
// 				return false;
// 		} else if (!id.equals(other.id))
// 			return false;
// 		return true;
// 	}
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	
// }


// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.EquipmentType;

/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.bean;



@Stateless
public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
    
    @PersistenceContext
    private EntityManager entityManager;
    
    public EquipmentModelBean() {
        super(EquipmentModel.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public boolean isNameAvailable(String name){
        TypedQuery<EquipmentModel> query = getEntityManager()
                    .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
        query.setParameter("name", name);
        return query.getResultList().isEmpty();
    }
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public boolean isEquipmentTypeInUse(EquipmentType equipmentType){