// Path: domsql/eclipse/plugins/com.ibm.domino.domsql.sqlite/src/com/ibm/domino/domsql/sqlite/DomSQLException.java
// public class DomSQLException {
// 
// 	public static SQLException create(Throwable t, String message) {
// 		SQLException e = new SQLException(message);
// 		if(t!=null) {
//             e.initCause(t);
// 		}
// 		return e;
// 	}
// 
// 	public static SQLException create(Throwable t, String message, Object... params) {
//         SQLException e = new SQLException(StringUtil.format(message, params));
//         if(t!=null) {
//             e.initCause(t);
//         }
//         return e;
// 	}
// 
// 	public static void setSqliteCode(SQLException exception, int sqliteCode) {
// 		//this.sqliteCode = sqliteCode;
// 	}
// }
// 
// Path: domsql/eclipse/plugins/com.ibm.domino.domsql.sqlite/src/com/ibm/domino/domsql/sqlite/driver/jni/NotesAPI.java
// public class NotesAPI {
// 	
// 	public static final int READ_MASK_NOTEID			= 0x00000001;
// 	public static final int READ_MASK_NOTEUNID			= 0x00000002;
// 	public static final int READ_MASK_NOTECLASS			= 0x00000004;
// 	public static final int READ_MASK_INDEXSIBLINGS		= 0x00000008;
// 	public static final int READ_MASK_INDEXCHILDREN		= 0x00000010;
// 	public static final int READ_MASK_INDEXDESCENDANTS	= 0x00000020;
// 	public static final int READ_MASK_INDEXANYUNREAD	= 0x00000040;
// 	public static final int READ_MASK_INDENTLEVELS		= 0x00000080;
// 	public static final int READ_MASK_SCORE				= 0x00000200;
// 	public static final int READ_MASK_INDEXUNREAD		= 0x00000400;
// 	public static final int READ_MASK_COLLECTIONSTATS	= 0x00000100;
// 	public static final int READ_MASK_INDEXPOSITION		= 0x00004000;
// 	public static final int READ_MASK_SUMMARYVALUES		= 0x00002000;
// 	public static final int READ_MASK_SUMMARY			= 0x00008000;
// 	
// 
//     ///////////////////////////////////////////////////////////
//     // Notes initialization routines
//     // For standalone apps
//     ///////////////////////////////////////////////////////////    
//     public static native void NotesInit() throws SQLException;
//     public static native void NotesTerm() throws SQLException;
//     public static native void NotesInitThread() throws SQLException;
//     public static native void NotesTermThread() throws SQLException;
// 
//     ///////////////////////////////////////////////////////////
//     // Access to notes.ini
//     ///////////////////////////////////////////////////////////
// 	public static final native int OSGetEnvironmentInt(String name) throws SQLException;
// 	public static final native long OSGetEnvironmentLong(String name) throws SQLException;
// 	public static final native String OSGetEnvironmentString(String name) throws SQLException;
// 	public static final native void OSSetEnvironmentInt(String name, int value) throws SQLException;
// 	public static final native void OSSetEnvironmentVariable(String name, String value) throws SQLException;
//     
//     
//     ///////////////////////////////////////////////////////////
//     // Database routines
//     ///////////////////////////////////////////////////////////
//     public static native long NSFDBOpen(String dbPath) throws SQLException;
//     public static native long NSFDBOpenEx(String dbPath, long hNames) throws SQLException;
//     public static native void NSFDBClose(long hDb) throws SQLException;
//     public static native long NSFDbNonDataModifiedTime(long hDb) throws SQLException;
// 
//     ///////////////////////////////////////////////////////////
//     // Note routines
//     ///////////////////////////////////////////////////////////
//     public static native long NSFNoteOpen(long hDb, int noteID, int flags) throws SQLException;
//     public static native void NSFNoteClose(long hNote) throws SQLException;
//     
//     ///////////////////////////////////////////////////////////
//     // View routines
//     ///////////////////////////////////////////////////////////
//     public static native int NIFFindView(long hDb, String viewName) throws SQLException;
//     
//     ///////////////////////////////////////////////////////////
//     // KFM
//     ///////////////////////////////////////////////////////////
//     public static native String SECKFMGetUserName() throws SQLException;
// }


