package org.apache.tinkerpop.gremlin.orientdb.structure;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.ODatabaseException;


public final class OrientGraphFactory {
    public OrientGraph open(String url, String user, String password) {
        return new OrientGraph(getDatabase(url, user, password));
    }

    protected ODatabaseDocumentTx getDatabase(String url, String user, String password) {
        final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
        db.open(user, password);

        return db;
    }
}

package org.apache.tinkerpop.gremlin.orientdb.structure;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.ODatabaseException;


public final class OrientGraphFactory {
    public static String ADMIN = "admin";
    protected final String url;
    protected final String user;
    protected final String password;

    public OrientGraphFactory(String url) {
        this.url = url;
        this.user = ADMIN;
        this.password = ADMIN;
    }

    public OrientGraphFactory(String url, String user, String password) {
        this.url = url;
        this.user = user;
        this.password = password;
    }

    public OrientGraph getTx() {
        return new OrientGraph(getDatabase(true, true));
    }

    /**
     * @param create
     *          if true automatically creates database if database with given URL does not exist
     * @param open
     *          if true automatically opens the database
     */
    public OrientGraph getTx(boolean create, boolean open) {
        return new OrientGraph(getDatabase(create, open));
    }

    /**
     * @param create
     *          if true automatically creates database if database with given URL does not exist
     * @param open
     *          if true automatically opens the database
     */
    protected ODatabaseDocumentTx getDatabase(boolean create, boolean open) {
        final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
        if (!db.getURL().startsWith("remote:") && !db.exists()) {
            if (create) db.create();
            else if (open) throw new ODatabaseException("Database '" + url + "' not found");
        } else if (open) db.open(user, password);

        return db;
    }
}

support memory driver