Factory method

@param parent NodeData
@param name  InternalQName
@param primaryTypeName InternalQName
@param index int
@param orderNumber int
@return
164595
public static ImportNodeData createNodeData(NodeData parent, InternalQName name, InternalQName primaryTypeName,
      int index, int orderNumber)
   {
      ImportNodeData nodeData = null;
      QPath path = QPath.makeChildPath(parent.getQPath(), name, index);
      nodeData =
         new ImportNodeData(path, IdGenerator.generate(), -1, primaryTypeName, new InternalQName[0], orderNumber,
            parent.getIdentifier(), parent.getACL());
      return nodeData;
   }
23896
private boolean createChild(Property sibling, String parentURI) {
        boolean skipped = sibling.getName().equals("children");

        if (!skipped) {
            //dump(sibling);
            String dataType = null;
            String uri = "";
            if (sibling.getValue().hasDefined("class-name")) {
                dataType = sibling.getValue().get("class-name").asString();
                uri = parentURI + "/" + sibling.getName();

                int idx = uri.indexOf(':');
                if (idx > 0) {
                    int idx2 = uri.lastIndexOf('/', idx);
                    if (idx2 >= 0 && (idx2 + 1) < uri.length())
                        uri = uri.substring(idx2 + 1);
                }
            }

            JndiEntry next = new JndiEntry(sibling.getName(), uri, dataType);
            if (sibling.getValue().hasDefined("value"))
                next.setValue(sibling.getValue().get("value").asString());

            stack.peek().getChildren().add(next);
            stack.push(next);
        }

        return skipped;
    }
611032
public static int computeIndexInParent(Object nodeObject)
    {
        if (nodeObject instanceof DefaultMutableTreeNode)
        {
            DefaultMutableTreeNode node = 
                (DefaultMutableTreeNode)nodeObject;
            TreeNode parent = node.getParent();
            if (parent == null)
            {
                return -1;
            }
            int childCount = parent.getChildCount();
            for (int i=0; i<childCount; i++)
            {
                TreeNode child = parent.getChildAt(i);
                if (child == nodeObject)
                {
                    return i;
                }
            }
        }
        return -1;
    }
1217419
protected NodeDataIndexing createNodeDataIndexing(TempNodeData tempNode) throws RepositoryException, SQLException,
      IOException, IllegalNameException
   {
      String parentCid;
      QPath parentPath;

      if (tempNode.cpid.equals(Constants.ROOT_PARENT_UUID))
      {
         // root node
         parentCid = null;
         parentPath = Constants.ROOT_PATH;
      }
      else
      {
         parentCid = tempNode.cpid;
         parentPath =
            QPath.makeChildPath(traverseQPath(tempNode.cpid), InternalQName.parse(tempNode.cname), tempNode.cindex);
      }

      // primary type if exists in the list of properties
      SortedSet<TempPropertyData> ptTempProp = tempNode.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
      ValueData ptValueData = ptTempProp.first().getValueData();
      long ptSize = ptTempProp.first().getSize();
      InternalQName ptName = InternalQName.parse(ValueDataUtil.getString(ptValueData));

      // mixins if exist in the list of properties
      List<ValueData> mixinsData = new ArrayList<ValueData>();
      List<InternalQName> mixins = new ArrayList<InternalQName>();
      long mixinsSize = 0;

      Set<TempPropertyData> mixinsTempProps = tempNode.properties.get(Constants.JCR_MIXINTYPES.getAsString());
      if (mixinsTempProps != null)
      {
         for (TempPropertyData mxnb : mixinsTempProps)
         {
            ValueData vdata = mxnb.getValueData();

            mixinsData.add(vdata);
            mixins.add(InternalQName.parse(ValueDataUtil.getString(vdata)));

            mixinsSize += mxnb.getSize();
         }
      }

      // build node data. No need to load ACL. The node will be pushed directly for reindexing. 
      NodeData nodeData =
         new PersistedNodeData(getIdentifier(tempNode.cid), parentPath, getIdentifier(parentCid), tempNode.cversion,
            tempNode.cnordernumb, ptName, mixins.toArray(new InternalQName[mixins.size()]), null);

      Map<String, PropertyData> childProps = new HashMap<String, PropertyData>();
      for (String propName : tempNode.properties.keySet())
      {
         ExtendedTempPropertyData prop = (ExtendedTempPropertyData)tempNode.properties.get(propName).first();

         String identifier = getIdentifier(prop.id);
         QPath qpath = QPath.makeChildPath(parentPath, InternalQName.parse(prop.name));

         List<ValueData> values = new ArrayList<ValueData>();
         long size = 0;

         if (propName.equals(Constants.JCR_PRIMARYTYPE.getAsString()))
         {
            values.add(ptValueData);
            size = ptSize;
         }
         else if (propName.equals(Constants.JCR_MIXINTYPES.getAsString()))
         {
            values = mixinsData;
            size = mixinsSize;
         }
         else
         {
            for (TempPropertyData tempProp : tempNode.properties.get(propName))
            {
               ExtendedTempPropertyData exTempProp = (ExtendedTempPropertyData)tempProp;

               values.add(exTempProp.getValueData());
               size += exTempProp.getSize();
            }
         }

         // build property data
         PropertyData pdata =
            new PersistedPropertyData(identifier, qpath, getIdentifier(tempNode.cid), prop.version, prop.type, prop.multi, values,
               new SimplePersistedSize(size));

         childProps.put(propName, pdata);
      }

      return new NodeDataIndexing(nodeData, childProps);
   }
