/** * Should be used only by console commands */ protected void checkCurrentObject() { if (currentRecord == null) throw new OSystemException("The is no current object selected: create a new one or load it"); }
public void declareRecordType(byte iByte, String iName, Class<? extends ORecord> iClass, final ORecordFactory iFactory) { if (recordTypes[iByte] != null) throw new OSystemException("Record type byte '" + iByte + "' already in use : " + recordTypes[iByte].getName()); recordTypeNames[iByte] = iName; recordTypes[iByte] = iClass; recordFactories[iByte] = iFactory; }
public V newInstanceOfDefaultClass() { if (defaultClass != null) { try { return defaultClass.newInstance(); } catch (Exception e) { throw OException.wrapException( new OSystemException(String.format("Error on creating new instance of default class '%s'", defaultClass)), e); } } return null; }
public V newInstance(final K iKey) { if (iKey == null && defaultClass == null) throw new IllegalArgumentException("Cannot create implementation for type null"); final Class<? extends V> cls = registry.get(iKey); if (cls != null) { try { return cls.newInstance(); } catch (Exception e) { final OSystemException exception = new OSystemException(String.format( "Error on creating new instance of class '%s' registered in factory with key '%s'", cls, iKey)); throw OException.wrapException(exception, e); } } return newInstanceOfDefaultClass(); }
/** * Should be used only by console commands */ protected void checkForDatabase() { if (currentDatabase == null) throw new OSystemException("Database not selected. Use 'connect <url> <user> <password>' to connect to a database."); if (currentDatabase.isClosed()) throw new ODatabaseException("Database '" + currentDatabaseName + "' is closed"); }
/** * Should be used only by console commands */ protected void checkForRemoteServer() { if (orientDB == null || OrientDBInternal.extract(orientDB).isEmbedded()) throw new OSystemException( "Remote server is not connected. Use 'connect remote:<host>[:<port>][/<database-name>]' to connect"); }
@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(); }
public TTYConsoleReader(boolean historyEnabled) { this.historyEnabled = historyEnabled; File file = getHistoryFile(true); BufferedReader reader; try { reader = new BufferedReader(new FileReader(file)); if (historyEnabled) { String historyEntry = reader.readLine(); while (historyEntry != null) { history.add(historyEntry); historyEntry = reader.readLine(); } } if (System.getProperty("file.encoding") != null) { inStream = new InputStreamReader(System.in, System.getProperty("file.encoding")); outStream = new PrintStream(System.out, false, System.getProperty("file.encoding")); } else { inStream = new InputStreamReader(System.in); outStream = System.out; } } catch (FileNotFoundException fnfe) { OLogManager.instance().error(this, "History file not found", fnfe); } catch (IOException ioe) { OLogManager.instance().error(this, "Error reading history file", ioe); } if (inStream == null) throw new OSystemException("Cannot access to the input stream. Check permissions of running process"); }
public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException { if (inputFile == null) throw new OSystemException("needed an input file as first argument"); if (dbURL == null) throw new OSystemException("needed an database location as second argument"); ODatabaseDocumentInternal db = new ODatabaseDocumentTx(dbURL); ODatabaseHelper.deleteDatabase(db, db.getType()); OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL); System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "..."); final long startTime = System.currentTimeMillis(); OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }) .setCurrentDatabase(g.getRawGraph()); console.run(); System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices()); g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute(); g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute(); g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute(); g.shutdown(); } }
throw new OSystemException("The record has been deleted"); if ("ORecordSerializerBinary".equals(currentDatabase.getSerializer().toString())) { byte[] buff = record.getBuffer();
throw new OSystemException("Property name is in the format <class>.<property>");