01: package org.apache.ojb.broker.locking;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.OJBRuntimeException;
19: import org.apache.ojb.broker.util.factory.ConfigurableFactory;
20:
21: /**
22: * This factory class creates LockManager instances according
23: * to the setting in the OJB properties file.
24: */
25: public class LockManagerHelper {
26: /**
27: * Get a {@link org.apache.ojb.odmg.locking.LockManager} instance. The implementation class is
28: * configured in the OJB properties file.
29: */
30: public static LockManager getLockManagerSpecifiedByConfiguration() {
31: try {
32: // create the kernel LockManager
33: LockManager lm = (new LockManagerFactory())
34: .createNewLockManager();
35: lm.setLockTimeout(LockManager.DEFAULT_LOCK_TIMEOUT);
36: return lm;
37: } catch (Exception e) {
38: throw new OJBRuntimeException(
39: "Unexpected failure while start LockManager", e);
40: }
41: }
42:
43: /**
44: * Factory to create kernel {@link LockManager} instances.
45: */
46: private static class LockManagerFactory extends ConfigurableFactory {
47: protected String getConfigurationKey() {
48: return "LockManagerClass";
49: }
50:
51: LockManager createNewLockManager() {
52: return (LockManager) this .createNewInstance();
53: }
54: }
55:
56: /**
57: * Get a {@link org.apache.ojb.odmg.locking.LockManager} instance. The implementation class is
58: * configured in the OJB properties file.
59: */
60: public static LockManager getCommonsLockManager() {
61: LockManager lm = new LockManagerCommonsImpl();
62: lm.setLockTimeout(LockManager.DEFAULT_LOCK_TIMEOUT);
63: return lm;
64: }
65: }
|