public AbstractOrientDbRepository(OrientDbConfig config, OPartitionedDatabasePoolFactory poolFactory) { this.config = config; this.pool = poolFactory.get(config.connectionString, config.user, config.password); }
public void startup() { startupIfEnginesAreMissing(); OPartitionedDatabasePool pool = new OPartitionedDatabasePoolFactory().get(type + ":" + name, "admin", "admin"); pool.setAutoCreate(true); db = pool.acquire(); ODatabaseRecordThreadLocal.instance().set(db); updateSchema(); }
public void setMaxPoolSize(int maxPoolSize) { checkForClose(); this.maxPoolSize = maxPoolSize; }
@Test public void testFilters() throws Exception { FiltersOrientDbRepository repository = new FiltersOrientDbRepository(config, new OPartitionedDatabasePoolFactory()); repository.init(); Assert.assertEquals(0, repository.getAllFiltered("type1").size()); repository.filter("type1", "value1"); repository.filter("type1", "value2"); Assert.assertEquals(2, repository.getAllFiltered("type1").size()); Assert.assertArrayEquals(new String[] { "value1", "value2" }, repository.getAllFiltered("type1").toArray()); repository.notFilter("type1", "value2"); Assert.assertEquals(1, repository.getAllFiltered("type1").size()); repository.destroy(); }
@Override public void onShutdown() { close(); }
@Test public void testConfigs() throws Exception { OrientDbConfigurationManager cm = new OrientDbConfigurationManager(config, new OPartitionedDatabasePoolFactory()); cm.setHostGroup("dev"); cm.init(); cm.putProperty(ConfigProperty.TEST1_CONFIG, "value"); cm.putProperty(ConfigProperty.POLL_INTERVAL, 16); Assert.assertEquals("value", cm.readString(ConfigProperty.TEST1_CONFIG)); Assert.assertEquals(16, cm.readInt(ConfigProperty.POLL_INTERVAL)); cm.destroy(); cm = new OrientDbConfigurationManager(config, new OPartitionedDatabasePoolFactory()); cm.setHostGroup("dev"); cm.init(); Assert.assertEquals("value", cm.readString(ConfigProperty.TEST1_CONFIG)); Assert.assertEquals(16, cm.readInt(ConfigProperty.POLL_INTERVAL)); cm.destroy(); }
@Override public ODatabaseDocumentInternal getThreadDatabase() { return poolFactory.get("memory:tinkerpop", "admin", "admin").acquire(); }
public void startup() { startupIfEnginesAreMissing(); OPartitionedDatabasePool pool = new OPartitionedDatabasePoolFactory().get(type + ":" + name, "admin", "admin"); pool.setAutoCreate(true); db = pool.acquire(); ODatabaseRecordThreadLocal.instance().set(db); updateSchema(); }
@Test public void testRoles() throws Exception { OPartitionedDatabasePoolFactory poolFactory = new OPartitionedDatabasePoolFactory(); AccountOrientDbRepository accRep = new AccountOrientDbRepository(config, poolFactory); accRep.init();
public Collection<OPartitionedDatabasePool> getPools() { checkForClose(); return Collections.unmodifiableCollection(poolStore.values()); }
@Provides public OPartitionedDatabasePool getPartitionedDatabasePool(IOrientDbSettings settings) { OrienteerWebSession session = OrienteerWebSession.get(); return settings.getDatabasePoolFactory().get(settings.getDBUrl(), session.getUsername(), session.getPassword()); }
connectionPool = new OPartitionedDatabasePoolFactory(connPoolSize) .get(ROOT_DATABASE_URL, orientDbStoreParams.getUserName(), orientDbStoreParams.getUserPassword()); } else { connectionPool = new OPartitionedDatabasePoolFactory().get(ROOT_DATABASE_URL, orientDbStoreParams.getUserName(), orientDbStoreParams.getUserPassword());
@Test public void test() throws Exception { AccountOrientDbRepository repository = new AccountOrientDbRepository(config, new OPartitionedDatabasePoolFactory()); repository.init(); Assert.assertFalse(repository.account("token").isPresent()); AccountImpl account = AccountImpl.createNew("abc", "Artem", "Dmitriev", "artem@reveno.org", "token", "pass", "salt", new ArrayList<>(), DateTime.now(DateTimeZone.UTC), Collections.emptySet()); account = (AccountImpl) repository.insert(account); Assert.assertNotNull(account.getOId()); Assert.assertTrue(repository.account("token").isPresent()); Assert.assertFalse(repository.account("token").get().isConfirmed()); Assert.assertTrue(repository.confirm("token", "salt")); Account account1 = repository.account("token").get(); Assert.assertTrue(account1.isConfirmed()); Assert.assertFalse(account1.isBlocked()); Assert.assertEquals(repository.accounts().size(), 1); Assert.assertNotNull(repository.account(account1.id()).get()); Assert.assertTrue(repository.account("abc", "pass", AccountRepository.LoginType.USERNAME).isPresent()); repository.block("abc"); account1 = repository.account("token").get(); Assert.assertTrue(account1.isBlocked()); account.setEmail("another@mail.ru"); repository.updateInfo(account); account1 = repository.account("token").get(); Assert.assertEquals(account.email(), account1.email()); Assert.assertTrue(account1.isBlocked()); repository.delete(account1); Assert.assertEquals(repository.accounts().size(), 0); repository.destroy(); }
public OPartitionedDatabasePool get(final String url, final String userName, final String userPassword) { checkForClose(); final PoolIdentity poolIdentity = new PoolIdentity(url, userName, userPassword); OPartitionedDatabasePool pool = poolStore.get(poolIdentity); if (pool != null && !pool.isClosed()) return pool; if (pool != null) poolStore.remove(poolIdentity, pool); while (true) { pool = new OPartitionedDatabasePool(url, userName, userPassword, 8, maxPoolSize); final OPartitionedDatabasePool oldPool = poolStore.putIfAbsent(poolIdentity, pool); if (oldPool != null) { if (!oldPool.isClosed()) { return oldPool; } else { poolStore.remove(poolIdentity, oldPool); } } else { return pool; } } }
public ODatabase<?> databaseOpen() throws Exception{ String url = getCamelContext().getProperty(OrientDBComponent.DB_URL); String username = getCamelContext().getProperty(OrientDBComponent.DB_USERNAME); String password = getCamelContext().getProperty(OrientDBComponent.DB_PASSWORD); if(url!=null && username!=null) { return dbPool.get(url, username, password).acquire(); }else{ throw new Exception("Cannot connect to OrientDB server without properties "+OrientDBComponent.DB_URL+" and "+OrientDBComponent.DB_USERNAME); } }
public void testOrientDbLifeCycle(String dbURL, boolean createDb, boolean dropDb) throws Exception { Orient.instance().startup(); assertNotNull(ODatabaseRecordThreadLocal.instance()); Orient.instance().removeShutdownHook(); OServer server = OServerMain.create(); server.startup(OrientDbTestWebApplication.class.getResource("db.config.xml").openStream()); server.activate(); if(createDb) { ODatabaseDocument dbToCreate = new ODatabaseDocumentTx(dbURL); if(!dbToCreate.exists()) dbToCreate.create(); dbToCreate.close(); } assertNotNull(ODatabaseRecordThreadLocal.instance()); ODatabaseDocument db = new OPartitionedDatabasePoolFactory().get(dbURL, "admin", "admin").acquire(); db.close(); assertNotNull(ODatabaseRecordThreadLocal.instance()); if(dropDb) { ODatabaseDocument dbToDrop = new ODatabaseDocumentTx(dbURL); dbToDrop.open("admin", "admin"); dbToDrop.drop(); } server.shutdown(); Orient.instance().shutdown(); // Thread.sleep(50); }
@Test public void testTriggers() throws Exception { TriggerOrientDbRepository r = new TriggerOrientDbRepository(config, new OPartitionedDatabasePoolFactory()); r.init(); Identifier accId = Identifier.fromStr("123");
protected ODatabaseDocument getDatabase(OrientDbWebApplication app) { IOrientDbSettings settings = app.getOrientDbSettings(); String username = settings.getAdminUserName(); String password = settings.getAdminPassword(); return settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); }
protected ODatabaseDocument getDatabase(OrientDbWebApplication app) { IOrientDbSettings settings = app.getOrientDbSettings(); String username = settings.getAdminUserName(); String password = settings.getAdminPassword(); return settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); }
@Override public Session openSession() { OrienteerWebApplication app = OrienteerWebApplication.lookupApplication(); IOrientDbSettings settings = app.getOrientDbSettings(); ODatabaseDocumentTx db = settings.getDatabasePoolFactory().get(settings.getDBUrl(), settings.getAdminUserName(), settings.getAdminPassword()).acquire(); // return new OPersistenceSession((ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get()); return new OPersistenceSession(db); }