Examples of EmbeddableType


Examples of javax.persistence.metamodel.EmbeddableType

                Field columnField = (Field) attrib.getJavaMember();
                if (attrib.getPersistentAttributeType().equals(PersistentAttributeType.EMBEDDED)
                        || attrib.getPersistentAttributeType().equals(PersistentAttributeType.ELEMENT_COLLECTION))
                {
                    EmbeddableType embeddedColumn = metaModel.embeddable(((AbstractAttribute) attrib)
                            .getBindableJavaType());

                    Object sourceEmbeddedObj = PropertyAccessorHelper.getObject(source, columnField);
                    if (sourceEmbeddedObj != null)
                    {
                        if (metaModel.isEmbeddable(((AbstractAttribute) attrib).getBindableJavaType()))
                        {
                            if (attrib.isCollection())
                            {
                                Class<?> ecDeclaredClass = columnField.getType();
                                Class<?> actualEcObjectClass = sourceEmbeddedObj.getClass();

                                Object targetCollectionObject = actualEcObjectClass.newInstance();

                                // Copy element collections for List and Set
                                if (sourceEmbeddedObj instanceof Collection)
                                {
                                    Class<?> genericClass = PropertyAccessorHelper.getGenericClass(columnField);

                                    for (Object sourceEcObj : (Collection) sourceEmbeddedObj)
                                    {
                                        Object targetEcObj = null;
                                        if (sourceEcObj != null
                                                && PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType()))
                                        {
                                            PropertyAccessor accessor = PropertyAccessorFactory
                                                    .getPropertyAccessor(sourceEcObj.getClass());
                                            if (accessor != null)
                                            {
                                                targetEcObj = accessor.getCopy(sourceEcObj);
                                            }
                                        }
                                        else if (sourceEcObj != null
                                                && PersistenceType.EMBEDDABLE.equals(embeddedColumn
                                                        .getPersistenceType()))
                                        {
                                            targetEcObj = genericClass.newInstance();

                                            for (Field f : genericClass.getDeclaredFields())
                                            {
                                                if (f != null && !Modifier.isStatic(f.getModifiers()))
                                                {
                                                    PropertyAccessorHelper.set(targetEcObj, f,
                                                            PropertyAccessorHelper.getObjectCopy(sourceEcObj, f));
                                                }
                                            }
                                        }
                                        if (List.class.isAssignableFrom(ecDeclaredClass))
                                        {
                                            Method m = actualEcObjectClass.getMethod("add", Object.class);
                                            m.invoke(targetCollectionObject, targetEcObj);

                                        }
                                        else if (Set.class.isAssignableFrom(ecDeclaredClass))
                                        {
                                            Method m = actualEcObjectClass.getMethod("add", Object.class);
                                            m.invoke(targetCollectionObject, targetEcObj);
                                        }
                                    }
                                }

                                // Copy element collection for Map
                                else if (sourceEmbeddedObj instanceof Map)
                                {
                                    for (Object sourceKey : ((Map) sourceEmbeddedObj).keySet())
                                    {
                                        Object targetKey = null;
                                        Object targetValue = null;
                                        if (PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType()))
                                        {
                                            // Create copy of map key
                                            if (sourceKey != null)
                                            {
                                                PropertyAccessor keyAccessor = PropertyAccessorFactory
                                                        .getPropertyAccessor(sourceKey.getClass());
                                                if (keyAccessor != null)
                                                {
                                                    targetKey = keyAccessor.getCopy(sourceKey);
                                                }
                                            }
                                            else
                                            {
                                                targetKey = null;
                                            }

                                            // Create copy of map value
                                            Object sourceValue = ((Map) sourceEmbeddedObj).get(sourceKey);
                                            if (sourceValue != null)
                                            {
                                                PropertyAccessor valueAccessor = PropertyAccessorFactory
                                                        .getPropertyAccessor(sourceValue.getClass());
                                                if (valueAccessor != null)
                                                {
                                                    targetValue = valueAccessor.getCopy(sourceValue);
                                                }
                                            }
                                            else
                                            {
                                                targetValue = null;
                                            }

                                            if (Map.class.isAssignableFrom(ecDeclaredClass))
                                            {
                                                Method m = actualEcObjectClass.getMethod("put", new Class[] {
                                                        Object.class, Object.class });
                                                m.invoke(targetCollectionObject,
                                                        new Object[] { targetKey, targetValue });
                                            }
                                        }
                                    }
                                }
                                PropertyAccessorHelper.set(target, columnField, targetCollectionObject);
                            }
                            else
                            {
                                // Copy embedded objects
                                Class<?> embeddedColumnClass = columnField.getType();
                                Object targetEmbeddedObj = embeddedColumnClass.newInstance();

                                Set<Attribute> columns = embeddedColumn.getAttributes();
                                for (Attribute column : columns)
                                {
                                    PropertyAccessorHelper.set(
                                            targetEmbeddedObj,
                                            (Field) column.getJavaMember(),
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

    {
        Class javaType = ((AbstractAttribute) attribute).getBindableJavaType();

        if (metaModel.isEmbeddable(javaType))
        {
            EmbeddableType compoundKey = metaModel.embeddable(javaType);
            Object compoundKeyObject = null;
            try
            {
                Set<Attribute> attributes = compoundKey.getAttributes();
                entity = KunderaCoreUtils.initialize(entityClazz, entity);

                for (Attribute compoundAttribute : attributes)
                {
                    compoundKeyObject = compoundKeyObject == null ? getCompoundKey(attribute, entity)
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

    protected void onWhereClause(EntityMetadata metadata, Object key, CQLTranslator translator,
        StringBuilder queryBuilder, MetamodelImpl metaModel, SingularAttribute attribute) {
        // SingularAttribute idAttribute = metadata.getIdAttribute();
        if (metaModel.isEmbeddable(attribute.getBindableJavaType())) {
            Field[] fields = attribute.getBindableJavaType().getDeclaredFields();
            EmbeddableType compoundKey = metaModel.embeddable(attribute.getBindableJavaType());

            for (Field field : fields) {
                if (field != null && !Modifier.isStatic(field.getModifiers())
                    && !Modifier.isTransient(field.getModifiers()) && !field.isAnnotationPresent(Transient.class)) {
                    attribute = (SingularAttribute) compoundKey.getAttribute(field.getName());
                    Object valueObject = PropertyAccessorHelper.getObject(key, field);
                    if (metaModel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) {
                        onWhereClause(metadata, valueObject, translator, queryBuilder, metaModel, attribute);
                    } else {
                        String columnName = ((AbstractAttribute) attribute).getJPAColumnName();
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

            byte[] columnName = PropertyAccessorHelper.get(entity, (Field) metadata.getIdAttribute().getJavaMember());

            for (String fieldName : embeddables.keySet())
            {
                EmbeddableType embeddedColumn = embeddables.get(fieldName);
                Attribute embeddedAttribute = entityType.getAttribute(fieldName);
                Object embeddedObject = PropertyAccessorHelper.getObject(entity,
                        (Field) embeddedAttribute.getJavaMember());

                if (embeddedObject != null)
                {
                    if (embeddedObject instanceof Collection)
                    {
                        for (Object obj : (Collection) embeddedObject)
                        {
                            Iterator<Attribute> iter = embeddedColumn.getAttributes().iterator();
                            while (iter.hasNext())
                            {
                                Attribute attrib = iter.next();
                                String rowKey = embeddedAttribute.getName() + Constants.INDEX_TABLE_ROW_KEY_DELIMITER
                                        + attrib.getName();
                                byte[] superColumnName = PropertyAccessorHelper
                                        .get(obj, (Field) attrib.getJavaMember());
                                if (superColumnName != null)
                                {
                                    deleteColumn(indexColumnFamily, rowKey, superColumnName,
                                            metadata.getPersistenceUnit(), consistencyLevel, columnName);
                                }
                            }
                        }
                    }
                    else
                    {

                        Iterator<Attribute> iter = embeddedColumn.getAttributes().iterator();
                        while (iter.hasNext())
                        {
                            Attribute attrib = iter.next();
                            String rowKey = embeddedAttribute.getName() + Constants.INDEX_TABLE_ROW_KEY_DELIMITER
                                    + attrib.getName();
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

            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;
            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();
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

        Map<Boolean, String> filterIdResult = new HashMap<Boolean, String>();

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

        EmbeddableType keyObj = null;
        if (metaModel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType()))
        {
            keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
        }
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

        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
        {
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

        onCollectionColumns(translator, tableInfo.getCollectionColumnMetadatas(), queryBuilder);

        // ideally it will always be one as more super column families
        // are not allowed with compound/composite key.
        List<EmbeddedColumnInfo> compositeColumns = tableInfo.getEmbeddedColumnMetadatas();
        EmbeddableType compoEmbeddableType = null;
        if (!compositeColumns.isEmpty())
        {
            compoEmbeddableType = compositeColumns.get(0).getEmbeddable();
            onCompositeColumns(translator, compositeColumns.get(0).getColumns(), queryBuilder, columns,
                    isCounterColumnType);
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

                List<ColumnInfo> columnInfos = tableInfo.getColumnMetadatas();

                List<EmbeddedColumnInfo> compositeColumns = tableInfo.getEmbeddedColumnMetadatas();
                if (compositeColumns != null && !compositeColumns.isEmpty())
                {
                    EmbeddableType embeddableType = compositeColumns.get(0).getEmbeddable();
                    for (ColumnInfo columnInfo : compositeColumns.get(0).getColumns())
                    {
                        name_types
                                .put(ByteBufferUtil.bytes(columnInfo.getColumnName()), UTF8Type.class.getSimpleName());
                        value_types.put(ByteBufferUtil.bytes(columnInfo.getColumnName()),
View Full Code Here

Examples of javax.persistence.metamodel.EmbeddableType

            EntityManager em = EMRepository.INSTANCE.getEM(sessionToken);
            entityClass = EntityUtils.getEntityClass(entityClassName, em);
            entityMetadata = EntityUtils.getEntityMetaData(entityClass.getSimpleName(), em);
            log.debug("GET: entityClass" + entityClass);
            MetamodelImpl metaModel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();
            EmbeddableType keyObj = null;
            Object key = null;
            id = java.net.URLDecoder.decode(id, "UTF-8");
            if (metaModel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType())) {
                keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
                key = JAXBUtils.toObject(id, keyObj.getJavaType(), mediaType);
            } else {
                ObjectMapper mapper = new ObjectMapper();
                key = mapper.convertValue(id, entityMetadata.getIdAttribute().getBindableJavaType());
            }
           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.