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

com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon DynamoDB module holds the client classes that are used for communicating with Amazon DynamoDB Service

There is a newer version: 1.12.753
Show newest version
/*
 * Copyright 2015-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed 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://aws.amazon.com/apache2.0
 *
 * This file 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.
 */
package com.amazonaws.services.dynamodbv2.datamodeling;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.FailedBatch;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.DeleteTableRequest;
import com.amazonaws.services.s3.model.Region;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Abstract implementation of {@code IDynamoDBMapper}. Convenient method forms pass through to the
 * corresponding overload that takes a request object, which throws an
 * {@code UnsupportedOperationException}.
 */
public class AbstractDynamoDBMapper implements IDynamoDBMapper {

    private final DynamoDBMapperConfig config;

    protected AbstractDynamoDBMapper(final DynamoDBMapperConfig defaults) {
        this.config = DynamoDBMapperConfig.DEFAULT.merge(defaults);
    }

    protected AbstractDynamoDBMapper() {
        this(DynamoDBMapperConfig.DEFAULT);
    }

    protected final String getTableName(Class clazz, Object object, DynamoDBMapperConfig config) {
        if (config.getObjectTableNameResolver() != null && object != null) {
            return config.getObjectTableNameResolver().getTableName(object, config);
        }
        return getTableName(clazz, config);
    }

    protected final String getTableName(Class clazz, DynamoDBMapperConfig config) {
        if (config.getTableNameResolver() == null) {
            return DynamoDBMapperConfig.DefaultTableNameResolver.INSTANCE.getTableName(clazz, config);
        }
        return config.getTableNameResolver().getTableName(clazz, config);
    }

    protected final DynamoDBMapperConfig mergeConfig(DynamoDBMapperConfig overrides) {
        return this.config.merge(overrides);
    }

    @Override
    public  DynamoDBMapperTableModel getTableModel(Class clazz) {
        return getTableModel(clazz, config);
    }