1130235
public boolean isOrderableChildNodesSupported(final InternalQName primaryType, final InternalQName[] mixinTypes)
      throws RepositoryException
   {

      final int nlen = mixinTypes != null ? mixinTypes.length : 0;
      for (int i = -1; i < nlen; i++)
      {
         InternalQName name;
         if (i < 0)
         {
            name = primaryType;
         }
         else
         {
            name = mixinTypes[i];
         }

         final NodeTypeData nt = this.nodeTypeRepository.getNodeType(name);

         if (nt != null)
         {
            if (nt.hasOrderableChildNodes())
            {
               return true;
            }

            final Set<InternalQName> supers = this.nodeTypeRepository.getSupertypes(nt.getName());
            for (final InternalQName suName : supers)
            {
               final NodeTypeData su = this.nodeTypeRepository.getNodeType(suName);
               if (su != null && su.hasOrderableChildNodes())
               {
                  return true;
               }
            }
         }
      }

      return false;
   }
286022
@SuppressWarnings({"unchecked", "rawtypes"})
    private InternalNode<?> combineIDDSameLevel(InternalNode n1,
                                                InternalNode n2) throws MIDDException {
        if (n1.getID() != n2.getID()) {
            throw new IllegalArgumentException("Both params should have the same variable level at their root");
        }

        if (n1.getType() != n2.getType()) {
            throw new IllegalArgumentException("Both IDD roots should have the same data type");
        }

        Partition p1 = PartitionBuilder.createPartition(n1.getIntervals());
        Partition p2 = PartitionBuilder.createPartition(n2.getIntervals());

        Partition<?> p = PartitionBuilder.union(p1, p2);
        if (p.size() == 0) {
            log.error("Empty unioned partition");
            return null;
        }

        InternalNodeState newState = combineIndeterminateStates(n1.getState(), n2.getState());

        InternalNode<?> n = NodeUtils.createInternalNode(n1.getID(), newState, n1.getType());

        for (Interval<?> interval : p.getIntervals()) {
            AbstractNode op1 = n1.getChild(interval);
            AbstractNode op2 = n2.getChild(interval);
            AbstractNode child = null;
            if (op1 != null && op2 != null) {
                child = combine(op1, op2);
            } else if (op1 != null || op2 != null) {
                child = GenericUtils.newInstance(op1 == null ? op2 : op1);
            } else {
                throw new RuntimeException("Error merging two partitions, " +
                        "the output partition has an item not belong to both previous ones");
            }

            if (child != null) {
                AbstractEdge<?> edge = EdgeUtils.createEdge(interval, n.getType());
                if (edge.getIntervals().size() == 0) {
                    throw new RuntimeException("Empty edge");
                }
                n.addChild(edge, child);
            }
        }

        return n;
    }