import java.sql.SQLException;
import java.util.HashMap;
import com.ibm.domino.domsql.sqlite.DomSQLException;
import com.ibm.domino.domsql.sqlite.driver.jni.NotesAPI;

        Context c = contexts.get();
        if(c!=null) {
            return c;
        }
        for(ContextFinder f=contextFinder; f!=null; f=f.next) {
        	c = f.find();
        	if(c!=null) {
        		return c;
        	}
        }
        throw new IllegalStateException("No current DomSQL context set");
    }

    public static void push(Context context) {
        contexts.set(context);
    }
    
    public static void pop() {
        contexts.remove();
    }
    
    private HashMap<String, Long> handles = new HashMap<String, Long>();
    
    public Context() {
    }

    public synchronized void close() {
        for(Long hDb: handles.values()) {
            try {
                if(shouldClose(hDb)) {

// Path: domsql/eclipse/plugins/com.ibm.domino.domsql.sqlite/src/com/ibm/domino/domsql/sqlite/DomSQLException.java
// public class DomSQLException {
// 
// 	public static SQLException create(Throwable t, String message) {
// 		SQLException e = new SQLException(message);
// 		if(t!=null) {
//             e.initCause(t);
// 		}
// 		return e;
// 	}
// 
// 	public static SQLException create(Throwable t, String message, Object... params) {
//         SQLException e = new SQLException(StringUtil.format(message, params));
//         if(t!=null) {
//             e.initCause(t);
//         }
//         return e;
// 	}
// 
// 	public static void setSqliteCode(SQLException exception, int sqliteCode) {
// 		//this.sqliteCode = sqliteCode;
// 	}
// }
// 
// Path: domsql/eclipse/plugins/com.ibm.domino.domsql.sqlite/src/com/ibm/domino/domsql/sqlite/driver/jni/NotesAPI.java
// public class NotesAPI {
// 	
// 	public static final int READ_MASK_NOTEID			= 0x00000001;
// 	public static final int READ_MASK_NOTEUNID			= 0x00000002;
// 	public static final int READ_MASK_NOTECLASS			= 0x00000004;
// 	public static final int READ_MASK_INDEXSIBLINGS		= 0x00000008;
// 	public static final int READ_MASK_INDEXCHILDREN		= 0x00000010;
// 	public static final int READ_MASK_INDEXDESCENDANTS	= 0x00000020;
// 	public static final int READ_MASK_INDEXANYUNREAD	= 0x00000040;
// 	public static final int READ_MASK_INDENTLEVELS		= 0x00000080;
// 	public static final int READ_MASK_SCORE				= 0x00000200;
// 	public static final int READ_MASK_INDEXUNREAD		= 0x00000400;
// 	public static final int READ_MASK_COLLECTIONSTATS	= 0x00000100;
// 	public static final int READ_MASK_INDEXPOSITION		= 0x00004000;
// 	public static final int READ_MASK_SUMMARYVALUES		= 0x00002000;
// 	public static final int READ_MASK_SUMMARY			= 0x00008000;
// 	
// 
//     ///////////////////////////////////////////////////////////
//     // Notes initialization routines
//     // For standalone apps
//     ///////////////////////////////////////////////////////////    
//     public static native void NotesInit() throws SQLException;
//     public static native void NotesTerm() throws SQLException;
//     public static native void NotesInitThread() throws SQLException;
//     public static native void NotesTermThread() throws SQLException;
// 
//     ///////////////////////////////////////////////////////////
//     // Access to notes.ini
//     ///////////////////////////////////////////////////////////
// 	public static final native int OSGetEnvironmentInt(String name) throws SQLException;
// 	public static final native long OSGetEnvironmentLong(String name) throws SQLException;
// 	public static final native String OSGetEnvironmentString(String name) throws SQLException;
// 	public static final native void OSSetEnvironmentInt(String name, int value) throws SQLException;
// 	public static final native void OSSetEnvironmentVariable(String name, String value) throws SQLException;
//     
//     
//     ///////////////////////////////////////////////////////////
//     // Database routines
//     ///////////////////////////////////////////////////////////
//     public static native long NSFDBOpen(String dbPath) throws SQLException;
//     public static native long NSFDBOpenEx(String dbPath, long hNames) throws SQLException;
//     public static native void NSFDBClose(long hDb) throws SQLException;
//     public static native long NSFDbNonDataModifiedTime(long hDb) throws SQLException;
// 
//     ///////////////////////////////////////////////////////////
//     // Note routines
//     ///////////////////////////////////////////////////////////
//     public static native long NSFNoteOpen(long hDb, int noteID, int flags) throws SQLException;
//     public static native void NSFNoteClose(long hNote) throws SQLException;
//     
//     ///////////////////////////////////////////////////////////
//     // View routines
//     ///////////////////////////////////////////////////////////
//     public static native int NIFFindView(long hDb, String viewName) throws SQLException;
//     
//     ///////////////////////////////////////////////////////////
//     // KFM
//     ///////////////////////////////////////////////////////////
//     public static native String SECKFMGetUserName() throws SQLException;
// }


// Path: domsql/eclipse/plugins/com.ibm.domino.domsql.sqlite/src/com/ibm/domino/domsql/sqlite/driver/Context.java
import java.sql.SQLException;
import java.util.HashMap;
import com.ibm.domino.domsql.sqlite.DomSQLException;
import com.ibm.domino.domsql.sqlite.driver.jni.NotesAPI;

        Context c = contexts.get();
        if(c!=null) {
            return c;
        }
        for(ContextFinder f=contextFinder; f!=null; f=f.next) {
        	c = f.find();
        	if(c!=null) {
        		return c;
        	}
        }
        throw new IllegalStateException("No current DomSQL context set");
    }

    public static void push(Context context) {
        contexts.set(context);
    }
    
    public static void pop() {
        contexts.remove();
    }
    
    private HashMap<String, Long> handles = new HashMap<String, Long>();
    
    public Context() {
    }

    public synchronized void close() {
        for(Long hDb: handles.values()) {
            try {
                if(shouldClose(hDb)) {

                    NotesAPI.NSFDBClose(hDb);
