// Generated by: hibernate/SpringHibernateDaoImpl.vsl in andromda-spring-cartridge.
// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package org.phoenixctms.ctsms.domain;

import java.util.Collection;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.phoenixctms.ctsms.query.CategoryCriterion;
import org.phoenixctms.ctsms.query.CriteriaUtil;
import org.phoenixctms.ctsms.util.DefaultSettings;
import org.phoenixctms.ctsms.util.SettingCodes;
import org.phoenixctms.ctsms.util.Settings;
import org.phoenixctms.ctsms.util.Settings.Bundle;
import org.phoenixctms.ctsms.vo.OpsSystBlockVO;

/**
 * @see OpsSystBlock
 */
public class OpsSystBlockDaoImpl
extends OpsSystBlockDaoBase
{

	@Override
	protected Collection<String> handleFindBlockPreferredRubricLabels(
			String preferredRubricLabelInfix, Integer limit) throws Exception {
		org.hibernate.Criteria opsSystBlockCriteria = this.getSession().createCriteria(OpsSystBlock.class);
		opsSystBlockCriteria.setCacheable(true);
		CategoryCriterion.apply(opsSystBlockCriteria, new CategoryCriterion(preferredRubricLabelInfix, "preferredRubricLabel", MatchMode.ANYWHERE));
		opsSystBlockCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("preferredRubricLabel", ""), Restrictions.isNull("preferredRubricLabel"))));
		// opsSystBlockCriteria.add(Restrictions.eq("revision", Settings.getString(SettingCodes.OPS_SYSTEMATICS_REVISION, Bundle.SETTINGS,
		// DefaultSettings.OPS_SYSTEMATICS_REVISION)));
		opsSystBlockCriteria.addOrder(Order.asc("preferredRubricLabel"));
		opsSystBlockCriteria.setProjection(Projections.distinct(Projections.property("preferredRubricLabel")));
		CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.OPS_SYST_BLOCK_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
				DefaultSettings.OPS_SYST_BLOCK_PREFERRED_RUBRIC_LABEL_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), opsSystBlockCriteria);
		return opsSystBlockCriteria.list();
	}

	/**
	 * Retrieves the entity object that is associated with the specified value object
	 * from the object store. If no such entity object exists in the object store,
	 * a new, blank entity is created
	 */
	private OpsSystBlock loadOpsSystBlockFromOpsSystBlockVO(OpsSystBlockVO opsSystBlockVO)
	{
		// TODO implement loadOpsSystBlockFromOpsSystBlockVO
		// throw new UnsupportedOperationException("org.phoenixctms.ctsms.domain.loadOpsSystBlockFromOpsSystBlockVO(OpsSystBlockVO) not yet implemented.");
		Long id = opsSystBlockVO.getId();
		OpsSystBlock opsSystBlock = null;
		if (id != null) {
			opsSystBlock = this.load(id);
		}
		if (opsSystBlock == null)
		{
			opsSystBlock = OpsSystBlock.Factory.newInstance();
		}
		return opsSystBlock;
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public OpsSystBlock opsSystBlockVOToEntity(OpsSystBlockVO opsSystBlockVO)
	{
		OpsSystBlock entity = this.loadOpsSystBlockFromOpsSystBlockVO(opsSystBlockVO);
		this.opsSystBlockVOToEntity(opsSystBlockVO, entity, true);
		return entity;
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public void opsSystBlockVOToEntity(
			OpsSystBlockVO source,
			OpsSystBlock target,
			boolean copyIfNull)
	{
		super.opsSystBlockVOToEntity(source, target, copyIfNull);
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public OpsSystBlockVO toOpsSystBlockVO(final OpsSystBlock entity)
	{
		return super.toOpsSystBlockVO(entity);
	}

	/**
	 * @inheritDoc
	 */
	@Override
	public void toOpsSystBlockVO(
			OpsSystBlock source,
			OpsSystBlockVO target)
	{
		super.toOpsSystBlockVO(source, target);
	}
}