Search in sources :

Example 1 with OStorageEntryConfiguration

use of com.orientechnologies.orient.core.config.OStorageEntryConfiguration in project orientdb by orientechnologies.

the class OGraphBatchInsert method begin.

/**
 * Creates the database (if it does not exist) and initializes batch operations. Call this once, before starting to create
 * vertices and edges.
 */
public void begin() {
    walActive = OGlobalConfiguration.USE_WAL.getValueAsBoolean();
    if (walActive)
        OGlobalConfiguration.USE_WAL.setValue(false);
    if (averageEdgeNumberPerNode > 0) {
        OGlobalConfiguration.RID_BAG_EMBEDDED_DEFAULT_SIZE.setValue(averageEdgeNumberPerNode);
        OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(bonsaiThreshold);
    }
    db = new ODatabaseDocumentTx(dbUrl);
    if (db.exists()) {
        db.open(userName, password);
    } else {
        db.create();
    }
    if (this.useLightWeigthEdges == null) {
        final List<OStorageEntryConfiguration> custom = (List<OStorageEntryConfiguration>) db.get(ODatabase.ATTRIBUTES.CUSTOM);
        for (OStorageEntryConfiguration c : custom) {
            if (c.name.equalsIgnoreCase("useLightweightEdges")) {
                this.useLightWeigthEdges = Boolean.parseBoolean(c.value);
                break;
            }
        }
        if (this.useLightWeigthEdges == null) {
            this.useLightWeigthEdges = true;
        }
    }
    createBaseSchema();
    out = estimatedEntries > 0 ? new HashMap<Long, List<Object>>(estimatedEntries) : new HashMap<Long, List<Object>>();
    in = estimatedEntries > 0 ? new HashMap<Long, List<Object>>(estimatedEntries) : new HashMap<Long, List<Object>>();
    OClass vClass = db.getMetadata().getSchema().getClass(this.vertexClass);
    int[] existingClusters = vClass.getClusterIds();
    for (int c = existingClusters.length; c <= parallel; c++) {
        vClass.addCluster(vClass.getName() + "_" + c);
    }
    clusterIds = vClass.getClusterIds();
    lastClusterPositions = new long[clusterIds.length];
    nextVerticesToCreate = new long[clusterIds.length];
    for (int i = 0; i < clusterIds.length; i++) {
        int clusterId = clusterIds[i];
        try {
            nextVerticesToCreate[i] = i;
            // THERE IS NO PUBLIC API FOR RETRIEVE THE LAST CLUSTER POSITION
            lastClusterPositions[i] = ((ODatabaseDocumentInternal) db).getStorage().getClusterById(clusterId).getLastPosition();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ArrayList(java.util.ArrayList) List(java.util.List) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration)

Example 2 with OStorageEntryConfiguration

use of com.orientechnologies.orient.core.config.OStorageEntryConfiguration 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)

Example 3 with OStorageEntryConfiguration

use of com.orientechnologies.orient.core.config.OStorageEntryConfiguration in project orientdb by orientechnologies.

the class OServerCommandGetDatabase method exec.

protected void exec(final OHttpRequest iRequest, final OHttpResponse iResponse, final String[] urlParts) throws InterruptedException, IOException {
    ODatabaseDocumentInternal db = null;
    try {
        if (urlParts.length > 2) {
            db = server.getDatabasePoolFactory().get(urlParts[1], urlParts[2], urlParts[3]).acquire();
        } else
            db = getProfiledDatabaseInstance(iRequest);
        final StringWriter buffer = new StringWriter();
        final OJSONWriter json = new OJSONWriter(buffer);
        json.beginObject();
        json.beginObject("server");
        json.writeAttribute("version", OConstants.ORIENT_VERSION);
        if (OConstants.getBuildNumber() != null)
            json.writeAttribute("build", OConstants.getBuildNumber());
        json.writeAttribute("osName", System.getProperty("os.name"));
        json.writeAttribute("osVersion", System.getProperty("os.version"));
        json.writeAttribute("osArch", System.getProperty("os.arch"));
        json.writeAttribute("javaVendor", System.getProperty("java.vm.vendor"));
        json.writeAttribute("javaVersion", System.getProperty("java.vm.version"));
        json.beginCollection("conflictStrategies");
        Set<String> strategies = Orient.instance().getRecordConflictStrategy().getRegisteredImplementationNames();
        int i = 0;
        for (String strategy : strategies) {
            json.write((i > 0 ? "," : "") + "\"" + strategy + "\"");
            i++;
        }
        json.endCollection();
        json.endObject();
        if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().getClasses() != null) {
            json.beginCollection("classes");
            List<String> classNames = new ArrayList<String>();
            for (OClass cls : db.getMetadata().getSchema().getClasses()) classNames.add(cls.getName());
            Collections.sort(classNames);
            for (String className : classNames) {
                final OClass cls = db.getMetadata().getSchema().getClass(className);
                try {
                    exportClass(db, json, cls);
                } catch (Exception e) {
                    OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
                }
            }
            json.endCollection();
        }
        if (db.getClusterNames() != null) {
            json.beginCollection("clusters");
            OCluster cluster;
            for (String clusterName : db.getClusterNames()) {
                try {
                    cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));
                } catch (IllegalArgumentException e) {
                    OLogManager.instance().error(this, "Cluster '%s' does not exist in database", clusterName);
                    continue;
                }
                try {
                    final String conflictStrategy = cluster.getRecordConflictStrategy() != null ? cluster.getRecordConflictStrategy().getName() : null;
                    json.beginObject();
                    json.writeAttribute("id", cluster.getId());
                    json.writeAttribute("name", clusterName);
                    json.writeAttribute("records", cluster.getEntries() - cluster.getTombstonesCount());
                    json.writeAttribute("conflictStrategy", conflictStrategy);
                    json.writeAttribute("size", "-");
                    json.writeAttribute("filled", "-");
                    json.writeAttribute("maxSize", "-");
                    json.writeAttribute("files", "-");
                } catch (Exception e) {
                    json.writeAttribute("records", "? (Unauthorized)");
                }
                json.endObject();
            }
            json.endCollection();
        }
        if (db.getUser() != null) {
            json.writeAttribute("currentUser", db.getUser().getName());
        // exportSecurityInfo(db, json);
        }
        final OIndexManagerProxy idxManager = db.getMetadata().getIndexManager();
        json.beginCollection("indexes");
        for (OIndex<?> index : idxManager.getIndexes()) {
            json.beginObject();
            try {
                json.writeAttribute("name", index.getName());
                json.writeAttribute("configuration", index.getConfiguration());
            // Exclude index size because it's too costly
            // json.writeAttribute("size", index.getSize());
            } catch (Exception e) {
                OLogManager.instance().error(this, "Cannot serialize index configuration", e);
            }
            json.endObject();
        }
        json.endCollection();
        json.beginObject("config");
        json.beginCollection("values");
        json.writeObjects(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", "charSet", "value", db.getStorage().getConfiguration().getCharset() }, new Object[] { "name", "timezone", "value", db.getStorage().getConfiguration().getTimeZone().getID() }, new Object[] { "name", "definitionVersion", "value", db.getStorage().getConfiguration().version }, new Object[] { "name", "clusterSelection", "value", db.getStorage().getConfiguration().getClusterSelection() }, new Object[] { "name", "minimumClusters", "value", db.getStorage().getConfiguration().getMinimumClusters() }, new Object[] { "name", "conflictStrategy", "value", db.getStorage().getConfiguration().getConflictStrategy() });
        json.endCollection();
        json.beginCollection("properties");
        if (db.getStorage().getConfiguration().getProperties() != null)
            for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().getProperties()) {
                if (entry != null) {
                    json.beginObject();
                    json.writeAttribute("name", entry.name);
                    json.writeAttribute("value", entry.value);
                    json.endObject();
                }
            }
        json.endCollection();
        json.endObject();
        json.endObject();
        json.flush();
        iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
    } finally {
        if (db != null)
            db.close();
    }
}
Also used : OJSONWriter(com.orientechnologies.orient.core.serialization.serializer.OJSONWriter) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) StringWriter(java.io.StringWriter) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCluster(com.orientechnologies.orient.core.storage.OCluster) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration)

