Example usage for javax.persistence.metamodel EmbeddableType getAttribute

List of usage examples for javax.persistence.metamodel EmbeddableType getAttribute

Introduction

In this page you can find the example usage for javax.persistence.metamodel EmbeddableType getAttribute.

Prototype

Attribute<? super X, ?> getAttribute(String name);

Source Link

Document

Return the attribute of the managed type that corresponds to the specified name.

Usage

From source file:com.impetus.kundera.utils.KunderaCoreUtils.java

private static void prepareLuceneQueryForPartitionKey(LuceneQueryBuilder queryBuilder, Object key,
        MetamodelImpl metaModel, String indexName, Class valueClazz) {
    Field[] fields = key.getClass().getDeclaredFields();
    EmbeddableType embeddable = metaModel.embeddable(key.getClass());
    boolean appendAnd = false;

    try {//from ww  w .j  a  va2 s . c o  m
        for (int i = 0; i < fields.length; i++) {
            if (!ReflectUtils.isTransientOrStatic(fields[i])) {
                if (metaModel.isEmbeddable(((AbstractAttribute) embeddable.getAttribute(fields[i].getName()))
                        .getBindableJavaType())) {
                    fields[i].setAccessible(true);
                    prepareLuceneQueryForPartitionKey(queryBuilder, fields[i].get(key), metaModel, indexName,
                            valueClazz);
                } else {
                    if (appendAnd) {
                        queryBuilder.buildQuery("AND", "AND", String.class);
                    }
                    appendAnd = true;
                    String fieldValue = PropertyAccessorHelper.getString(key, fields[i]);
                    fieldValue = fieldValue.replaceAll("[^a-zA-Z0-9]", "_");
                    queryBuilder.appendIndexName(indexName).appendPropertyName(fields[i].getName())
                            .buildQuery("=", fieldValue, valueClazz);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        logger.error("Error during prepare composite key, Caused by {}.", e);
        throw new PersistenceException(e);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    }
}

From source file:com.impetus.kundera.utils.KunderaCoreUtils.java

/**
 * Prepares composite key as a lucene key.
 * /*ww  w. jav a2  s.  com*/
 * @param m
 *            entity metadata
 * @param metaModel
 *            meta model.
 * @param compositeKey
 *            composite key instance
 * @return redis key
 */
public static String prepareCompositeKey(final SingularAttribute attribute, final MetamodelImpl metaModel,
        final Object compositeKey) {
    Field[] fields = attribute.getBindableJavaType().getDeclaredFields();
    EmbeddableType embeddable = metaModel.embeddable(attribute.getBindableJavaType());
    StringBuilder stringBuilder = new StringBuilder();

    try {
        for (Field f : fields) {
            if (!ReflectUtils.isTransientOrStatic(f)) {
                if (metaModel.isEmbeddable(
                        ((AbstractAttribute) embeddable.getAttribute(f.getName())).getBindableJavaType())) {
                    f.setAccessible(true);
                    stringBuilder.append(
                            prepareCompositeKey((SingularAttribute) embeddable.getAttribute(f.getName()),
                                    metaModel, f.get(compositeKey)))
                            .append(LUCENE_COMPOSITE_KEY_SEPERATOR);
                } else {
                    String fieldValue = PropertyAccessorHelper.getString(compositeKey, f);
                    fieldValue = fieldValue.replaceAll("[^a-zA-Z0-9]", "_");

                    stringBuilder.append(fieldValue);
                    stringBuilder.append(LUCENE_COMPOSITE_KEY_SEPERATOR);
                }
            }
        }
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    } catch (IllegalArgumentException e) {
        logger.error("Error during prepare composite key, Caused by {}.", e);
        throw new PersistenceException(e);
    }

    if (stringBuilder.length() > 0) {
        stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(LUCENE_COMPOSITE_KEY_SEPERATOR));
    }
    return stringBuilder.toString();
}

From source file:com.impetus.client.rdbms.query.RDBMSEntityReader.java

/**
 * // ww w  .j  av  a  2  s  .  c o m
 * @param entityMetadata
 * @param primaryKeys
 * @param aliasName
 * @param queryBuilder
 * @param entityType
 */
private void onCondition(EntityMetadata entityMetadata, MetamodelImpl metamodel, Set<String> primaryKeys,
        String aliasName, StringBuilder queryBuilder, EntityType entityType) {
    if (primaryKeys == null) {
        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);
                    String embeddedColumnName = propertyName.substring(indexOf + 1, propertyName.length());
                    String fieldName = entityMetadata.getFieldName(jpaColumnName);
                    Attribute attribute = entityType.getAttribute(fieldName);
                    EmbeddableType embeddedType = metamodel
                            .embeddable(((AbstractAttribute) attribute).getBindableJavaType());
                    Attribute embeddedAttribute = embeddedType.getAttribute(embeddedColumnName);

                    addClause(entityMetadata, aliasName, queryBuilder, entityType, value, condition, fieldName,
                            embeddedAttribute);
                } else {
                    String fieldName = entityMetadata.getFieldName(propertyName);
                    Attribute attribute = entityType.getAttribute(fieldName);
                    if (metamodel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) {
                        EmbeddableType embeddedType = metamodel
                                .embeddable(((AbstractAttribute) attribute).getBindableJavaType());
                        Set<Attribute> attributes = embeddedType.getAttributes();
                        for (Attribute embeddedAttribute : attributes) {
                            Object embeddedAttributevalue = PropertyAccessorHelper.getObject(value,
                                    (Field) embeddedAttribute.getJavaMember());
                            addClause(entityMetadata, aliasName, queryBuilder, entityType,
                                    embeddedAttributevalue, condition, propertyName, embeddedAttribute);
                            queryBuilder.append(" and ");
                        }

                        queryBuilder.delete(queryBuilder.lastIndexOf("and"),
                                queryBuilder.lastIndexOf("and") + 3);
                    } else if (((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName()
                            .equals(propertyName)) {
                        addClause(entityMetadata, aliasName, queryBuilder, entityType, value, condition,
                                propertyName, entityMetadata.getIdAttribute());
                    } else {
                        addClause(entityMetadata, aliasName, queryBuilder, entityType, value, condition,
                                propertyName, attribute);
                    }
                }
            } else {
                queryBuilder.append(" ");
                queryBuilder.append(o);
                queryBuilder.append(" ");
            }
        }
    } else {
        queryBuilder.append(aliasName);
        queryBuilder.append(".");
        queryBuilder.append(((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName());
        queryBuilder.append(" ");
        queryBuilder.append("IN(");
        int count = 0;
        Attribute col = entityMetadata.getIdAttribute();
        boolean isString = isStringProperty(entityType, col);
        for (String key : primaryKeys) {
            appendStringPrefix(queryBuilder, isString);
            queryBuilder.append(key);
            appendStringPrefix(queryBuilder, isString);
            if (++count != primaryKeys.size()) {
                queryBuilder.append(",");
            } else {
                queryBuilder.append(")");
            }
        }
    }
}

From source file:com.impetus.client.kudu.schemamanager.KuduDBSchemaManager.java

private void addPrimaryKeyColumnsFromEmbeddable(List<ColumnSchema> columns, EmbeddableType embeddable,
        Field[] fields, MetamodelImpl metaModel) {
    for (Field f : fields) {
        if (!ReflectUtils.isTransientOrStatic(f)) {
            if (f.getType().isAnnotationPresent(Embeddable.class)) {
                // nested
                addPrimaryKeyColumnsFromEmbeddable(columns, (EmbeddableType) metaModel.embeddable(f.getType()),
                        f.getType().getDeclaredFields(), metaModel);
            } else {
                Attribute attribute = embeddable.getAttribute(f.getName());
                columns.add(//from   w  ww. j av a 2s.c  o m
                        new ColumnSchema.ColumnSchemaBuilder(((AbstractAttribute) attribute).getJPAColumnName(),
                                KuduDBValidationClassMapper.getValidTypeForClass(f.getType())).key(true)
                                        .build());
            }
        }
    }

}

From source file:com.impetus.client.cassandra.query.ResultIterator.java

/**
 * Id value in byte arr.//from   w  w  w.  j  a  va2s.c  om
 * 
 * @return the byte[]
 */
private byte[] idValueInByteArr() {
    Object entity = results.get(results.size() - 1);
    Object id = PropertyAccessorHelper.getId(entity, entityMetadata);
    String idName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();
    Class idClazz = ((AbstractAttribute) entityMetadata.getIdAttribute()).getBindableJavaType();
    MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
            .getMetamodel(entityMetadata.getPersistenceUnit());

    EmbeddableType keyObj = null;
    ByteBuffer bytes = null;

    // if the key attribute is composite
    if (metaModel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType())) {
        keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
        Field embeddedField = getPartitionKeyField();
        Attribute partitionKey = keyObj.getAttribute(embeddedField.getName());
        Object partitionKeyValue = PropertyAccessorHelper.getObject(id, (Field) partitionKey.getJavaMember());
        bytes = CassandraUtilities.toBytes(partitionKeyValue, (Field) partitionKey.getJavaMember());
    } else {
        bytes = query.getBytesValue(idName, entityMetadata, id);
    }
    return bytes.array();
}

From source file:com.impetus.client.cassandra.query.ResultIterator.java

/**
 * Parse and append cql3 token function for iter.next() call.
 * /*from   w  ww.  j a va  2s.co  m*/
 * @param translator
 *            cql translator.
 * @param query
 *            the query
 * @return parsed/append cql3 query.
 */
private String prepareNext(CQLTranslator translator, String query) {
    if (checkOnEmptyResult()) {
        String idName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();
        Map<Boolean, String> filterOnId = getConditionOnIdColumn(idName);

        if (filterOnId.get(true) != null) {
            String condition = filterOnId.get(true);
            // means id clause present in query.
            // now if id attribute is embeddable then fetch partition key
            // for token
            // if condition is with equals then no need to go for another
            // fetch.

            if (condition.equals("=")) {
                // no need to fetch another record, as there will be only
                // one
                return null;
            } else if (condition.endsWith(">") || condition.equals(">=")) {
                query = replaceAppliedToken(query);
                return query;
            }
        }

        // Means there is an previous entity.
        Object entity = results.get(results.size() - 1);
        Class idClazz = ((AbstractAttribute) entityMetadata.getIdAttribute()).getBindableJavaType();
        Object id = PropertyAccessorHelper.getId(entity, entityMetadata);
        StringBuilder builder = new StringBuilder(CQLTranslator.TOKEN);
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(entityMetadata.getPersistenceUnit());

        EmbeddableType keyObj = null;
        // Bytes bytes = null;
        String columnName = null;
        if (metaModel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType())) {
            keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
            Field embeddedField = getPartitionKeyField();
            Attribute partitionKey = keyObj.getAttribute(embeddedField.getName());
            Object partitionKeyValue = PropertyAccessorHelper.getObject(id,
                    (Field) partitionKey.getJavaMember());
            columnName = ((AbstractAttribute) partitionKey).getJPAColumnName();
            id = partitionKeyValue;
            idClazz = ((AbstractAttribute) partitionKey).getBindableJavaType();
            // StringBuilder pkNameTokens = new StringBuilder("token(");
            // StringBuilder pkValueTokens = new StringBuilder("token(");
            // buildPartitionKeyTokens(metaModel,
            // entityMetadata.getIdAttribute(), id, translator,
            // pkNameTokens,
            // pkValueTokens);

        } else {
            columnName = CassandraUtilities.getIdColumnName(kunderaMetadata, entityMetadata, externalProperties,
                    ((CassandraClientBase) client).isCql3Enabled(entityMetadata));
        }

        translator.appendColumnName(builder, columnName);
        builder.append(CQLTranslator.CLOSE_BRACKET);
        builder.append(" > ");
        builder.append(CQLTranslator.TOKEN);
        translator.appendValue(builder, idClazz, id, false, false);
        builder.append(CQLTranslator.CLOSE_BRACKET);
        return builder.toString();
    }
    return null;
}

