Build the prefetch criteria

@param ids Collection of identities of M side
@param fkCol indirection table fks to this class
@param itemFkCol indirection table fks to item class
@param itemPkField
@return the Criteria
484727
private Criteria buildPrefetchCriteriaSingleKey(Collection ids, String fkCol, String itemFkCol,
            FieldDescriptor itemPkField)
    {
        Criteria crit = new Criteria();
        ArrayList values = new ArrayList(ids.size());
        Iterator iter = ids.iterator();
        Identity id;

        while (iter.hasNext())
        {
            id = (Identity) iter.next();
            values.add(id.getPrimaryKeyValues()[0]);
        }

        switch (values.size())
        {
            case 0 :
                break;
            case 1 :
                crit.addEqualTo(fkCol, values.get(0));
                break;
            default :
                // create IN (...) for the single key field
                crit.addIn(fkCol, values);
                break;
        }

        crit.addEqualToField(itemPkField.getAttributeName(), itemFkCol);

        return crit;
    }
1019981
@Override
    public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName,
            Object columnValue, Class entityClazz)
    {
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz);

        List<Object> primaryKeys = new ArrayList<Object>();

        DBCollection dbCollection = mongoDb.getCollection(tableName);
        BasicDBObject query = new BasicDBObject();

        query.put(columnName, MongoDBUtils.populateValue(columnValue, columnValue.getClass()));

        DBCursor cursor = dbCollection.find(query);
        KunderaCoreUtils.printQuery("Find id by column:" + query, showQuery);
        DBObject fetchedDocument = null;

        while (cursor.hasNext())
        {
            fetchedDocument = cursor.next();
            Object primaryKey = fetchedDocument.get(pKeyName);
            primaryKey = MongoDBUtils.getTranslatedObject(primaryKey, primaryKey.getClass(), metadata.getIdAttribute()
                    .getJavaType());
            primaryKeys.add(primaryKey);
        }

        if (primaryKeys != null && !primaryKeys.isEmpty())
        {
            return primaryKeys.toArray(new Object[0]);
        }
        return null;

    }
1214455
public void fillGroupItem(Item item, CmsGroup group, List<CmsGroup> indirects) {

        item.getItemProperty(TableProperty.Name).setValue(group.getName());
        item.getItemProperty(TableProperty.Description).setValue(group.getDescription(A_CmsUI.get().getLocale()));
        item.getItemProperty(TableProperty.OU).setValue(group.getOuFqn());
        if (indirects.contains(group)) {
            item.getItemProperty(TableProperty.INDIRECT).setValue(Boolean.TRUE);
        }
    }
750102
private void prefetchRelationships(Query query)
    {
        List prefetchedRel;
        Collection owners;
        String relName;
        RelationshipPrefetcher[] prefetchers;

        if (query == null || query.getPrefetchedRelationships() == null || query.getPrefetchedRelationships().isEmpty())
        {
            return;
        }

        if (!supportsAdvancedJDBCCursorControl())
        {
            logger.info("prefetching relationships requires JDBC level 2.0");
            return;
        }

        // prevent releasing of DBResources
        setInBatchedMode(true);

        prefetchedRel = query.getPrefetchedRelationships();
        prefetchers = new RelationshipPrefetcher[prefetchedRel.size()];

        // disable auto retrieve for all prefetched relationships
        for (int i = 0; i < prefetchedRel.size(); i++)
        {
            relName = (String) prefetchedRel.get(i);
            prefetchers[i] = getBroker().getRelationshipPrefetcherFactory()
                    .createRelationshipPrefetcher(getQueryObject().getClassDescriptor(), relName);
            prefetchers[i].prepareRelationshipSettings();
        }

        // materialize ALL owners of this Iterator
        owners = getOwnerObjects();

        // prefetch relationships and associate with owners
        for (int i = 0; i < prefetchedRel.size(); i++)
        {
            prefetchers[i].prefetchRelationship(owners);
        }

        // reset auto retrieve for all prefetched relationships
        for (int i = 0; i < prefetchedRel.size(); i++)
        {
            prefetchers[i].restoreRelationshipSettings();
        }

        try
        {
            getRsAndStmt().m_rs.beforeFirst(); // reposition resultset jdbc 2.0
        }
        catch (SQLException e)
        {
            logger.error("beforeFirst failed !", e);
        }

        setInBatchedMode(false);
        setHasCalledCheck(false);
    }