Example 4 with OStorageEntryConfiguration

use of com.orientechnologies.orient.core.config.OStorageEntryConfiguration in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method listProperties.

@ConsoleCommand(description = "Display the database properties")
public void listProperties() {
    if (currentDatabase == null)
        return;
    final OStorage stg = currentDatabase.getStorage();
    final OStorageConfiguration dbCfg = stg.getConfiguration();
    message("\n\nDATABASE PROPERTIES");
    if (dbCfg.getProperties() != null) {
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        if (dbCfg.name != null)
            resultSet.add(new ODocument().field("NAME", "Name").field("VALUE", dbCfg.name));
        resultSet.add(new ODocument().field("NAME", "Version").field("VALUE", dbCfg.version));
        resultSet.add(new ODocument().field("NAME", "Conflict-Strategy").field("VALUE", dbCfg.getConflictStrategy()));
        resultSet.add(new ODocument().field("NAME", "Date-Format").field("VALUE", dbCfg.dateFormat));
        resultSet.add(new ODocument().field("NAME", "Datetime-Format").field("VALUE", dbCfg.dateTimeFormat));
        resultSet.add(new ODocument().field("NAME", "Timezone").field("VALUE", dbCfg.getTimeZone().getID()));
        resultSet.add(new ODocument().field("NAME", "Locale-Country").field("VALUE", dbCfg.getLocaleCountry()));
        resultSet.add(new ODocument().field("NAME", "Locale-Language").field("VALUE", dbCfg.getLocaleLanguage()));
        resultSet.add(new ODocument().field("NAME", "Charset").field("VALUE", dbCfg.getCharset()));
        resultSet.add(new ODocument().field("NAME", "Schema-RID").field("VALUE", dbCfg.schemaRecordId, OType.LINK));
        resultSet.add(new ODocument().field("NAME", "Index-Manager-RID").field("VALUE", dbCfg.indexMgrRecordId, OType.LINK));
        resultSet.add(new ODocument().field("NAME", "Dictionary-RID").field("VALUE", dbCfg.dictionaryRecordId, OType.LINK));
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
        message("\n");
        if (!dbCfg.getProperties().isEmpty()) {
            message("\n\nDATABASE CUSTOM PROPERTIES:");
            final List<ODocument> dbResultSet = new ArrayList<ODocument>();
            for (OStorageEntryConfiguration cfg : dbCfg.getProperties()) dbResultSet.add(new ODocument().field("NAME", cfg.name).field("VALUE", cfg.value));
            final OTableFormatter dbFormatter = new OTableFormatter(this);
            dbFormatter.writeRecords(dbResultSet, -1);
        }
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 5 with OStorageEntryConfiguration

use of com.orientechnologies.orient.core.config.OStorageEntryConfiguration in project orientdb by orientechnologies.

the class OrientBaseGraph method readDatabaseConfiguration.

@SuppressWarnings("unchecked")
private void readDatabaseConfiguration() {
    final ODatabaseDocumentTx databaseDocumentTx = getRawGraph();
    final List<OStorageEntryConfiguration> custom = (List<OStorageEntryConfiguration>) databaseDocumentTx.get(ATTRIBUTES.CUSTOM);
    for (OStorageEntryConfiguration c : custom) {
        if (c.name.equals("useLightweightEdges"))
            setUseLightweightEdges(Boolean.parseBoolean(c.value));
        else if (// Since v2.2.0
        c.name.equals("txRequiredForSQLGraphOperations"))
            setTxRequiredForSQLGraphOperations(Boolean.parseBoolean(c.value));
        else if (// Since v2.2.0
        c.name.equals("maxRetries"))
            setMaxRetries(Integer.parseInt(c.value));
        else if (c.name.equals("useClassForEdgeLabel"))
            setUseClassForEdgeLabel(Boolean.parseBoolean(c.value));
        else if (c.name.equals("useClassForVertexLabel"))
            setUseClassForVertexLabel(Boolean.parseBoolean(c.value));
        else if (c.name.equals("useVertexFieldsForEdgeLabels"))
            setUseVertexFieldsForEdgeLabels(Boolean.parseBoolean(c.value));
        else if (c.name.equals("standardElementConstraints"))
            setStandardElementConstraints(Boolean.parseBoolean(c.value));
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration)

Aggregations

OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OJSONWriter (com.orientechnologies.orient.core.serialization.serializer.OJSONWriter)2 OCluster (com.orientechnologies.orient.core.storage.OCluster)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OStorageConfiguration (com.orientechnologies.orient.core.config.OStorageConfiguration)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)1 ORole (com.orientechnologies.orient.core.metadata.security.ORole)1 OUser (com.orientechnologies.orient.core.metadata.security.OUser)1 OStorage (com.orientechnologies.orient.core.storage.OStorage)1 ArrayList (java.util.ArrayList)1