view src/main/java/nl/cwi/monetdb/embedded/MonetDBEmbeddedInstance.java @ 34:068ec5964f28 embedded

Major cleaning on the Embedded code. Added support for prepared statements, fetching rows, mapping results into Java Classes incrementally and future async support.
author Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
date Tue, 01 Nov 2016 17:35:36 +0100 (2016-11-01)
parents 787a4fdba56e
children 5e58809cfbed
line wrap: on
line source
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0.  If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Copyright 2016 MonetDB B.V.
 */

package nl.cwi.monetdb.embedded;

/**
 * The MonetDB's JNI library loader for Java.
 * <br/>
 * <strong>Note</strong>: The MonetDB's JNI library must be successfully loaded in order to the other methods work.
 *
 * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a>
 */
public class MonetDBEmbeddedInstance {

    private static boolean isEmbeddedInstanceInitialized = false;

    private static final String NATIVE_LIB_NAME = "monetdb5";

    /**
     * Tries to load the JNI library with MonetDBLite from the current Java Classpath
     *
     * @param libraryName The library name, if null will load the default name "monetdb5"
     * @return A boolean indicating if the load was successful
     */
    public static boolean TryLoadEmbeddedInstanceFromName(String libraryName) {
        if(!isEmbeddedInstanceInitialized) {
            if(libraryName == null) {
                libraryName = NATIVE_LIB_NAME;
            }
            System.loadLibrary(libraryName);
            isEmbeddedInstanceInitialized = true;
        }
        return true;
    }

    /**
     * Tries to load the JNI library with MonetDBLite from the given path
     *
     * @param libraryPath The full library path name
     * @return A boolean indicating if the load was successful
     */
    public static boolean TryLoadEmbeddedInstanceFromPath(String libraryPath) {
        if(!isEmbeddedInstanceInitialized) {
            if(libraryPath == null) {
                System.load(NATIVE_LIB_NAME);
            }
            System.load(libraryPath);
            isEmbeddedInstanceInitialized = true;
        }
        return true;
    }

    /**
     * Check if the JNI library with MonetDBLite has been loaded yet or not
     *
     * @return A boolean indicating if it is loaded
     */
    public static boolean IsEmbeddedInstanceInitialized() {
        return isEmbeddedInstanceInitialized;
    }
}