From source file:com.impetus.client.cassandra.query.ResultIterator.java

private void buildPartitionKeyTokens(MetamodelImpl metaModel, SingularAttribute idAttribute, Object id,
        CQLTranslator translator, StringBuilder pkNameTokens, StringBuilder pkValueTokens) {
    EmbeddableType keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
    Field embeddedField = getPartitionKeyField();

    if (embeddedField == null) {
        // use tokens on the fields (no clustering keys
        Field[] fields = entityMetadata.getIdAttribute().getBindableJavaType().getDeclaredFields();

        for (Field field : fields) {
            Object value = PropertyAccessorHelper.getObject(id, field);
            String columnName = ((AbstractAttribute) keyObj.getAttribute(field.getName())).getJPAColumnName();
            translator.appendColumnName(pkNameTokens, columnName);
            translator.appendValue(pkValueTokens, field.getType(), value, false, false);
        }/*from   w  w w .j  av a  2s . co  m*/
    } else {
        // use tokens for partition key fields (fields in embeddedField) and
        // where clause for clustering fields
        Attribute partitionKey = keyObj.getAttribute(embeddedField.getName());
        EmbeddableType partitionKeyObj = metaModel.embeddable(partitionKey.getJavaType());
        Object partitionKeyValue = PropertyAccessorHelper.getObject(id, (Field) partitionKey.getJavaMember());
        Field[] fields = partitionKey.getJavaType().getDeclaredFields();
        // handle for part keys
        for (Field field : fields) {
            if (!ReflectUtils.isTransientOrStatic(field)) {
                Object value = PropertyAccessorHelper.getObject(partitionKeyValue, field);
                String columnName = ((AbstractAttribute) partitionKeyObj.getAttribute(field.getName()))
                        .getJPAColumnName();
                translator.appendColumnName(pkNameTokens, columnName);
                translator.appendValue(pkValueTokens, field.getType(), value, false, false);
                pkNameTokens.append(CQLTranslator.COMMA_STR);
                pkValueTokens.append(CQLTranslator.COMMA_STR);
            }
        }
        pkNameTokens.delete(pkNameTokens.lastIndexOf(CQLTranslator.COMMA_STR), pkNameTokens.length());
        pkValueTokens.delete(pkValueTokens.lastIndexOf(CQLTranslator.COMMA_STR), pkValueTokens.length());
        pkNameTokens.append(CQLTranslator.CLOSE_BRACKET);
        pkValueTokens.append(CQLTranslator.CLOSE_BRACKET);

        // TODO: handle for cluster keys
        throw new UnsupportedOperationException(
                "Pagination is not suported via ThriftClient on primary key with clustering keys...");
    }

}