166878
private int getNextChildIndex(InternalQName nameToAdd, InternalQName primaryTypeName, NodeData parentNode,
      NodeDefinitionData def) throws RepositoryException, ItemExistsException
   {
      boolean allowSns = def.isAllowsSameNameSiblings();

      int ind = 1;

      boolean hasSibling = dataManager.hasItemData(parentNode, new QPathEntry(nameToAdd, ind), ItemType.NODE);
      while (hasSibling)
      {
         if (allowSns)
         {
            ind++;
            hasSibling = dataManager.hasItemData(parentNode, new QPathEntry(nameToAdd, ind), ItemType.NODE);
         }
         else
         {
            throw new ItemExistsException("The node " + nameToAdd + " already exists in " + getPath()
               + " and same name sibling is not allowed ");
         }
      };

      return ind;
   }
409209
public Iterable<DContact> queryByFirstName(Object parent, java.lang.String firstName) {
    return queryByField(parent, DContactMapper.Field.FIRSTNAME.getFieldName(), firstName);
  }
313532
private Order create(
            final String number,
            final String customerName,
            final LocalDate date,
            final String preferences,
            final ExecutionContext executionContext) {
        return executionContext.add(this, orders.create(number, customerName, date, preferences));
    }
193114
public NodeType findNodeType(InternalQName nodeTypeName) throws NoSuchNodeTypeException, RepositoryException
   {

      NodeTypeData ntdata = typesManager.getNodeType(nodeTypeName);
      if (ntdata != null)
      {
         return new NodeTypeImpl(ntdata, typesManager, this, locationFactory, valueFactory, dataManager);
      }
      throw new NoSuchNodeTypeException("Nodetype not found " + nodeTypeName.getAsString());
   }
899969
private ObjectNode internalCreateRequest(String methodName, Object arguments, String id) {
		final ObjectNode request = mapper.createObjectNode();
		addId(id, request);
		addProtocolAndMethod(methodName, request);
		addParameters(arguments, request);
		addAdditionalHeaders(request);
		notifyBeforeRequestListener(request);
		return request;
	}
716812
public Iterable<DContact> queryBySecondaryCustomIndex(Object parent, java.lang.String secondaryCustomIndex) {
    return queryByField(parent, DContactMapper.Field.SECONDARYCUSTOMINDEX.getFieldName(), secondaryCustomIndex);
  }
239887
private Document updateOrCreateIndex(EntityMetadata metadata, final MetamodelImpl metaModel, Object entity,
            String parentId, Class<?> clazz, boolean isUpdate)
    {
        boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
        if (!metadata.isIndexable())
        {
            return null;
        }

        Document document = null;
        Object embeddedObject = null;
        Object rowKey = null;

        try
        {
            rowKey = PropertyAccessorHelper.getId(entity, metadata);
        }
        catch (PropertyAccessException e1)
        {
            throw new LuceneIndexingException("Can't access Primary key property from " + metadata.getEntityClazz(), e1);
        }

        if (metadata.getType().equals(EntityMetadata.Type.SUPER_COLUMN_FAMILY))
        {
            Map<String, EmbeddableType> embeddables = metaModel.getEmbeddables(metadata.getEntityClazz());

            Iterator<String> iter = embeddables.keySet().iterator();

            while (iter.hasNext())
            {

                String attributeName = iter.next();
                EmbeddableType embeddableAttribute = embeddables.get(attributeName);
                EntityType entityType = metaModel.entity(metadata.getEntityClazz());

                embeddedObject = PropertyAccessorHelper.getObject(entity, (Field) entityType
                        .getAttribute(attributeName).getJavaMember());

                if (embeddedObject == null)
                {
                    continue;
                }
                if (embeddedObject instanceof Collection<?>)
                {
                    document = updateOrCreateIndexCollectionTypeEmbeddedObject(metadata, metaModel, entity, parentId,
                            clazz, isUpdate, document, embeddedObject, rowKey, attributeName, embeddableAttribute);
                }
                else
                {
                    document = prepareDocumentForSuperColumn(metadata, entity, attributeName, parentId, clazz);
                    createSuperColumnDocument(metadata, entity, document,
                            metaModel.isEmbeddable(embeddedObject.getClass()) ? embeddedObject : entity,
                            embeddableAttribute, metaModel);
                    if (isUpdate)
                    {
                        updateDocument(parentId, document, null);
                    }
                    else
                    {
                        indexDocument(metadata, document);
                    }
                }
            }
        }
        else
        {
            document = updateOrCreateIndexNonSuperColumnFamily(metadata, metaModel, entity, parentId, clazz, isUpdate,
                    isEmbeddedId, rowKey);
        }
        return document;

    }
