View Javadoc

1   /*
2    * Copyright 2006-2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.item.database.orm;
18  
19  import org.hibernate.Query;
20  import org.hibernate.Session;
21  import org.hibernate.StatelessSession;
22  
23  /**
24   * <p>Abstract Hibernate Query Provider to serve as a base class for all
25   * Hibernate {@link Query} providers.</p>
26   *
27   * <p>The implementing provider can be configured to use either
28   * {@link StatelessSession} sufficient for simple mappings without the need
29   * to cascade to associated objects or standard Hibernate {@link Session}
30   * for more advanced mappings or when caching is desired.</p>
31   *
32   * @author Anatoly Polinsky
33   * @author Dave Syer
34   *
35   * @since 2.1
36   *
37   */
38  public abstract class AbstractHibernateQueryProvider implements HibernateQueryProvider {
39  
40  	private StatelessSession statelessSession;
41  	private Session statefulSession;
42  
43  	@Override
44  	public void setStatelessSession(StatelessSession statelessSession) {
45  		this.statelessSession = statelessSession;
46  	}
47  
48  	@Override
49  	public void setSession(Session statefulSession) {
50  		this.statefulSession = statefulSession;
51  	}
52  
53  	public boolean isStatelessSession() {
54  		return this.statefulSession==null && this.statelessSession!=null;
55  	}
56  
57  	protected StatelessSession getStatelessSession() {
58  		return statelessSession;
59  	}
60  
61  	protected Session getStatefulSession() {
62  		return statefulSession;
63  	}
64  }