FileDocCategorySizeDatePackage
JEDirectory.javaAPI DocApache Lucene 2.1.06958Wed Feb 14 10:46:08 GMT 2007org.apache.lucene.store.je

JEDirectory

public class JEDirectory extends Directory
Port of Andi Vajda's DbDirectory to to Java Edition of Berkeley Database A JEDirectory is a Berkeley DB JE based implementation of {@link org.apache.lucene.store.Directory Directory}. It uses two {@link com.sleepycat.je.Database Db} database handles, one for storing file records and another for storing file data blocks.
author
Aaron Donovan

Fields Summary
protected Set
openFiles
protected com.sleepycat.je.Database
files
protected com.sleepycat.je.Database
blocks
protected com.sleepycat.je.Transaction
txn
protected int
flags
Constructors Summary
public JEDirectory(com.sleepycat.je.Transaction txn, com.sleepycat.je.Database files, com.sleepycat.je.Database blocks, int flags)
Instantiate a DbDirectory. The same threading rules that apply to Berkeley DB handles apply to instances of DbDirectory.

param
txn a transaction handle that is going to be used for all db operations done by this instance. This parameter may be null.
param
files a db handle to store file records.
param
blocks a db handle to store file data blocks.
param
flags flags used for db read operations.


                                                                                                                                                 

          
                         
        super();

        this.txn = txn;
        this.files = files;
        this.blocks = blocks;
        this.flags = flags;
    
public JEDirectory(com.sleepycat.je.Transaction txn, com.sleepycat.je.Database files, com.sleepycat.je.Database blocks)

        this(txn, files, blocks, 0);
    
Methods Summary
public voidclose()

        flush();
    
public org.apache.lucene.store.IndexOutputcreateOutput(java.lang.String name)

        return new JEIndexOutput(this, name, true);
    
public voiddeleteFile(java.lang.String name)

        new File(name).delete(this);
    
public booleanfileExists(java.lang.String name)

        return new File(name).exists(this);
    
public longfileLength(java.lang.String name)

        File file = new File(name);

        if (file.exists(this))
            return file.getLength();

        throw new IOException("File does not exist: " + name);
    
public longfileModified(java.lang.String name)

        File file = new File(name);

        if (file.exists(this))
            return file.getTimeModified();

        throw new IOException("File does not exist: " + name);
    
public voidflush()
Flush the currently open files. After they have been flushed it is safe to commit the transaction without closing this DbDirectory instance first.

see
setTransaction

        Iterator iterator = openFiles.iterator();

        while (iterator.hasNext()) {
            System.out
                    .println(((JEIndexOutput) iterator.next()).file.getName());
            // ((IndexOutput) iterator.next()).flush();
        }
    
public java.lang.String[]list()

        Cursor cursor = null;
        List list = new ArrayList();

        try {
            try {
                DatabaseEntry key = new DatabaseEntry(new byte[0]);
                DatabaseEntry data = new DatabaseEntry(null);

                data.setPartial(true);
                // TODO see if cursor needs configuration
                cursor = files.openCursor(txn, null);
                // TODO see if LockMode should be set
                if (cursor.getNext(key, data, null) != OperationStatus.NOTFOUND) {
                    ByteArrayInputStream buffer = new ByteArrayInputStream(key
                            .getData());
                    DataInputStream in = new DataInputStream(buffer);
                    String name = in.readUTF();

                    in.close();
                    list.add(name);

                    while (cursor.getNext(key, data, null) != OperationStatus.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 org.apache.lucene.store.LockmakeLock(java.lang.String name)

        return new JELock();
    
public org.apache.lucene.store.IndexInputopenInput(java.lang.String name)

        return new JEIndexInput(this, name);
    
public voidrenameFile(java.lang.String from, java.lang.String to)

        new File(from).rename(this, to);
    
public voidsetTransaction(com.sleepycat.je.Transaction txn)
Once a transaction handle was committed it is no longer valid. In order to continue using this JEDirectory instance after a commit, the transaction handle has to be replaced.

param
txn the new transaction handle to use

        this.txn = txn;
    
public voidtouchFile(java.lang.String name)

        File file = new File(name);
        long length = 0L;

        if (file.exists(this))
            length = file.getLength();

        file.modify(this, length, System.currentTimeMillis());