From source file:com.impetus.client.mongodb.query.MongoDBQuery.java

/**
 * Creates MongoDB Query object from filterClauseQueue.
 * //from  w  w  w . j a v  a 2  s  . com
 * @param m
 *            the m
 * @param filterClauseQueue
 *            the filter clause queue
 * @return the basic db object
 */
public BasicDBObject createSubMongoQuery(EntityMetadata m, Queue filterClauseQueue) {
    BasicDBObject query = new BasicDBObject();
    BasicDBObject compositeColumns = new BasicDBObject();

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

    AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(m.getEntityClazz());

    for (Object object : filterClauseQueue) {
        boolean isCompositeColumn = false;

        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 (managedType.hasLobAttribute()) {
                EntityType entity = metaModel.entity(m.getEntityClazz());
                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 = "metadata." + property;
            } else {
                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) {
                    EmbeddableType embeddableType = metaModel
                            .embeddable(m.getIdAttribute().getBindableJavaType());
                    AbstractAttribute attribute = (AbstractAttribute) embeddableType.getAttribute(property);

                    property = new StringBuffer("_id.").append(attribute.getJPAColumnName()).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("<>")) {

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

                }
            }

            // TODO: Add support for other operators like >, <, >=, <=,
            // order by asc/ desc, limit, skip, count etc
        }
    }
    if (!compositeColumns.isEmpty()) {
        query.append("_id", compositeColumns);
    }

    return query;
}

