// $Id: DAMLDB.java,v 1.7 2001/09/21 20:03:39 mdean Exp $


package org.daml.damldb;


/**
 * Java interface to DAML DB memory-mapped persistent store.
 */
public class DAMLDB
{
    public static final long NULL_STATEMENT_ID = 0xffffffffL;
    public static final long NULL_RESOURCE_ID = 0xffffffffL;

    public static final long STATEMENT_FLAG_VALID = 0x1;
    public static final long STATEMENT_FLAG_DELETED = 0x2;
    public static final long STATEMENT_FLAG_LITERAL_OBJECT = 0x4;

    public static final long RESOURCE_FLAG_VALID = 0x1;
    public static final long RESOURCE_FLAG_DELETED = 0x2;
    public static final long RESOURCE_FLAG_LITERAL = 0x4;

    /**
     * open/map the databases
     */
    public static native void init();

    /**
     * return the number of statements in the database.
     */
    public static native long size();

    /**
     * returns statement index
     */
    public static native long firstSubject(long resource);
    /**
     * returns statement index
     */
    public static native long firstPredicate(long resource);
    /**
     * returns statement index
     */
    public static native long firstObject(long resource);

    /**
     * returns resource index
     */
    public static native long subject(long statement);
    /**
     * returns resource index
     */
    public static native long predicate(long statement);
    /**
     * returns resource index
     */
    public static native long object(long statement);
    /**
     * returns resource index
     */
    public static native long source(long statement);
    /**
     * returns flags
     */
    public static native int statementFlags(long statement);

    /**
     * returns statement index
     */
    public static native long nextSubject(long statement);
    /**
     * returns statement index
     */
    public static native long nextPredicate(long statement);
    /**
     * returns statement index
     */
    public static native long nextObject(long statement);

    public static native long toLong(String string);
    public static native String toString(long index);

    /**
     * returns statement index
     */
    public static native long addStatement(long source, long subject, long predicate, long object);
    /**
     * returns resource index
     */
    public static native long addResource(String string);

    static 
    {
	System.loadLibrary("damldbjni");
	init();
    }
}
