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

br.com.arsmachina.controller.impl.ReadableControllerImpl Maven / Gradle / Ivy

// Copyright 2008-2013 Thiago H. de Paula Figueiredo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package br.com.arsmachina.controller.impl;

import java.io.Serializable;
import java.util.List;

import br.com.arsmachina.controller.ReadableController;
import br.com.arsmachina.dao.ReadableDAO;
import br.com.arsmachina.dao.SortCriterion;

/**
 * Abstract class that implements the {@link ReadableController} interface by delegating all method
 * calls to a {@link ReadableDAO} passed through its constructor.
 * 
 * @author Thiago H. de Paula Figueiredo
 * @param  the entity class related to this controller.
 * @param  the type of the field that represents the entity class' primary key.
 */
public abstract class ReadableControllerImpl implements ReadableController {

	private ReadableDAO dao;

	/**
	 * Single constructor of this class.
	 * 
	 * @param dao a {@link DAO}. It cannot be null.
	 */
	public ReadableControllerImpl(ReadableDAO dao) {

		if (dao == null) {
			throw new IllegalArgumentException("Parameter dao cannot be null");
		}

		this.dao = dao;

	}

	/**
	 * Invokes dao.countAll().
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#countAll()
	 */
	public long countAll() {
		return dao.countAll();
	}

	/**
	 * Invokes dao.findAll().
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#findAll()
	 */
	public List findAll() {
		return dao.findAll();
	}

	/**
	 * Invokes dao.findAll().
	 * @param firstResult
	 * @param maxResults
	 * @param sortCriteria
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#findAll(int, int, br.com.arsmachina.dao.SortConstraint[])
	 */
	public List findAll(int firstResult, int maxResults, SortCriterion... sortCriteria) {
		return dao.findAll(firstResult, maxResults, sortCriteria);
	}

	/**
	 * Invokes dao.findById().
	 * @param ids
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#findById(K[])
	 */
	public List findByIds(K... ids) {
		return dao.findByIds(ids);
	}

	/**
	 * Invokes dao.findByExample().
	 * @param example
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#findByExample(java.lang.Object)
	 */
	public List findByExample(T example) {
		return dao.findByExample(example);
	}

	/**
	 * Invokes dao.findById().
	 * @param id
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#findById(java.io.Serializable)
	 */
	public T findById(K id) {
		return dao.findById(id);
	}

	/**
	 * Invokes dao.refresh().
	 * @param object
	 * @see br.com.arsmachina.dao.ReadableDAO#refresh(java.lang.Object)
	 */
	public T refresh(T object) {
		return dao.refresh(object);
	}

	/**
	 * Invokes dao.reattach().
	 * @param object
	 * @return
	 * @see br.com.arsmachina.dao.ReadableDAO#reattach(java.lang.Object)
	 */
	public T reattach(T object) {
		return dao.reattach(object);
	}

}