Package com.impetus.kundera.query.KunderaQuery

Examples of com.impetus.kundera.query.KunderaQuery.FilterClause


            boolean isSubCondition = false;

            if (object instanceof FilterClause)
            {
                FilterClause filter = (FilterClause) object;
                String property = filter.getProperty();
                String condition = filter.getCondition();
                Object value = filter.getValue().get(0);

                // value is string but field.getType is different, then get
                // value using

                Field f = null;

                // if alias is still present .. means it is an enclosing
                // document search.

                if (((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(property))
                {
                    property = "_id";
                    f = (Field) m.getIdAttribute().getJavaMember();
                    if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())
                            && value.getClass().isAssignableFrom(f.getType()))
                    {
                        EmbeddableType compoundKey = metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
                        compositeColumns = MongoDBUtils.getCompoundKeyColumns(m, value, compoundKey);
                        isCompositeColumn = true;
                        continue;
                    }
                }
                else if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())
                        && StringUtils.contains(property, '.'))
                {
                    // Means it is a case of composite column.
                    property = property.substring(property.indexOf(".") + 1);
                    isCompositeColumn = true;
                } /*
                   * if a composite key. "." assuming "." is part of property in
                   * case of embeddable only
                   */
                else if (StringUtils.contains(property, '.'))
                {
                    EntityType entity = metaModel.entity(m.getEntityClazz());
                    StringTokenizer tokenizer = new StringTokenizer(property, ".");
                    String embeddedAttributeAsStr = tokenizer.nextToken();
                    String embeddableAttributeAsStr = tokenizer.nextToken();
                    Attribute embeddedAttribute = entity.getAttribute(embeddedAttributeAsStr);
                    EmbeddableType embeddableEntity = metaModel.embeddable(((AbstractAttribute) embeddedAttribute)
                            .getBindableJavaType());
                    f = (Field) embeddableEntity.getAttribute(embeddableAttributeAsStr).getJavaMember();
                    property = ((AbstractAttribute) embeddedAttribute).getJPAColumnName()
                            + "."
                            + ((AbstractAttribute) embeddableEntity.getAttribute(embeddableAttributeAsStr))
                                    .getJPAColumnName();
                }
                else
                {
                    EntityType entity = metaModel.entity(m.getEntityClazz());
                    String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();

                    if (!property.equals(discriminatorColumn))
                    {
                        String fieldName = m.getFieldName(property);
                        f = (Field) entity.getAttribute(fieldName).getJavaMember();
                    }
                }

                if (value.getClass().isAssignableFrom(String.class) && f != null
                        && !f.getType().equals(value.getClass()))
                {
                    value = PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),
                            value.toString());
                }
                value = MongoDBUtils.populateValue(value, value.getClass());

                // Property, if doesn't exist in entity, may be there in a
                // document embedded within it, so we have to check that
                // TODO: Query should actually be in a format
                // documentName.embeddedDocumentName.column, remove below if
                // block once this is decided

                // Query could be geospatial in nature
                if (f != null && f.getType().equals(Point.class))
                {
                    GeospatialQuery geospatialQueryimpl = GeospatialQueryFactory.getGeospatialQueryImplementor(
                            condition, value);
                    query = (BasicDBObject) geospatialQueryimpl.createGeospatialQuery(property, value, query);

                }
                else
                {

                    if (isCompositeColumn)
                    {
                        property = new StringBuffer("_id.").append(property).toString();
                    }
                    if (condition.equals("="))
                    {
                        query.append(property, value);

                    }
                    else if (condition.equalsIgnoreCase("like"))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$regex",
                                    createLikeRegex((String) value)));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$regex", createLikeRegex((String) value)));
                        }

                    }
                    else if (condition.equalsIgnoreCase(">"))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$gt", value));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$gt", value));
                        }
                    }
                    else if (condition.equalsIgnoreCase(">="))
                    {

                        if (query.containsField(property))

                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$gte", value));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$gte", value));
                        }

                    }
                    else if (condition.equalsIgnoreCase("<"))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$lt", value));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$lt", value));
                        }

                    }
                    else if (condition.equalsIgnoreCase("<="))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$lte", value));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$lte", value));
                        }

                    }
                    else if (condition.equalsIgnoreCase("in"))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$in", filter.getValue()));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$in", filter.getValue()));
                        }

                    }
                    else if (condition.equalsIgnoreCase("not in"))
                    {

                        if (query.containsField(property))
                        {
                            query.get(property);
                            query.put(property, ((BasicDBObject) query.get(property)).append("$nin", filter.getValue()));
                        }
                        else
                        {
                            query.append(property, new BasicDBObject("$nin", filter.getValue()));
                        }

                    }
                    else if (condition.equalsIgnoreCase("<>"))
                    {
View Full Code Here


        for (Object o : getKunderaQuery().getFilterClauseQueue())
        {
            if (o instanceof FilterClause)
            {
                FilterClause clause = ((FilterClause) o);
                FilterBuilder currentFilter = getFilter(clause, m, entity);
                if (interFilter != null)
                {
                    if (interFilter.equalsIgnoreCase("and"))
                    {
View Full Code Here

        for (Object object : kunderaQuery.getFilterClauseQueue())
        {
            if (object instanceof FilterClause)
            {
                FilterClause filter = (FilterClause) object;
                String property = filter.getProperty();
                String condition = filter.getCondition();
                String valueAsString = filter.getValue().get(0).toString();
                String fieldName = metadata.getFieldName(property);
                boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
                String idColumn = ((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName();
                valueClazz = getValueType(entity, fieldName);

                if (isEmbeddedId)
                {
                    if (idColumn.equals(property))
                    {
                        valueAsString = prepareCompositeKey(metadata, metaModel, filter.getValue().get(0));
                        queryBuilder.appendIndexName(metadata.getIndexName()).appendPropertyName(idColumn)
                                .buildQuery(condition, valueAsString, valueClazz);
                    }
                    else
                    {
View Full Code Here

        for (Object o : query.getKunderaQuery().getFilterClauseQueue())
        {
            if (o instanceof FilterClause)
            {
                FilterClause clause = ((FilterClause) o);
                String fieldName = clause.getProperty();
                String condition = clause.getCondition();

                if (keyObj != null && fieldName.equals(idColumn)
                        || (keyObj != null && StringUtils.contains(fieldName, '.')) || (idColumn.equals(fieldName)))
                {
                    filterIdResult.put(true, condition);
View Full Code Here

        Queue queue = getKunderaQuery().getFilterClauseQueue();
        KunderaQuery kunderaQuery = getKunderaQuery();

        for (Object primaryKey : primaryKeys)
        {
            FilterClause filterClause = kunderaQuery.new FilterClause(columnName, equals, primaryKey);
            kunderaQuery.setFilter(kunderaQuery.getEntityAlias()+"."+columnName +" = "+primaryKey);
            queue.clear();
            queue.add(filterClause);
            List<Object> object = findUsingLucene(m, client);
            if (object != null && !object.isEmpty())
View Full Code Here

            for (Object object : kunderaQuery.getFilterClauseQueue())
            {
                if (object instanceof FilterClause)
                {
                    boolean appended = false;
                    FilterClause filter = (FilterClause) object;
                    // property
                    sb.append(filter.getProperty());

                    // joiner
                    String appender = "";
                    String condition = filter.getCondition().trim();
                    if (condition.equals("="))
                    {
                        sb.append(":");
                    }
                    else if (condition.equalsIgnoreCase("like"))
                    {
                        sb.append(":");
                        appender = "*";
                    }
                    else if (condition.equalsIgnoreCase(">"))
                    {
                        // TODO: Amresh need to look for "String.class"
                        // parameter.
                        sb.append(appendRange(filter.getValue().get(0).toString(), false, true, String.class));
                        appended = true;
                    }
                    else if (condition.equalsIgnoreCase(">="))
                    {
                        sb.append(appendRange(filter.getValue().get(0).toString(), true, true, String.class));
                        appended = true;
                    }
                    else if (condition.equalsIgnoreCase("<"))
                    {
                        sb.append(appendRange(filter.getValue().get(0).toString(), false, false, String.class));
                        appended = true;
                    }
                    else if (condition.equalsIgnoreCase("<="))
                    {
                        sb.append(appendRange(filter.getValue().get(0).toString(), true, false, String.class));
                        appended = true;
                    }

                    // value. if not already appended.
                    if (!appended)
                    {
                        if (appender.equals("") && filter.getValue() != null
                                && filter.getValue().get(0).toString().contains(" "))
                        {
                            sb.append("\"");
                            sb.append(filter.getValue().get(0).toString());
                            sb.append("\"");
                        }
                        else
                        {
                            sb.append(filter.getValue().get(0));
                            sb.append(appender);
                        }

                    }
                }
View Full Code Here

        {
            for (Object o : conditions)
            {
                if (o instanceof FilterClause)
                {
                    FilterClause clause = ((FilterClause) o);
                    Object value = clause.getValue().get(0);
                    String propertyName = clause.getProperty();
                    String condition = clause.getCondition();

                    if (StringUtils.contains(propertyName, '.'))
                    {
                        int indexOf = propertyName.indexOf(".");
                        String jpaColumnName = propertyName.substring(0, indexOf);
View Full Code Here

            String idColumn = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();
            for (Object o : kunderaQuery.getFilterClauseQueue())
            {
                if (o instanceof FilterClause)
                {
                    FilterClause filterClause = (FilterClause) o;
                    if (!idColumn.equals(filterClause.getProperty())
                            || opsNotAllowed.contains(filterClause.getCondition()))
                    {
                        result = false;
                        break;
                    }
                    result = true;
View Full Code Here

        for (Object o : getKunderaQuery().getFilterClauseQueue())
        {
            if (o instanceof FilterClause)
            {
                FilterClause clause = ((FilterClause) o);
                String fieldName = clause.getProperty();
                // in case id column matches with field name, set it for first
                // time.
                if (!idPresent && idColumn.equalsIgnoreCase(fieldName))
                {
                    idPresent = true;
                }

                String condition = clause.getCondition();
                List<Object> value = clause.getValue();
                if (value != null && value.size() > 1)
                {
                    log.error("IN clause is not enabled for thrift, use cql3.");
                    throw new QueryHandlerException("IN clause is not enabled for thrift, use cql3.");
                }
View Full Code Here

        boolean allowFiltering = false;
        for (Object o : getKunderaQuery().getFilterClauseQueue())
        {
            if (o instanceof FilterClause)
            {
                FilterClause clause = ((FilterClause) o);
                String fieldName = clause.getProperty();
                String condition = clause.getCondition();
                List<Object> value = clause.getValue();
                boolean useInClause = condition.trim().equalsIgnoreCase("IN");

                // if compound key field is given in where clause.
                isPresent = true;
View Full Code Here

TOP

Related Classes of com.impetus.kundera.query.KunderaQuery.FilterClause

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.