01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.compass.core;
18:
19: /**
20: * Callback interface for Compass code. To be used with CompassTemplate's
21: * execute methods, assumably often as anonymous classes within a method
22: * implementation. The typical implementation will call
23: * CompassSession.load/find/save to perform some operations on searchable
24: * objects.
25: *
26: * @author kimchy
27: */
28: public interface CompassCallback<T> {
29:
30: /**
31: * Gets called by <code>CompassTemplate.execute</code> with an active
32: * Compass Session. Does not need to care about activating or closing the
33: * Session, or handling transactions.
34: *
35: * <p>If called within a thread-bound Compass transaction (initiated by an
36: * outer compass transaction abstraction), the code will simply get executed
37: * on the outer compass transaction with its transactional semantics.
38: *
39: * <p>Allows for returning a result object created within the callback, i.e. a
40: * domain object or a hits of domain objects. Note that there's special
41: * support for single step actions: see CompassTemplate.find etc. A thrown
42: * RuntimeException is treated as application exception, it gets propagated
43: * to the caller of the template.
44: */
45: T doInCompass(CompassSession session) throws CompassException;
46: }
|