001/*
002 * Copyright 2006-2008 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.batch.item.database.orm;
018
019import org.hibernate.query.Query;
020import org.hibernate.Session;
021import org.hibernate.StatelessSession;
022import org.springframework.batch.item.ItemReader;
023
024/**
025 * <p>
026 * Interface defining the functionality to be provided for generating queries
027 * for use with Hibernate {@link ItemReader}s or other custom built artifacts.
028 * </p>
029 * 
030 * @author Anatoly Polinsky
031 * @author Dave Syer
032 * 
033 * @since 2.1
034 * 
035 */
036public interface HibernateQueryProvider<T> {
037
038        /**
039         * <p>
040         * Create the query object which type will be determined by the underline
041         * implementation (e.g. Hibernate, JPA, etc.)
042         * </p>
043         * 
044         * @return created query
045         */
046        Query<T> createQuery();
047
048        /**
049         * <p>
050         * Inject a {@link Session} that can be used as a factory for queries. The
051         * state of the session is controlled by the caller (i.e. it should be
052         * closed if necessary).
053         * </p>
054         * 
055         * <p>
056         * Use either this method or {@link #setStatelessSession(StatelessSession)}
057         * </p>
058         * 
059         * @param session the {@link Session} to set
060         */
061        void setSession(Session session);
062
063        /**
064         * <p>
065         * Inject a {@link StatelessSession} that can be used as a factory for
066         * queries. The state of the session is controlled by the caller (i.e. it
067         * should be closed if necessary).
068         * </p>
069         * 
070         * <p>
071         * Use either this method or {@link #setSession(Session)}
072         * </p>
073         * 
074         * @param session the {@link StatelessSession} to set
075         */
076        void setStatelessSession(StatelessSession session);
077
078}