Sort {@link EntityType} collection based on their dependencies.

@param entityTypes entity meta data collection
@return sorted entity meta data collection based on dependencies
186736
public List<EntityType> resolve(Collection<EntityType> entityTypes) {
    if (entityTypes.isEmpty()) {
      return emptyList();
    }
    if (entityTypes.size() == 1) {
      return singletonList(entityTypes.iterator().next());
    }

    // EntityType doesn't have equals/hashcode methods, map to nodes first
    // ensure that nodes exist for all dependencies
    Set<EntityTypeNode> entityTypeNodes =
        entityTypes
            .stream()
            .map(EntityTypeNode::new)
            .flatMap(
                node -> Stream.concat(Stream.of(node), expandEntityTypeDependencies(node).stream()))
            .collect(toCollection(HashSet::new));

    // Sort nodes based on dependencies
    List<EntityTypeNode> resolvedEntityMetaNodes =
        genericDependencyResolver.resolve(entityTypeNodes, getDependencies());
    // Map nodes back to EntityType
    List<EntityType> resolvedEntityMetas =
        resolvedEntityMetaNodes.stream().map(EntityTypeNode::getEntityType).collect(toList());

    // getDependencies might have included items that are not in the input list, remove additional
    // items
    if (resolvedEntityMetas.size() == entityTypes.size()) {
      return resolvedEntityMetas;
    } else {
      Map<String, EntityType> entityTypeMap =
          entityTypes.stream().collect(toMap(EntityType::getId, Function.identity()));
      return resolvedEntityMetas
          .stream()
          .filter(resolvedEntityMeta -> entityTypeMap.containsKey(resolvedEntityMeta.getId()))
          .collect(toList());
    }
  }
116725
public Query orderby(final Collection<? extends Expression> orderbyColumns) {
        if (orderbyColumns == null) {
            return this;
        }

        this.orderbyColumns.addAll(orderbyColumns);

        return this;
    }
465646
public <E> List<E> find(Class<E> entityClass, Object... primaryKeys)
    {
        List<E> entities = new ArrayList<E>();
        if (primaryKeys == null)
        {
            return entities;
        }
        Set<Object> pKeys = new HashSet<Object>(Arrays.asList(primaryKeys));
        for (Object primaryKey : pKeys)
        {
            E e = find(entityClass, primaryKey);
            if (e != null)
            {
                entities.add(e);
            }
        }
        return entities;
    }
110546
private static Collection<Class> scanEntityClasses(String... persistenceXmlFiles) {
        DDLGenerator.Profile profile = new DDLGenerator.Profile(null);
        profile.addPersistenceFile(persistenceXmlFiles);
        return profile.getEntityClasses();
    }
1339184
private List returnEntityObjectList(EntityMetadata m, List<HBaseDataWrapper> results, List outputResults)
    {
        Map<Object, Object> entityListMap = new HashMap<Object, Object>();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        EntityType entityType = metaModel.entity(m.getEntityClazz());
        List<AbstractManagedType> subManagedTypes = ((AbstractManagedType) entityType).getSubManagedType();
        Map<String, Class> discrValueToEntityClazz = new HashMap<String, Class>();
        String discrColumn = null;
        if (subManagedTypes != null && !subManagedTypes.isEmpty())
        {
            for (AbstractManagedType subEntity : subManagedTypes)
            {
                discrColumn = ((AbstractManagedType) subEntity).getDiscriminatorColumn();
                discrValueToEntityClazz.put(subEntity.getDiscriminatorValue(), subEntity.getJavaType());
            }
        }
        for (HBaseDataWrapper data : results)
        {
            Class clazz = null;
            if (discrValueToEntityClazz != null && !discrValueToEntityClazz.isEmpty())
            {
                String discrColumnKey = HBaseUtils.getColumnDataKey(m.getTableName(), discrColumn);
                String discrValue = Bytes.toString(data.getColumnValue(discrColumnKey));
                clazz = discrValueToEntityClazz.get(discrValue);
                m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz);
            }
            else
            {
                clazz = m.getEntityClazz();
            }

            Object entity = KunderaCoreUtils.createNewInstance(clazz); // Entity
            Object rowKeyValue = HBaseUtils.fromBytes(m, metaModel, data.getRowKey());
            if (!metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
            {
                PropertyAccessorHelper.setId(entity, m, rowKeyValue);
            }
            if (entityListMap.get(rowKeyValue) != null)
            {
                entity = entityListMap.get(rowKeyValue);
            }
            entity = populateEntityFromHBaseData(entity, data, m, null);
            if (entity != null)
            {
                entityListMap.put(rowKeyValue, entity);
            }
        }
        for (Object obj : entityListMap.values())
        {
            outputResults.add(obj);
        }
        return outputResults;
    }
