Package com.google.storage.onestore.v3.OnestoreEntity.Path

Examples of com.google.storage.onestore.v3.OnestoreEntity.Path.Element


            List<Key> deleteList =
                (List<Key>) entity.getProperty(DELETE_LIST_PROPERTY);
            List<Entity> putEntities = new ArrayList<Entity>();
            if (putList != null) {
                for (Blob blob : putList) {
                    EntityProto proto = putReq.addEntity();
                    proto.mergeFrom(blob.getBytes());
                    putEntities.add(EntityTranslator.createFromPb(proto));
                }
            }
            if (putEntities.size() > 0) {
                DatastoreUtil.put(ds, null, putEntities);
View Full Code Here


        List<Blob> putList = new ArrayList<Blob>();
        List<Key> deleteList = new ArrayList<Key>();
        for (Key key : journalMap.keySet()) {
            Entity targetEntity = journalMap.get(key);
            boolean put = targetEntity != null;
            EntityProto targetProto =
                put ? EntityTranslator.convertToPb(targetEntity) : null;
            int size = put ? targetProto.encodingSize() : 0;
            if (totalSize != 0
                && totalSize + size + DatastoreUtil.EXTRA_SIZE > DatastoreUtil.MAX_ENTITY_SIZE) {
                entity.setUnindexedProperty(PUT_LIST_PROPERTY, putList);
                entity.setUnindexedProperty(DELETE_LIST_PROPERTY, deleteList);
                DatastoreUtil.put(ds, null, entity);
                entities.add(entity);
                entity = createEntity(ds, globalTransactionKey);
                putList = new ArrayList<Blob>();
                deleteList = new ArrayList<Key>();
                totalSize = 0;
            }
            if (put) {
                byte[] content = new byte[targetProto.encodingSize()];
                targetProto.outputTo(content, 0);
                putList.add(new Blob(content));
            } else {
                deleteList.add(key);
            }
            totalSize += size + DatastoreUtil.EXTRA_SIZE;
View Full Code Here

            throws NullPointerException {
        if (entity == null) {
            throw new NullPointerException(
                "The entity parameter must not be null.");
        }
        EntityProto pb = EntityTranslator.convertToPb(entity);
        byte[] buf = new byte[pb.encodingSize()];
        pb.outputTo(buf, 0);
        return buf;
    }
View Full Code Here

            throws NullPointerException {
        if (bytes == null) {
            throw new NullPointerException(
                "The bytes parameter must not be null.");
        }
        EntityProto pb = new EntityProto();
        pb.mergeFrom(bytes);
        return EntityTranslator.createFromPb(pb);
    }
View Full Code Here

            throws NullPointerException {
        if (entity == null) {
            throw new NullPointerException(
                "The entity parameter must not be null.");
        }
        EntityProto pb = EntityTranslator.convertToPb(entity);
        byte[] buf = new byte[pb.encodingSize()];
        pb.outputTo(buf, 0);
        return buf;
    }
View Full Code Here

            throws NullPointerException {
        if (bytes == null) {
            throw new NullPointerException(
                "The bytes parameter must not be null.");
        }
        EntityProto pb = new EntityProto();
        pb.mergeFrom(bytes);
        return EntityTranslator.createFromPb(pb);
    }
View Full Code Here

    } else {

      Schema schema = DatastoreUtil.getSchema();
      List<EntityProto> entityProtoList = schema.kinds();
      EntityProto targetEntity = null;
      for (EntityProto entityProto : entityProtoList) {
        String kindName = DatastoreUtil.getKind(entityProto.getKey());
        if (kind.equals(kindName)) {
          targetEntity = entityProto;
          break;
        }
      }
      if (targetEntity == null) {
        throw new RuntimeException("The specified kind has no property");
      }
      List<Property> propertys = targetEntity.propertys();
      for (Property property : propertys) {
        GbProperty gbProperty = new GbProperty();
        gbProperty.setName(property.getName());
        list.add(gbProperty);
      }
View Full Code Here

        (!indexOnlyQuery.hasKeyProperty() ||
            indexProperties.get(0).getDirectionEnum() == Property.Direction.ASCENDING)) {
      return null;
    }

    Index index = new Index();
    index.setEntityType(query.getKind());
    index.setAncestor(isAncestor);
    index.mutablePropertys().addAll(indexProperties);
    return index;
  }
