Search in sources :

Example 6 with OCluster

use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.

the class BrowseSpeedTest method browseStorageClusters.

protected void browseStorageClusters() throws IOException {
    ODatabaseDocumentTx db = openDatabase();
    final long total = db.countClass(CLASS);
    final OClass cls = db.getMetadata().getSchema().getClass(CLASS);
    final int[] clIds = cls.getPolymorphicClusterIds();
    long start = System.currentTimeMillis();
    int loaded = 0;
    ORecord rec;
    for (int clId : clIds) {
        OCluster cluster = db.getStorage().getClusterById(clId);
        final long clusterRecords = cluster.getEntries();
        for (long rid = 0; rid < clusterRecords; ++rid) {
            final ORawBuffer buffer = cluster.readRecord(rid, true);
            loaded++;
        }
    }
    long end = System.currentTimeMillis();
    System.out.println("Browse clusters " + total + " and loaded " + loaded + " took " + (end - start));
    db.close();
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 7 with OCluster

use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.

the class BrowseSpeedTest method browseStorageClusters.

protected void browseStorageClusters() throws IOException {
    ODatabaseDocumentTx db = openDatabase();
    final long total = db.countClass(className);
    final OClass cls = db.getMetadata().getSchema().getClass(className);
    final int[] clIds = cls.getPolymorphicClusterIds();
    long start = System.currentTimeMillis();
    int loaded = 0;
    for (int clId : clIds) {
        OCluster cluster = db.getStorage().getClusterById(clId);
        final long clusterRecords = cluster.getEntries();
        for (long rid = 0; rid < clusterRecords; ++rid) {
            final ORawBuffer buffer = cluster.readRecord(rid, true);
            loaded++;
        }
    }
    long end = System.currentTimeMillis();
    System.out.println("Browse clusters " + total + " and loaded " + loaded + " took " + (end - start));
    db.close();
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 8 with OCluster

use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.

the class OCommandExecutorSQLAlterCluster method execute.

/**
   * Execute the ALTER CLUSTER.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final List<OCluster> clusters = getClusters();
    if (clusters.isEmpty())
        throw new OCommandExecutionException("Cluster '" + clusterName + "' not found");
    Object result = null;
    for (OCluster cluster : getClusters()) {
        if (clusterId > -1 && clusterName.equals(String.valueOf(clusterId))) {
            clusterName = cluster.getName();
            result = getDatabase().alterCluster(clusterName, attribute, value);
        } else {
            clusterId = cluster.getId();
            result = getDatabase().alterCluster(clusterId, attribute, value);
        }
    }
    return result;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 9 with OCluster

use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.

the class OLiveQueryTest method testLiveInsertOnCluster.

@Test
public void testLiveInsertOnCluster() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest");
    db.activateOnCurrentThread();
    db.create();
    try {
        OClass clazz = db.getMetadata().getSchema().createClass("test");
        int defaultCluster = clazz.getDefaultClusterId();
        OCluster cluster = db.getStorage().getClusterById(defaultCluster);
        MyLiveQueryListener listener = new MyLiveQueryListener();
        db.query(new OLiveQuery<ODocument>("live select from cluster:" + cluster.getName(), listener));
        db.command(new OCommandSQL("insert into cluster:" + cluster.getName() + " set name = 'foo', surname = 'bar'")).execute();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Assert.assertEquals(listener.ops.size(), 1);
        for (ORecordOperation doc : listener.ops) {
            Assert.assertEquals(doc.type, ORecordOperation.CREATED);
            Assert.assertEquals(((ODocument) doc.record).field("name"), "foo");
        }
    } finally {
        db.drop();
    }
}
Also used : ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 10 with OCluster

use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.

the class OServerCommandPostDatabase method sendDatabaseInfo.

protected void sendDatabaseInfo(final OHttpRequest iRequest, final OHttpResponse iResponse, final ODatabaseDocumentInternal db) throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer);
    json.beginObject();
    if (db.getMetadata().getSchema().getClasses() != null) {
        json.beginCollection(1, false, "classes");
        Set<String> exportedNames = new HashSet<String>();
        for (OClass cls : db.getMetadata().getSchema().getClasses()) {
            if (!exportedNames.contains(cls.getName()))
                try {
                    exportClass(db, json, cls);
                    exportedNames.add(cls.getName());
                } catch (Exception e) {
                    OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
                }
        }
        json.endCollection(1, true);
    }
    if (db.getClusterNames() != null) {
        json.beginCollection(1, false, "clusters");
        OCluster cluster;
        for (String clusterName : db.getClusterNames()) {
            cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));
            try {
                json.beginObject(2, true, null);
                json.writeAttribute(3, false, "id", cluster.getId());
                json.writeAttribute(3, false, "name", clusterName);
                json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
                json.writeAttribute(3, false, "size", "-");
                json.writeAttribute(3, false, "filled", "-");
                json.writeAttribute(3, false, "maxSize", "-");
                json.writeAttribute(3, false, "files", "-");
            } catch (Exception e) {
                json.writeAttribute(3, false, "records", "? (Unauthorized)");
            }
            json.endObject(2, false);
        }
        json.endCollection(1, true);
    }
    if (db.getUser() != null)
        json.writeAttribute(1, false, "currentUser", db.getUser().getName());
    json.beginCollection(1, false, "users");
    OUser user;
    for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
        user = new OUser(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", user.getName());
        json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
        json.endObject(2, false);
    }
    json.endCollection(1, true);
    json.beginCollection(1, true, "roles");
    ORole role;
    for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
        role = new ORole(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", role.getName());
        json.writeAttribute(3, false, "mode", role.getMode().toString());
        json.beginCollection(3, true, "rules");
        for (Map.Entry<String, Byte> rule : role.getRules().entrySet()) {
            json.beginObject(4);
            json.writeAttribute(4, true, "name", rule.getKey());
            json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
            json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
            json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
            json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
            json.endObject(4, true);
        }
        json.endCollection(3, false);
        json.endObject(2, true);
    }
    json.endCollection(1, true);
    json.beginObject(1, true, "config");
    json.beginCollection(2, true, "values");
    json.writeObjects(3, true, null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat }, new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] { "name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name", "localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name", "definitionVersion", "value", db.getStorage().getConfiguration().version });
    json.endCollection(2, true);
    json.beginCollection(2, true, "properties");
    if (db.getStorage().getConfiguration().getProperties() != null)
        for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().getProperties()) {
            if (entry != null) {
                json.beginObject(3, true, null);
                json.writeAttribute(4, false, "name", entry.name);
                json.writeAttribute(4, false, "value", entry.value);
                json.endObject(3, true);
            }
        }
    json.endCollection(2, true);
    json.endObject(1, true);
    json.endObject();
    json.flush();
    iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
}
Also used : OJSONWriter(com.orientechnologies.orient.core.serialization.serializer.OJSONWriter) ORole(com.orientechnologies.orient.core.metadata.security.ORole) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) StringWriter(java.io.StringWriter) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCluster(com.orientechnologies.orient.core.storage.OCluster) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration) Map(java.util.Map) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCluster (com.orientechnologies.orient.core.storage.OCluster)12 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)9 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 IOException (java.io.IOException)3 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)2 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)2 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)2 OJSONWriter (com.orientechnologies.orient.core.serialization.serializer.OJSONWriter)2 ORawBuffer (com.orientechnologies.orient.core.storage.ORawBuffer)2 OStorage (com.orientechnologies.orient.core.storage.OStorage)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OException (com.orientechnologies.common.exception.OException)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OIOException (com.orientechnologies.common.io.OIOException)1