From source file:com.impetus.client.cassandra.query.CassQuery.java

/**
 * Gets the column list.//from   w ww .  j av  a 2  s .c  om
 * 
 * @param m
 *            the m
 * @param metamodel
 *            the metamodel
 * @param results
 *            the results
 * @param compoundKey
 *            the compound key
 * @return the column list
 */
List<String> getColumnList(EntityMetadata m, MetamodelImpl metamodel, String[] results,
        EmbeddableType compoundKey) {
    List<String> columns = new ArrayList<String>();
    if (results != null && results.length > 0) {
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(m.getPersistenceUnit());
        EntityType entity = metaModel.entity(m.getEntityClazz());

        String keyFieldName = CassandraUtilities.getIdColumnName(kunderaMetadata, m, externalProperties,
                ((CassandraClientBase) persistenceDelegeator.getClient(m)).isCql3Enabled(m));
        for (int i = 1; i < results.length; i++) {
            if (results[i] != null) {
                if (results[i].indexOf(".") > 0) {
                    String fieldName = results[i].substring(0, results[i].indexOf("."));
                    String embeddedFieldName = results[i].substring(results[i].indexOf(".") + 1,
                            results[i].length());
                    AbstractAttribute attribute = (AbstractAttribute) entity.getAttribute(fieldName);
                    EmbeddableType embeddable = metamodel.embeddable(attribute.getBindableJavaType());
                    Attribute embeddableAttribute = embeddable.getAttribute(embeddedFieldName);
                    columns.add(((AbstractAttribute) embeddableAttribute).getJPAColumnName());
                } else {
                    Attribute attribute = entity.getAttribute(results[i]);
                    if (attribute == null) {
                        throw new QueryHandlerException("Column type is null for : " + results);
                    } else if (m.getIdAttribute().equals(attribute) && compoundKey != null) {
                        Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields();
                        for (Field field : fields) {
                            if (!ReflectUtils.isTransientOrStatic(field)) {
                                Attribute compositeColumn = compoundKey.getAttribute(field.getName());
                                columns.add(((AbstractAttribute) compositeColumn).getJPAColumnName());
                            }
                        }
                    } else if (m.getIdAttribute().equals(attribute) && compoundKey == null) {
                        columns.add(keyFieldName);
                    } else {
                        columns.add(((AbstractAttribute) attribute).getJPAColumnName());
                    }
                }
            }
        }
        return columns;
    }

    if (log.isInfoEnabled()) {
        log.info("No record found, returning null.");
    }
    return null;
}

