/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package io.spine.server.storage.jdbc.query;

import com.google.protobuf.Message;
import io.spine.server.storage.jdbc.IdColumn;
import io.spine.server.storage.jdbc.Serializer;

/**
 * An abstract base for the write queries to an {@link io.spine.server.storage.jdbc.AggregateTable}.
 *
 * @author Alexander Aleksandrov
 */
abstract class WriteAggregateQuery<I, R extends Message> extends WriteQuery {

    private final I id;
    private final R record;
    private final int idIndexInQuery;
    private final int recordIndexInQuery;
    private final IdColumn<I> idColumn;

    R getRecord() {
        return record;
    }

    WriteAggregateQuery(Builder<? extends Builder, ? extends WriteAggregateQuery, I, R> builder) {
        super(builder);
        this.idIndexInQuery = builder.idIndexInQuery;
        this.recordIndexInQuery = builder.recordIndexInQuery;
        this.idColumn = builder.idColumn;
        this.id = builder.id;
        this.record = builder.record;
    }

    @Override
    protected Parameters getQueryParameters() {
        final Parameters.Builder builder = Parameters.newBuilder();

        idColumn.setId(idIndexInQuery, id, builder);

        final byte[] serializedRecord = Serializer.serialize(record);
        return builder.addParameter(recordIndexInQuery, serializedRecord)
                      .build();
    }

    @SuppressWarnings("ClassNameSameAsAncestorName")
    abstract static class Builder<B extends Builder<B, Q, I, R>,
                                  Q extends WriteAggregateQuery,
                                  I,
                                  R extends Message>
            extends WriteQuery.Builder<B, Q> {

        private int idIndexInQuery;
        private int recordIndexInQuery;
        private IdColumn<I> idColumn;
        private I id;
        private R record;

        public B setId(I id) {
            this.id = id;
            return getThis();
        }

        public B setRecord(R record) {
            this.record = record;
            return getThis();
        }

        public B setIdColumn(IdColumn<I> idColumn) {
            this.idColumn = idColumn;
            return getThis();
        }

        public B setIdIndexInQuery(int idIndexInQuery) {
            this.idIndexInQuery = idIndexInQuery;
            return getThis();
        }

        public B setRecordIndexInQuery(int recordIndexInQuery) {
            this.recordIndexInQuery = recordIndexInQuery;
            return getThis();
        }
    }
}

@@ -2844,31 +2844,24 @@
 d;%0A%0A        
-public 
 B setId(I id
@@ -2860,24 +2860,24 @@
 tId(I id) %7B%0A
+
             
@@ -2931,39 +2931,32 @@
      %7D%0A%0A        
-public 
 B setRecord(R re
@@ -3042,31 +3042,24 @@
  %7D%0A%0A        
-public 
 B setIdColum
@@ -3167,31 +3167,24 @@
  %7D%0A%0A        
-public 
 B setIdIndex
@@ -3304,24 +3304,24 @@
      %7D%0A%0A
+
         
 public B
@@ -3316,15 +3316,8 @@
     
-public 
 B se

Remove `public` modifiers from a package-local class