Search in sources :

Example 6 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class SQLDeleteTest method deleteInPool.

@Test
public void deleteInPool() {
    OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
    ODatabaseDocumentTx db = pool.acquire();
    final Long total = db.countClass("Profile");
    final List<ODocument> resultset = db.query(new OSQLSynchQuery<Object>("select from Profile where sex = 'male' and salary > 120 and salary <= 133"));
    final Number records = (Number) db.command(new OCommandSQL("delete from Profile where sex = 'male' and salary > 120 and salary <= 133")).execute();
    Assert.assertEquals(records.intValue(), resultset.size());
    Assert.assertEquals(db.countClass("Profile"), total - records.intValue());
    db.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 7 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project YCSB by brianfrankcooper.

the class OrientDBClient method init.

/**
   * Initialize any state for this DB. Called once per DB instance; there is one DB instance per client thread.
   */
public void init() throws DBException {
    // initialize OrientDB driver
    final Properties props = getProperties();
    String url = props.getProperty(URL_PROPERTY, URL_PROPERTY_DEFAULT);
    String user = props.getProperty(USER_PROPERTY, USER_PROPERTY_DEFAULT);
    String password = props.getProperty(PASSWORD_PROPERTY, PASSWORD_PROPERTY_DEFAULT);
    Boolean newdb = Boolean.parseBoolean(props.getProperty(NEWDB_PROPERTY, NEWDB_PROPERTY_DEFAULT));
    String remoteStorageType = props.getProperty(STORAGE_TYPE_PROPERTY);
    INIT_LOCK.lock();
    try {
        clientCounter++;
        if (!initialized) {
            OGlobalConfiguration.dumpConfiguration(System.out);
            LOG.info("OrientDB loading database url = " + url);
            ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
            if (db.getStorage().isRemote()) {
                isRemote = true;
            }
            if (!dbChecked) {
                if (!isRemote) {
                    if (newdb) {
                        if (db.exists()) {
                            db.open(user, password);
                            LOG.info("OrientDB drop and recreate fresh db");
                            db.drop();
                        }
                        db.create();
                    } else {
                        if (!db.exists()) {
                            LOG.info("OrientDB database not found, creating fresh db");
                            db.create();
                        }
                    }
                } else {
                    OServerAdmin server = new OServerAdmin(url).connect(user, password);
                    if (remoteStorageType == null) {
                        throw new DBException("When connecting to a remote OrientDB instance, " + "specify a database storage type (plocal or memory) with " + STORAGE_TYPE_PROPERTY);
                    }
                    if (newdb) {
                        if (server.existsDatabase()) {
                            LOG.info("OrientDB drop and recreate fresh db");
                            server.dropDatabase(remoteStorageType);
                        }
                        server.createDatabase(db.getName(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
                    } else {
                        if (!server.existsDatabase()) {
                            LOG.info("OrientDB database not found, creating fresh db");
                            server.createDatabase(server.getURL(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType);
                        }
                    }
                    server.close();
                }
                dbChecked = true;
            }
            if (db.isClosed()) {
                db.open(user, password);
            }
            if (!db.getMetadata().getSchema().existsClass(CLASS)) {
                db.getMetadata().getSchema().createClass(CLASS);
            }
            db.close();
            if (databasePool == null) {
                databasePool = new OPartitionedDatabasePool(url, user, password);
            }
            initialized = true;
        }
    } catch (Exception e) {
        LOG.error("Could not initialize OrientDB connection pool for Loader: " + e.toString());
        e.printStackTrace();
    } finally {
        INIT_LOCK.unlock();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException)

Example 8 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project YCSB by brianfrankcooper.

the class OrientDBClientTest method deleteTest.

@Test
public void deleteTest() {
    String user0 = "user0";
    String user1 = "user1";
    String user2 = "user2";
    insertRow(user0);
    insertRow(user1);
    insertRow(user2);
    orientDBClient.delete(CLASS, user1);
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        assertNotNull("Assert user0 still exists", dictionary.get(user0));
        assertNull("Assert user1 does not exist", dictionary.get(user1));
        assertNotNull("Assert user2 still exists", dictionary.get(user2));
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 9 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project YCSB by brianfrankcooper.

the class OrientDBClientTest method insertTest.

@Test
public void insertTest() {
    String insertKey = "user0";
    Map<String, ByteIterator> insertMap = insertRow(insertKey);
    OPartitionedDatabasePool pool = orientDBClient.getDatabasePool();
    try (ODatabaseDocumentTx db = pool.acquire()) {
        ODictionary<ORecord> dictionary = db.getDictionary();
        ODocument result = dictionary.get(insertKey);
        assertTrue("Assert a row was inserted.", result != null);
        for (int i = 0; i < NUM_FIELDS; i++) {
            assertEquals("Assert all inserted columns have correct values.", result.field(FIELD_PREFIX + i), insertMap.get(FIELD_PREFIX + i).toString());
        }
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ORecord(com.orientechnologies.orient.core.record.ORecord) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 10 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class DbCreationTest method testOpenCloseConnectionPool.

@Test(dependsOnMethods = { "testCreateAndConnectionPool" })
public void testOpenCloseConnectionPool() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    if (!ODatabaseHelper.existsDatabase(db, null)) {
        ODatabaseHelper.createDatabase(db, url, getStorageType());
        db.close();
    }
    if (pool != null) {
        pool.close();
    }
    pool = new OPartitionedDatabasePool(url, "admin", "admin");
    for (int i = 0; i < 500; i++) {
        pool.acquire().close();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Aggregations

OPartitionedDatabasePool (com.orientechnologies.orient.core.db.OPartitionedDatabasePool)17 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 Test (org.testng.annotations.Test)5 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ByteIterator (com.yahoo.ycsb.ByteIterator)2 StringByteIterator (com.yahoo.ycsb.StringByteIterator)2 File (java.io.File)2 Test (org.junit.Test)2 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)1 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)1 ODatabaseCompare (com.orientechnologies.orient.core.db.tool.ODatabaseCompare)1 OEntityManager (com.orientechnologies.orient.core.entity.OEntityManager)1 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1