private String determineLocation() { // Tries to find the most useful (neither generic, nor reflection nor our framework) point in the stacktrace StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); int idx = 1; while (idx++ < stackTrace.length) { StackTraceElement currentElement = stackTrace[idx]; if (!currentElement.getClassName().startsWith("sirius.db") && !currentElement.getClassName() .startsWith("com.sun") && !currentElement.getClassName().startsWith("java.")) { return currentElement.toString(); } } // That's the best guess anyway return Values.of(stackTrace).at(5).asString("<unknown>"); }
/** * Creates a wrapper for the given list * * @param list the list to wrap * @return a wrapped instance of the given list */ @Nonnull public static Values of(@Nonnull List<?> list) { Objects.requireNonNull(list); Values result = new Values(); result.dataList = list; return result; }
/** * Returns the element at the given column in "Excel style" notation. * <p> * Therefore <b>"A"</b> will return the first element (which is at index 0). <b>"Z"</b> will return the 26th * element * (at index 25). <b>"AH"</b> will return the 34th element (at index 33). * * @param excelStyleIndex a column index in "Excel Notation" (A, B, ..., AA, AB, ...) * @return the element at the given index wrapped as value or an empty value if no such element exists */ @Nonnull public Value at(@Nonnull String excelStyleIndex) { return at(convertExcelColumn(excelStyleIndex)); }
private void delete(Output output, Values values) { Class<? extends Entity> type = UpdateMappingCommand.findTypeOrReportError(output, values.at(1).asString()); if (type != null) { AtomicInteger rows = new AtomicInteger(); index.select(type).deliberatelyUnrouted().query(values.at(2).asString()).iterateAll(e -> { index.delete(e); rows.incrementAndGet(); }); outputAffectedRows(output, rows); } }
private void readRow() throws IOException { List<String> row = Lists.newArrayList(); while (!isEOF() && !isAtNewline()) { row.add(readField()); if (buffer == separator) { read(); } } if (limit.nextRow()) { consumer.accept(Values.of(row)); } }
private void resave(Output output, Values values) { Class<? extends Entity> type = UpdateMappingCommand.findTypeOrReportError(output, values.at(1).asString()); if (type != null) { AtomicInteger rows = new AtomicInteger(); index.select(type).deliberatelyUnrouted().query(values.at(2).asString()).iterateAll(e -> { index.update(e); rows.incrementAndGet(); }); outputAffectedRows(output, rows); } }
@Override public void execute(Output output, String... params) throws Exception { String filter = Values.of(params).at(0).toLowerCase(); output.apply("%-39s %40s", "NAME", "VALUE"); output.separator(); for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) { if (Strings.isEmpty(filter) || prop.getKey().toString().toLowerCase().contains(filter) || prop.getValue() .toString() .toLowerCase() .contains( filter)) { output.apply("%-39s %40s", prop.getKey(), prop.getValue()); } } output.separator(); }
private void update(Output output, Values values) { Class<? extends Entity> type = UpdateMappingCommand.findTypeOrReportError(output, values.at(1).asString()); if (type != null) { EntityDescriptor ed = index.getDescriptor(type); AtomicInteger rows = new AtomicInteger(); String filterText = values.at(2).asString(); if ("-".equals(filterText)) { filterText = null; } index.select(type).deliberatelyUnrouted().query(filterText).limit(500).iterateAll(e -> { ed.getProperty(values.at(3).asString()).readFromSource(e, values.at(4).get()); index.update(e); rows.incrementAndGet(); }); outputAffectedRows(output, rows); } }
/** * Creates a wrapper for the given array * * @param array the array to wrap * @return a wrapped instance of the given array */ @Nonnull public static Values of(@Nonnull Object[] array) { Objects.requireNonNull(array); Values result = new Values(); result.dataArray = array; return result; }
@Override public void execute(Output output, String... params) throws Exception { Values values = Values.of(params); if ("query".equalsIgnoreCase(values.at(0).asString())) { query(output, values); } else if ("update".equalsIgnoreCase(values.at(0).asString())) { update(output, values); } else if ("delete".equalsIgnoreCase(values.at(0).asString())) { delete(output, values); } else if ("resave".equalsIgnoreCase(values.at(0).asString())) { resave(output, values); } else if ("unbalance".equalsIgnoreCase(values.at(0).asString())) { unbalance(output); } else if ("balance".equalsIgnoreCase(values.at(0).asString())) { balance(output); } else { output.apply("Unknown command: %s", values.at(0)); output.line("Use: query <type> <filter>"); output.line(" or update <type> <filter> <field> <value> (Limit 500)"); output.line(" or delete <type> <filter>"); output.line(" or resave <type> <filter>"); output.line(" or unbalance"); output.line(" or balance"); } }
private void query(Output output, Values values) { Class<? extends Entity> type = UpdateMappingCommand.findTypeOrReportError(output, values.at(1).asString()); if (type != null) { output.line("Results (limited at 500):"); output.separator(); AtomicInteger rows = new AtomicInteger(); for (Entity e : index.select(type) .deliberatelyUnrouted() .query(values.at(2).asString()) .limit(500) .queryList()) { output.line(e.toDebugString()); rows.incrementAndGet(); } outputAffectedRows(output, rows); } }