/** * validate embedded column . * * @param metadata * the metadata * @param embeddedColumns * the embedded columns * @return true, if successful */ private boolean validateEmbeddedColumns(EntityMetadata metadata, Collection<EmbeddableType> embeddedColumns) { boolean isValid = false; Iterator<EmbeddableType> iter = embeddedColumns.iterator(); while (iter.hasNext()) { isValid = validateColumns(metadata, iter.next().getAttributes()) ? true : false; } return isValid; }
/** * Populate embedded column. * * @param entity * the entity * @param result * the result * @param embeddable * the embeddable * @param metaModel * the meta model */ private void populateEmbeddedColumn(Object entity, RowResult result, EmbeddableType embeddable, MetamodelImpl metaModel) { Set<Attribute> attributes = embeddable.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); iterateAndPopulateEntity(entity, result, metaModel, iterator); }
/** * Populate partial row for embedded column. * * @param row * the row * @param embeddable * the embeddable * @param EmbEntity * the emb entity * @param metaModel * the meta model */ private void populatePartialRowForEmbeddedColumn(PartialRow row, EmbeddableType embeddable, Object EmbEntity, MetamodelImpl metaModel) { Set<Attribute> attributes = embeddable.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); iterateAndPopulateRow(row, EmbEntity, metaModel, iterator); }
/** * Creates the columns field map. * * @param m * the m * @param superColumn * the super column * @return the map */ public static Map<String, Field> createColumnsFieldMap(EntityMetadata m, EmbeddableType superColumn) { Map<String, Field> columnNameToFieldMap = new HashMap<String, Field>(); Set<Attribute> attributes = superColumn.getAttributes(); for (Attribute column : attributes) { columnNameToFieldMap.put(((AbstractAttribute) column).getJPAColumnName(), (Field) column.getJavaMember()); } return columnNameToFieldMap; }
List<ColumnInfo> columns = new ArrayList<ColumnInfo>(); Set attributes = embeddableType.getAttributes(); Iterator<Attribute> iter = attributes.iterator();
/** * @param translatedColumns * @param metaModel * @param col */ private void onEmbeddable(List<String> translatedColumns, MetamodelImpl metaModel, Attribute col, boolean isEmbeddable) { if (isEmbeddable) { EmbeddableType embeddableType = metaModel.embeddable(col.getJavaType()); Set<Attribute> attributes = embeddableType.getAttributes(); for (Attribute attribute : attributes) { translatedColumns.add(((AbstractAttribute) attribute).getJPAColumnName()); } } else { translatedColumns.add(((AbstractAttribute) col).getJPAColumnName()); } }
private static void getAttributeOfEmbedddable(Map<String, Field> columnNameToFieldMap, Metamodel metaModel, Attribute attribute) { EmbeddableType embeddable = metaModel.embeddable(((AbstractAttribute) attribute).getBindableJavaType()); Iterator<Attribute> embeddableIter = embeddable.getAttributes().iterator(); while (embeddableIter.hasNext()) { Attribute embedAttrib = embeddableIter.next(); // Reason is to avoid in case embeddable attribute within // embeddable. if (!((MetamodelImpl) metaModel).isEmbeddable(embedAttrib.getJavaType())) { columnNameToFieldMap.put(((AbstractAttribute) embedAttrib).getJPAColumnName(), (Field) embedAttrib.getJavaMember()); } else { getAttributeOfEmbedddable(columnNameToFieldMap, metaModel, embedAttrib); } } }
/** * Gets the composite id embeddables. * * @param embeddable * the embeddable * @param compositeEmbeddables * the composite embeddables * @param metaModel * the meta model * @return the composite id embeddables */ private void getCompositeIdEmbeddables(EmbeddableType embeddable, List compositeEmbeddables, MetamodelImpl metaModel) { compositeEmbeddables.add(embeddable.getJavaType().getSimpleName()); for (Object column : embeddable.getAttributes()) { Attribute columnAttribute = (Attribute) column; Field f = (Field) columnAttribute.getJavaMember(); if (columnAttribute.getJavaType().isAnnotationPresent(Embeddable.class)) { getCompositeIdEmbeddables(metaModel.embeddable(columnAttribute.getJavaType()), compositeEmbeddables, metaModel); } } }
/** * On embeddable. * * @param entityType * the entity type * @param column * the column * @param entity * the entity * @param embeddableType * the embeddable type * @param jsonObject * the json object */ private static void onEmbeddable(EntityType entityType, Attribute column, Object entity, EmbeddableType embeddableType, JsonObject jsonObject) { Object embeddedObject = PropertyAccessorHelper.getObject(entity, (Field) column.getJavaMember()); String embeddedColumnName = ((AbstractAttribute) column).getJPAColumnName(); Set<Attribute> embeddableAttributes = embeddableType.getAttributes(); jsonObject.add(embeddedColumnName, getJsonObject(embeddableAttributes, embeddedObject)); }
/** * On via embeddable. * * @param entityType * the entity type * @param column * the column * @param m * the m * @param entity * the entity * @param embeddable * the embeddable * @param jsonObj * the json obj */ private static void onViaEmbeddable(EntityType entityType, Attribute column, EntityMetadata m, Object entity, EmbeddableType embeddable, JsonObject jsonObj) { Field embeddedField = (Field) column.getJavaMember(); JsonElement embeddedDocumentObject = jsonObj.get(((AbstractAttribute) column).getJPAColumnName()); if (!column.isCollection()) { PropertyAccessorHelper.set( entity, embeddedField, getObjectFromJson(embeddedDocumentObject.getAsJsonObject(), ((AbstractAttribute) column).getBindableJavaType(), embeddable.getAttributes())); } }
private void prepareEmbeddedIdFields(Set<Attribute> embeddedAttributes, MetamodelImpl metaModel, Map<String, Object> embeddedIdFields, Document doc, EntityMetadata metadata) { for (Attribute attribute : embeddedAttributes) { if (!ReflectUtils.isTransientOrStatic((Field) attribute.getJavaMember())) { if (metaModel.isEmbeddable(attribute.getJavaType())) { EmbeddableType embeddable = metaModel.embeddable(attribute.getJavaType()); prepareEmbeddedIdFields(embeddable.getAttributes(), metaModel, embeddedIdFields, doc, metadata); } else { String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); embeddedIdFields.put(columnName, doc.get(metadata.getEntityClazz().getSimpleName() + "." + columnName)); } } } }
Set<Attribute> cols = partitionCol.getAttributes(); for (Attribute col : cols) { Field f = (Field) col.getJavaMember();
/** * Assert on embeddable type. * * @param <X> * the generic type * @param entityClazz * the entity clazz * @param attribute * the attribute * @param embeddableType * the embeddable type * @param attributeName * the attribute name * @param attributeClazz * the attribute clazz */ @SuppressWarnings({ "rawtypes", "unchecked" }) private <X> void assertOnEmbeddableType(Class entityClazz, Attribute<X, String> attribute, EmbeddableType<X> embeddableType, String attributeName, Class attributeClazz) { Assert.assertNotSame(entityClazz.getDeclaredFields().length, embeddableType.getAttributes().size()); Assert.assertEquals(1, embeddableType.getAttributes().size()); Assert.assertEquals(entityClazz, embeddableType.getJavaType()); Attribute attributeTwo = (Attribute) embeddableType.getAttribute(attributeName); Assert.assertNotNull(attribute); Assert.assertEquals(attributeClazz, attributeTwo.getJavaType()); Assert.assertEquals(attributeName, attributeTwo.getName()); }
private void populateEntityFromDocument(Object entity, Object rowKey, MetamodelImpl metaModel, AbstractAttribute attrib) throws InstantiationException, IllegalAccessException { EmbeddableType embeddable = metaModel.embeddable(attrib.getBindableJavaType()); Iterator<Attribute> iter = embeddable.getAttributes().iterator(); Object compoundKey = attrib.getBindableJavaType().newInstance(); while (iter.hasNext()) { AbstractAttribute compositeAttrib = (AbstractAttribute) iter.next(); Object value = ((BasicDBObject) rowKey).get(compositeAttrib.getJPAColumnName()); if (metaModel.isEmbeddable(compositeAttrib.getBindableJavaType())) { populateEntityFromDocument(compoundKey, value, metaModel, compositeAttrib); } else { PropertyAccessorHelper.set(compoundKey, (Field) compositeAttrib.getJavaMember(), value); } } PropertyAccessorHelper.set(entity, (Field) attrib.getJavaMember(), compoundKey); }
private void updateOrCreateIndexEmbeddedIdFields(Set<Attribute> embeddedAttributes, MetamodelImpl metaModel, Document document, EntityMetadata metadata, Object rowKey) { try { for (Attribute attribute : embeddedAttributes) { if (!ReflectUtils.isTransientOrStatic((Field) attribute.getJavaMember())) { if (metaModel.isEmbeddable(attribute.getJavaType())) { EmbeddableType embeddable = metaModel.embeddable(attribute.getJavaType()); updateOrCreateIndexEmbeddedIdFields(embeddable.getAttributes(), metaModel, document, metadata, ((Field) attribute.getJavaMember()).get(rowKey)); } else { String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); Object embeddedColumn = PropertyAccessorHelper.getObject(rowKey, (Field) attribute.getJavaMember()); updateDocument(embeddedColumn.toString(), document, columnName); } } } } catch (IllegalAccessException e) { log.error(e.getMessage()); } }
/** * Populate embeddable object. * * @param data * the data * @param obj * the obj * @param m * the m * @param clazz * the clazz * @param prefix * @return the object */ private Object populateEmbeddableObject(HBaseDataWrapper data, Object obj, EntityMetadata m, Class clazz, String prefix) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel( m.getPersistenceUnit()); Set<Attribute> attributes = metaModel.embeddable(clazz).getAttributes(); writeValuesToEntity(obj, data, m, metaModel, attributes, null, null, -1, prefix); return obj; }
/** * Process embeddable attribute. * * @param entity * the entity * @param metamodel * the metamodel * @param row * the row * @param schemaTable * the schema table * @param metadata * the metadata * @param attribute * the attribute */ private void processEmbeddableAttribute(Object entity, MetamodelImpl metamodel, Row row, Table schemaTable, EntityMetadata metadata, Attribute attribute) { // process on embeddables. EmbeddableType embeddable = metamodel.embeddable(((AbstractAttribute) attribute).getBindableJavaType()); Set<Attribute> embeddedAttributes = embeddable.getAttributes(); Object embeddedObject = PropertyAccessorHelper.getObject(entity, (Field) attribute.getJavaMember()); for (Attribute embeddedAttrib : embeddedAttributes) { setField(row, schemaTable, embeddedObject, embeddedAttrib); } }
private static void populateEmbeddedIdFieldsUtil(Set<Attribute> embeddedAttributes, MetamodelImpl metaModel, Set<String> embeddedIdFields) { for (Attribute attribute : embeddedAttributes) { if (!ReflectUtils.isTransientOrStatic((Field) attribute.getJavaMember())) { if (metaModel.isEmbeddable(attribute.getJavaType())) { EmbeddableType embeddable = metaModel.embeddable(attribute.getJavaType()); populateEmbeddedIdFieldsUtil(embeddable.getAttributes(), metaModel, embeddedIdFields); } else { String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); embeddedIdFields.add(columnName); } } } }
/** * recursively populate all the fields present in partition key * * @param embeddedAttributes * @param metaModel * @param embeddedIdFields */ private static void populateEmbeddedIdFields(Set<Attribute> embeddedAttributes, MetamodelImpl metaModel, Set<String> embeddedIdFields) { for (Attribute attribute : embeddedAttributes) { if (!ReflectUtils.isTransientOrStatic((Field) attribute.getJavaMember())) { if (metaModel.isEmbeddable(attribute.getJavaType())) { EmbeddableType embeddable = metaModel.embeddable(attribute.getJavaType()); populateEmbeddedIdFieldsUtil(embeddable.getAttributes(), metaModel, embeddedIdFields); } } } }
/** * Adds the index properties. * * @param metadata * the metadata * @param entity * the object * @param document * the document * @param metaModel */ protected void addEntityFieldsToDocument(EntityMetadata metadata, Object entity, Document document, MetamodelImpl metaModel) { String indexName = metadata.getIndexName(); Map<String, PropertyIndex> indexProperties = metadata.getIndexProperties(); for (String columnName : indexProperties.keySet()) { PropertyIndex index = indexProperties.get(columnName); java.lang.reflect.Field property = index.getProperty(); String propertyName = index.getName(); addFieldToDocument(entity, document, property, propertyName, indexName); } if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) { Object id = PropertyAccessorHelper.getId(entity, metadata); EmbeddableType embeddableId = metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType()); Set<Attribute> embeddedAttributes = embeddableId.getAttributes(); indexCompositeKey(embeddedAttributes, metadata, id, document, metaModel); } }