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.spring.device.ojb;
18:
19: import org.apache.ojb.broker.PersistenceBroker;
20: import org.compass.gps.CompassGpsException;
21: import org.compass.gps.device.ojb.OjbGpsDevice;
22: import org.springframework.orm.ojb.OjbFactoryUtils;
23: import org.springframework.orm.ojb.PersistenceBrokerTemplate;
24:
25: /**
26: * An extension of the <code>OjbGpsDevice</code> that utilizes Spring ojb
27: * features. Uses Spring <code>PersistenceBrokerTemplate</code> and
28: * <code>OjbFactoryUtils</code> to get the current
29: * <code>PersistenceBroker</code> for batch indexing (the <code>index()</code>
30: * operation).
31: * <p/>
32: * You can provide the <code>PersistenceBrokerTemplate</code>, though it is
33: * not required since it is created the same way the
34: * <code>PersistenceBrokerDaoSupport</code> does.
35: * <p/>
36: * Can be used with
37: * {@link SpringOjbGpsDeviceInterceptor} to
38: * provide real-time data mirroring without the need to write any code.
39: *
40: * @author kimchy
41: */
42: public class SpringOjbGpsDevice extends OjbGpsDevice {
43:
44: private PersistenceBrokerTemplate persistenceBrokerTemplate = createPersistenceBrokerTemplate();
45:
46: protected PersistenceBrokerTemplate createPersistenceBrokerTemplate() {
47: return new PersistenceBrokerTemplate();
48: }
49:
50: /**
51: * Uses Spring <code>PersistenceBrokerTemplate<code> and <code>OjbFactoryUtils</code>
52: * to get OJB <code>PersistenceBroker</code>
53: */
54: protected PersistenceBroker doGetIndexPersistentBroker()
55: throws CompassGpsException {
56: return OjbFactoryUtils.getPersistenceBroker(
57: persistenceBrokerTemplate.getPbKey(),
58: persistenceBrokerTemplate.isAllowCreate());
59: }
60:
61: /**
62: * Returns the Spring's <code>PersistenceBrokerTemplate<code>.
63: */
64: public PersistenceBrokerTemplate getPersistenceBrokerTemplate() {
65: return persistenceBrokerTemplate;
66: }
67:
68: /**
69: * Sets Spring's
70: * <code>PersistenceBrokerTemplate<code> to be used to fetch OJB
71: * <code>PersistenceBroker</code> for batch indexing (the <code>index()</code> operation).
72: * <p/>
73: * This is an optional parameter, since the <code>PersistenceBrokerTemplate</code> can be automatically created.
74: *
75: * @param persistenceBrokerTemplate
76: */
77: public void setPersistenceBrokerTemplate(
78: PersistenceBrokerTemplate persistenceBrokerTemplate) {
79: this.persistenceBrokerTemplate = persistenceBrokerTemplate;
80: }
81: }
|