protected void dumpResultSet(final int limit) { new OTableFormatter(this).setMaxWidthSize(getConsoleWidth()).setMaxMultiValueEntries(getMaxMultiValueEntries()) .writeRecords(currentResultSet, limit); }
public void writeRecords(final List<? extends OIdentifiable> resultSet, final int limit, final OCallable<Object, OIdentifiable> iAfterDump) { final Map<String, Integer> columns = parseColumns(resultSet, limit); dumpRecordInTable(fetched++, record, columns); if (iAfterDump != null) iAfterDump.call(record); printHeaderLine(columns); out.onMessage("\nLIMIT EXCEEDED: resultset contains more items not displayed (limit=" + limit + ")"); return; printHeaderLine(columns); dumpRecordInTable(-1, footer, columns); printHeaderLine(columns);
public void dumpRecordInTable(final int iIndex, final OIdentifiable iRecord, final Map<String, Integer> iColumns) { if (iIndex == 0) printHeader(iColumns); Object value = getFieldValue(iIndex, iRecord, columnName); String valueAsString = null; valueAsString = formatCell(columnName, columnWidth, valueAsString);
final OTableFormatter formatter = new OTableFormatter(this); formatter.setColumnAlignment("RECORDS", OTableFormatter.ALIGNMENT.RIGHT); formatter.setFooter(footer); formatter.writeRecords(resultSet, -1);
@ConsoleCommand(description = "Return all configured properties") public void properties() { message("\nPROPERTIES:"); final List<ODocument> resultSet = new ArrayList<ODocument>(); for (Entry<String, String> p : properties.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); message("\n"); }
value = coll; } else if (OMultiValue.isMultiValue(value)) { value = OTableFormatter.getPrettyFieldMultiValue(OMultiValue.getMultiValueIterator(value), getMaxMultiValueEntries()); final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1);
new OTableFormatter(this).setMaxWidthSize(getConsoleWidth()).writeRecords(servers, -1);
printHeaderLine(iColumns); int i = 0; columnRow.append(String.format("%-" + column.getValue() + "s", formatCell(colName, column.getValue(), colName))); buffer.append(String.format("%-" + column.getValue() + "s", formatCell(colName, column.getValue(), metadataValue))); printHeaderLine(iColumns); printHeaderLine(iColumns);
public static String getPrettyFieldMultiValue(final Iterator<?> iterator, final int maxMultiValueEntries) { final StringBuilder value = new StringBuilder("["); for (int i = 0; iterator.hasNext(); i++) { if (i >= maxMultiValueEntries) { if (iterator instanceof OSizeable) { value.append("(size="); value.append(((OSizeable) iterator).size()); value.append(")"); } else value.append("(more)"); break; } if (i > 0) value.append(','); value.append(getPrettyFieldValue(iterator.next(), maxMultiValueEntries)); } value.append("]"); return value.toString(); }
final Object fieldValue = getFieldValue(iIndex, iRecord, fieldName);
public static Object getPrettyFieldValue(Object value, final int multiValueMaxEntries) { if (value instanceof OMultiCollectionIterator<?>) value = getPrettyFieldMultiValue(((OMultiCollectionIterator<?>) value).iterator(), multiValueMaxEntries); else if (value instanceof ORidBag) value = getPrettyFieldMultiValue(((ORidBag) value).rawIterator(), multiValueMaxEntries); else if (value instanceof Iterator) value = getPrettyFieldMultiValue((Iterator<?>) value, multiValueMaxEntries); else if (value instanceof Collection<?>) value = getPrettyFieldMultiValue(((Collection<?>) value).iterator(), multiValueMaxEntries); else if (value instanceof ORecord) { if (((ORecord) value).getIdentity().equals(ORecordId.EMPTY_RECORD_ID)) { value = ((ORecord) value).toString(); } else { value = ((ORecord) value).getIdentity().toString(); } } else if (value instanceof Date) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null) value = db.getStorage().getConfiguration().getDateTimeFormatInstance().format((Date) value); else { value = DEF_DATEFORMAT.format((Date) value); } } else if (value instanceof byte[]) value = "byte[" + ((byte[]) value).length + "]"; return value; }
columns.put(c, getColumnSize(fetched, rec, c, columns.get(c))); columns.put(fieldName, getColumnSize(fetched, doc, fieldName, columns.get(fieldName))); columns.put(fieldName, getColumnSize(fetched, footer, fieldName, columns.get(fieldName)));
final OTableFormatter formatter = new OTableFormatter(this); formatter.setColumnAlignment("COUNT", OTableFormatter.ALIGNMENT.RIGHT); footer.field("COUNT", totalElements); formatter.setFooter(footer); formatter.writeRecords(resultSet, -1);
@ConsoleCommand(description = "List all the active connections to the server", onlineHelp = "Console-Command-List-Connections") public void listConnections() throws IOException { checkForRemoteServer(); OrientDBRemote remote = (OrientDBRemote) OrientDBInternal.extract(orientDB); final ODocument serverInfo = remote.getServerInfo(currentDatabaseUserName, currentDatabaseUserPassword); final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>(); final List<Map<String, Object>> connections = serverInfo.field("connections"); for (Map<String, Object> conn : connections) { final ODocument row = new ODocument(); String commandDetail = (String) conn.get("commandInfo"); if (commandDetail != null && ((String) conn.get("commandDetail")).length() > 1) commandDetail += " (" + conn.get("commandDetail") + ")"; row.fields("ID", conn.get("connectionId"), "REMOTE_ADDRESS", conn.get("remoteAddress"), "PROTOC", conn.get("protocol"), "LAST_OPERATION_ON", conn.get("lastCommandOn"), "DATABASE", conn.get("db"), "USER", conn.get("user"), "COMMAND", commandDetail, "TOT_REQS", conn.get("totalRequests")); resultSet.add(row); } Collections.sort(resultSet, new Comparator<OIdentifiable>() { @Override public int compare(final OIdentifiable o1, final OIdentifiable o2) { final String o1s = ((ODocument) o1).field("LAST_OPERATION_ON"); final String o2s = ((ODocument) o2).field("LAST_OPERATION_ON"); return o2s.compareTo(o1s); } }); final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); out.println(); }
private Object getFieldValue(final int iIndex, final OIdentifiable iRecord, final String iColumnName) { Object value = null; if (iColumnName.equals("#")) // RECORD NUMBER value = iIndex > -1 ? iIndex : ""; else if (iColumnName.equals("@RID")) // RID value = iRecord.getIdentity().toString(); else if (iRecord instanceof ODocument) value = ((ODocument) iRecord).getProperty(iColumnName); else if (iRecord instanceof OBlob) value = "<binary> (size=" + ((OBlob) iRecord).toStream().length + " bytes)"; else if (iRecord instanceof OIdentifiable) { final ORecord rec = iRecord.getRecord(); if (rec instanceof ODocument) value = ((ODocument) rec).getProperty(iColumnName); else if (rec instanceof OBlob) value = "<binary> (size=" + ((OBlob) rec).toStream().length + " bytes)"; } return getPrettyFieldValue(value, maxMultiValueEntries); }
final OTableFormatter formatter = new OTableFormatter(this); formatter.setColumnAlignment("ID", OTableFormatter.ALIGNMENT.RIGHT); formatter.setColumnAlignment("COUNT", OTableFormatter.ALIGNMENT.RIGHT); formatter.setColumnAlignment("OWNER_SERVER", OTableFormatter.ALIGNMENT.CENTER); formatter.setColumnAlignment("OTHER_SERVERS", OTableFormatter.ALIGNMENT.CENTER); formatter.setColumnAlignment("AUTO_DEPLOY_NEW_NODE", OTableFormatter.ALIGNMENT.CENTER); if (!isRemote) { formatter.setColumnAlignment("SPACE-USED", OTableFormatter.ALIGNMENT.RIGHT); if (commandOptions.containsKey("-v")) { formatter.setColumnAlignment("TOMBSTONES", OTableFormatter.ALIGNMENT.RIGHT); formatter.setFooter(footer); formatter.writeRecords(resultSet, -1);
private void browseRecords(final OIdentifiableIterator<?> it) { final int limit = Integer.parseInt(properties.get("limit")); final OTableFormatter tableFormatter = new OTableFormatter(this).setMaxWidthSize(getConsoleWidth()) .setMaxMultiValueEntries(maxMultiValueEntries); setResultset(new ArrayList<OIdentifiable>()); while (it.hasNext() && currentResultSet.size() <= limit) currentResultSet.add(it.next()); tableFormatter.writeRecords(currentResultSet, limit); }
@ConsoleCommand(description = "Return all the configuration values") public void config() throws IOException { if (orientDB != null && !OrientDBInternal.extract(orientDB).isEmbedded()) { final Map<String, String> values = ((OrientDBRemote) OrientDBInternal.extract(orientDB)) .getGlobalConfigurations(currentDatabaseUserName, currentDatabaseUserPassword); 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", (Object) cfg.getValue()); } final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); } message("\n"); }
resultSet.add(new ODocument().field("NAME", "Index-Manager-RID").field("VALUE", dbCfg.getIndexMgrRecordId(), OType.LINK)); final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); dbResultSet.add(new ODocument().field("NAME", cfg.name).field("VALUE", cfg.value)); final OTableFormatter dbFormatter = new OTableFormatter(this); dbFormatter.writeRecords(dbResultSet, -1);
final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1);