View Javadoc

    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
    32  /***
    33   * @version $Revision: 1.1 $
    34   */
    35  public class BDbPersistenceAdapter extends PersistenceAdapterSupport {
    36      protected DbEnv environment;
    37
    38      public BDbPersistenceAdapter(DbEnv environment) {
    39          this.environment = environment;
    40      }
    41
    42      public MessageStore createQueueMessageStore(String destinationName) throws JMSException {
    43          return null; /*** TODO */
    44      }
    45
    46      public TopicMessageStore createTopicMessageStore(String destinationName) {
    47          return null; /*** TODO */
    48      }
    49
    50      public PreparedTransactionStore createPreparedTransactionStore() throws JMSException {
    51          return null;  /*** TODO */
    52      }
    53
    54      public void beginTransaction() throws JMSException {
    55          try {
    56              BDbHelper.createTransaction(environment);
    57          }
    58          catch (DbException e) {
    59              throw JMSExceptionHelper.newJMSException("Failed to commit transaction. Reason: " + e, e);
    60          }
    61      }
    62
    63      public void commitTransaction() throws JMSException {
    64          BDbHelper.commitTransaction(BDbHelper.getTransaction());
    65      }
    66
    67      public void rollbackTransaction() {
    68          BDbHelper.rollbackTransaction(BDbHelper.getTransaction());
    69      }
    70
    71      public void start() throws JMSException {
    72      }
    73
    74      public void stop() throws JMSException {
    75          try {
    76              environment.close(0);
    77          }
    78          catch (DbException e) {
    79              throw JMSExceptionHelper.newJMSException("Failed to close environment. Reason: " + e, e);
    80          }
    81      }
    82
    83      // Implementation methods
    84      //-------------------------------------------------------------------------
    85      protected Db createDatabase(String name) throws JMSException, FileNotFoundException, DbException {
    86          return BDbHelper.open(environment, name, false);
    87      }
    88
    89  }