@Override public void close() { orient.close(); }
default OrientDB newOrientDB() { return new OrientDB(this); }
/** * Open a database * * @param database the database to open * @param user username of a database user or a server user allowed to open the database * @param password related to the specified username * * @return the opened database */ public ODatabaseSession open(String database, String user, String password) { return open(database, user, password, OrientDBConfig.defaultConfig()); }
/** * Open a new database pool from a environment and a database name with a custom configuration, useful in case the application * access to only a database or do not manipulate databases. * * @param environment the url for an environemnt, like "embedded:/the/environment/path/" or "remote:localhost" * @param database the database for the current url. * @param user the database user for the current pool of databases. * @param password the password relative to the user * @param configuration the configuration relative to the current pool. */ public ODatabasePool(String environment, String database, String user, String password, OrientDBConfig configuration) { orientDb = new OrientDB(environment, configuration); autoclose = true; internal = orientDb.openPool(database, user, password, configuration); }
/** * @param create if true automatically creates database if database with given * URL does not exist * @param open if true automatically opens the database */ public ODatabaseDocument getDatabase(boolean create, boolean open) { if (create && type.isPresent()) { this.factory.createIfNotExists(dbName, type.get()); } return this.factory.open(dbName, user, password); }
public OrientJdbcConnection(final String jdbcdDUrl, final Properties info) { this.dbUrl = jdbcdDUrl.replace("jdbc:orient:", ""); this.info = info; readOnly = false; final String username = info.getProperty("user", "admin"); final String password = info.getProperty("password", "admin"); final String serverUsername = info.getProperty("serverUser", ""); final String serverPassword = info.getProperty("serverPassword", ""); OURLConnection connUrl = OURLHelper.parseNew(dbUrl); orientDB = new OrientDB(connUrl.getType() + ":" + connUrl.getPath(), serverUsername, serverPassword, OrientDBConfig.defaultConfig()); if (!serverUsername.isEmpty() && !serverPassword.isEmpty()) { orientDB.createIfNotExists(connUrl.getDbName(), connUrl.getDbType().orElse(ODatabaseType.MEMORY)); } database = orientDB.open(connUrl.getDbName(), username, password); orientDBisPrivate = true; status = ODatabase.STATUS.OPEN; }
orient = new OrientDB("embedded:" + dbCtx, dbUser, dbPassword, null); if (orient.exists(dbCtx) && dbAutoDropIfExists) { orient.drop(dbCtx); if (!orient.exists(dbCtx)) { orient.create(dbCtx, ODatabaseType.MEMORY); dbCtx = dbCtx.substring(0, dbCtx.lastIndexOf("/")); orient = new OrientDB("embedded:" + dbCtx, dbUser, dbPassword, null); if (orient.exists(dbName) && dbAutoDropIfExists) { orient.drop(dbName); if (!orient.exists(dbName) && dbAutoCreate) { orient.create(dbName, ODatabaseType.PLOCAL); orient = new OrientDB("remote:" + dbCtx, serverUser, serverPassword, null); String dbName = dbCtx.substring(dbCtx.lastIndexOf("/")); if (orient.exists(dbName) && dbAutoDropIfExists) { orient.drop(dbName); if (!orient.exists(dbName) && dbAutoCreate) { orient.create(dbName, ODatabaseType.PLOCAL);
orientDB = new OrientDB(urlConnection.getType() + ":" + urlConnection.getPath(), currentDatabaseUserName, currentDatabaseUserPassword, config.build()); config.build()); } else { orientDB.create(urlConnection.getDbName(), type); currentDatabase = (ODatabaseDocumentInternal) orientDB.open(urlConnection.getDbName(), userName, userPassword); currentDatabaseName = currentDatabase.getName();
@ConsoleCommand(aliases = { "use database" }, description = "Connect to a database or a remote Server instance", onlineHelp = "Console-Command-Connect") public void connect( @ConsoleParameter(name = "url", description = "The url of the remote server or the database to connect to in the format '<mode>:<path>'") String iURL, @ConsoleParameter(name = "user", description = "User name") String iUserName, @ConsoleParameter(name = "password", description = "User password", optional = true) String iUserPassword) throws IOException { disconnect(); if (iUserPassword == null) { message("Enter password: "); final BufferedReader br = new BufferedReader(new InputStreamReader(this.in)); iUserPassword = br.readLine(); message("\n"); } currentDatabaseUserName = iUserName; currentDatabaseUserPassword = iUserPassword; urlConnection = OURLHelper.parseNew(iURL); orientDB = new OrientDB(urlConnection.getType() + ":" + urlConnection.getPath(), iUserName, iUserPassword, OrientDBConfig.defaultConfig()); if (!"".equals(urlConnection.getDbName())) { // OPEN DB message("\nConnecting to database [" + iURL + "] with user '" + iUserName + "'..."); currentDatabase = (ODatabaseDocumentInternal) orientDB.open(urlConnection.getDbName(), iUserName, iUserPassword); currentDatabaseName = currentDatabase.getName(); } message("OK"); final ODocument distribCfg = getDistributedConfiguration(); if (distribCfg != null) listServers(); }
@Override public Connection getConnection(String username, String password) throws SQLException { if (orientDB == null) { Properties info = new Properties(this.info); info.put("user", username); info.put("password", password); final String serverUsername = info.getProperty("serverUser", ""); final String serverPassword = info.getProperty("serverPassword", ""); String orientDbUrl = dbUrl.replace("jdbc:orient:", ""); OURLConnection connUrl = OURLHelper.parseNew(orientDbUrl); OrientDBConfig settings = OrientDBConfig.builder() .addConfig(OGlobalConfiguration.DB_POOL_MIN, Integer.valueOf(info.getProperty("db.pool.min", "1"))) .addConfig(OGlobalConfiguration.DB_POOL_MAX, Integer.valueOf(info.getProperty("db.pool.max", "10"))) .build(); orientDB = new OrientDB(connUrl.getType() + ":" + connUrl.getPath(), serverUsername, serverPassword, settings); if (!serverUsername.isEmpty() && !serverPassword.isEmpty()) orientDB.createIfNotExists(connUrl.getDbName(), connUrl.getDbType().orElse(ODatabaseType.MEMORY)); pool = new ODatabasePool(orientDB, connUrl.getDbName(), username, password); } return new OrientJdbcConnection(pool.acquire(), orientDB, info); }
/** * Create a new database if not exists * * @param database database name * @param type can be plocal or memory * * @return true if the database has been created, false if already exists */ public boolean createIfNotExists(String database, ODatabaseType type) { return createIfNotExists(database, type, OrientDBConfig.defaultConfig()); }
/** * Create a new database * * @param database database name * @param type can be plocal or memory */ public void create(String database, ODatabaseType type) { create(database, type, OrientDBConfig.defaultConfig()); }
public boolean isOpen() { return factory.isOpen(); } }
@ConsoleCommand(description = "Delete the current database", onlineHelp = "Console-Command-Drop-Database") public void dropDatabase( @ConsoleParameter(name = "storage-type", description = "Storage type of server database", optional = true) String storageType) throws IOException { checkForDatabase(); final String dbName = currentDatabase.getName(); currentDatabase.close(); if (storageType != null && !"plocal".equalsIgnoreCase(storageType)&& !"local".equalsIgnoreCase(storageType)&& !"memory".equalsIgnoreCase(storageType)) { message("\n\nInvalid storage type for db: '" + storageType + "'"); return; } orientDB.drop(dbName); currentDatabase = null; currentDatabaseName = null; message("\n\nDatabase '" + dbName + "' deleted successfully"); }
orientDB.createIfNotExists(dbUrlConnection.getDbName(), dbType); db = (ODatabaseDocumentInternal) orientDB.open(dbUrlConnection.getDbName(), userName, password);
/** * Open a new database pool from a url and additional configuration, useful in case the application access to only a database or * do not manipulate databases. * * @param url the full url for a database, like "embedded:/full/path/to/database" or "remote:localhost/database" * @param user the database user for the current pool of databases. * @param password the password relative to the user * @param configuration the configuration relative to the current pool. */ public ODatabasePool(String url, String user, String password, OrientDBConfig configuration) { OURLConnection val = OURLHelper.parseNew(url); orientDb = new OrientDB(val.getType() + ":" + val.getPath(), configuration); autoclose = true; internal = orientDb.openPool(val.getDbName(), user, password, configuration); }
/** * @param create if true automatically creates database if database with given * URL does not exist * @param open if true automatically opens the database */ protected ODatabaseDocument acquireFromPool(boolean create, boolean open) { if (create && type.isPresent()) { this.factory.createIfNotExists(dbName, type.get()); } final ODatabaseDocument databaseDocument = this.pool.acquire(); if (databaseDocument.isClosed()) { throw new IllegalStateException("Database returned from document is closed"); } return databaseDocument; }