/*
 * 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.dao;

import java.io.Serializable;

import anyframe.common.Page;
import anyframe.common.util.SearchVO;

/**
 * Generic DAO (Data Access Object) with common methods
 * to CRUD POJOs.
 * <p>
 * Extend this interface if you want typesafe (no
 * casting necessary) DAO's for your domain objects.
 * @author <a href="mailto:bwnoll@gmail.com">Bryan Noll</a>
 * @author modified by SooYeon Park
 * @param <T>
 *        a type variable
 * @param <PK>
 *        the primary key for that type
 */
public interface GenericDao<T, PK extends Serializable> {

    /**
     * Generic method to get an object based on class
     * and identifier. An
     * ObjectRetrievalFailureException Runtime
     * Exception is thrown if nothing is found.
     * @param id
     *        the identifier (primary key) of the
     *        object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id) throws Exception;

    /**
     * Checks for existence of an object of type T
     * using the id arg.
     * @param id
     *        the id of the entity
     * @return - true if it exists, false if it doesn't
     */
    boolean exists(PK id) throws Exception;

    /**
     * Generic method to save an object - handles both
     * update and insert.
     * @param object
     *        the object to save
     * @return the persisted object
     */
    T save(T object) throws Exception;

    /**
     * Generic method to delete an object based on
     * class and id
     * @param id
     *        the identifier (primary key) of the
     *        object to remove
     */
    void remove(PK id) throws Exception;

    /**
     * Generic method to get object list based on
     * search condition and search keyword
     * @param searchVO
     *        search condition and search keyword
     */
    public Page getList(SearchVO searchVO) throws Exception;

}

