<p>
Construct a partition key for the given entity.
</p>
<p>
This is a convenient way to find the partition that a given entity is
written to, or to find a partition using objects from the entity domain.
</p>
422093
public static <E> PartitionKey partitionKeyForEntity(PartitionStrategy strategy,
      E entity, EntityAccessor<E> accessor) {
    return partitionKeyForEntity(strategy, entity, accessor, null);
  }
49468
public Integer getNodesPartitionIdForKey(int nodeId, final byte[] key) {
        // this is all the partitions the key replicates to.
        List<Integer> partitionIds = getReplicatingPartitionList(key);
        for(Integer partitionId: partitionIds) {
            // check which of the replicating partitions belongs to the node in
            // question
            if(getNodeIdForPartitionId(partitionId) == nodeId) {
                return partitionId;
            }
        }
        return null;
    }
1044888
private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) {
    EntityType entityType = (EntityType) entityTypes.get(entityName);
    if (null == entityType) {
      ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
      if (null == cm) {
        logger.error("Cannot find ClassMetadata for {}", entityName);
        return null;
      }
      entityType = new EntityType(cm.getEntityName(), cm.getMappedClass(), cm.getIdentifierPropertyName(),
          new IdentifierType(cm.getIdentifierType().getReturnedClass()));
      entityTypes.put(cm.getEntityName(), entityType);

      Map<String, Type> propertyTypes = entityType.getPropertyTypes();
      String[] ps = cm.getPropertyNames();
      for (int i = 0; i < ps.length; i++) {
        org.hibernate.type.Type type = cm.getPropertyType(ps[i]);
        if (type.isEntityType()) {
          propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName()));
        } else if (type.isComponentType()) {
          propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i]));
        } else if (type.isCollectionType()) {
          propertyTypes.put(ps[i],
              buildCollectionType(sessionFactory, defaultCollectionClass(type), entityName + "." + ps[i]));
        }
      }
    }
    return entityType;
  }
1258783
def _delete_entity(partition_key, row_key, if_match):
    '''
     
    '''
    _validate_not_none('if_match', if_match)
    _validate_not_none('partition_key', partition_key)
    _validate_not_none('row_key', row_key)
    request = HTTPRequest()
    request.method = 'DELETE'
    request.headers = [_DEFAULT_ACCEPT_HEADER,
                        ('If-Match', _to_str(if_match))]

    return request
1282906
@Override
    public Data readBackupData(Data key) {
        Record record = getRecord(key);

        if (record == null) {
            return null;
        } else {
            if (partitionService.isPartitionOwner(partitionId)) {
                // set last access time to prevent
                // premature removal of the entry because
                // of idleness based expiry
                record.setLastAccessTime(Clock.currentTimeMillis());
            }
        }

        Object value = record.getValue();
        mapServiceContext.interceptAfterGet(name, value);
        // this serialization step is needed not to expose the object, see issue 1292
        return mapServiceContext.toData(value);
    }
1288760
def entity(self) -> dict:        
            
        image = {}
        image['PartitionKey'] = self.getPartitionKey()
        image['RowKey'] = self.getRowKey()
        for key, value in vars(self).items():
            if not key.startswith('_') and key not in ['','PartitionKey','RowKey']:
                if type(value) in [str, int, bool, datetime.date, datetime.datetime]:
                    image[key] = value                    
        return image
395772
public RemotablePartitionEntity updateRemotablePartitionOnRecovery(PersistenceServiceUnit psu,
                                                                       final RemotablePartitionEntity partition) {
        // TODO Auto-generated method stub
        EntityManager em = psu.createEntityManager();
        try {
            return new TranRequest<RemotablePartitionEntity>(em) {
                @Override
                public RemotablePartitionEntity call() {
                    RemotablePartitionKey key = new RemotablePartitionKey(partition);
                    RemotablePartitionEntity remotablePartition = entityMgr.find(RemotablePartitionEntity.class, key);
                    remotablePartition.setLastUpdated(new Date());
                    return remotablePartition;
                }
            }.runInNewOrExistingGlobalTran();
        } finally {
            em.close();
        }
    }
322302
private void buildEntityFromCursor(Object entity, HashMap obj, EntityType entityType)
    {
        Iterator<Attribute> iter = entityType.getAttributes().iterator();
        while (iter.hasNext())
        {
            Attribute attribute = iter.next();
            Field field = (Field) attribute.getJavaMember();
            if (field.isAnnotationPresent(Id.class))
            {
                PropertyAccessorHelper.set(entity, field, obj.get(ID));
            }
            else
            {
                PropertyAccessorHelper.set(entity, field, obj.get(((AbstractAttribute) attribute).getJPAColumnName()));
            }

        }
    }
