1 | /* |
2 | * Copyright 2006-2008 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 | public void setStatelessSession(StatelessSession statelessSession) { |
44 | this.statelessSession = statelessSession; |
45 | } |
46 | |
47 | public void setSession(Session statefulSession) { |
48 | this.statefulSession = statefulSession; |
49 | } |
50 | |
51 | public boolean isStatelessSession() { |
52 | return this.statefulSession==null && this.statelessSession!=null; |
53 | } |
54 | |
55 | protected StatelessSession getStatelessSession() { |
56 | return statelessSession; |
57 | } |
58 | |
59 | protected Session getStatefulSession() { |
60 | return statefulSession; |
61 | } |
62 | } |