Search in sources :

Example 11 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method configGet.

@ConsoleCommand(description = "Return the value of a configuration value")
public void configGet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName) throws IOException {
    final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
    if (config == null)
        throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' wasn't found");
    final String value;
    if (serverAdmin != null) {
        value = serverAdmin.getGlobalConfiguration(config);
        message("\nRemote configuration: ");
    } else {
        value = config.getValueAsString();
        message("\nLocal configuration: ");
    }
    out.println(iConfigName + " = " + value);
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 12 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method listIndexes.

@ConsoleCommand(description = "Display all indexes", aliases = { "indexes" }, onlineHelp = "Console-Command-List-Indexes")
public void listIndexes() {
    if (currentDatabaseName != null) {
        message("\n\nINDEXES");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        int totalIndexes = 0;
        long totalRecords = 0;
        final List<OIndex<?>> indexes = new ArrayList<OIndex<?>>(currentDatabase.getMetadata().getIndexManager().getIndexes());
        Collections.sort(indexes, new Comparator<OIndex<?>>() {

            public int compare(OIndex<?> o1, OIndex<?> o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }
        });
        long totalIndexedRecords = 0;
        for (final OIndex<?> index : indexes) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            final long indexSize = index.getKeySize();
            totalIndexedRecords += indexSize;
            row.field("NAME", index.getName());
            row.field("TYPE", index.getType());
            row.field("RECORDS", indexSize);
            try {
                final OIndexDefinition indexDefinition = index.getDefinition();
                final long size = index.getKeySize();
                if (indexDefinition != null) {
                    row.field("CLASS", indexDefinition.getClassName());
                    row.field("COLLATE", indexDefinition.getCollate().getName());
                    final List<String> fields = indexDefinition.getFields();
                    final StringBuilder buffer = new StringBuilder();
                    for (int i = 0; i < fields.size(); ++i) {
                        if (buffer.length() > 0)
                            buffer.append(",");
                        buffer.append(fields.get(i));
                        buffer.append("(");
                        buffer.append(indexDefinition.getTypes()[i]);
                        buffer.append(")");
                    }
                    row.field("FIELDS", buffer.toString());
                }
                totalIndexes++;
                totalRecords += size;
            } catch (Exception ignored) {
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        final ODocument footer = new ODocument();
        footer.field("NAME", "TOTAL");
        footer.field("RECORDS", totalIndexedRecords);
        formatter.setFooter(footer);
        formatter.writeRecords(resultSet, -1);
    } else
        message("\nNo database selected yet.");
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 13 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method configSet.

@ConsoleCommand(description = "Change the value of a configuration value")
public void configSet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName, @ConsoleParameter(name = "config-value", description = "Value to set") final String iConfigValue) throws IOException {
    final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
    if (config == null)
        throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' not found");
    if (serverAdmin != null) {
        serverAdmin.setGlobalConfiguration(config, iConfigValue);
        message("\nRemote configuration value changed correctly");
    } else {
        config.setValue(iConfigValue);
        message("\nLocal configuration value changed correctly");
    }
    out.println();
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 14 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method importDatabase.

@ConsoleCommand(description = "Import a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Import")
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") final String text) throws IOException {
    checkForDatabase();
    message("\nImporting database " + text + "...");
    final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
    final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
    final String options = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
    try {
        if (currentDatabase.getStorage().isRemote()) {
            ODatabaseImportRemote databaseImport = new ODatabaseImportRemote(currentDatabase, fileName, this);
            databaseImport.setOptions(options);
            databaseImport.importDatabase();
            databaseImport.close();
        } else {
            ODatabaseImport databaseImport = new ODatabaseImport(currentDatabase, fileName, this);
            databaseImport.setOptions(options);
            databaseImport.importDatabase();
            databaseImport.close();
        }
    } catch (ODatabaseImportException e) {
        printError(e);
    }
}
Also used : ODatabaseImportRemote(com.orientechnologies.orient.client.remote.ODatabaseImportRemote) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 15 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method infoProperty.

@ConsoleCommand(description = "Display a class property", onlineHelp = "Console-Command-Info-Property")
public void infoProperty(@ConsoleParameter(name = "property-name", description = "The name of the property as <class>.<property>") final String iPropertyName) {
    checkForDatabase();
    if (iPropertyName.indexOf('.') == -1)
        throw new OSystemException("Property name is in the format <class>.<property>");
    final String[] parts = iPropertyName.split("\\.");
    final OClass cls = currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClass(parts[0]);
    if (cls == null) {
        message("\n! Class '" + parts[0] + "' does not exist in the database '" + currentDatabaseName + "'");
        return;
    }
    final OProperty prop = cls.getProperty(parts[1]);
    if (prop == null) {
        message("\n! Property '" + parts[1] + "' does not exist in class '" + parts[0] + "'");
        return;
    }
    message("\nPROPERTY '" + prop.getFullName() + "'\n");
    message("\nType.................: " + prop.getType());
    message("\nMandatory............: " + prop.isMandatory());
    message("\nNot null.............: " + prop.isNotNull());
    message("\nRead only............: " + prop.isReadonly());
    message("\nDefault value........: " + prop.getDefaultValue());
    message("\nMinimum value........: " + prop.getMin());
    message("\nMaximum value........: " + prop.getMax());
    message("\nREGEXP...............: " + prop.getRegexp());
    message("\nCollate..............: " + prop.getCollate());
    message("\nLinked class.........: " + prop.getLinkedClass());
    message("\nLinked type..........: " + prop.getLinkedType());
    if (prop.getCustomKeys().size() > 0) {
        message("\n\nCUSTOM ATTRIBUTES");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final String k : prop.getCustomKeys()) {
            try {
                final ODocument row = new ODocument();
                resultSet.add(row);
                row.field("NAME", k);
                row.field("VALUE", prop.getCustom(k));
            } catch (Exception ignored) {
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
    final Collection<OIndex<?>> indexes = prop.getAllIndexes();
    if (!indexes.isEmpty()) {
        message("\n\nINDEXES (" + indexes.size() + " altogether)");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final OIndex<?> index : indexes) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", index.getName());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null) {
                final List<String> fields = indexDefinition.getFields();
                row.field("PROPERTIES", fields);
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OSystemException(com.orientechnologies.common.exception.OSystemException) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Aggregations

ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)36 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OSystemException (com.orientechnologies.common.exception.OSystemException)10 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)9 OIOException (com.orientechnologies.common.io.OIOException)8 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)8 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 Method (java.lang.reflect.Method)4 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)3 OGlobalConfiguration (com.orientechnologies.orient.core.config.OGlobalConfiguration)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 OIndex (com.orientechnologies.orient.core.index.OIndex)3 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)3 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)2 ODatabaseImportException (com.orientechnologies.orient.core.db.tool.ODatabaseImportException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2