    @Override
    public  DynamoDBMapperTableModel getTableModel(Class clazz, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  T load(Class clazz, Object hashKey, DynamoDBMapperConfig config) {
        return load(clazz, hashKey, (Object)null, config);
    }

    @Override
    public  T load(Class clazz, Object hashKey) {
        return load(clazz, hashKey, (Object)null, config);
    }

    @Override
    public  T load(Class clazz, Object hashKey, Object rangeKey) {
        return load(clazz, hashKey, rangeKey, config);
    }

    @Override
    public  T load(Class clazz, Object hashKey, Object rangeKey, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  T load(T keyObject) {
        return load(keyObject, config);
    }

    @Override
    public  T load(T keyObject, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  T marshallIntoObject(Class clazz, Map itemAttributes) {
        return marshallIntoObject(clazz, itemAttributes, config);
    }

    public  T marshallIntoObject(Class clazz, Map itemAttributes, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  List marshallIntoObjects(Class clazz, List> itemAttributes) {
        return marshallIntoObjects(clazz, itemAttributes, config);
    }

    public  List marshallIntoObjects(Class clazz, List> itemAttributes, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  void save(T object) {
        save(object, (DynamoDBSaveExpression)null, config);
    }

    @Override
    public  void save(T object, DynamoDBSaveExpression saveExpression) {
        save(object, saveExpression, config);
    }

    @Override
    public  void save(T object, DynamoDBMapperConfig config) {
        save(object, (DynamoDBSaveExpression)null, config);
    }

    @Override
    public  void save(T object, DynamoDBSaveExpression saveExpression, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public void delete(Object object) {
        delete(object, (DynamoDBDeleteExpression)null, config);
    }

    @Override
    public void delete(Object object, DynamoDBDeleteExpression deleteExpression) {
        delete(object, deleteExpression, config);
    }

    @Override
    public void delete(Object object, DynamoDBMapperConfig config) {
        delete(object, (DynamoDBDeleteExpression)null, config);
    }

    @Override
    public  void delete(T object, DynamoDBDeleteExpression deleteExpression, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public void transactionWrite(TransactionWriteRequest transactionWriteRequest) {
        transactionWrite(transactionWriteRequest, (DynamoDBMapperConfig) null);
    }

    @Override
    public void transactionWrite(TransactionWriteRequest transactionWriteRequest, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public List transactionLoad(TransactionLoadRequest transactionLoadRequest) {
        return transactionLoad(transactionLoadRequest, (DynamoDBMapperConfig) null);
    }

    @Override
    public List transactionLoad(TransactionLoadRequest transactionLoadRequest, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public List batchDelete(Iterable objectsToDelete) {
        return batchWrite(Collections.emptyList(), objectsToDelete, config);
    }

    @Override
    public List batchDelete(Object... objectsToDelete) {
        return batchWrite(Collections.emptyList(), Arrays.asList(objectsToDelete), config);
    }

    @Override
    public List batchSave(Iterable objectsToSave) {
        return batchWrite(objectsToSave, Collections.emptyList(), config);
    }

    @Override
    public List batchSave(Object... objectsToSave) {
        return batchWrite(Arrays.asList(objectsToSave), Collections.emptyList(), config);
    }

    @Override
    public List batchWrite(Iterable objectsToWrite,
                                        Iterable objectsToDelete) {
        return batchWrite(objectsToWrite, objectsToDelete, config);
    }

    @Override
    public List batchWrite(Iterable objectsToWrite,
                                        Iterable objectsToDelete,
                                        DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public Map> batchLoad(Iterable itemsToGet) {
        return batchLoad(itemsToGet, config);
    }

    @Override
    public Map> batchLoad(Iterable itemsToGet, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public Map> batchLoad(Map, List> itemsToGet) {
        return batchLoad(itemsToGet, config);
    }

    @Override
    public Map> batchLoad(Map, List> itemsToGet, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  PaginatedScanList scan(Class clazz, DynamoDBScanExpression scanExpression) {
        return scan(clazz, scanExpression, config);
    }

    @Override
    public  PaginatedScanList scan(Class clazz,
                                         DynamoDBScanExpression scanExpression,
                                         DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  PaginatedParallelScanList parallelScan(Class clazz,
                                                         DynamoDBScanExpression scanExpression,
                                                         int totalSegments) {
        return parallelScan(clazz, scanExpression, totalSegments, config);
    }

    @Override
    public  PaginatedParallelScanList parallelScan(Class clazz,
                                                         DynamoDBScanExpression scanExpression,
                                                         int totalSegments,
                                                         DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  ScanResultPage scanPage(Class clazz, DynamoDBScanExpression scanExpression) {
        return scanPage(clazz, scanExpression, config);
    }

    @Override
    public  ScanResultPage scanPage(Class clazz,
                                          DynamoDBScanExpression scanExpression,
                                          DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public int count(Class clazz, DynamoDBScanExpression scanExpression) {
        return count(clazz, scanExpression, config);
    }

    @Override
    public int count(Class clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  PaginatedQueryList query(Class clazz, DynamoDBQueryExpression queryExpression) {
        return query(clazz, queryExpression, config);
    }

    @Override
    public  PaginatedQueryList query(Class clazz,
                                           DynamoDBQueryExpression queryExpression,
                                           DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  QueryResultPage queryPage(Class clazz, DynamoDBQueryExpression queryExpression) {
        return queryPage(clazz, queryExpression, config);
    }

    @Override
    public  QueryResultPage queryPage(Class clazz,
                                            DynamoDBQueryExpression queryExpression,
                                            DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public  int count(Class clazz, DynamoDBQueryExpression queryExpression) {
        return count(clazz, queryExpression, config);
    }

    @Override
    public  int count(Class clazz, DynamoDBQueryExpression queryExpression, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public S3ClientCache getS3ClientCache() {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public S3Link createS3Link(String bucketName, String key) {
        return createS3Link((Region)null, bucketName, key);
    }

    @Override
    public S3Link createS3Link(Region s3region, String bucketName, String key) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public S3Link createS3Link(String s3region, String bucketName, String key) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public CreateTableRequest generateCreateTableRequest(Class clazz) {
        return generateCreateTableRequest(clazz, config);
    }

    public  CreateTableRequest generateCreateTableRequest(Class clazz, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

    @Override
    public DeleteTableRequest generateDeleteTableRequest(Class clazz) {
        return generateDeleteTableRequest(clazz, config);
    }

    public  DeleteTableRequest generateDeleteTableRequest(Class clazz, DynamoDBMapperConfig config) {
        throw new UnsupportedOperationException("operation not supported in " + getClass());
    }

}