Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Pegasus is a framework for building robust, scalable service architectures using dynamic discovery and simple asychronous type-checked REST + JSON APIs.
/*
Copyright (c) 2013 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.
*/
package com.linkedin.restli.common;
import com.linkedin.data.DataMap;
import com.linkedin.data.schema.DataSchema;
import com.linkedin.data.schema.DataSchemaUtil;
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.schema.TyperefDataSchema;
import com.linkedin.data.template.DataTemplateUtil;
import com.linkedin.data.template.GetMode;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.data.template.SetMode;
import com.linkedin.util.CustomTypeUtil;
import java.util.Map;
/**
* Represents an entity in the form of a key-value pair where the key can be a primitive, a {@link CompoundKey}, or a
* {@link ComplexResourceKey} and the value is a {@link RecordTemplate}
*
* @author kparikh
*/
public class KeyValueRecord extends RecordTemplate
{
public static final String KEY_FIELD_NAME = "key";
public static final String VALUE_FIELD_NAME = "value";
public static final String PARAMS_FIELD_NAME = "$params";
/**
* Needed by {@link DataTemplateUtil#templateConstructor(Class)}
* @param dataMap provides the contents of the key
*/
public KeyValueRecord(DataMap dataMap)
{
super(dataMap, null);
}
/*package private*/KeyValueRecord()
{
super(new DataMap(), null);
}
/**
* Sets a primitive key. If the key is a typeref the typeref is followed and the primitive value is stored.
* @param keyField key field
* @param key the primitive key to set
* @param keyType the type of the key
*/
@SuppressWarnings("unchecked")
void setPrimitiveKey(RecordDataSchema.Field keyField, K key, TypeSpec keyType)
{
DataSchema keySchema = keyType.getSchema();
if (keySchema.isPrimitive())
{
putDirect(keyField, keyType.getType(), keyType.getType(), key, SetMode.IGNORE_NULL);
return;
}
switch (keySchema.getType())
{
case TYPEREF:
TyperefDataSchema typerefDataSchema = (TyperefDataSchema)keySchema;
DataSchema.Type dereferencedType = keySchema.getDereferencedType();
Class> javaClassForSchema = CustomTypeUtil.getJavaCustomTypeClassFromSchema(typerefDataSchema);
if (javaClassForSchema == null)
{
// typeref to a primitive. In this case the keyClass is a primitive, and so is the key.
putDirect(keyField, keyType.getType(), keyType.getType(), key, SetMode.IGNORE_NULL);
}
else
{
// typeref to a custom type. In this case the keyClass is the typeref class, but the class of the key
// is the custom class.
Class> keyDereferencedClass = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(dereferencedType);
putDirect(keyField, (Class