1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * 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 package org.codehaus.activemq.store.bdbn;
19
20 import com.sleepycat.db.Db;
21 import com.sleepycat.db.DbEnv;
22 import com.sleepycat.db.DbException;
23 import org.codehaus.activemq.service.impl.PersistenceAdapterSupport;
24 import org.codehaus.activemq.store.MessageStore;
25 import org.codehaus.activemq.store.PreparedTransactionStore;
26 import org.codehaus.activemq.store.TopicMessageStore;
27 import org.codehaus.activemq.util.JMSExceptionHelper;
28
29 import javax.jms.JMSException;
30 import java.io.FileNotFoundException;
31 import java.util.Map;
32
33 /***
34 * @version $Revision: 1.2 $
35 */
36 public class BDbPersistenceAdapter extends PersistenceAdapterSupport {
37 protected DbEnv environment;
38
39 public BDbPersistenceAdapter(DbEnv environment) {
40 this.environment = environment;
41 }
42
43 public Map getInitialDestinations() {
44 return null; /*** TODO */
45 }
46
47 public MessageStore createQueueMessageStore(String destinationName) throws JMSException {
48 return null; /*** TODO */
49 }
50
51 public TopicMessageStore createTopicMessageStore(String destinationName) {
52 return null; /*** TODO */
53 }
54
55 public PreparedTransactionStore createPreparedTransactionStore() throws JMSException {
56 return null; /*** TODO */
57 }
58
59 public void beginTransaction() throws JMSException {
60 try {
61 BDbHelper.createTransaction(environment);
62 }
63 catch (DbException e) {
64 throw JMSExceptionHelper.newJMSException("Failed to commit transaction. Reason: " + e, e);
65 }
66 }
67
68 public void commitTransaction() throws JMSException {
69 BDbHelper.commitTransaction(BDbHelper.getTransaction());
70 }
71
72 public void rollbackTransaction() {
73 BDbHelper.rollbackTransaction(BDbHelper.getTransaction());
74 }
75
76 public void start() throws JMSException {
77 }
78
79 public void stop() throws JMSException {
80 try {
81 environment.close(0);
82 }
83 catch (DbException e) {
84 throw JMSExceptionHelper.newJMSException("Failed to close environment. Reason: " + e, e);
85 }
86 }
87
88
89
90 protected Db createDatabase(String name) throws JMSException, FileNotFoundException, DbException {
91 return BDbHelper.open(environment, name, false);
92 }
93
94 }