All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nan21.dnet.module.md.res.business.serviceimpl.AssetBaseService Maven / Gradle / Ivy

The newest version!
/* 
 * DNet eBusiness Suite
 * Copyright: 2010-2013 Nan21 Electronics SRL. All rights reserved.
 * Use is subject to license terms.
 */

package net.nan21.dnet.module.md.res.business.serviceimpl;

import java.util.List;
import javax.persistence.EntityManager;
import net.nan21.dnet.core.api.session.Session;
import net.nan21.dnet.core.business.service.entity.AbstractEntityService;
import net.nan21.dnet.module.bd.org.domain.entity.Organization;
import net.nan21.dnet.module.md.mm.prod.domain.entity.Product;
import net.nan21.dnet.module.md.res.business.service.IAssetBaseService;
import net.nan21.dnet.module.md.res.domain.entity.AssetBase;

/**
 * Repository functionality for {@link AssetBase} domain entity. It contains
 * finder methods based on unique keys as well as reference fields.
 * 
 */
public class AssetBaseService extends AbstractEntityService
		implements
			IAssetBaseService {

	public AssetBaseService() {
		super();
	}

	public AssetBaseService(EntityManager em) {
		super();
		this.setEntityManager(em);
	}

	@Override
	public Class getEntityClass() {
		return AssetBase.class;
	}

	/**
	 * Find by unique key
	 */
	public AssetBase findByCode(String code) {
		return (AssetBase) this.getEntityManager()
				.createNamedQuery(AssetBase.NQ_FIND_BY_CODE)
				.setParameter("pClientId", Session.user.get().getClientId())
				.setParameter("pCode", code).getSingleResult();
	}

	/**
	 * Find by reference: org
	 */
	public List findByOrg(Organization org) {
		return this.findByOrgId(org.getId());
	}

	/**
	 * Find by ID of reference: org.id
	 */
	public List findByOrgId(Long orgId) {
		return (List) this
				.getEntityManager()
				.createQuery(
						"select e from AssetBase e where e.clientId = :pClientId and e.org.id = :pOrgId",
						AssetBase.class)
				.setParameter("pClientId", Session.user.get().getClientId())
				.setParameter("pOrgId", orgId).getResultList();
	}

	/**
	 * Find by reference: product
	 */
	public List findByProduct(Product product) {
		return this.findByProductId(product.getId());
	}

	/**
	 * Find by ID of reference: product.id
	 */
	public List findByProductId(Long productId) {
		return (List) this
				.getEntityManager()
				.createQuery(
						"select e from AssetBase e where e.clientId = :pClientId and e.product.id = :pProductId",
						AssetBase.class)
				.setParameter("pClientId", Session.user.get().getClientId())
				.setParameter("pProductId", productId).getResultList();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy