1 17 package org.apache.excalibur.store.impl; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 22 import com.coyotegulch.jisp.BTreeIndex; 23 import com.coyotegulch.jisp.IndexedObjectDatabase; 24 import com.coyotegulch.jisp.KeyNotFound; 25 26 import org.apache.avalon.framework.activity.Disposable; 27 import org.apache.avalon.framework.parameters.ParameterException; 28 import org.apache.avalon.framework.parameters.Parameterizable; 29 import org.apache.avalon.framework.parameters.Parameters; 30 import org.apache.avalon.framework.thread.ThreadSafe; 31 import org.apache.excalibur.store.Store; 32 33 41 public class JispFilesystemStore extends AbstractJispFilesystemStore 42 implements Store, 43 ThreadSafe, 44 Parameterizable, 45 Disposable { 46 47 63 public void parameterize(Parameters params) throws ParameterException 64 { 65 try 67 { 68 final String dir = params.getParameter("directory"); 69 this.setDirectory(new File (dir)); 70 } 71 catch (IOException e) 72 { 73 throw new ParameterException("Unable to set directory", e); 74 } 75 76 final String databaseName = params.getParameter("data-file", "store.dat"); 77 final String indexName = params.getParameter("index-file", "store.idx"); 78 final int order = params.getParameterAsInteger("order", 301); 79 if (getLogger().isDebugEnabled()) 80 { 81 getLogger().debug("Database file name = " + databaseName); 82 getLogger().debug("Index file name = " + indexName); 83 getLogger().debug("Order=" + order); 84 } 85 86 final File databaseFile = new File (m_directoryFile, databaseName); 87 final File indexFile = new File (m_directoryFile, indexName); 88 89 if (getLogger().isDebugEnabled()) 90 { 91 getLogger().debug("Initializing JispFilesystemStore"); 92 } 93 94 try 95 { 96 final boolean isOld = databaseFile.exists(); 97 if (getLogger().isDebugEnabled()) 98 { 99 getLogger().debug("initialize(): Datafile exists: " + isOld); 100 } 101 102 if (!isOld) { 103 m_Index = new BTreeIndex(indexFile.toString(), 104 order, super.getNullKey(), false); 105 } else { 106 m_Index = new BTreeIndex(indexFile.toString()); 107 } 108 m_Database = new IndexedObjectDatabase(databaseFile.toString(), !isOld); 109 m_Database.attachIndex(m_Index); 110 } 111 catch (KeyNotFound ignore) 112 { 113 } 114 catch (Exception e) 115 { 116 getLogger().error("initialize(..) Exception", e); 117 } 118 } 119 120 public void dispose() 121 { 122 try 123 { 124 getLogger().debug("Disposing"); 125 126 if (m_Index != null) 127 { 128 m_Index.close(); 129 } 130 131 if (m_Database != null) 132 { 133 m_Database.close(); 134 } 135 } 136 catch (Exception e) 137 { 138 getLogger().error("dispose(..) Exception", e); 139 } 140 } 141 } 142 | Popular Tags |