001/* 002 * Copyright 2006-2013 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; 022 023/** 024 * <p>Abstract Hibernate Query Provider to serve as a base class for all 025 * Hibernate {@link Query} providers.</p> 026 * 027 * <p>The implementing provider can be configured to use either 028 * {@link StatelessSession} sufficient for simple mappings without the need 029 * to cascade to associated objects or standard Hibernate {@link Session} 030 * for more advanced mappings or when caching is desired.</p> 031 * 032 * @author Anatoly Polinsky 033 * @author Dave Syer 034 * 035 * @since 2.1 036 * 037 */ 038public abstract class AbstractHibernateQueryProvider<T> implements HibernateQueryProvider<T> { 039 040 private StatelessSession statelessSession; 041 private Session statefulSession; 042 043 @Override 044 public void setStatelessSession(StatelessSession statelessSession) { 045 this.statelessSession = statelessSession; 046 } 047 048 @Override 049 public void setSession(Session statefulSession) { 050 this.statefulSession = statefulSession; 051 } 052 053 public boolean isStatelessSession() { 054 return this.statefulSession==null && this.statelessSession!=null; 055 } 056 057 protected StatelessSession getStatelessSession() { 058 return statelessSession; 059 } 060 061 protected Session getStatefulSession() { 062 return statefulSession; 063 } 064}