Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.lucene.store.db;

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 import java.util.Set;
 import java.util.List;
 
 
 import  com.sleepycat.db.internal.DbEnv;
 import  com.sleepycat.db.internal.Db;
 import  com.sleepycat.db.internal.DbConstants;
 import  com.sleepycat.db.DatabaseEntry;
 import  com.sleepycat.db.internal.Dbc;
 import  com.sleepycat.db.internal.DbTxn;
 import  com.sleepycat.db.DatabaseException;
 
 import  com.sleepycat.db.Database;
 import  com.sleepycat.db.Transaction;
A DbDirectory is a Berkeley DB 4.3 based implementation of Directory. It uses two Db database handles, one for storing file records and another for storing file data blocks.
 
 
 public class DbDirectory extends Directory {
 
     protected Set openFiles = Collections.synchronizedSet(new HashSet());
     protected Db filesblocks;
     protected DbTxn txn;
     protected int flags;

    
Instantiate a DbDirectory. The same threading rules that apply to Berkeley DB handles apply to instances of DbDirectory.

Parameters:
txn a transaction handle that is going to be used for all db operations done by this instance. This parameter may be null.
files a db handle to store file records.
blocks a db handle to store file data blocks.
flags flags used for db read operations.
 
 
     public DbDirectory(DbTxn txn, Db files, Db blocksint flags)
     {
         super();
 
         this. = txn;
         this. = files;
         this. = blocks;
         this. = flags;
     }
 
     public DbDirectory(Transaction txn, Database files, Database blocks,
                        int flags)
     {
         super();
 
         this. = txn != null ? DbHandleExtractor.getDbTxn(txn) : null;
         this. = DbHandleExtractor.getDb(files);
         this. = DbHandleExtractor.getDb(blocks);
         this. = flags;
     }
 
     public DbDirectory(Transaction txn, Database files, Database blocks)
     {
         this(txnfilesblocks, 0);
     }
 
    public void close()
        throws IOException
    {
        flush();
    }

    
Flush the currently open files. After they have been flushed it is safe to commit the transaction without closing this DbDirectory instance first.

See also:
setTransaction
    public void flush()
        throws IOException
    {
        Iterator iterator = .iterator();
        
        while (iterator.hasNext())
            ((IndexOutputiterator.next()).flush();
    }
    public IndexOutput createOutput(String name)
        throws IOException
    {
        return new DbIndexOutput(thisnametrue);
    }
    public void deleteFile(String name)
        throws IOException
    {
        new File(name).delete(this);
    }
    public boolean fileExists(String name)
        throws IOException
    {
        return new File(name).exists(this);
    }
    public long fileLength(String name)
        throws IOException
    {
        File file = new File(name);
        if (file.exists(this))
            return file.getLength();
        throw new IOException("File does not exist: " + name);
    }
    
    public long fileModified(String name)
        throws IOException
    {
        File file = new File(name);
        if (file.exists(this))
            return file.getTimeModified();
        throw new IOException("File does not exist: " + name);
    }
    public String[] list()
        throws IOException
    {
        Dbc cursor = null;
        List list = new ArrayList();
        try {
            try {
                DatabaseEntry key = new DatabaseEntry(new byte[0]);
                DatabaseEntry data = new DatabaseEntry((byte[]) null);
                data.setPartial(true);
                cursor = .cursor();
                if (cursor.get(keydata,
                               DbConstants.DB_SET_RANGE | ) != DbConstants.DB_NOTFOUND)
                {
                    ByteArrayInputStream buffer =
                        new ByteArrayInputStream(key.getData());
                    DataInputStream in = new DataInputStream(buffer);
                    String name = in.readUTF();
                
                    in.close();
                    list.add(name);
                    while (cursor.get(keydata,
                                      DbConstants.DB_NEXT | ) != DbConstants.DB_NOTFOUND) {
                        buffer = new ByteArrayInputStream(key.getData());
                        in = new DataInputStream(buffer);
                        name = in.readUTF();
                        in.close();
                        list.add(name);
                    }
                }
            } finally {
                if (cursor != null)
                    cursor.close();
            }
        } catch (DatabaseException e) {
            throw new IOException(e.getMessage());
        }
        return (String[]) list.toArray(new String[list.size()]);
    }
    public IndexInput openInput(String name)
        throws IOException
    {
        return new DbIndexInput(thisname);
    }
    public Lock makeLock(String name)
    {
        return new DbLock();
    }
    public void renameFile(String fromString to)
        throws IOException
    {
        new File(from).rename(thisto);
    }
    public void touchFile(String name)
        throws IOException
    {
        File file = new File(name);
        long length = 0L;
        if (file.exists(this))
            length = file.getLength();
        file.modify(thislength, System.currentTimeMillis());
    }

    
Once a transaction handle was committed it is no longer valid. In order to continue using this DbDirectory instance after a commit, the transaction handle has to be replaced.

Parameters:
txn the new transaction handle to use
    public void setTransaction(Transaction txn)
    {
        setTransaction(txn != null ? DbHandleExtractor.getDbTxn(txn) : null);
    }

    
Once a transaction handle was committed it is no longer valid. In order to continue using this DbDirectory instance after a commit, the transaction handle has to be replaced.

Parameters:
txn the new transaction handle to use
    public void setTransaction(DbTxn txn)
    {
        this. = txn;
    }
New to GrepCode? Check out our FAQ X