/** * Populate entity. * * @param entity * the entity * @param result * the result * @param entityType * the entity type * @param metaModel * the meta model */ public void populateEntity(Object entity, RowResult result, EntityType entityType, MetamodelImpl metaModel) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); iterateAndPopulateEntity(entity, result, metaModel, iterator); }
@Override public Object getEntityFromDocument(Class<?> entityClass, JsonObject obj, EntityType entityType) { Object entity = KunderaCoreUtils.createNewInstance(entityClass); Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); iterateAndPopulateEntity(entity, obj, iterator); return entity; }
public static void onJPAColumnMapping(final EntityType entityType, EntityMetadata entityMetadata) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); // jpa column mapping is for non id columns only. if (!entityMetadata.getIdAttribute().equals(attribute)) { entityMetadata.addJPAColumnMapping(((AbstractAttribute) attribute).getJPAColumnName(), attribute.getName()); } } entityMetadata.setEntityType(entityType); }
/** * Builds the entity from cursor. * * @param entity * the entity * @param obj * the obj * @param entityType * the entity type * @return the object */ private void buildEntityFromCursor(Object entity, HashMap obj, EntityType entityType) { Iterator<Attribute> iter = entityType.getAttributes().iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); Field field = (Field) attribute.getJavaMember(); if (field.isAnnotationPresent(Id.class)) { PropertyAccessorHelper.set(entity, field, obj.get(ID)); } else { PropertyAccessorHelper.set(entity, field, obj.get(((AbstractAttribute) attribute).getJPAColumnName())); } } }
/** * Custom implementation to offer map of embeddables available for given * entityType. * * @param clazz * entity class * @return map of holding {@link EmbeddableType} as value and attribute name * as key. */ public Map<String, EmbeddableType> getEmbeddables(Class clazz) { Map<String, EmbeddableType> embeddableAttibutes = new HashMap<String, EmbeddableType>(); if (entityTypes != null) { EntityType entity = entityTypes.get(clazz); Iterator<Attribute> iter = entity.getAttributes().iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); if (isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { embeddableAttibutes.put(attribute.getName(), embeddable(((AbstractAttribute) attribute).getBindableJavaType())); } } } return embeddableAttibutes; }
/** * Adds the source. * * @param entity * the entity * @param values * the values * @param entityType * the entity type */ private void addSource(Object entity, Map<String, Object> values, EntityType entityType) { Set<Attribute> attributes = entityType.getAttributes(); for (Attribute attrib : attributes) { if (!attrib.isAssociation()) { Object value = PropertyAccessorHelper.getObject(entity, (Field) attrib.getJavaMember()); values.put(((AbstractAttribute) attrib).getJPAColumnName(), value); } } }
/** * Populate metadata. * * @param entityType * the EntityType * @param <X> * the generic type * @param metadata * the metadata * @throws RuleValidationException */ private <X> void populateRelationMetaData(EntityType entityType, Class<X> clazz, EntityMetadata metadata) { Set<Attribute> attributes = entityType.getAttributes(); for (Attribute attribute : attributes) { if (attribute.isAssociation()) { addRelationIntoMetadata(clazz, (Field) attribute.getJavaMember(), metadata); } } }
/** * Populate rmap. * * @param entityMetadata * the entity metadata * @param entity * the entity * @return the map object */ private MapObject populateRmap(EntityMetadata entityMetadata, Object entity) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(entityMetadata.getPersistenceUnit()); Class entityClazz = entityMetadata.getEntityClazz(); EntityType entityType = metaModel.entity(entityClazz); Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); return iterateAndPopulateRmap(entity, metaModel, iterator); }
/** * Checks whether an entity with given metadata contains a collection field * * @param m * @return */ public static boolean containsBasicElementCollectionField(final EntityMetadata m, final KunderaMetadata kunderaMetadata) { Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Iterator<Attribute> iter = entityType.getAttributes().iterator(); while (iter.hasNext()) { Attribute attr = iter.next(); if (attr.isCollection() && !attr.isAssociation() && isBasicElementCollectionField((Field) attr.getJavaMember())) { return true; } } return false; }
/** * Populate partial row. * * @param row * the row * @param entityMetadata * the entity metadata * @param entity * the entity */ private void populatePartialRow(PartialRow row, EntityMetadata entityMetadata, Object entity) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(entityMetadata.getPersistenceUnit()); Class entityClazz = entityMetadata.getEntityClazz(); EntityType entityType = metaModel.entity(entityClazz); Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); iterateAndPopulateRow(row, entity, metaModel, iterator); }
@Override public JsonDocument getDocumentFromEntity(EntityMetadata entityMetadata, Object entity, KunderaMetadata kunderaMetadata) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(entityMetadata.getPersistenceUnit()); Class entityClazz = entityMetadata.getEntityClazz(); EntityType entityType = metaModel.entity(entityClazz); Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iterator = attributes.iterator(); JsonObject obj = iterateAndPopulateJsonObject(entity, iterator, entityMetadata.getTableName()); Object id = PropertyAccessorHelper.getId(entity, entityMetadata); return JsonDocument.create(entityMetadata.getTableName() + CouchbaseConstants.ID_SEPARATOR + id.toString(), obj); }
Set<Attribute> columns = entityType.getAttributes(); for (Attribute column : columns)
private static void getEmbeddableType(EntityMetadata m, Map<String, Field> columnNameToFieldMap, Map<String, Field> superColumnNameToFieldMap, final KunderaMetadata kunderaMetadata) { Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); if (((MetamodelImpl) metaModel).isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { superColumnNameToFieldMap.put(((AbstractAttribute) attribute).getJPAColumnName(), (Field) attribute.getJavaMember()); if (columnNameToFieldMap != null) { getAttributeOfEmbedddable(columnNameToFieldMap, metaModel, attribute); } } else { if (columnNameToFieldMap != null) { columnNameToFieldMap.put(((AbstractAttribute) attribute).getJPAColumnName(), (Field) attribute.getJavaMember()); } } } }
/** * Gets the lob from GFS entity. * * @param gfs * the gfs * @param m * the m * @param entity * the entity * @param kunderaMetadata * the kundera metadata * @return the lob from gfs entity */ public Object getLobFromGFSEntity(GridFS gfs, EntityMetadata m, Object entity, KunderaMetadata kunderaMetadata) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set<Attribute> columns = entityType.getAttributes(); for (Attribute column : columns) { boolean isLob = ((Field) column.getJavaMember()).getAnnotation(Lob.class) != null; if (isLob) { return PropertyAccessorHelper.getObject(entity, (Field) column.getJavaMember()); } } return null; }
@Test public void testMappedMetamodel() { EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata( ((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance(), Employee.class); MetamodelImpl metaModel = (MetamodelImpl) ((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance() .getApplicationMetadata().getMetamodel(persistenceUnit); EntityType entityType = metaModel.entity(Employee.class); Set<Attribute> attributes = entityType.getAttributes(); Assert.assertEquals(5, attributes.size()); Assert.assertNotNull(entityMetadata.getIdAttribute()); Assert.assertNotNull("id", entityMetadata.getIdAttribute().getName()); }
m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set<Attribute> attributes = entityType.getAttributes(); String[] columns = new String[attributes.size() - 1]; int count = 0;
isvalid = validateColumns(metadata, entity.getAttributes()) ? true : false;
Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator();
m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set<Attribute> attributes = entityType.getAttributes(); if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
Set<Attribute> columns = entityType.getAttributes(); for (Attribute column : columns)