@ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export") public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") final String iText) throws IOException { checkForDatabase(); out.println(new StringBuilder("Exporting current database to: ").append(iText).append(" in GZipped JSON format ...")); final List<String> items = OStringSerializerHelper.smartSplit(iText, ' '); final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1); final String options = fileName != null ? iText.substring(items.get(0).length() + items.get(1).length() + 1).trim() : iText; try { new ODatabaseExport(currentDatabase, fileName, this).setOptions(options).exportDatabase().close(); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(aliases = { "display" }, description = "Display current record attributes", onlineHelp = "Console-Command-Display-Record") public void displayRecord( @ConsoleParameter(name = "number", description = "The number of the record in the most recent result set") final String iRecordNumber) { checkForDatabase(); if (iRecordNumber == null || currentResultSet == null) checkCurrentObject(); else { int recNumber = Integer.parseInt(iRecordNumber); if (currentResultSet.size() == 0) throw new OSystemException("No result set where to find the requested record. Execute a query first."); if (currentResultSet.size() <= recNumber) throw new OSystemException("The record requested is not part of current result set (0" + (currentResultSet.size() > 0 ? "-" + (currentResultSet.size() - 1) : "") + ")"); setCurrentRecord(recNumber); } dumpRecordDetails(); }
private Object sqlCommand(final String iExpectedCommand, String iReceivedCommand, final String iMessage, final boolean iIncludeResult) { checkForDatabase(); if (iReceivedCommand == null) return null; iReceivedCommand = iExpectedCommand + " " + iReceivedCommand.trim(); resetResultSet(); final long start = System.currentTimeMillis(); final Object result; try (OResultSet rs = currentDatabase.command(iReceivedCommand)) { result = rs.stream().map(x -> x.toElement()).collect(Collectors.toList()); } float elapsedSeconds = getElapsedSecs(start); if (iIncludeResult) message(iMessage, result, elapsedSeconds); else message(iMessage, elapsedSeconds); return result; } }
/** * Should be used only by console commands */ public void loadRecordInternal(String iRecordId, String iFetchPlan) { checkForDatabase(); currentRecord = currentDatabase.load(new ORecordId(iRecordId), iFetchPlan); displayRecord(null); message("\nOK"); }
@ConsoleCommand(description = "Delete the current database", onlineHelp = "Console-Command-Drop-Database") public void dropDatabase( @ConsoleParameter(name = "storage-type", description = "Storage type of server database", optional = true) String storageType) throws IOException { checkForDatabase(); final String dbName = currentDatabase.getName(); currentDatabase.close(); if (storageType != null && !"plocal".equalsIgnoreCase(storageType)&& !"local".equalsIgnoreCase(storageType)&& !"memory".equalsIgnoreCase(storageType)) { message("\n\nInvalid storage type for db: '" + storageType + "'"); return; } orientDB.drop(dbName); currentDatabase = null; currentDatabaseName = null; message("\n\nDatabase '" + dbName + "' deleted successfully"); }
@ConsoleCommand(description = "Declare an intent", onlineHelp = "") public void declareIntent( @ConsoleParameter(name = "Intent name", description = "name of the intent to execute") final String iIntentName) { checkForDatabase(); message("\nDeclaring intent '" + iIntentName + "'..."); if (iIntentName.equalsIgnoreCase("massiveinsert")) currentDatabase.declareIntent(new OIntentMassiveInsert()); else if (iIntentName.equalsIgnoreCase("massiveread")) currentDatabase.declareIntent(new OIntentMassiveRead()); else if (iIntentName.equalsIgnoreCase("null")) currentDatabase.declareIntent(null); else throw new IllegalArgumentException( "Intent '" + iIntentName + "' not supported. Available ones are: massiveinsert, massiveread, null"); message("\nIntent '" + iIntentName + "' set successfully"); }
@ConsoleCommand(description = "Browse all records of a class", onlineHelp = "Console-Command-Browse-Class") public void browseClass(@ConsoleParameter(name = "class-name", description = "The name of the class") final String iClassName) { checkForDatabase(); resetResultSet(); final OIdentifiableIterator<?> it = currentDatabase.browseClass(iClassName); browseRecords(it); }
/** * Should be used only by console commands */ public void reloadRecordInternal(String iRecordId, String iFetchPlan) { checkForDatabase(); currentRecord = currentDatabase .executeReadRecord(new ORecordId(iRecordId), null, -1, iFetchPlan, true, false, false, OStorage.LOCKING_STRATEGY.NONE, new SimpleRecordReader(false)); displayRecord(null); message("\nOK"); }
@ConsoleCommand(description = "Browse all records of a cluster", onlineHelp = "Console-Command-Browse-Cluster") public void browseCluster( @ConsoleParameter(name = "cluster-name", description = "The name of the cluster") final String iClusterName) { checkForDatabase(); resetResultSet(); final ORecordIteratorCluster<?> it = currentDatabase.browseCluster(iClusterName); browseRecords(it); }
@ConsoleCommand(description = "Load a sql script into the current database", splitInWords = true, onlineHelp = "Console-Command-Load-Script") public void loadScript(@ConsoleParameter(name = "scripPath", description = "load script scriptPath") final String scriptPath) throws IOException { checkForDatabase(); message("\nLoading script " + scriptPath + "..."); executeBatch(scriptPath); message("\nLoaded script " + scriptPath); }
@ConsoleCommand(description = "Remove the association in the dictionary", onlineHelp = "Console-Command-Dictionary-Remove") public void dictionaryRemove(@ConsoleParameter(name = "key", description = "The key to remove") final String iKey) { checkForDatabase(); boolean result = currentDatabase.getDictionary().remove(iKey); if (!result) message("\nEntry not found in dictionary."); else message("\nEntry removed from the dictionary."); }
@ConsoleCommand(description = "Loook up a record using the dictionary. If found, set it as the current record", onlineHelp = "Console-Command-Dictionary-Get") public void dictionaryGet(@ConsoleParameter(name = "key", description = "The key to search") final String iKey) { checkForDatabase(); currentRecord = currentDatabase.getDictionary().get(iKey); if (currentRecord == null) message("\nEntry not found in dictionary."); else { currentRecord = (ORecord) currentRecord.load(); displayRecord(null); } }
@ConsoleCommand(description = "Rolls back transaction changes to the previous state") public void rollback() throws IOException { checkForDatabase(); if (!currentDatabase.getTransaction().isActive()) { message("\nError: no active transaction is running right now."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } final long begin = System.currentTimeMillis(); final int txId = currentDatabase.getTransaction().getId(); currentDatabase.rollback(); message("\nTransaction " + txId + " has been rollbacked in " + (System.currentTimeMillis() - begin) + "ms"); }
@ConsoleCommand(description = "Commits transaction changes to the database") public void commit() throws IOException { checkForDatabase(); if (!currentDatabase.getTransaction().isActive()) { message("\nError: no active transaction is currently open."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } final long begin = System.currentTimeMillis(); final int txId = currentDatabase.getTransaction().getId(); currentDatabase.commit(); message("\nTransaction " + txId + " has been committed in " + (System.currentTimeMillis() - begin) + "ms"); }
@ConsoleCommand(description = "Remove a cluster in the current database. The cluster can be physical or memory") public void dropCluster( @ConsoleParameter(name = "cluster-name", description = "The name or the id of the cluster to remove") String iClusterName) { checkForDatabase(); message("\nDropping cluster [" + iClusterName + "] in database " + currentDatabaseName + "..."); boolean result = currentDatabase.dropCluster(iClusterName, false); if (!result) { // TRY TO GET AS CLUSTER ID try { int clusterId = Integer.parseInt(iClusterName); if (clusterId > -1) { result = currentDatabase.dropCluster(clusterId, true); } } catch (Exception ignored) { } } if (result) message("\nCluster correctly removed"); else message("\nCannot find the cluster to remove"); updateDatabaseInfo(); }
@ConsoleCommand(description = "Export a database schema") public void exportSchema(@ConsoleParameter(name = "output-file", description = "Output file path") final String iOutputFilePath) throws IOException { checkForDatabase(); message("\nExporting current database to: " + iOutputFilePath + "..."); try { ODatabaseExport exporter = new ODatabaseExport(currentDatabase, iOutputFilePath, this); exporter.setIncludeRecords(false); exporter.exportDatabase().close(); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(description = "Freeze database and flush on the disk", onlineHelp = "Console-Command-Freeze-Database") public void freezeDatabase( @ConsoleParameter(name = "storage-type", description = "Storage type of server database", optional = true) String storageType) throws IOException { checkForDatabase(); final String dbName = currentDatabase.getName(); if (currentDatabase.getURL().startsWith(OEngineRemote.NAME)) { if (storageType == null) storageType = "plocal"; new OServerAdmin(currentDatabase.getURL()).connect(currentDatabaseUserName, currentDatabaseUserPassword) .freezeDatabase(storageType); } else { // LOCAL CONNECTION currentDatabase.freeze(); } message("\n\nDatabase '" + dbName + "' was frozen successfully"); }
@ConsoleCommand(description = "Release database after freeze", onlineHelp = "Console-Command-Release-Db") public void releaseDatabase( @ConsoleParameter(name = "storage-type", description = "Storage type of server database", optional = true) String storageType) throws IOException { checkForDatabase(); final String dbName = currentDatabase.getName(); if (currentDatabase.getURL().startsWith(OEngineRemote.NAME)) { if (storageType == null) storageType = "plocal"; new OServerAdmin(currentDatabase.getURL()).connect(currentDatabaseUserName, currentDatabaseUserPassword) .releaseDatabase(storageType); } else { // LOCAL CONNECTION currentDatabase.release(); } message("\n\nDatabase '" + dbName + "' was released successfully"); }
@ConsoleCommand(description = "Insert or modify an entry in the database dictionary. The entry is comprised of key=String, value=record-id", onlineHelp = "Console-Command-Dictionary-Put") public void dictionaryPut(@ConsoleParameter(name = "key", description = "The key to bind") final String iKey, @ConsoleParameter(name = "record-id", description = "The record-id of the record to bind to the key") final String iRecordId) { checkForDatabase(); currentRecord = currentDatabase.load(new ORecordId(iRecordId)); if (currentRecord == null) message("\nError: record with id '" + iRecordId + "' was not found in database"); else { currentDatabase.getDictionary().put(iKey, currentRecord); displayRecord(null); message("\nThe entry " + iKey + "=" + iRecordId + " has been inserted in the database dictionary"); } }
@ConsoleCommand(description = "Begins a transaction. All the changes will remain local") public void begin() throws IOException { checkForDatabase(); if (currentDatabase.getTransaction().isActive()) { message("\nError: an active transaction is currently open (id=" + currentDatabase.getTransaction().getId() + "). Commit or rollback before starting a new one."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } currentDatabase.begin(); message("\nTransaction " + currentDatabase.getTransaction().getId() + " is running"); }