@Override StringBuilder buildQueryString(List<Object> variables, CodecRegistry codecRegistry) { StringBuilder builder = new StringBuilder(); builder.append( isCounterOp() ? "BEGIN COUNTER BATCH" : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); if (!usings.usings.isEmpty()) { builder.append(" USING "); Utils.joinAndAppend(builder, codecRegistry, " AND ", usings.usings, variables); } builder.append(' '); for (int i = 0; i < statements.size(); i++) { RegularStatement stmt = statements.get(i); if (stmt instanceof BuiltStatement) { BuiltStatement bst = (BuiltStatement) stmt; builder.append(maybeAddSemicolon(bst.buildQueryString(variables, codecRegistry))); } else { String str = stmt.getQueryString(codecRegistry); builder.append(str); if (!str.trim().endsWith(";")) builder.append(';'); // Note that we force hasBindMarkers if there is any non-BuiltStatement, so we know // that we can only get there with variables == null assert variables == null; } } builder.append("APPLY BATCH;"); return builder; }
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * @throws IllegalArgumentException if counter and non-counter operations are mixed. */ public Batch add(RegularStatement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException( "Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); if (statement instanceof BuiltStatement) { this.hasBindMarkers |= ((BuiltStatement) statement).hasBindMarkers; } else { // For non-BuiltStatement, we cannot know if it includes a bind makers and we assume it does. // In practice, // this means we will always serialize values as strings when there is non-BuiltStatement this.hasBindMarkers = true; this.nonBuiltStatementValues += ((SimpleStatement) statement).valuesCount(); } setDirty(); return this; }
@Override StringBuilder buildQueryString(List<Object> variables, CodecRegistry codecRegistry) { StringBuilder builder = new StringBuilder(); builder.append(isCounterOp() ? "BEGIN COUNTER BATCH" : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); if (!usings.usings.isEmpty()) { builder.append(" USING "); Utils.joinAndAppend(builder, codecRegistry, " AND ", usings.usings, variables); } builder.append(' '); for (int i = 0; i < statements.size(); i++) { RegularStatement stmt = statements.get(i); if (stmt instanceof BuiltStatement) { BuiltStatement bst = (BuiltStatement) stmt; builder.append(maybeAddSemicolon(bst.buildQueryString(variables, codecRegistry))); } else { String str = stmt.getQueryString(codecRegistry); builder.append(str); if (!str.trim().endsWith(";")) builder.append(';'); // Note that we force hasBindMarkers if there is any non-BuiltStatement, so we know // that we can only get there with variables == null assert variables == null; } } builder.append("APPLY BATCH;"); return builder; }
@Override StringBuilder buildQueryString(List<Object> variables, CodecRegistry codecRegistry) { StringBuilder builder = new StringBuilder(); builder.append(isCounterOp() ? "BEGIN COUNTER BATCH" : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); if (!usings.usings.isEmpty()) { builder.append(" USING "); Utils.joinAndAppend(builder, codecRegistry, " AND ", usings.usings, variables); } builder.append(' '); for (int i = 0; i < statements.size(); i++) { RegularStatement stmt = statements.get(i); if (stmt instanceof BuiltStatement) { BuiltStatement bst = (BuiltStatement) stmt; builder.append(maybeAddSemicolon(bst.buildQueryString(variables, codecRegistry))); } else { String str = stmt.getQueryString(codecRegistry); builder.append(str); if (!str.trim().endsWith(";")) builder.append(';'); // Note that we force hasBindMarkers if there is any non-BuiltStatement, so we know // that we can only get there with variables == null assert variables == null; } } builder.append("APPLY BATCH;"); return builder; }
@Override StringBuilder buildQueryString(List<Object> variables, CodecRegistry codecRegistry) { StringBuilder builder = new StringBuilder(); builder.append(isCounterOp() ? "BEGIN COUNTER BATCH" : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); if (!usings.usings.isEmpty()) { builder.append(" USING "); Utils.joinAndAppend(builder, codecRegistry, " AND ", usings.usings, variables); } builder.append(' '); for (int i = 0; i < statements.size(); i++) { RegularStatement stmt = statements.get(i); if (stmt instanceof BuiltStatement) { BuiltStatement bst = (BuiltStatement) stmt; builder.append(maybeAddSemicolon(bst.buildQueryString(variables, codecRegistry))); } else { String str = stmt.getQueryString(codecRegistry); builder.append(str); if (!str.trim().endsWith(";")) builder.append(';'); // Note that we force hasBindMarkers if there is any non-BuiltStatement, so we know // that we can only get there with variables == null assert variables == null; } } builder.append("APPLY BATCH;"); return builder; }
StringBuilder builder = new StringBuilder(); builder.append(isCounterOp() ? "BEGIN COUNTER BATCH" : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH"));
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * @throws IllegalArgumentException if counter and non-counter operations * are mixed. */ public Batch add(RegularStatement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException("Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); if (statement instanceof BuiltStatement) { this.hasBindMarkers |= ((BuiltStatement) statement).hasBindMarkers; } else { // For non-BuiltStatement, we cannot know if it includes a bind makers and we assume it does. In practice, // this means we will always serialize values as strings when there is non-BuiltStatement this.hasBindMarkers = true; this.nonBuiltStatementValues += ((SimpleStatement) statement).valuesCount(); } setDirty(); return this; }
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * @throws IllegalArgumentException if counter and non-counter operations * are mixed. */ public Batch add(RegularStatement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException("Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); if (statement instanceof BuiltStatement) { this.hasBindMarkers |= ((BuiltStatement) statement).hasBindMarkers; } else { // For non-BuiltStatement, we cannot know if it includes a bind makers and we assume it does. In practice, // this means we will always serialize values as strings when there is non-BuiltStatement this.hasBindMarkers = true; this.nonBuiltStatementValues += ((SimpleStatement) statement).valuesCount(); } setDirty(); return this; }
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * @throws IllegalArgumentException if counter and non-counter operations * are mixed. */ public Batch add(RegularStatement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException("Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); if (statement instanceof BuiltStatement) { this.hasBindMarkers |= ((BuiltStatement) statement).hasBindMarkers; } else { // For non-BuiltStatement, we cannot know if it includes a bind makers and we assume it does. In practice, // this means we will always serialize values as strings when there is non-BuiltStatement this.hasBindMarkers = true; this.nonBuiltStatementValues += ((SimpleStatement) statement).valuesCount(); } setDirty(); return this; }
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * * @throws IllegalArgumentException if counter and non-counter operations * are mixed. */ public Batch add(RegularStatement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException("Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); if (statement instanceof BuiltStatement) this.hasBindMarkers = ((BuiltStatement)statement).hasBindMarkers; else // For non-BuiltStatement, we cannot know if it includes a bind makers. So we assume it does. this.hasBindMarkers = true; checkForBindMarkers(null); if (routingKey == null && statement.getRoutingKey() != null) routingKey = statement.getRoutingKey(); return this; }