824181
public void addFkToItemClass(String column)
    {
        if (fksToItemClass == null)
        {
            fksToItemClass = new Vector();
        }
        fksToItemClass.add(column);
        fksToItemClassAry = null;
    }
542315
public Query getPKQuery(Identity oid)
    {
        Object[] values = oid.getPrimaryKeyValues();
        ClassDescriptor cld = pb.getClassDescriptor(oid.getObjectsTopLevelClass());
        FieldDescriptor[] fields = cld.getPkFields();
        Criteria criteria = new Criteria();

        for (int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fld = fields[i];
            criteria.addEqualTo(fld.getAttributeName(), values[i]);
        }
        return QueryFactory.newQuery(cld.getClassOfObject(), criteria);
    }
1126467
def get_relationship_targets(item_ids, relationships, id2rec):
    """"""
    # Requirements to use this function:
    #     1) item Terms must have been loaded with 'relationships'
    #     2) item IDs in 'item_ids' arguement must be present in id2rec
    #     3) Arg, 'relationships' must be True or an iterable
    reltgt_objs_all = set()
    for goid in item_ids:
        obj = id2rec[goid]
        for reltype, reltgt_objs_cur in obj.relationship.items():
            if relationships is True or reltype in relationships:
                reltgt_objs_all.update(reltgt_objs_cur)
    return reltgt_objs_all
174899
public List getMtoNImplementor(CollectionDescriptor cod, Object obj)
    {
        ResultSetAndStatement rs = null;
        ArrayList result = new ArrayList();
        ClassDescriptor cld = pb.getDescriptorRepository().getDescriptorFor(obj.getClass());
        ValueContainer[] pkValues = pb.serviceBrokerHelper().getKeyValues(cld, obj);
        String[] pkColumns = cod.getFksToThisClass();
        String[] fkColumns = cod.getFksToItemClass();
        String table = cod.getIndirectionTable();

        String selectStmt = pb.serviceSqlGenerator().getSelectMNStatement(table, fkColumns, pkColumns);

        ClassDescriptor itemCLD = pb.getDescriptorRepository().getDescriptorFor(cod.getItemClass());
        Collection extents = pb.getDescriptorRepository().getAllConcreteSubclassDescriptors(itemCLD);
        if(extents.size() > 0)
        {
            itemCLD = (ClassDescriptor) extents.iterator().next();
        }
        FieldDescriptor[] itemClassPKFields = itemCLD.getPkFields();
        if(itemClassPKFields.length != fkColumns.length)
        {
            throw new PersistenceBrokerException("All pk fields of the element-class need to" +
                    " be declared in the indirection table. Element class is "
                    + itemCLD.getClassNameOfObject() + " with " + itemClassPKFields.length + " pk-fields." +
                    " Declared 'fk-pointing-to-element-class' elements in collection-descriptor are"
                    + fkColumns.length);
        }
        try
        {
            rs = pb.serviceJdbcAccess().executeSQL(selectStmt, cld, pkValues, Query.NOT_SCROLLABLE);
            while(rs.m_rs.next())
            {
                ValueContainer[] row = new ValueContainer[fkColumns.length];
                for(int i = 0; i < row.length; i++)
                {
                    row[i] = new ValueContainer(rs.m_rs.getObject(i + 1), itemClassPKFields[i].getJdbcType());
                }
                result.add(new MtoNBroker.Key(row));
            }
        }
        catch(PersistenceBrokerException e)
        {
            throw e;
        }
        catch(SQLException e)
        {
            throw new PersistenceBrokerSQLException(e);
        }
        finally
        {
            if(rs != null) rs.close();
        }
        return result;
    }
