private final int[] executeStatic() { List<Query> queries = new ArrayList<Query>(); QueryCollector collector = new QueryCollector(); Configuration local = configuration.derive( Utils.combine( configuration.executeListenerProviders(), new DefaultExecuteListenerProvider(collector))); for (int i = 0; i < records.length; i++) { Configuration previous = ((AttachableInternal) records[i]).configuration(); try { records[i].attach(local); executeAction(i); } catch (QueryCollectorSignal e) { Query query = e.getQuery(); if (query.isExecutable()) { queries.add(query); } } finally { records[i].attach(previous); } } // Resulting statements can be batch executed in their requested order int[] result = create.batch(queries).execute(); updateChangedFlag(); return result; }
@Override public void addChargePoint(List<String> chargeBoxIdList) { BatchBindStep batch = ctx.batch(ctx.insertInto(CHARGE_BOX).set(CHARGE_BOX.CHARGE_BOX_ID, "")); for (String s : chargeBoxIdList) { batch.bind(s); } batch.execute(); }
private final int[] executeStatic() { List<Query> queries = new ArrayList<Query>(); for (Object[] bindValues : allBindValues) { for (int i = 0; i < bindValues.length; i++) { query.bind(i + 1, bindValues[i]); } queries.add(create.query(query.getSQL(INLINED))); } return create.batch(queries).execute(); }
/** Blocking version of {@link AsyncSpanConsumer#accept} */ @Override public void accept(List<Span> spans) { if (spans.isEmpty()) return; try (Connection conn = datasource.getConnection()) { DSLContext create = context.get(conn); List<Query> inserts = new ArrayList<>(); for (Span span : spans) { Long overridingTimestamp = authoritativeTimestamp(span); Long timestamp = overridingTimestamp != null ? overridingTimestamp : guessTimestamp(span); Map<TableField<Record, ?>, Object> updateFields = new LinkedHashMap<>(); if (!span.name.equals("") && !span.name.equals("unknown")) { updateFields.put(ZIPKIN_SPANS.NAME, span.name); } // replace any tentative timestamp with the authoritative one. if (overridingTimestamp != null) { updateFields.put(ZIPKIN_SPANS.START_TS, overridingTimestamp); } if (span.duration != null) { updateFields.put(ZIPKIN_SPANS.DURATION, span.duration); } InsertSetMoreStep<Record> insertSpan = create .insertInto(ZIPKIN_SPANS) .set(ZIPKIN_SPANS.TRACE_ID, span.traceId) .set(ZIPKIN_SPANS.ID, span.id) .set(ZIPKIN_SPANS.PARENT_ID, span.parentId) .set(ZIPKIN_SPANS.NAME, span.name) .set(ZIPKIN_SPANS.DEBUG, span.debug) .set(ZIPKIN_SPANS.START_TS, timestamp) .set(ZIPKIN_SPANS.DURATION, span.duration); if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) { insertSpan.set(ZIPKIN_SPANS.TRACE_ID_HIGH, span.traceIdHigh); } inserts.add( updateFields.isEmpty() ? insertSpan.onDuplicateKeyIgnore() : insertSpan.onDuplicateKeyUpdate().set(updateFields)); for (Annotation annotation : span.annotations) { InsertSetMoreStep<Record> insert = create .insertInto(ZIPKIN_ANNOTATIONS) .set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId) .set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id) .set(ZIPKIN_ANNOTATIONS.A_KEY, annotation.value) .set(ZIPKIN_ANNOTATIONS.A_TYPE, -1) .set(ZIPKIN_ANNOTATIONS.A_TIMESTAMP, annotation.timestamp); if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) { insert.set(ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, span.traceIdHigh); } if (annotation.endpoint != null) { insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME, annotation.endpoint.serviceName); insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4, annotation.endpoint.ipv4); if (annotation.endpoint.ipv6 != null && schema.hasIpv6) { insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6, annotation.endpoint.ipv6); } insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT, annotation.endpoint.port); } inserts.add(insert.onDuplicateKeyIgnore()); } for (BinaryAnnotation annotation : span.binaryAnnotations) { InsertSetMoreStep<Record> insert = create .insertInto(ZIPKIN_ANNOTATIONS) .set(ZIPKIN_ANNOTATIONS.TRACE_ID, span.traceId) .set(ZIPKIN_ANNOTATIONS.SPAN_ID, span.id) .set(ZIPKIN_ANNOTATIONS.A_KEY, annotation.key) .set(ZIPKIN_ANNOTATIONS.A_VALUE, annotation.value) .set(ZIPKIN_ANNOTATIONS.A_TYPE, annotation.type.value) .set(ZIPKIN_ANNOTATIONS.A_TIMESTAMP, timestamp); if (span.traceIdHigh != 0 && schema.hasTraceIdHigh) { insert.set(ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, span.traceIdHigh); } if (annotation.endpoint != null) { insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME, annotation.endpoint.serviceName); insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4, annotation.endpoint.ipv4); if (annotation.endpoint.ipv6 != null && schema.hasIpv6) { insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6, annotation.endpoint.ipv6); } insert.set(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT, annotation.endpoint.port); } inserts.add(insert.onDuplicateKeyIgnore()); } } create.batch(inserts).execute(); } catch (SQLException e) { throw new RuntimeException(e); // TODO } }
private final int[] executePrepared() { Map<String, List<Query>> queries = new LinkedHashMap<String, List<Query>>(); QueryCollector collector = new QueryCollector(); // Add the QueryCollector to intercept query execution after rendering Configuration local = configuration.derive( Utils.combine( configuration.executeListenerProviders(), new DefaultExecuteListenerProvider(collector))); // [#1537] Communicate with UpdatableRecordImpl local.data(Utils.DATA_OMIT_RETURNING_CLAUSE, true); // [#1529] Avoid DEBUG logging of single INSERT / UPDATE statements local.settings().setExecuteLogging(false); for (int i = 0; i < records.length; i++) { Configuration previous = ((AttachableInternal) records[i]).configuration(); try { records[i].attach(local); executeAction(i); } catch (QueryCollectorSignal e) { Query query = e.getQuery(); String sql = e.getSQL(); // Aggregate executable queries by identical SQL if (query.isExecutable()) { List<Query> list = queries.get(sql); if (list == null) { list = new ArrayList<Query>(); queries.put(sql, list); } list.add(query); } } finally { records[i].attach(previous); } } // Execute one batch statement for each identical SQL statement. Every // SQL statement may have several queries with different bind values. // The order is preserved as much as possible List<Integer> result = new ArrayList<Integer>(); for (Entry<String, List<Query>> entry : queries.entrySet()) { BatchBindStep batch = create.batch(entry.getValue().get(0)); for (Query query : entry.getValue()) { batch.bind(query.getBindValues().toArray()); } int[] array = batch.execute(); for (int i : array) { result.add(i); } } int[] array = new int[result.size()]; for (int i = 0; i < result.size(); i++) { array[i] = result.get(i); } updateChangedFlag(); return array; }