1129730
Node<K, V> find(K key, boolean create) {
    Comparator<? super K> comparator = this.comparator;
    Node<K, V> nearest = root;
    int comparison = 0;

    if (nearest != null) {
      // Micro-optimization: avoid polymorphic calls to Comparator.compare().
      @SuppressWarnings("unchecked") // Throws a ClassCastException below if there's trouble.
          Comparable<Object> comparableKey = (comparator == NATURAL_ORDER)
          ? (Comparable<Object>) key
          : null;

      while (true) {
        comparison = (comparableKey != null)
            ? comparableKey.compareTo(nearest.key)
            : comparator.compare(key, nearest.key);

        // We found the requested key.
        if (comparison == 0) {
          return nearest;
        }

        // If it exists, the key is in a subtree. Go deeper.
        Node<K, V> child = (comparison < 0) ? nearest.left : nearest.right;
        if (child == null) {
          break;
        }

        nearest = child;
      }
    }

    // The key doesn't exist in this tree.
    if (!create) {
      return null;
    }

    // Create the node and add it to the tree or the table.
    Node<K, V> header = this.header;
    Node<K, V> created;
    if (nearest == null) {
      // Check that the value is comparable if we didn't do any comparisons.
      if (comparator == NATURAL_ORDER && !(key instanceof Comparable)) {
        throw new ClassCastException(key.getClass().getName() + " is not Comparable");
      }
      created = new Node<K, V>(nearest, key, header, header.prev);
      root = created;
    } else {
      created = new Node<K, V>(nearest, key, header, header.prev);
      if (comparison < 0) { // nearest.key is higher
        nearest.left = created;
      } else { // comparison > 0, nearest.key is lower
        nearest.right = created;
      }
      rebalance(nearest, true);
    }
    size++;
    modCount++;

    return created;
  }
1221743
@Nonnull
  public final ITEMTYPE createChildItem (@Nullable final DATATYPE aData)
  {
    // create new item
    final ITEMTYPE aItem = m_aFactory.create (thisAsT ());
    if (aItem == null)
      throw new IllegalStateException ("null item created!");
    aItem.setData (aData);
    internalAddChild (aItem);
    return aItem;
  }
787406
protected AstNode parseCreateIndex( DdlTokenStream tokens,
                                        AstNode parentNode ) throws ParsingException {
        assert tokens != null;
        assert parentNode != null;

        markStartOfStatement(tokens);
        // CREATE [UNIQUE] INDEX index-Name
        // ON table-Name ( Simple-column-Name [ ASC | DESC ] [ , Simple-column-Name [ ASC | DESC ]] * )
        tokens.consume(CREATE); // CREATE

        boolean isUnique = tokens.canConsume("UNIQUE");

        tokens.consume("INDEX");
        String indexName = parseName(tokens);
        tokens.consume("ON");
        String tableName = parseName(tokens);

        AstNode indexNode = nodeFactory().node(indexName, parentNode, TYPE_CREATE_INDEX_STATEMENT);

        indexNode.setProperty(UNIQUE_INDEX, isUnique);
        indexNode.setProperty(TABLE_NAME, tableName);

        parseIndexTableColumns(tokens, indexNode);

        parseUntilTerminator(tokens);

        markEndOfStatement(tokens, indexNode);

        return indexNode;
    }
621314
protected List<NodeData> getDirectChildNodesData(NodeData parent, List<QPathEntryFilter> itemDataFilters)
      throws RepositoryException, IllegalStateException
   {
      checkIfOpened();
      if (itemDataFilters.isEmpty())
      {
         return new ArrayList<NodeData>();
      }

      List<NodeData> children = new ArrayList<NodeData>();
      for (Iterator<QPathEntryFilter> it = itemDataFilters.iterator(); it.hasNext(); )
      {
         QPathEntryFilter filter = it.next();
         if (filter.isExactName())
         {
            NodeData data = (NodeData)getItemData(parent, filter.getQPathEntry(), ItemType.NODE);
            if (data != null)
            {
               children.add(data);
            }
            it.remove();
         }
      }
      if (!itemDataFilters.isEmpty())
      {
         children.addAll(getChildNodesDataInternal(parent, itemDataFilters));
      }
      return children;
   }