6131
public static function selectByIds($ids, array $options = [], array $criteria = [])
    {
        $criteria = static::cleanCriteria($criteria);
        if (empty($criteria)) {
            $criteria['select'] = ['*'];
        }

        if (is_array($ids)) {
            $ids = implode(',', $ids);
        }

        $pk = static::getPrimaryKeyStatic();
        if (!empty($ids)) {
            $idsPhrase = " $pk IN ($ids) ";

            $condition = array_get($criteria, 'condition');

            if (!empty($condition)) {
                $condition .= ' AND ' . $idsPhrase;
            } else {
                $condition = $idsPhrase;
            }

            $criteria['condition'] = $condition;
        }

        $data = static::selectByRequest($criteria, $options);

        $data = static::cleanResult($data, array_get($criteria, 'select'));
        if (!is_array($ids)) {
            $ids = explode(',', $ids);
        }
        if (count($data) != count($ids)) {
            $out = [];
            $continue = array_get_bool($options, ApiOptions::CONTINUES);
            foreach ($ids as $index => $id) {
                $found = false;
                foreach ($data as $record) {
                    if ($id == array_get($record, $pk)) {
                        $out[$index] = $record;
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    $out[$index] = new NotFoundException("Record with identifier '$id' not found.");
                    if (!$continue) {
                        break;
                    }
                }
            }

            throw new BatchException($out, 'Batch Error: Not all requested records could be retrieved.');
        }

        return $data;
    }
760376
public void setIndexForItems(final Map<String, Integer> columnLabelIndexMap) {
        setIndexForAggregationItem(columnLabelIndexMap);
        setIndexForOrderItem(columnLabelIndexMap, orderByItems);
        setIndexForOrderItem(columnLabelIndexMap, groupByItems);
    }
897196
def prefetchDeclarativeIds(self, Declarative, count) -> Deferred:
        
        return self._dbConn.prefetchDeclarativeIds(Declarative=Declarative, count=count)
157715
@Override
    public java.util.concurrent.Future<BatchGetItemResult> batchGetItemAsync(java.util.Map<String, KeysAndAttributes> requestItems,
            String returnConsumedCapacity) {

        return batchGetItemAsync(new BatchGetItemRequest().withRequestItems(requestItems).withReturnConsumedCapacity(returnConsumedCapacity));
    }
157793
@Override
    public <E> List<E> getColumnsById(String schemaName, String joinTableName, String joinColumnName,
            String inverseJoinColumnName, Object parentId, Class columnJavaType)
    {
        List<E> foreignKeys = new ArrayList<E>();

        DBCollection dbCollection = mongoDb.getCollection(joinTableName);
        BasicDBObject query = new BasicDBObject();

        query.put(joinColumnName, MongoDBUtils.populateValue(parentId, parentId.getClass()));
        KunderaCoreUtils.printQuery("Find by Id:" + query, showQuery);
        DBCursor cursor = dbCollection.find(query);
        DBObject fetchedDocument = null;

        while (cursor.hasNext())
        {
            fetchedDocument = cursor.next();
            Object foreignKey = fetchedDocument.get(inverseJoinColumnName);
            foreignKey = MongoDBUtils.getTranslatedObject(foreignKey, foreignKey.getClass(), columnJavaType);
            foreignKeys.add((E) foreignKey);
        }
        return foreignKeys;
    }
124290
public CreateCollectionRequestBuilder<T,ID> create(List<T> items)
    {
        return new CreateCollectionRequestBuilder<T,ID>(version,type,entityName,items);
    }
1098746
private Criteria buildPrefetchCriteria(Collection ids, String[] fkCols, String[] itemFkCols,
            FieldDescriptor[] itemPkFields)
    {
        if (fkCols.length == 1 && itemFkCols.length == 1)
        {
            return buildPrefetchCriteriaSingleKey(ids, fkCols[0], itemFkCols[0], itemPkFields[0]);
        }
        else
        {
            return buildPrefetchCriteriaMultipleKeys(ids, fkCols, itemFkCols, itemPkFields);
        }

    }
685090
public <T> T queryColumns(K key, List<N> columns,
      ColumnFamilyRowMapper<K, N, T> mapper) {
    HSlicePredicate<N> predicate = new HSlicePredicate<N>(topSerializer);
    predicate.setColumnNames(columns);        
    return doExecuteSlice(key, predicate, mapper);
  }
572757
@Override
    public <E> List<E> getColumnsById(String schemaName, String joinTableName, String joinColumnName,
            String inverseJoinColumnName, Object parentId, Class columnJavaType)
    {
        List<Object> foreignKeys = new ArrayList<Object>();

        if (getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0))
        {
            foreignKeys = getColumnsByIdUsingCql(schemaName, joinTableName, joinColumnName, inverseJoinColumnName,
                    parentId, columnJavaType);
        }
        else
        {
            Selector selector = clientFactory.getSelector(pool);

            List<Column> columns = selector.getColumnsFromRow(joinTableName,
                    Bytes.fromByteArray(PropertyAccessorHelper.getBytes(parentId)),
                    Selector.newColumnsPredicateAll(true, 10), getConsistencyLevel());

            foreignKeys = dataHandler.getForeignKeysFromJoinTable(inverseJoinColumnName, columns, columnJavaType);

            if (log.isInfoEnabled())
            {
                log.info("Returning number of keys from join table", foreignKeys != null ? foreignKeys.size() : null);
            }
        }
        return (List<E>) foreignKeys;
    }