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 import org.springframework.batch.item.ItemReader;
23
24 /**
25 * <p>
26 * Interface defining the functionality to be provided for generating queries
27 * for use with Hibernate {@link ItemReader}s or other custom built artifacts.
28 * </p>
29 *
30 * @author Anatoly Polinsky
31 * @author Dave Syer
32 *
33 * @since 2.1
34 *
35 */
36 public interface HibernateQueryProvider {
37
38 /**
39 * <p>
40 * Create the query object which type will be determined by the underline
41 * implementation (e.g. Hibernate, JPA, etc.)
42 * </p>
43 *
44 * @return created query
45 */
46 Query createQuery();
47
48 /**
49 * <p>
50 * Inject a {@link Session} that can be used as a factory for queries. The
51 * state of the session is controlled by the caller (i.e. it should be
52 * closed if necessary).
53 * </p>
54 *
55 * <p>
56 * Use either this method or {@link #setStatelessSession(StatelessSession)}
57 * </p>
58 *
59 * @param session the {@link Session} to set
60 */
61 void setSession(Session session);
62
63 /**
64 * <p>
65 * Inject a {@link StatelessSession} that can be used as a factory for
66 * queries. The state of the session is controlled by the caller (i.e. it
67 * should be closed if necessary).
68 * </p>
69 *
70 * <p>
71 * Use either this method or {@link #setSession(Session)}
72 * </p>
73 *
74 * @param session the {@link StatelessSession} to set
75 */
76 void setStatelessSession(StatelessSession session);
77
78 }