@Override public void renderEnd(ExecuteContext ctx) { // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying. if (brave.serverSpanThreadBinder().getCurrentServerSpan() == null || brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() == null) { return; } brave.clientTracer().startNewSpan(ctx.type().toString().toLowerCase()); String[] batchSQL = ctx.batchSQL(); if (!StringUtils.isBlank(ctx.sql())) { brave.clientTracer().submitBinaryAnnotation(SQL_QUERY, ctx.sql()); } else if (batchSQL.length > 0 && batchSQL[batchSQL.length - 1] != null) { brave.clientTracer().submitBinaryAnnotation(SQL_QUERY, StringUtils.join(batchSQL, '\n')); } brave.clientTracer() .setClientSent(mysqlEndpoint.ipv4, mysqlEndpoint.port, mysqlEndpoint.serviceName); }
@Override public String getJavaClassName(Definition definition, Mode mode) { StringBuilder result = new StringBuilder(); if (mode == Mode.RECORD) { result.append('R'); } else if (mode == Mode.DEFAULT) { result.append('T'); } else if (mode == Mode.INTERFACE) { result.append('I'); } result.append(StringUtils.toCamelCase(definition.getOutputName())); if (mode == Mode.RECORD) { result.append("Record"); } else if (mode == Mode.DAO) { result.append("Dao"); } return result.toString(); }
/** * Generates a serial number and signature, and adds them to the list of expressions */ private void convertExpressionList(List<Expression> expressions) { // Obtain the data bytes final List<String> data = expressions.stream() .map(expression -> { // Get rid of those pesky quotes if (expression instanceof StringValue) { return ((StringValue) expression).getValue(); } return expression.toString(); }) .collect(Collectors.toList()); final String dataString = StringUtils.join(data.toArray()); final byte[] dataBytes = dataString.getBytes(Charsets.UTF_8); DataConverter converter = new DataConverter(dataBytes, codeGen, icrl); // Add base64 representation of signature to store it in the query properly final String signatureString = Convert.toBase64(converter.getSignature()); expressions.add(new HexValue("from_base64('" + signatureString + "')")); // Add serial number to expression list Long serial = converter.getSerial(); expressions.add(new DoubleValue(serial.toString())); }
private void updateBestTopics() throws SQLException { int docId = -1; ArrayList<Integer> topicList = new ArrayList<Integer>(); Statement updateStmt = database.getConnection().createStatement(); ResultSet fulltextRS = database.executeQuery("SELECT DOCUMENT_ID,TOPIC_ID FROM DOCUMENT_TOPIC ORDER BY DOCUMENT_ID, PR_TOPIC_GIVEN_DOCUMENT DESC"); while(fulltextRS.next()) { if(docId != fulltextRS.getInt("DOCUMENT_ID")) { if(!topicList.isEmpty()) { updateStmt.executeUpdate("UPDATE " + this.tableName + " SET BEST_TOPICS='" + StringUtils.join(topicList.toArray(), ",") + "' WHERE DOCUMENT_ID=" + docId); } topicList = new ArrayList<Integer>(); docId = fulltextRS.getInt("DOCUMENT_ID"); documentList.add(docId); } else { topicList.add(fulltextRS.getInt("TOPIC_ID")); } } updateStmt.executeUpdate("UPDATE " + this.tableName + " SET BEST_TOPICS='" + StringUtils.join(topicList.toArray(), ",") + "' WHERE DOCUMENT_ID=" + docId); }
@Override public boolean hostHasContainerLabel(Long hostId, String labelKey, String labelValue) { List<? extends Instance> instances = instanceDao.getNonRemovedInstanceOn(hostId); boolean found = false; for (Instance instance : instances) { Map<String, Object> labels = DataAccessor.fieldMapRO(instance, InstanceConstants.FIELD_LABELS); Map<String, Object> labelsLowerCased = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); labelsLowerCased.putAll(labels); if (labelsLowerCased.containsKey(labelKey)) { Object value = labelsLowerCased.get(labelKey); if (value == null) { continue; } if (StringUtils.equals(labelValue.toLowerCase(), value.toString().toLowerCase())) { found = true; break; } } } return found; }
private void writeDatamodel(@NotNull final Iterable<EcrfDatamodelField> datamodelFields, @NotNull final Supplier<InsertValuesStep4> inserter) { context.batch(StreamSupport.stream(datamodelFields.spliterator(), false).map(field -> { final String codeList = StringUtils.join(field.codeList().values().toArray(), ","); //noinspection unchecked return inserter.get().values(field.name(), field.description(), codeList, field.isRelevant() ? "TRUE" : "FALSE"); }).collect(Collectors.toList())).execute(); }
private Stream<List<String>> convertLineOCT(Stream<List<String>> csvInput) throws IOException { return csvInput.map(line -> { // Combine the list into a string final String data = StringUtils.join(line.toArray()); final byte[] dataBytes = data.getBytes(Charsets.UTF_8); convertLine(line, dataBytes, codeGen, icrl); return line; }); }
private String evaluateMacros(String valueStr, Instance instance) { if (valueStr.contains(SERVICE_NAME_MACRO) || valueStr.contains(STACK_NAME_MACRO)) { Map<String, String> labels = DataAccessor.getLabels(instance); String serviceLaunchConfigName = ""; String stackName = ""; if (labels != null && !labels.isEmpty()) { for (Map.Entry<String, String> label : labels.entrySet()) { String value = label.getValue(); if (SystemLabels.LABEL_STACK_NAME.equals(label.getKey())) { stackName = value; } else if (SystemLabels.LABEL_STACK_SERVICE_NAME.equals(label.getKey())) { if (value != null) { int i = value.indexOf('/'); if (i != -1) { serviceLaunchConfigName = value.substring(i + 1); } } } } } if (!StringUtils.isBlank(stackName)) { valueStr = valueStr.replace(STACK_NAME_MACRO, stackName); } if (!StringUtils.isBlank(serviceLaunchConfigName)) { valueStr = valueStr.replace(SERVICE_NAME_MACRO, serviceLaunchConfigName); } } return valueStr; }
@Override public void serialize(Record record, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { for (Field<?> field : record.fields()) { Object value = record.getValue(field); if (value != null) { jgen.writeFieldName(StringUtils.toCamelCaseLC(field.getName())); jgen.writeObject(value); } } }
@NotNull private static String readEnsemblQuery() throws IOException { final List<String> lines = Resources.readLines(Resources.getResource("ensembl_query.sql"), Charset.defaultCharset()); return StringUtils.join(lines.toArray(), "\n"); }
private String getSQLPart(ArrayList<String> part, String glue) { return StringUtils.join(part.toArray(new String[part.size()]), glue); }