/*
 * Copyright 2002-2009 the original author or authors.
 *
 * 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 anyframe.core.basis.service.impl;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import anyframe.common.Page;
import anyframe.common.util.SearchVO;
import anyframe.core.basis.dao.GenericDao;
import anyframe.core.basis.service.GenericManager;

/**
 * This class serves as the Base class for all other
 * Managers - namely to hold common CRUD methods that
 * they might all use. You should only need to extend
 * this class when your require custom CRUD logic.
 * <p>
 * 
 * @author <a href="mailto:matt@raibledesigns.com">Matt
 *         Raible</a>
 * @author modified by SooYeon Park
 * @param <T>
 *        a type variable
 * @param <PK>
 *        the primary key for that type
 */
public class GenericManagerImpl<T, PK extends Serializable> implements
        GenericManager<T, PK> {
    /**
     * Log variable for all child classes. Uses
     * LogFactory.getLog(getClass()) from Commons
     * Logging
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * GenericDao instance, set by constructor of child
     * classes
     */
    protected GenericDao<T, PK> dao;

    public GenericManagerImpl() {
    }

    public GenericManagerImpl(GenericDao<T, PK> genericDao) {
        this.dao = genericDao;
    }

    /**
     * {@inheritDoc}
     */
    public T get(PK id) throws Exception {
        return dao.get(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean exists(PK id) throws Exception {
        return dao.exists(id);
    }

    /**
     * {@inheritDoc}
     */
    public T save(T object) throws Exception {
        return dao.save(object);
    }

    /**
     * {@inheritDoc}
     */
    public void remove(PK id) throws Exception {
        dao.remove(id);
    }

    /**
     * {@inheritDoc}
     */
    public Page getList(SearchVO searchVO) throws Exception {
        return dao.getList(searchVO);
    }
}