From source file:com.impetus.client.cassandra.query.CassQuery.java

/**
 * Extract composite key./*w w w .  jav a 2 s  .c o m*/
 * 
 * @param metaModel
 *            the meta model
 * @param keyObj
 *            the key obj
 * @param builder
 *            the builder
 * @param translator
 *            the translator
 * @param value
 *            the value
 * @param useInClause
 *            the use in clause
 * @param columnValues
 *            the column values
 * @param field
 *            the field
 * @return true, if successful
 */
private boolean extractCompositeKey(MetamodelImpl metaModel, EmbeddableType keyObj, StringBuilder builder,
        CQLTranslator translator, List<Object> value, boolean useInClause,
        Map<Attribute, List<Object>> columnValues, Field field) {
    Attribute compositeColumn = keyObj.getAttribute(field.getName());
    String jpaColumnName = ((AbstractAttribute) compositeColumn).getJPAColumnName();

    if (useInClause) {
        for (Object embeddedObject : value) {

            Object valueObject = PropertyAccessorHelper.getObject(embeddedObject, field);
            // Checking for composite partition key.
            if (metaModel.isEmbeddable(((AbstractAttribute) compositeColumn).getBindableJavaType())) {
                Set<Attribute> attributes = metaModel
                        .embeddable(((AbstractAttribute) compositeColumn).getBindableJavaType())
                        .getAttributes();

                // Iterating over composite partition key columns.
                for (Attribute nestedAttribute : attributes) {
                    List<Object> valueList = columnValues.get(compositeColumn);

                    if (valueList == null) {
                        valueList = new ArrayList<Object>();
                    }

                    Object obj = PropertyAccessorHelper.getObject(valueObject,
                            (Field) nestedAttribute.getJavaMember());
                    valueList.add(obj);
                    columnValues.put(nestedAttribute, valueList);
                }
            } else {
                List<Object> valueList = columnValues.get(compositeColumn);

                if (valueList == null) {
                    valueList = new ArrayList<Object>();
                }
                valueList.add(valueObject);
                columnValues.put(compositeColumn, valueList);
            }
        }
    } else {
        Object valueObject = PropertyAccessorHelper.getObject(value.isEmpty() ? null : value.get(0), field);

        // Checking for composite partition key.
        if (metaModel.isEmbeddable(((AbstractAttribute) compositeColumn).getBindableJavaType())) {
            Set<Attribute> attributes = metaModel
                    .embeddable(((AbstractAttribute) compositeColumn).getBindableJavaType()).getAttributes();

            // Iterating over composite partition key columns.
            for (Attribute nestedAttribute : attributes) {
                String columnName = ((AbstractAttribute) nestedAttribute).getJPAColumnName();
                Object obj = PropertyAccessorHelper.getObject(valueObject,
                        (Field) nestedAttribute.getJavaMember());
                translator.buildWhereClause(builder, nestedAttribute.getJavaType(), columnName, obj,
                        CQLTranslator.EQ_CLAUSE, false);
            }
            // returning true because builder has AND clause at end.
            return true;
        } else {
            translator.buildWhereClause(builder, field.getType(), jpaColumnName, valueObject,
                    CQLTranslator.EQ_CLAUSE, false);
            // returning true because builder has AND clause at end.
            return true;
        }
    }
    // returning false because builder does not have AND clause at end.
    return false;
}