602268
public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes) {
        checkNotNull(mediaTypes, "'mediaTypes' must not be null");
        if (mediaTypes.size() > 1) {
            Collections.sort(mediaTypes, Ordering.compound(
                    ImmutableList.of(MediaType.SPECIFICITY_COMPARATOR, MediaType.QUALITY_VALUE_COMPARATOR)));
        }
    }
300561
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException
   {
      EntityCollection ec = new EntityCollection();
      NodeTypeIterator allTypes = getAllNodeTypes();
      while (allTypes.hasNext())
      {
         NodeType type = allTypes.nextNodeType();
         if (!type.isMixin())
         {
            ec.add(type);
         }
      }
      return ec;
   }
675153
public static <T> Query<T> query(Class<T> entityType) {
        Assert.notNull(entityType, "entityType must not null");
        return Ebean.find(entityType);
    }
280270
public function getByIds($entityType, array $ids, array $params = [])
    {
        $validIds = array_values(array_unique(array_filter($ids, [__CLASS__, 'isIdValid'])));

        if (count($validIds) === 0) {
            return [];
        }

        $doSortByIds = empty($params['sort']);
        $results = $this->search($entityType, ['_id' => ['$in' => $validIds]], $params);
        if (!$doSortByIds) {
            return $results;
        }

        $flipped = array_flip($validIds);
        foreach ($results as $result) {
            $flipped[$result['_id']] = $result;
        }
        return array_filter(array_values($flipped), function ($result) {
            return is_array($result) && count($result) > 0;
        });

    }
1157048
function checkEntityTypes(em, entityTypes) {
    assertParam(entityTypes, "entityTypes").isString().isOptional().or().isNonEmptyArray().isString()
        .or().isInstanceOf(EntityType).or().isNonEmptyArray().isInstanceOf(EntityType).check();
    if (typeof entityTypes === "string") {
      entityTypes = em.metadataStore._getEntityType(entityTypes, false);
    } else if (Array.isArray(entityTypes) && typeof entityTypes[0] === "string") {
      entityTypes = entityTypes.map(function (etName) {
        return em.metadataStore._getEntityType(etName, false);
      });
    }
    return entityTypes;
  }
1050269
public <E> List<E> updateWithOptimisticLock(List<E> entities) {
    if (entities == null || entities.isEmpty()) {
      return new ArrayList<>();
    }
    Class<?> entityClass = entities.get(0).getClass();
    PropertyMetadata versionMetadata = EntityIntrospector.getVersionMetadata(entityClass);
    if (versionMetadata == null) {
      return update(entities);
    } else {
      return updateWithOptimisticLockInternal(entities, versionMetadata);
    }
  }
384615
public static Optional<MappingColumn> getVersionMappingColumn(final Class<?> entityType) {
		return Arrays.stream(getMappingColumns(entityType))
				.filter(MappingColumn::isVersion)
				.findFirst();
	}
579813
public void sortTypes(String sortParams) {

        List<CmsResourceTypeBean> types = getSearchTypes();
        SortParams sort = SortParams.valueOf(sortParams);
        switch (sort) {
            case title_asc:
                Collections.sort(types, new CmsComparatorTitle(true));
                break;
            case title_desc:
                Collections.sort(types, new CmsComparatorTitle(false));
                break;
            case type_asc:
                Collections.sort(types, new CmsComparatorType(true));
                break;
            case type_desc:
                Collections.sort(types, new CmsComparatorType(false));
                break;
            case dateLastModified_asc:
            case dateLastModified_desc:
            case path_asc:
            case path_desc:
            case tree:
            default:
                // not supported
                return;
        }
        m_handler.onUpdateTypes(types, m_searchObject.getTypes());
    }
514597
@Override
  public <T> List<T> findAll(Class<T> entityClass) {
    return findAll(Util.determineCollectionName(entityClass));
  }
1213708
static Stream<Attribute> getPersistedAttributes(EntityType entityType) {
    return stream(entityType.getAtomicAttributes())
        .filter(atomicAttr -> atomicAttr.getExpression() == null);
  }
268051
public void assignManagedTypes(Map<Class<?>, EntityType<?>> managedTypes)
    {
        if (this.entityTypes == null)
        {
            this.entityTypes = managedTypes;
        }
        else
        {
            this.entityTypes.putAll(managedTypes);
        }
    }
262171
public List<String> listEntities(final String entityType) throws AtlasServiceException {
        JSONObject jsonResponse = callAPIWithRetries(API.LIST_ENTITIES, null, new ResourceCreator() {
            @Override
            public WebResource createResource() {
                WebResource resource = getResource(API.LIST_ENTITIES);
                resource = resource.queryParam(TYPE, entityType);
                return resource;
            }
        });
        return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
    }