All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glowroot.storage.simplerepo.ImmutableParameterizedSql Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.storage.simplerepo;

import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Immutable implementation of {@link TracePointQueryBuilder.ParameterizedSql}.
 * 

* Use builder to create immutable instances: * {@code ImmutableParameterizedSql.builder()}. * Use static factory method to create immutable instances: * {@code ImmutableParameterizedSql.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "TracePointQueryBuilder.ParameterizedSql"}) @Immutable final class ImmutableParameterizedSql extends TracePointQueryBuilder.ParameterizedSql { private final String sql; private final ImmutableList args; private ImmutableParameterizedSql(String sql, Iterable args) { this.sql = Preconditions.checkNotNull(sql); this.args = ImmutableList.copyOf(args); } private ImmutableParameterizedSql( ImmutableParameterizedSql original, String sql, ImmutableList args) { this.sql = sql; this.args = args; } /** * @return value of {@code sql} attribute */ @JsonProperty @Override String sql() { return sql; } /** * @return value of {@code args} attribute */ @JsonProperty @Override ImmutableList args() { return args; } /** * Copy current immutable object by setting value for {@link TracePointQueryBuilder.ParameterizedSql#sql() sql}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for sql * @return modified copy of the {@code this} object */ public final ImmutableParameterizedSql withSql(String value) { if (this.sql == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableParameterizedSql(this, newValue, this.args); } /** * Copy current immutable object with elements that replace content of {@link TracePointQueryBuilder.ParameterizedSql#args() args}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableParameterizedSql withArgs(java.lang.Object... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableParameterizedSql(this, this.sql, newValue); } /** * Copy current immutable object with elements that replace content of {@link TracePointQueryBuilder.ParameterizedSql#args() args}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of args elements to set * @return modified copy of {@code this} object */ public final ImmutableParameterizedSql withArgs(Iterable elements) { if (this.args == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableParameterizedSql(this, this.sql, newValue); } /** * This instance is equal to instances of {@code ImmutableParameterizedSql} with equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableParameterizedSql && equalTo((ImmutableParameterizedSql) another); } private boolean equalTo(ImmutableParameterizedSql another) { return sql.equals(another.sql) && args.equals(another.args); } /** * Computes hash code from attributes: {@code sql}, {@code args}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + sql.hashCode(); h = h * 17 + args.hashCode(); return h; } /** * Prints immutable value {@code ParameterizedSql...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("ParameterizedSql") .add("sql", sql) .add("args", args) .toString(); } /** * Simple representation of this value type suitable Jackson binding * @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure */ @Deprecated static final class Json { @JsonProperty @Nullable String sql; @JsonProperty @Nullable ImmutableList args; } /** * @param json JSON-bindable data structure * @return immutable value type * @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure */ @Deprecated @JsonCreator static ImmutableParameterizedSql fromJson(Json json) { ImmutableParameterizedSql.Builder builder = ImmutableParameterizedSql.builder(); if (json.sql != null) { builder.sql(json.sql); } if (json.args != null) { builder.addAllArgs(json.args); } return builder.build(); } /** * Construct new immutable {@code ParameterizedSql} instance. * @param sql value for {@code sql} * @param args value for {@code args} * @return immutable ParameterizedSql instance */ public static ImmutableParameterizedSql of(String sql, ImmutableList args) { return of(sql, (Iterable) args); } /** * Construct new immutable {@code ParameterizedSql} instance. * @param sql value for {@code sql} * @param args value for {@code args} * @return immutable ParameterizedSql instance */ public static ImmutableParameterizedSql of(String sql, Iterable args) { return new ImmutableParameterizedSql(sql, args); } /** * Creates immutable copy of {@link TracePointQueryBuilder.ParameterizedSql}. * Uses accessors to get values to initialize immutable instance. * If an instance is already immutable, it is returned as is. * @param instance instance to copy * @return copied immutable ParameterizedSql instance */ static ImmutableParameterizedSql copyOf(TracePointQueryBuilder.ParameterizedSql instance) { if (instance instanceof ImmutableParameterizedSql) { return (ImmutableParameterizedSql) instance; } return ImmutableParameterizedSql.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.storage.simplerepo.ImmutableParameterizedSql ImmutableParameterizedSql}. * @return new ImmutableParameterizedSql builder */ static ImmutableParameterizedSql.Builder builder() { return new ImmutableParameterizedSql.Builder(); } /** * Builds instances of {@link org.glowroot.storage.simplerepo.ImmutableParameterizedSql ImmutableParameterizedSql}. * Initialize attributes and then invoke {@link #build()} method to create * immutable instance. *

{@code Builder} is not thread safe and generally should not be stored in field or collection, * but used immediately to create instances. */ @NotThreadSafe static final class Builder { private static final long INIT_BIT_SQL = 0x1L; private long initBits = 0x1; private @Nullable String sql; private ImmutableList.Builder argsBuilder = ImmutableList.builder(); private Builder() {} /** * Fill builder with attribute values from provided {@link TracePointQueryBuilder.ParameterizedSql} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(TracePointQueryBuilder.ParameterizedSql instance) { Preconditions.checkNotNull(instance); sql(instance.sql()); addAllArgs(instance.args()); return this; } /** * Initializes value for {@link TracePointQueryBuilder.ParameterizedSql#sql() sql}. * @param sql value for sql * @return {@code this} builder for chained invocation */ public final Builder sql(String sql) { this.sql = Preconditions.checkNotNull(sql); initBits &= ~INIT_BIT_SQL; return this; } /** * Adds one element to {@link TracePointQueryBuilder.ParameterizedSql#args() args} list. * @param element args element * @return {@code this} builder for chained invocation */ public final Builder addArgs(java.lang.Object element) { argsBuilder.add(element); return this; } /** * Adds elements to {@link TracePointQueryBuilder.ParameterizedSql#args() args} list. * @param elements array of args elements * @return {@code this} builder for chained invocation */ public final Builder addArgs(java.lang.Object... elements) { argsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link TracePointQueryBuilder.ParameterizedSql#args() args} list. * @param elements iterable of args elements * @return {@code this} builder for chained invocation */ public final Builder args(Iterable elements) { argsBuilder = ImmutableList.builder(); return addAllArgs(elements); } /** * Adds elements to {@link TracePointQueryBuilder.ParameterizedSql#args() args} list. * @param elements iterable of args elements * @return {@code this} builder for chained invocation */ public final Builder addAllArgs(Iterable elements) { argsBuilder.addAll(elements); return this; } /** * Builds new {@link org.glowroot.storage.simplerepo.ImmutableParameterizedSql ImmutableParameterizedSql}. * @return immutable instance of ParameterizedSql * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableParameterizedSql build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableParameterizedSql(null, sql, argsBuilder.build()); } private boolean sqlIsSet() { return (initBits & INIT_BIT_SQL) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!sqlIsSet()) attributes.add("sql"); return "Cannot build ParameterizedSql, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy