001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.kaha; 018 019import java.io.File; 020import java.io.IOException; 021import java.util.concurrent.atomic.AtomicLong; 022 023import org.apache.activemq.kaha.impl.KahaStore; 024 025/** 026 * Factory for creating stores 027 * 028 * 029 */ 030public final class StoreFactory { 031 032 private StoreFactory() { 033 } 034 035 /** 036 * open or create a Store 037 * 038 * @param name 039 * @param mode 040 * @return the opened/created store 041 * @throws IOException 042 */ 043 public static Store open(String name, String mode) throws IOException { 044 return new KahaStore(name, mode,new AtomicLong()); 045 } 046 047 /** 048 * Open or create a Store 049 * 050 * @param directory 051 * @param mode 052 * @return 053 * @throws IOException 054 */ 055 public static Store open(File directory, String mode) throws IOException { 056 return new KahaStore(directory, mode, new AtomicLong()); 057 } 058 059 /** 060 * open or create a Store 061 * @param name 062 * @param mode 063 * @param size 064 * @return the opened/created store 065 * @throws IOException 066 */ 067 public static Store open(String name, String mode, AtomicLong size) throws IOException { 068 return new KahaStore(name, mode,size); 069 } 070 071 072 /** 073 * Open or create a Store 074 * 075 * @param directory 076 * @param mode 077 * @param size 078 * @return 079 * @throws IOException 080 */ 081 public static Store open(File directory, String mode, AtomicLong size) throws IOException { 082 return new KahaStore(directory, mode, size); 083 } 084 085 086 /** 087 * Delete a database 088 * 089 * @param name of the database 090 * @return true if successful 091 * @throws IOException 092 */ 093 public static boolean delete(String name) throws IOException { 094 KahaStore store = new KahaStore(name, "rw"); 095 return store.delete(); 096 } 097 098 /** 099 * Delete a database 100 * 101 * @param directory 102 * @return true if successful 103 * @throws IOException 104 */ 105 public static boolean delete(File directory) throws IOException { 106 KahaStore store = new KahaStore(directory, "rw"); 107 return store.delete(); 108 } 109}