View Full Code Here

   * query, or {@code null} if no index is needed.
   */
  protected Index minimumCompositeIndexForQuery(IndexComponentsOnlyQuery indexOnlyQuery,
      Collection<Index> indexes) {

    Index suggestedIndex = compositeIndexForQuery(indexOnlyQuery);
    if (suggestedIndex == null) {
      return null;
    }

    class EqPropsAndAncestorConstraint {
      final Set<String> equalityProperties;
      final boolean ancestorConstraint;

      EqPropsAndAncestorConstraint(Set<String> equalityProperties, boolean ancestorConstraint) {
        this.equalityProperties = equalityProperties;
        this.ancestorConstraint = ancestorConstraint;
      }
    }

    Map<List<Property>, EqPropsAndAncestorConstraint> remainingMap =
        new HashMap<List<Property>, EqPropsAndAncestorConstraint>();

index_for:
    for (Index index : indexes) {
      if (
          !indexOnlyQuery.getQuery().getKind().equals(index.getEntityType()) ||
          (!indexOnlyQuery.getQuery().hasAncestor() && index.isAncestor())) {
        continue;
      }

      int postfixSplit = index.propertySize();
      for (IndexComponent component : Lists.reverse(indexOnlyQuery.getPostfix())) {
        if (!component.matches(index.propertys().subList(postfixSplit - component.size(),
            postfixSplit))) {
          continue index_for;
        }
        postfixSplit -= component.size();
      }

      Set<String> indexEqProps = Sets.newHashSetWithExpectedSize(postfixSplit);
      for (Property prop : index.propertys().subList(0, postfixSplit)) {
        if (!indexOnlyQuery.getPrefix().contains(prop.getName())) {
          continue index_for;
        }
        indexEqProps.add(prop.getName());
      }

      List<Property> indexPostfix = index.propertys().subList(postfixSplit, index.propertySize());

      Set<String> remainingEqProps;
      boolean remainingAncestor;
      {
        EqPropsAndAncestorConstraint remaining = remainingMap.get(indexPostfix);
        if (remaining == null) {
          remainingEqProps = Sets.newHashSet(indexOnlyQuery.getPrefix());
          remainingAncestor = indexOnlyQuery.getQuery().hasAncestor();
        } else {
          remainingEqProps = remaining.equalityProperties;
          remainingAncestor = remaining.ancestorConstraint;
        }
      }

      boolean modified = remainingEqProps.removeAll(indexEqProps);
      if (remainingAncestor && index.isAncestor()) {
        modified = true;
        remainingAncestor = false;
      }

      if (remainingEqProps.isEmpty() && !remainingAncestor) {
        return null;
      }

      if (!modified) {
        continue;
      }

      remainingMap.put(indexPostfix,
          new EqPropsAndAncestorConstraint(remainingEqProps, remainingAncestor));
    }

    if (remainingMap.isEmpty()) {
      return suggestedIndex;
    }

    int minimumCost = Integer.MAX_VALUE;
    List<Property> minimumPostfix = null;
    EqPropsAndAncestorConstraint minimumRemaining = null;
    for (Map.Entry<List<Property>, EqPropsAndAncestorConstraint> entry : remainingMap.entrySet()) {
      int cost = entry.getValue().equalityProperties.size();
      if (entry.getValue().ancestorConstraint) {
        cost += 2;
      }
      if (cost < minimumCost) {
        minimumCost = cost;
        minimumPostfix = entry.getKey();
        minimumRemaining = entry.getValue();
      }
    }

    suggestedIndex.clearProperty();
    suggestedIndex.setAncestor(minimumRemaining.ancestorConstraint);
    for (String name : minimumRemaining.equalityProperties) {
      suggestedIndex.addProperty().setName(name).setDirection(Direction.ASCENDING);
    }
    Collections.sort(suggestedIndex.mutablePropertys(), PROPERTY_NAME_COMPARATOR);

    suggestedIndex.mutablePropertys().addAll(minimumPostfix);
    return suggestedIndex;
  }
View Full Code Here

      clone.getPosition().setStartInclusive(!clone.getPosition().isStartInclusive());
    } else if (clone.hasPostfixPosition()) {
      IndexPostfix postfixPosition = clone.getPostfixPosition();
      postfixPosition.setBefore(!postfixPosition.isBefore());
    } else if (clone.hasAbsolutePosition()) {
      IndexPosition absolutePosition = clone.getAbsolutePosition();
      absolutePosition.setBefore(!absolutePosition.isBefore());
    }
    return new Cursor(clone);
  }
View Full Code Here

TOP

Related Classes of com.google.storage.onestore.v3.OnestoreEntity.Path.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.