public static void checkRowChange()

in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/utils/ParamChecker.java [24:84]


    public static void checkRowChange(TableMeta tableMeta, RowChange rowChange, WriterConfig config)
            throws ClientException {
        // check table name
        if (!tableMeta.getTableName().equals(rowChange.getTableName())) {
            throw new ClientException("The row to write belongs to another table.");
        }

        // check row size
        if (rowChange.getDataSize() > config.getMaxBatchSize()) {
            throw new ClientException("The row size exceeds the max batch size: " + config.getMaxBatchSize() + ".");
        }


        Map<String, PrimaryKeySchema> pkDefinedInMeta = tableMeta.getPrimaryKeySchemaMap();
        Map<String, PrimaryKeyColumn> pkInRow = rowChange.getPrimaryKey().getPrimaryKeyColumnsMap();
        if (pkDefinedInMeta.size() != pkInRow.size()) {
            throw new ClientException("The primary key schema is not match which defined in table meta.");
        }

        for (Map.Entry<String, PrimaryKeySchema> entry : pkDefinedInMeta.entrySet()) {
            PrimaryKeyValue value = pkInRow.get(entry.getKey()).getValue();

            // schema checking
            if (value == null) {
                throw new ClientException("Can't find primary key column '" + entry.getKey() + "' in row.");
            }

            if (value.isPlaceHolderForAutoIncr()) {
                if (entry.getValue().getOption() != PrimaryKeyOption.AUTO_INCREMENT) {
                    throw new ClientException("The type of primary key column '" + entry.getKey() + "' should not be AUTO_INCREMENT.");
                }
            } else if (value.getType() != entry.getValue().getType()) {
                throw new ClientException("The type of primary key column '" + entry.getKey() + "' is " + value.getType() +
                        ", but it's defined as " + entry.getValue().getType() + " in table meta.");
            }

            // value size checking
            if (value.getDataSize() > config.getMaxPKColumnSize()) {
                throw new ClientException("The size of primary key column '" + entry.getKey() + "' has exceeded the max length:" + config.getMaxPKColumnSize() + ".");
            }
        }

        int columnsCount = 0;
        if (rowChange instanceof RowPutChange) {
            RowPutChange rowPut = (RowPutChange) rowChange;
            columnsCount = rowPut.getColumnsToPut().size();
            for (Column column : rowPut.getColumnsToPut()) {
                checkColumn(pkDefinedInMeta, column, config);
            }
        } else if (rowChange instanceof RowUpdateChange) {
            RowUpdateChange rowUpdate = (RowUpdateChange) rowChange;
            columnsCount = rowUpdate.getColumnsToUpdate().size();
            for (Pair<Column, RowUpdateChange.Type> pair : rowUpdate.getColumnsToUpdate()) {
                checkColumn(pkDefinedInMeta, pair.first, config);
            }
        }

        if (columnsCount > config.getMaxColumnsCount()) {
            throw new ClientException("The count of attribute columns exceeds the maximum: " + config.getMaxColumnsCount() + ".");
        }
    }