use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method disconnect.
@ConsoleCommand(aliases = { "close database" }, description = "Disconnect from the current database", onlineHelp = "Console-Command-Disconnect")
public void disconnect() {
if (serverAdmin != null) {
message("\nDisconnecting from remote server [" + serverAdmin.getURL() + "]...");
serverAdmin.close(true);
serverAdmin = null;
message("\nOK");
}
if (currentDatabase != null) {
message("\nDisconnecting from the database [" + currentDatabaseName + "]...");
final OStorage stg = Orient.instance().getStorage(currentDatabase.getURL());
currentDatabase.activateOnCurrentThread();
if (!currentDatabase.isClosed())
currentDatabase.close();
// FORCE CLOSING OF STORAGE: THIS CLEAN UP REMOTE CONNECTIONS
if (stg != null)
stg.close(true, false);
currentDatabase = null;
currentDatabaseName = null;
currentRecord = null;
message("OK");
}
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method listServerUsers.
@SuppressWarnings("unchecked")
@ConsoleCommand(description = "Display all the server user names. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-List-Server-User")
public void listServerUsers() {
final File serverCfgFile = new File("../config/orientdb-server-config.xml");
if (!serverCfgFile.exists())
throw new OConfigurationException("Cannot access to file " + serverCfgFile);
try {
final OServerConfigurationManager serverCfg = new OServerConfigurationManager(serverCfgFile);
message("\nSERVER USERS\n");
final Set<OServerUserConfiguration> users = serverCfg.getUsers();
if (users.isEmpty())
message("\nNo users found");
else
for (OServerUserConfiguration u : users) {
message("\n- '%s', permissions: %s", u.name, u.resources);
}
} catch (Exception e) {
error("\nError on loading %s file: %s", serverCfgFile, e.toString());
}
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method listClasses.
@ConsoleCommand(description = "Display all the configured classes", aliases = { "classes" }, onlineHelp = "Console-Command-List-Classes")
public void listClasses() {
if (currentDatabaseName != null) {
message("\n\nCLASSES");
final List<ODocument> resultSet = new ArrayList<ODocument>();
long totalElements = 0;
long count;
final List<OClass> classes = new ArrayList<OClass>(currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClasses());
Collections.sort(classes, new Comparator<OClass>() {
public int compare(OClass o1, OClass o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (OClass cls : classes) {
try {
final ODocument row = new ODocument();
resultSet.add(row);
final StringBuilder clusters = new StringBuilder(1024);
if (cls.isAbstract())
clusters.append("-");
else {
int[] clusterIds = cls.getClusterIds();
for (int i = 0; i < clusterIds.length; ++i) {
if (i > 0)
clusters.append(",");
clusters.append(currentDatabase.getClusterNameById(clusterIds[i]));
clusters.append("(");
clusters.append(clusterIds[i]);
clusters.append(")");
}
}
count = currentDatabase.countClass(cls.getName(), false);
totalElements += count;
final String superClasses = cls.hasSuperClasses() ? Arrays.toString(cls.getSuperClassesNames().toArray()) : "";
row.field("NAME", cls.getName());
row.field("SUPER-CLASSES", superClasses);
row.field("CLUSTERS", clusters);
row.field("COUNT", count);
} catch (Exception ignored) {
// IGNORED
}
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.setColumnAlignment("COUNT", OTableFormatter.ALIGNMENT.RIGHT);
final ODocument footer = new ODocument();
footer.field("NAME", "TOTAL");
footer.field("COUNT", totalElements);
formatter.setFooter(footer);
formatter.writeRecords(resultSet, -1);
message("\n");
} else
message("\nNo database selected yet.");
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method config.
@ConsoleCommand(description = "Return all the configuration values")
public void config() throws IOException {
if (serverAdmin != null) {
// REMOTE STORAGE
final Map<String, String> values = serverAdmin.getGlobalConfigurations();
message("\nREMOTE SERVER CONFIGURATION");
final List<ODocument> resultSet = new ArrayList<ODocument>();
for (Entry<String, String> p : values.entrySet()) {
final ODocument row = new ODocument();
resultSet.add(row);
row.field("NAME", p.getKey());
row.field("VALUE", p.getValue());
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
} else {
// LOCAL STORAGE
message("\nLOCAL SERVER CONFIGURATION");
final List<ODocument> resultSet = new ArrayList<ODocument>();
for (OGlobalConfiguration cfg : OGlobalConfiguration.values()) {
final ODocument row = new ODocument();
resultSet.add(row);
row.field("NAME", cfg.getKey());
row.field("VALUE", cfg.getValue());
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
}
message("\n");
}
use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method repairDatabase.
@ConsoleCommand(description = "Repair database structure")
public void repairDatabase(@ConsoleParameter(name = "options", description = "Options: -v", optional = true) final String iOptions) throws IOException {
checkForDatabase();
message("\nRepairing database...");
boolean verbose = iOptions != null && iOptions.contains("-v");
new ODatabaseRepair().setDatabase(currentDatabase).setOutputListener(new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
message(iText);
}
}).setVerbose(verbose).run();
}
Aggregations