当前位置: 首页>>代码示例>>Java>>正文


Java EdmEntityType.getKeyPredicateNames方法代码示例

本文整理汇总了Java中org.apache.olingo.commons.api.edm.EdmEntityType.getKeyPredicateNames方法的典型用法代码示例。如果您正苦于以下问题:Java EdmEntityType.getKeyPredicateNames方法的具体用法?Java EdmEntityType.getKeyPredicateNames怎么用?Java EdmEntityType.getKeyPredicateNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.olingo.commons.api.edm.EdmEntityType的用法示例。


在下文中一共展示了EdmEntityType.getKeyPredicateNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
public Entity create(final EdmEntitySet edmEntitySet) throws DataProviderException {
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
  EntityCollection entitySet = readAll(edmEntitySet);
  final List<Entity> entities = entitySet.getEntities();
  final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
  Entity newEntity = new Entity();
  newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
  for (final String keyName : edmEntityType.getKeyPredicateNames()) {
    newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
  }

  createProperties(edmEntityType, newEntity.getProperties());
  try {
    newEntity
        .setId(URI.create(odata.createUriHelper().buildCanonicalURL(edmEntitySet, newEntity)));
  } catch (final SerializerException e) {
    throw new DataProviderException("Unable to set entity ID!", e);
  }
  entities.add(newEntity);

  return newEntity;
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:23,代码来源:DataProvider.java

示例2: create

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
public Entity create(final EdmEntitySet edmEntitySet) throws DataProviderException {
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
  EntityCollection entitySet = readAll(edmEntitySet);
  final List<Entity> entities = entitySet.getEntities();
  final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntityType);
  Entity newEntity = new Entity();
  newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
  for (final String keyName : edmEntityType.getKeyPredicateNames()) {
    newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
  }

  createProperties(edmEntityType, newEntity.getProperties());
  try {
    newEntity.setId(URI.create(odata.createUriHelper().buildCanonicalURL(edmEntitySet, newEntity)));
  } catch (final SerializerException e) {
    throw new DataProviderException("Unable to set entity ID!", HttpStatusCode.INTERNAL_SERVER_ERROR, e);
  }
  entities.add(newEntity);

  return newEntity;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:DataProvider.java

示例3: getEntityId

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  try {
    if (entity != null) {
      if (entity.getId() == null) {
        if (entityType == null || entityType.getKeyPredicateNames() == null
            || name == null) {
          throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
        } else {
          final UriHelper uriHelper = new UriHelperImpl();
          entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
          return entity.getId().toASCIIString();
        }
      } else {
        return entity.getId().toASCIIString();
      }
    }
    return null;
  } catch (Exception e) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:29,代码来源:JsonDeltaSerializerWithNavigations.java

示例4: getEntityId

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  try {
    if (entity != null) {
      if (entity.getId() == null) {
        if (entityType == null || entityType.getKeyPredicateNames() == null
            || name == null) {
          throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
        } else {
          final UriHelper uriHelper = new UriHelperImpl();
          entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
          return entity.getId().toASCIIString();
        }
      } else {
        return entity.getId().toASCIIString();
      }
    } 
    return null;
  } catch (Exception e) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:29,代码来源:JsonDeltaSerializer.java

示例5: update

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
    final Entity changedEntity, final boolean patch, final boolean isInsert)
        throws DataProviderException {

  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final List<String> keyNames = entityType.getKeyPredicateNames();

  // Update Properties
  for (final String propertyName : entityType.getPropertyNames()) {
    if (!keyNames.contains(propertyName)) {
      updateProperty(entityType.getStructuralProperty(propertyName),
          entity.getProperty(propertyName), changedEntity.getProperty(propertyName), patch);
    }
  }

  // For insert operations collection navigation property bind operations and deep insert
  // operations can be combined.
  // In this case, the bind operations MUST appear before the deep insert operations in the
  // payload.
  // => Apply bindings first
  final boolean navigationBindingsAvailable = !changedEntity.getNavigationBindings().isEmpty();
  if (navigationBindingsAvailable) {
    applyNavigationBinding(rawBaseUri, edmEntitySet, entity,
        changedEntity.getNavigationBindings());
  }

  // Deep insert (only if not an update)
  if (isInsert) {
    handleDeepInsert(rawBaseUri, edmEntitySet, entity, changedEntity);
  } else {
    handleDeleteSingleNavigationProperties(edmEntitySet, entity, changedEntity);
  }

  // Update the ETag if present.
  updateETag(entity);
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:37,代码来源:DataProvider.java

示例6: update

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
    final Entity changedEntity, final boolean patch, final boolean isInsert) throws DataProviderException {

  final EdmEntityType entityType = changedEntity.getType()!=null ?
      edm.getEntityType(new FullQualifiedName(changedEntity.getType())):edmEntitySet.getEntityType();
  final List<String> keyNames = entityType.getKeyPredicateNames();

  // Update Properties
  for (final String propertyName : entityType.getPropertyNames()) {
    if (!keyNames.contains(propertyName)) {
      updateProperty(entityType.getStructuralProperty(propertyName),
          entity.getProperty(propertyName),
          changedEntity.getProperty(propertyName),
          patch);
    }
  }

  // For insert operations collection navigation property bind operations and deep insert operations can be combined.
  // In this case, the bind operations MUST appear before the deep insert operations in the payload.
  // => Apply bindings first
  final boolean navigationBindingsAvailable = !changedEntity.getNavigationBindings().isEmpty();
  if (navigationBindingsAvailable) {
    applyNavigationBinding(rawBaseUri, edmEntitySet, entity, changedEntity.getNavigationBindings());
  }

  // Deep insert (only if not an update)
  if (isInsert) {
    handleDeepInsert(rawBaseUri, edmEntitySet, entity, changedEntity);
  } else {
    handleDeleteSingleNavigationProperties(edmEntitySet, entity, changedEntity);
  }

  // Update the ETag if present.
  updateETag(entity);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:36,代码来源:DataProvider.java

示例7: compoundKey

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
private static List<UriParameter> compoundKey(UriTokenizer tokenizer, final EdmEntityType edmEntityType,
    final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {

  List<UriParameter> parameters = new ArrayList<UriParameter>();
  List<String> parameterNames = new ArrayList<String>();

  // To validate that each key predicate is exactly specified once, we use a list to pick from.
  List<String> remainingKeyNames = new ArrayList<String>(edmEntityType.getKeyPredicateNames());

  // At least one key predicate is mandatory.  Try to fetch all.
  boolean hasComma = false;
  do {
    final String keyPredicateName = tokenizer.getText();
    if (parameterNames.contains(keyPredicateName)) {
      throw new UriValidationException("Duplicated key property " + keyPredicateName,
          UriValidationException.MessageKeys.DOUBLE_KEY_PROPERTY, keyPredicateName);
    }
    if (remainingKeyNames.isEmpty()) {
      throw new UriParserSemanticException("Too many key properties.",
          UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES,
          Integer.toString(parameters.size()), Integer.toString(parameters.size() + 1));
    }
    if (!remainingKeyNames.remove(keyPredicateName)) {
      throw new UriValidationException("Unknown key property " + keyPredicateName,
          UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, keyPredicateName);
    }
    parameters.add(keyValuePair(tokenizer, keyPredicateName, edmEntityType, edm, referringType, aliases));
    parameterNames.add(keyPredicateName);
    hasComma = tokenizer.next(TokenKind.COMMA);
    if (hasComma) {
      ParserHelper.requireNext(tokenizer, TokenKind.ODataIdentifier);
    }
  } while (hasComma);
  ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);

  return parameters;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:39,代码来源:ParserHelper.java

示例8: buildKeyPredicate

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
@Override
public String buildKeyPredicate(final EdmEntityType edmEntityType, final Entity entity) throws SerializerException {
  StringBuilder result = new StringBuilder();
  final List<String> keyNames = edmEntityType.getKeyPredicateNames();
  boolean first = true;
  for (final String keyName : keyNames) {
    EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(keyName);
    if (first) {
      first = false;
    } else {
      result.append(',');
    }
    if (keyNames.size() > 1) {
      result.append(Encoder.encode(keyName)).append('=');
    }
    final EdmProperty edmProperty =  refType.getProperty();
    if (edmProperty == null) {
      throw new SerializerException("Property not found (possibly an alias): " + keyName,
          SerializerException.MessageKeys.MISSING_PROPERTY, keyName);
    }
    final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType();
    final Object propertyValue = findPropertyRefValue(entity, refType);
    try {
      final String value = type.toUriLiteral(
          type.valueToString(propertyValue,
              edmProperty.isNullable(), edmProperty.getMaxLength(),
              edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()));
      result.append(Encoder.encode(value));
    } catch (final EdmPrimitiveTypeException e) {
      throw new SerializerException("Wrong key value!", e,
          SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), 
          propertyValue != null ? propertyValue.toString(): null);
    }
  }
  return result.toString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:37,代码来源:UriHelperImpl.java

示例9: getEntityId

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @param entityType 
 * @param name 
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  if(entity != null && entity.getId() == null) {
    if(entityType == null || entityType.getKeyPredicateNames() == null 
        || name == null) {
      throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
    }else{
      final UriHelper uriHelper = new UriHelperImpl(); 
      entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
    }
  }
  return entity.getId().toASCIIString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ODataJsonSerializer.java

示例10: areKeyPredicateNamesSelected

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
private boolean areKeyPredicateNamesSelected(SelectOption select, EdmEntityType type) {
  if (select == null || ExpandSelectHelper.isAll(select)) {
    return true;
  }
  final Set<String> selected = ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
  for (String key : type.getKeyPredicateNames()) {
    if (!selected.contains(key)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:13,代码来源:ODataJsonSerializer.java

示例11: getEntityId

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @param entityType the entity Type
 * @param name the entity name
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  if(entity.getId() == null) {
    if((entity == null || entityType == null || entityType.getKeyPredicateNames() == null 
        || name == null)) {
      throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
    }else{
      final UriHelper uriHelper = new UriHelperImpl(); 
      entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
    }
  }
  return entity.getId().toASCIIString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ODataXmlSerializer.java

示例12: buildLocation

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
public static String buildLocation(String baseURL, Entity entity, String enitySetName, EdmEntityType type) 
    throws EdmPrimitiveTypeException {
  StringBuilder location = new StringBuilder();

  location.append(baseURL).append("/").append(enitySetName);
  
  int i = 0;
  boolean usename = type.getKeyPredicateNames().size() > 1;
  location.append("(");
  for (String key : type.getKeyPredicateNames()) {
    if (i > 0) {
      location.append(",");
    }
    i++;
    if (usename) {
      location.append(key).append("=");
    }
    
    EdmProperty property = (EdmProperty)type.getProperty(key);
    String propertyType = entity.getProperty(key).getType();
    Object propertyValue = entity.getProperty(key).getValue();
    
    if (propertyValue == null) {
      throw new EdmPrimitiveTypeException("The key value for property "+key+" is invalid; Key value cannot be null");
    }
    
    if(propertyType.startsWith("Edm.")) {
      propertyType = propertyType.substring(4);
    }
    EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(propertyType);
    String value =  EdmPrimitiveTypeFactory.getInstance(kind).valueToString(
        propertyValue, true, property.getMaxLength(), property.getPrecision(), property.getScale(), true);
    if (kind == EdmPrimitiveTypeKind.String) {
        value = EdmString.getInstance().toUriLiteral(Encoder.encode(value));
    }
    location.append(value);
  }
  location.append(")");
  return location.toString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:41,代码来源:EntityResponse.java

示例13: getKeyPredicatesFromEntity

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
private ODataEntry getKeyPredicatesFromEntity(EdmEntityType entityType, Entity entity)
        throws ODataApplicationException {
    ODataEntry keyPredicates = new ODataEntry();
    for (String key : entityType.getKeyPredicateNames()) {
        EdmProperty propertyType = (EdmProperty) entityType.getProperty(key);
        keyPredicates.addValue(key, readPrimitiveValueInString(propertyType, entity.getProperty(key).getValue()));
    }
    return keyPredicates;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:10,代码来源:ODataAdapter.java

示例14: findFreeComposedKey

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
private Map<String, Object> findFreeComposedKey(final List<Entity> entities,
    final EdmEntityType entityType) throws DataProviderException {
  // Weak key construction
  final HashMap<String, Object> keys = new HashMap<String, Object>();
  for (final String keyName : entityType.getKeyPredicateNames()) {
    final FullQualifiedName typeName =
        entityType.getProperty(keyName).getType().getFullQualifiedName();
    Object newValue;

    if (EdmPrimitiveTypeKind.Int16.getFullQualifiedName().equals(typeName)) {
      newValue = (short) KEY_INT_16.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = (short) KEY_INT_16.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int32.getFullQualifiedName().equals(typeName)) {
      newValue = KEY_INT_32.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_32.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int64.getFullQualifiedName().equals(typeName)) {
      // Integer keys
      newValue = KEY_INT_64.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_64.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(typeName)) {
      // String keys
      newValue = String.valueOf(KEY_STRING.incrementAndGet());

      while (!isFree(newValue, keyName, entities)) {
        newValue = String.valueOf(KEY_STRING.incrementAndGet());
      }
    } else {
      throw new DataProviderException("Key type not supported", HttpStatusCode.NOT_IMPLEMENTED);
    }

    keys.put(keyName, newValue);
  }

  return keys;
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:45,代码来源:DataProvider.java

示例15: findFreeComposedKey

import org.apache.olingo.commons.api.edm.EdmEntityType; //导入方法依赖的package包/类
private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
    throws DataProviderException {
  // Weak key construction
  final HashMap<String, Object> keys = new HashMap<String, Object>();
  List<String> keyPredicateNames = entityType.getKeyPredicateNames();
  for (final String keyName : keyPredicateNames) {
    EdmType type = entityType.getProperty(keyName).getType();
    FullQualifiedName typeName = type.getFullQualifiedName();
    if (type instanceof EdmTypeDefinition) {
      typeName = ((EdmTypeDefinition) type).getUnderlyingType().getFullQualifiedName();
    }
    Object newValue;

    if (EdmPrimitiveTypeKind.Int16.getFullQualifiedName().equals(typeName)) {
      newValue = (short) KEY_INT_16.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = (short) KEY_INT_16.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int32.getFullQualifiedName().equals(typeName)) {
      newValue = KEY_INT_32.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_32.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.Int64.getFullQualifiedName().equals(typeName)) {
      // Integer keys
      newValue = KEY_INT_64.incrementAndGet();

      while (!isFree(newValue, keyName, entities)) {
        newValue = KEY_INT_64.incrementAndGet();
      }
    } else if (EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(typeName)) {
      // String keys
      newValue = String.valueOf(KEY_STRING.incrementAndGet());

      while (!isFree(newValue, keyName, entities)) {
        newValue = String.valueOf(KEY_STRING.incrementAndGet());
      }
    } else if (type instanceof EdmEnumType) {
      /* In case of an enum key we only support composite keys. This way we can 0 as a key */
      if (keyPredicateNames.size() <= 1) {
        throw new DataProviderException("Single Enum as key not supported", HttpStatusCode.NOT_IMPLEMENTED);
      }
      newValue = new Short((short) 1);
    } else {
      throw new DataProviderException("Key type not supported", HttpStatusCode.NOT_IMPLEMENTED);
    }

    keys.put(keyName, newValue);
  }

  return keys;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:55,代码来源:DataProvider.java


注:本文中的org.apache.olingo.commons.api.edm.EdmEntityType.getKeyPredicateNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。