DataRecord.java 2.9 KB
Newer Older
K
KomachiSion 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

18
package org.apache.shardingsphere.scaling.core.execute.executor.record;
A
avalon566 已提交
19

20
import lombok.RequiredArgsConstructor;
邱鹿 Lucas 已提交
21
import lombok.ToString;
22
import org.apache.shardingsphere.scaling.core.job.position.Position;
23 24

import lombok.EqualsAndHashCode;
25 26
import lombok.Getter;
import lombok.Setter;
A
avalon566 已提交
27 28

import java.util.ArrayList;
29
import java.util.LinkedList;
A
avalon566 已提交
30 31 32
import java.util.List;

/**
A
avalon566 已提交
33
 * Data record.
A
avalon566 已提交
34
 */
35 36
@Setter
@Getter
37
@EqualsAndHashCode(of = {"tableName", "primaryKeyValue"}, callSuper = false)
邱鹿 Lucas 已提交
38
@ToString
39
public final class DataRecord extends Record {
40 41 42 43 44
    
    private final List<Column> columns;
    
    private final List<Object> primaryKeyValue = new LinkedList<>();
    
45 46
    private final List<Object> oldPrimaryKeyValues = new ArrayList<>();
    
A
avalon566 已提交
47
    private String type;
48
    
A
avalon566 已提交
49
    private String tableName;
50
    
51 52
    public DataRecord(final Position position, final int columnCount) {
        super(position);
A
avalon566 已提交
53
        columns = new ArrayList<>(columnCount);
A
avalon566 已提交
54
    }
55
    
A
avalon566 已提交
56 57
    /**
     * Add a column to record.
K
KomachiSion 已提交
58
     *
A
avalon566 已提交
59 60 61
     * @param data column
     */
    public void addColumn(final Column data) {
A
avalon566 已提交
62
        columns.add(data);
63 64
        if (data.isPrimaryKey()) {
            primaryKeyValue.add(data.getValue());
65
            oldPrimaryKeyValues.add(data.getOldValue());
66
        }
A
avalon566 已提交
67
    }
68
    
A
avalon566 已提交
69 70
    /**
     * Return column count.
K
KomachiSion 已提交
71
     *
A
avalon566 已提交
72 73
     * @return count
     */
A
avalon566 已提交
74 75 76
    public int getColumnCount() {
        return columns.size();
    }
77
    
A
avalon566 已提交
78 79
    /**
     * Get column by index.
K
KomachiSion 已提交
80
     *
A
avalon566 已提交
81 82 83 84
     * @param index of column
     * @return column
     */
    public Column getColumn(final int index) {
A
avalon566 已提交
85 86
        return columns.get(index);
    }
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    
    /**
     * Get key.
     *
     * @return key
     */
    public Key getKey() {
        return new Key(tableName, primaryKeyValue);
    }
    
    /**
     * Get old key.
     *
     * @return key
     */
    public Key getOldKey() {
        return new Key(tableName, oldPrimaryKeyValues);
    }
    
    @EqualsAndHashCode
    @RequiredArgsConstructor
    public static class Key {
        
        private final String tableName;
        
        private final List<Object> primaryKeyValues;
    }
A
avalon566 已提交
114
}