764598
public Key toKey() {
    AutoBuffer bs = new AutoBuffer();
    bs.put4(_data_id);
    bs.put8(_seed);
    bs.put1(_producerId);
    _tree.write(bs);
    Key key = Key.make((byte)1,Key.DFJ_INTERNAL_USER, H2O.SELF);
    DKV.put(key,new Value(key, bs.buf()));
    return key;
  }
595790
public String getOrGenerateDocumentId(Object entity) {
        Reference<String> idHolder = new Reference<>();
        tryGetIdFromInstance(entity, idHolder);
        String id = idHolder.value;
        if (id == null) {
            // Generate the key up front
            id = _generateId.apply(entity);
        }

        if (id != null && id.startsWith("/")) {
            throw new IllegalStateException("Cannot use value '" + id + "' as a document id because it begins with a '/'");
        }
        return id;
    }
943837
def <<(entity)
      url_chunk, options = setup_entity_post_request(entity)
      result = execute_entity_post_request(options, url_chunk)
      if entity.is_new?
        doc = ::Nokogiri::XML(result.body).remove_namespaces!
        primary_key_node = doc.xpath("//content/properties/#{entity.primary_key}").first
        entity[entity.primary_key] = primary_key_node.content unless primary_key_node.nil?
      end

      unless result.code.to_s =~ /^2[0-9][0-9]$/
        entity.errors << ['could not commit entity']
      end

      entity
    end
621469
protected EnhanceEntity findById(Object primaryKey, EntityMetadata m, Client client)
    {
        try
        {
            Object o = client.find(m.getEntityClazz(), primaryKey);

            if (o == null)
            {
                // No entity found
                return null;
            }
            else
            {
                return o instanceof EnhanceEntity ? (EnhanceEntity) o : new EnhanceEntity(o, getId(o, m), null);
            }
        }
        catch (Exception e)
        {
            throw new EntityReaderException(e);
        }
    }
749087
private DBObject createQueryPartition(MongoPartition partition) {

        QueryBuilder queryBuilderMin = QueryBuilder.start(partition.getKey());
        DBObject bsonObjectMin = queryBuilderMin.greaterThanEquals(partition.splitWrapper().getStartToken()).get();

        QueryBuilder queryBuilderMax = QueryBuilder.start(partition.getKey());
        DBObject bsonObjectMax = queryBuilderMax.lessThan(partition.splitWrapper().getEndToken()).get();

        QueryBuilder queryBuilder = QueryBuilder.start();
        if (partition.splitWrapper().getStartToken() != null) {
            queryBuilder.and(bsonObjectMin);
        }

        if (partition.splitWrapper().getEndToken() != null) {
            queryBuilder.and(bsonObjectMax);
        }

        LOG.debug("mongodb query "+queryBuilder.get());

        return queryBuilder.get();
    }
742181
public Entity javaToDatastore(Key parentKey, Object javaObject) {
		Key key = keyProperty.getValue(javaObject);
		Entity entity = key == null? new Entity(kind, parentKey) : new Entity(key); 
		for (Entry<String, PropertyMetadata<?, ?>> entry : properties.entrySet()) {
			PropertyMetadata property = entry.getValue();
			Object javaValue = property.getValue(javaObject);
			property.setEntityValue(entity, javaValue);
		}
		return entity;
	}
643514
public EntityContainer getEntityContainer(String id) {
        EntityContainer ec = (EntityContainer) getPmsession().getContainer(id);
        if (ec == null) {
            ec = getPresentationManager().newEntityContainer(id);
            getPmsession().setContainer(id, ec);
        }
        return ec;
    }
849043
private static org.hibernate.engine.spi.EntityKey getOptionalObjectKey(QueryParameters queryParameters, SharedSessionContractImplementor session) {
		final Object optionalObject = queryParameters.getOptionalObject();
		final Serializable optionalId = queryParameters.getOptionalId();
		final String optionalEntityName = queryParameters.getOptionalEntityName();

		if ( optionalObject != null && optionalEntityName != null ) {
			return session.generateEntityKey( optionalId, session.getEntityPersister( optionalEntityName, optionalObject ) );
		}
		else {
			return null;
		}
	}
678889
private boolean hasPrimaryKey(T entity) {
        Object pk = getPrimaryKey(entity);
        if (pk == null) {
            return false;
        } else {
            if (pk instanceof Number && ((Number) pk).longValue() == 0) {
                return false;
            }
        }
        return true;
    }