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);
}
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.");
}
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();
}
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);
}
}
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);
}
}
Aggregations