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

com.linkedin.restli.internal.client.BatchKVResponseDecoder Maven / Gradle / Ivy

/*
   Copyright (c) 2012 LinkedIn Corp.

   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://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.
*/

/**
 * $Id: $
 */

package com.linkedin.restli.internal.client;

import java.util.Map;

import com.linkedin.data.DataMap;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.restli.client.response.BatchKVResponse;
import com.linkedin.restli.common.ComplexKeySpec;
import com.linkedin.restli.common.ComplexResourceKey;
import com.linkedin.restli.common.CompoundKey;
import com.linkedin.restli.common.CompoundKey.TypeInfo;
import com.linkedin.restli.common.ProtocolVersion;
import com.linkedin.restli.common.RestConstants;
import com.linkedin.restli.common.TypeSpec;

/**
 * Converts a raw RestResponse into a type-bound batch response.
 * @author Steven Ihde
 * @version $Revision: $
 */

public class BatchKVResponseDecoder extends RestResponseDecoder>
{
  private final TypeSpec _elementType;
  private final TypeSpec _keyType;
  private final Map _keyParts;
  private final ComplexKeySpec _complexKeyType;

  /**
   * @param elementClass provides the entity type of the collection.
   *
   * @param keyClass provides the class identifying the key type.
   *   
    *
  • For collection resources must be a primitive or a typeref to a primitive.
  • *
  • For an association resources must be {@link CompoundKey} and keyParts must contain an entry for each association key field.
  • *
  • For complex resources must be {@link ComplexResourceKey}, keyKeyClass must contain the * key's record template class and if the resource has a key params their record template type keyParamsClass must be provided.
  • * @param keyParts provides a map for association keys of each key name to {@link TypeInfo}, for non-association resources must be an empty map. * @param keyKeyClass provides the record template class for the key for complex key resources, otherwise null. * @param keyParamsClass provides the record template class for the key params for complex key resources, otherwise null. */ public BatchKVResponseDecoder(Class elementClass, Class keyClass, Map keyParts, Class keyKeyClass, Class keyParamsClass) { this(TypeSpec.forClassMaybeNull(elementClass), TypeSpec.forClassMaybeNull(keyClass), keyParts, ComplexKeySpec.forClassesMaybeNull(keyKeyClass, keyParamsClass)); } /** * @param elementType provides the entity type of the collection. * * @param keyType provides the class identifying the key type. *
      *
    • For collection resources must be a primitive or a typeref to a primitive.
    • *
    • For an association resources must be {@link CompoundKey} and keyParts must contain an entry for each association key field.
    • *
    • For complex resources must be {@link ComplexResourceKey}, keyKeyClass must contain the * key's record template class and if the resource has a key params their record template type keyParamsClass must be provided.
    • * @param keyParts provides a map for association keys of each key name to {@link TypeInfo}, for non-association resources must be an empty map. * @param complexKeyType provides the type of the key for complex key resources, otherwise null. */ public BatchKVResponseDecoder(TypeSpec elementType, TypeSpec keyType, Map keyParts, ComplexKeySpec complexKeyType) { _elementType = elementType; _keyType = keyType; _keyParts = keyParts; _complexKeyType = complexKeyType; } @Override public Class getEntityClass() { return _elementType.getType(); } @Override public BatchKVResponse wrapResponse(DataMap dataMap, Map headers, ProtocolVersion version) { return dataMap == null ? null : new BatchKVResponse(dataMap, _keyType, _elementType, _keyParts, _complexKeyType, version); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy