Parses and translates query into HBase filter and invokes client's method
to return list of entities.

@param m
Entity metadata
@param client
hbase client
@return list of entities.
335281
private void onQuery(EntityMetadata m, Client client)
    {

        try
        {
            // Called only in case of standalone entity.
            FilterList filter = null;
            if (translator.getFilter() != null)
            {
                filter = new FilterList(translator.getFilter());
            }
            String[] columnAsArr = getColumnsAsArray();

            if (isFindKeyOnly(m, columnAsArr))
            {
                this.handler.setFilter(new KeyOnlyFilter());
            }

            if (filter == null && columns != null)
            {
                handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                        translator.getEndRow(), columnAsArr, null);
            }
            if (MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata()))
            {
                if (filter == null)
                {
                    // means complete scan without where clause, scan all
                    // records.
                    // findAll.
                    if (translator.isRangeScan())
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                                translator.getEndRow(), columnAsArr, null);
                    }
                    else
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, null, null, columnAsArr, null);
                    }
                }
                else
                {
                    // means WHERE clause is present.
                    if (translator.isRangeScan())
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                                translator.getEndRow(), columnAsArr, filter);
                    }
                    else
                    {
                        // if range query. means query over id column. create
                        // range
                        // scan method.

                        handler.readData(m.getSchema(), entityMetadata.getEntityClazz(), entityMetadata, null,
                                m.getRelationNames(), filter, columnAsArr);
                    }
                }
            }
        }
        catch (IOException ioex)
        {
            log.error("Error while executing query{} , Caused by:", ioex);
            throw new QueryHandlerException("Error while executing , Caused by:", ioex);
        }
    }
1032611
public Object next(EntityMetadata m, List<Map<String, Object>> columnsToOutput)
    {
        Object entity = null;
        HBaseDataWrapper result = ((HBaseReader) hbaseReader).next();
        List<HBaseDataWrapper> results = new ArrayList<HBaseDataWrapper>();
        results.add(result);
        try
        {
            List output = onRead(m, columnsToOutput,
                    gethTable(HBaseUtils.getHTableName(m.getSchema(), m.getTableName())), results);
            return output != null && !output.isEmpty() ? output.get(0) : output;
        }
        catch (IOException e)
        {
            logger.error("Error during finding next record, Caused by: .", e);
            throw new KunderaException(e);
        }
    }
146672
private List<?> populateEntityObjectsList(DataFrame dataFrame, EntityMetadata m)
    {
        List results = new ArrayList();
        String[] columns = dataFrame.columns();
        Map<String, Integer> map = createMapOfColumnIndex(columns);
        for (Row row : dataFrame.collectAsList())
        {
            Object entity = populateEntityFromDataFrame(m, map, row);
            results.add(entity);
        }
        return results;
    }
1010837
public static List<Audit> findByEntity(EntityManager em, JPAEntity entity) {
        return findByEntity(em, entity, null);
    }
251748
@GetMapping("/sp/{client}/metadata")
    public ResponseEntity<String> getServiceProviderMetadataByName(@PathVariable("client") final String client) {
        val saml2Client = (SAML2Client) builtClients.findClient(client);
        if (saml2Client != null) {
            return getSaml2ClientServiceProviderMetadataResponseEntity(saml2Client);
        }
        return getNotAcceptableResponseEntity();
    }
180782
@Override
    protected List<E> populateEntities(EntityMetadata m, Client client) throws Exception
    {
        int count = 0;
        List results = new ArrayList();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                m.getPersistenceUnit());
        EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz());
        Map<String, Object> relationalValues = new HashMap<String, Object>();
        if (rSet == null)
        {
            String parsedQuery = query.onQueryOverCQL3(m, client, metaModel, null);
            Statement statement = new SimpleStatement(parsedQuery);
            statement.setFetchSize(fetchSize);
            rSet = ((DSClient) client).executeStatement(statement);
            rowIter = rSet.iterator();
        }
        while (rowIter.hasNext() && count++ < fetchSize)
        {
            Object entity = null;
            Row row = rowIter.next();
            ((DSClient) client).populateObjectFromRow(entityMetadata, metaModel, entityType, results, relationalValues,
                    entity, row);
        }
        return results;
    }
903914
@Override
    protected List populateEntities(EntityMetadata m, Client client)
    {
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();
        try
        {
            String query = appMetadata.getQuery(getJPAQuery());
            if (kunderaQuery.isNative())
            {
                // Native Query Support is enabled
                kunderaQuery.setAggregated(isAggregatedQuery());
                return ((SparkClient) client).executeQuery(query == null ? getJPAQuery() : query, m, kunderaQuery);
            }
        }
        catch (Exception e)
        {

            logger.error("Error during executing query, Caused by:", e);
            throw new QueryHandlerException(e);
        }
        return null;
    }
887755
public List<?> getList(PMContext ctx) throws PMException {
        final EntityFilter filter = (ctx != null && this.equals(ctx.getEntity())) ? ctx.getEntityContainer().getFilter() : null;
        return getList(ctx, filter, null, null, null);
    }
885561
static public List<ColumnMetaData> createList(ResultSetMetaData m) throws SQLException{
		List<ColumnMetaData> result = new ArrayList<ColumnMetaData>(m.getColumnCount());
		for (int i = 1; i <= m.getColumnCount(); i ++){
			ColumnMetaData cm = new ColumnMetaData(m, i);
			result.add(cm);
		}
		return result;
	}
1181511
public Object next(EntityMetadata m, List<Map<String, Object>> columnsToOutput)
    {
        return ((HBaseDataHandler) handler).next(m, columnsToOutput);
    }
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;
    }
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);
        }
    }
517681
private List<HBaseCell> getRelationCell(EntityMetadata m, Object rowId, List<RelationHolder> relations)
            throws IOException
    {
        List<HBaseCell> relationCells = new ArrayList<HBaseCell>();
        for (RelationHolder relation : relations)
        {
            HBaseCell hBaseCell = new HBaseCell(m.getTableName(), relation.getRelationName(),
                    relation.getRelationValue());
            relationCells.add(hBaseCell);
        }
        return relationCells;
    }
753292
@Override
    public Map<String, DbColumnType> getQueryMetadata(Expression query) throws DatabaseEngineException {
        final String queryString = translate(query);
        logger.trace(queryString);
        return getQueryMetadata(queryString);
    }
71764
public List find(String nativeQuery, List<String> relations, EntityMetadata m)
    {
        List entities = new ArrayList();

        s = getStatelessSession();

        SQLQuery q = s.createSQLQuery(nativeQuery);
        q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

        List result = q.list();

        try
        {
            MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                    m.getPersistenceUnit());

            EntityType entityType = metaModel.entity(m.getEntityClazz());

            List<AbstractManagedType> subManagedType = ((AbstractManagedType) entityType).getSubManagedType();
            for (Object o : result)
            {
                Map<String, Object> relationValue = null;
                Object entity = null;
                EntityMetadata subEntityMetadata = null;
                if (!subManagedType.isEmpty())
                {
                    for (AbstractManagedType subEntity : subManagedType)
                    {
                        String discColumn = subEntity.getDiscriminatorColumn();
                        String disColValue = subEntity.getDiscriminatorValue();
                        Object value = ((Map<String, Object>) o).get(discColumn);
                        if (value != null && value.toString().equals(disColValue))
                        {
                            subEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                                    subEntity.getJavaType());
                            break;
                        }
                    }
                    entity = instantiateEntity(subEntityMetadata.getEntityClazz(), entity);
                    relationValue = HibernateUtils.getTranslatedObject(kunderaMetadata, entity,
                            (Map<String, Object>) o, m);

                }
                else
                {
                    entity = instantiateEntity(m.getEntityClazz(), entity);
                    relationValue = HibernateUtils.getTranslatedObject(kunderaMetadata, entity,
                            (Map<String, Object>) o, m);
                }

                if (relationValue != null && !relationValue.isEmpty())
                {
                    entity = new EnhanceEntity(entity, PropertyAccessorHelper.getId(entity, m), relationValue);
                }
                entities.add(entity);
            }
            return entities;
        }
        catch (Exception e)
        {
            if (e.getMessage().equals("Can not be translated into entity."))
            {
                return result;
            }
            throw new EntityReaderException(e);
        }
    }
455837
public static List<ModelServiceInstance> filter(ServiceInstanceQuery query, List<ModelServiceInstance> list) {

        List<ModelServiceInstance> instances = new ArrayList<ModelServiceInstance>();
        for (ModelServiceInstance instance : list) {
            boolean passed = true;
            for (QueryCriterion criterion : query.getCriteria()) {
                if (criterion.isMatch(instance.getMetadata()) == false) {
                    passed = false;
                    break;
                }
            }
            if (passed) {
                instances.add(instance);
            }
        }
        return instances;

    }
470869
public List<?> getList(PMContext ctx, EntityFilter filter) throws PMException {
        return getList(ctx, filter, null, null, null);
    }