/** * Open a new database pool on a specific environment. * * @param environment the starting environment. * @param database the database name * @param user the database user for the current pool of databases. * @param password the password relative to the user name */ public ODatabasePool(OrientDB environment, String database, String user, String password) { this(environment, database, user, password, OrientDBConfig.defaultConfig()); }
public static OrientDBConfig defaultConfig() { return new OrientDBConfig(); }
private void applyAttributes(OrientDBConfig config) { if (config != null) { for (Entry<ATTRIBUTES, Object> attrs : config.getAttributes().entrySet()) { this.set(attrs.getKey(), attrs.getValue()); } } }
protected OrientDBConfig solveConfig(OrientDBConfig config) { if (config != null) { config.setParent(this.configurations); return config; } else { OrientDBConfig cfg = OrientDBConfig.defaultConfig(); cfg.setParent(this.configurations); return cfg; } }
public void reCreatePool() { close(); OrientDBConfig config = OrientDBConfig.defaultConfig(); config.getConfigurations().setValue(OGlobalConfiguration.DB_POOL_MAX, this.maxSize); this.pool = new ODatabasePool(this.orientdb, this.dbName, this.userName, this.password, config); }
@Override public synchronized ODatabaseSession acquire() { return pool.getResource(null, config.getConfigurations().getValueAsLong(DB_POOL_ACQUIRE_TIMEOUT)); }
factory = getOrCreateEmbeddedFactory(baseUrl, null); factory.create(dbName, null, null, ODatabaseType.MEMORY, config); OrientDBConfig openConfig = OrientDBConfig.builder().fromContext(config.getConfigurations()).build(); internal = (ODatabaseDocumentInternal) factory.open(dbName, "admin", "admin", openConfig); for (Map.Entry<ATTRIBUTES, Object> attr : preopenAttributes.entrySet()) { factory = getOrCreateEmbeddedFactory(baseUrl, null); factory.create(dbName, null, null, ODatabaseType.PLOCAL, config); OrientDBConfig openConfig = OrientDBConfig.builder().fromContext(config.getConfigurations()).build(); internal = (ODatabaseDocumentInternal) factory.open(dbName, "admin", "admin", openConfig); for (Map.Entry<ATTRIBUTES, Object> attr : preopenAttributes.entrySet()) {
@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); }
static OrientDBInternal distributed(String directoryPath, OrientDBConfig configuration) { OrientDBInternal factory; try { String className = "com.orientechnologies.orient.core.db.OrientDBDistributed"; ClassLoader loader; if (configuration != null) { loader = configuration.getClassLoader(); } else { loader = OrientDBInternal.class.getClassLoader(); } Class<?> kass = loader.loadClass(className); Constructor<?> constructor = kass.getConstructor(String.class, OrientDBConfig.class, Orient.class); factory = (OrientDBInternal) constructor.newInstance(directoryPath, configuration, Orient.instance()); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException e) { throw OException.wrapException(new ODatabaseException("OrientDB distributed API missing"), e); } catch (InvocationTargetException e) { //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw OException.wrapException(new ODatabaseException("Error creating OrientDB remote factory"), e.getTargetException()); } return factory; }
public synchronized void loadAllDatabases() { if (basePath != null) { scanDatabaseDirectory(new File(basePath), (name) -> { if (!storages.containsKey(name)) { OAbstractPaginatedStorage storage = getOrInitStorage(name); // THIS OPEN THE STORAGE ONLY THE FIRST TIME storage.open(getConfigurations().getConfigurations()); } }); } }
OrientDBConfigBuilder builder = OrientDBConfig.builder(); final String connectionStrategy = pars != null ? (String) pars.get("connectionStrategy") : null; if (connectionStrategy != null)
/** * Create a new remote factory * * @param hosts array of hosts * @param configuration configuration for the specific factory for the list of option {@see OGlobalConfiguration}. * * @return a new remote databases factory */ static OrientDBInternal remote(String[] hosts, OrientDBConfig configuration) { OrientDBInternal factory; try { String className = "com.orientechnologies.orient.core.db.OrientDBRemote"; ClassLoader loader; if (configuration != null) { loader = configuration.getClassLoader(); } else { loader = OrientDBInternal.class.getClassLoader(); } Class<?> kass = loader.loadClass(className); Constructor<?> constructor = kass.getConstructor(String[].class, OrientDBConfig.class, Orient.class); factory = (OrientDBInternal) constructor.newInstance(hosts, configuration, Orient.instance()); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException e) { throw OException.wrapException(new ODatabaseException("OrientDB client API missing"), e); } catch (InvocationTargetException e) { //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw OException.wrapException(new ODatabaseException("Error creating OrientDB remote factory"), e.getTargetException()); } return factory; }
/** * Open a new database pool from a environment and a database name, 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 */ public ODatabasePool(String environment, String database, String user, String password) { this(environment, database, user, password, OrientDBConfig.defaultConfig()); }
public ODatabasePoolImpl(OrientDBInternal factory, String database, String user, String password, OrientDBConfig config) { int max = config.getConfigurations().getValueAsInteger(DB_POOL_MAX); // TODO use configured max pool = new OResourcePool(max, new OResourcePoolListener<Void, ODatabaseDocumentInternal>() { @Override public ODatabaseDocumentInternal createNewResource(Void iKey, Object... iAdditionalArgs) { return factory.poolOpen(database, user, password, ODatabasePoolImpl.this); } @Override public boolean reuseResource(Void iKey, Object[] iAdditionalArgs, ODatabaseDocumentInternal iValue) { if (iValue.getStorage().isClosed()) { return false; } iValue.reuse(); return true; } }); this.factory = factory; this.config = config; }
OrientDBConfigBuilder config = OrientDBConfig.builder();
public OrientDBConfig build() { return new OrientDBConfig(configurations, attributes, listeners, classLoader); }
/** * Open a new database pool from a url, 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 */ public ODatabasePool(String url, String user, String password) { this(url, user, password, OrientDBConfig.defaultConfig()); }
final OContextConfiguration config = configurations.getConfigurations(); final OContextConfiguration config = configurations.getConfigurations(); if (config != null) { maxSegSize = config.getValueAsLong(OGlobalConfiguration.WAL_MAX_SEGMENT_SIZE) * 1024 * 1024; int sizePercent; if (configurations != null) { final OContextConfiguration config = configurations.getConfigurations(); OContextConfiguration config = configurations.getConfigurations(); if (config != null) { minSegSize = config.getValueAsLong(OGlobalConfiguration.WAL_MIN_SEG_SIZE) * 1024 * 1024;
/** * 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()); }
protected ODatabaseDocumentEmbedded internalCreate(OrientDBConfig config, OAbstractPaginatedStorage storage) { try { storage.create(config.getConfigurations()); } catch (IOException e) { throw OException.wrapException(new ODatabaseException("Error on database creation"), e); } ORecordSerializer serializer = ORecordSerializerFactory.instance().getDefaultRecordSerializer(); if (serializer.toString().equals("ORecordDocument2csv")) throw new ODatabaseException("Impossible to create the database with ORecordDocument2csv serializer"); storage.setRecordSerializer(serializer.toString(), serializer.getCurrentVersion()); // since 2.1 newly created databases use strict SQL validation by default storage.setProperty(OStatement.CUSTOM_STRICT_SQL, "true"); // No need to close final ODatabaseDocumentEmbedded embedded = factory.newInstance(storage); embedded.setSerializer(serializer); embedded.internalCreate(config); return embedded; }