toAttrJoinType = parentJoinAttr.getJavaType(); } else if( parentJoinAttr instanceof PluralAttribute ) { toAttrJoinType = ((PluralAttribute) parentJoinAttr).getElementType().getJavaType(); } else { String joinName = parentJoinAttr.getDeclaringType().getJavaType().getSimpleName() + "." + parentJoinAttr.getName(); throw new IllegalStateException("Unknown attribute type encountered when trying to join " + joinName ); fieldParentJoin = grandparentJoin.join((SetAttribute) parentJoinAttr); } else { throw new IllegalStateException("Unknown attribute type encountered when trying to join" + parentJoinAttr.getName() );
if (!ASSOCIATION_TYPES.containsKey(attribute.getPersistentAttributeType())) { return false; if (isLeafProperty && !isForSelection && !attribute.isCollection()) { return false; Class<? extends Annotation> associationAnnotation = ASSOCIATION_TYPES.get(attribute.getPersistentAttributeType()); Member member = attribute.getJavaMember();
private <X> void registerAttribute(Class metamodelClass, Attribute<X, ?> attribute) { final String name = attribute.getName(); try { attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED || attribute.getDeclaringType().getPersistenceType() == Type.PersistenceType.EMBEDDABLE;
private String [] createOriginalAndExpectedKeys(Attribute embeddedAttr, PluralAttribute listAttr) { String originalKey = embeddedAttr.getDeclaringType().getJavaType().getName() + "." + embeddedAttr.getName() + "." + listAttr.getName(); String copyKey = listAttr.getDeclaringType().getJavaType().getName() + "." + listAttr.getName(); String [] keys = { originalKey, copyKey }; return keys; }
.getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, associationAttribute.getPersistentAttributeType()); Assert.assertEquals(AssociationEntity.class, associationAttribute.getJavaType()); Assert.assertEquals(true, associationAttribute.isAssociation()); Assert.assertEquals(OToOOwnerEntity.class, associationAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("association", associationAttribute.getName());
Set attributes = entityType.getAttributes(); if (!attr.isAssociation()) if (((MetamodelImpl) metaModel).isEmbeddable(attr.getJavaType())) EmbeddableType embeddable = metaModel.embeddable(attr.getJavaType()); EmbeddedColumnInfo embeddedColumnInfo = getEmbeddedColumn(tableInfo, embeddable, attr.getName(), attr.getJavaType(), ((Field) ((Field) attr.getJavaMember()))); else if (!attr.isCollection() && !((SingularAttribute) attr).isId()) if (((Field) attr.getJavaMember()).getAnnotation(Lob.class) != null) else if (attr.isCollection() && MetadataUtils.isBasicElementCollectionField((Field) attr.getJavaMember())) cci.setType(attr.getJavaType()); cci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember())); else if (attr.isCollection() && !MetadataUtils.isBasicElementCollectionField((Field) attr.getJavaMember())) eci.setType(attr.getJavaType()); eci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember()));
Set<Attribute> attributes = entityType.getAttributes(); for (Attribute attribute : attributes) if (!attribute.getName().equals(m.getIdAttribute().getName()) && !attribute.isAssociation()) Field field = (Field) ((Attribute) attribute).getJavaMember(); byte[] name = ByteBufferUtil.bytes(((AbstractAttribute) attribute).getJPAColumnName()).array(); if (metaModel.isEmbeddable(attribute.isCollection() ? ((PluralAttribute) attribute) .getBindableJavaType() : attribute.getJavaType()))
.getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, associationAttribute.getPersistentAttributeType()); Assert.assertEquals(AssociationBiEntity.class, associationAttribute.getJavaType()); Assert.assertEquals(true, associationAttribute.isAssociation()); Assert.assertEquals(OToOOwnerBiEntity.class, associationAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("association", associationAttribute.getName()); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, ownerAttribute.getPersistentAttributeType()); Assert.assertEquals(OToOOwnerBiEntity.class, ownerAttribute.getJavaType()); Assert.assertEquals(true, ownerAttribute.isAssociation()); Assert.assertEquals(AssociationBiEntity.class, ownerAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("owner", ownerAttribute.getName()); Assert.assertEquals(managedTypes.get(AssociationBiEntity.class), ownerAttribute.getDeclaringType()); Assert.assertEquals(AssociationBiEntity.class, ownerAttribute.getJavaMember().getDeclaringClass()); Assert.assertEquals(OToOOwnerBiEntity.class, ownerAttribute.getJavaType()); Assert.assertEquals(managedTypes.get(OToOOwnerBiEntity.class), ((SingularAttribute<? super X, ?>) ownerAttribute).getType());
Set<Attribute> attributes = entityType.getSingularAttributes(); for (Attribute attribute : attributes) Field field = (Field) attribute.getJavaMember(); if (!attribute.isCollection() && !attribute.isAssociation())
/** * 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; }
public <T> Subgraph<T> addSubgraph(Attribute<X, T> attribute) { Class type = attribute.getJavaType(); if (attribute.isCollection()) { type = ((PluralAttribute) attribute).getBindableJavaType(); } return addSubgraph(attribute.getName(), type); }
Set<Attribute> columns = entityType.getAttributes(); for (Attribute column : columns) boolean isLob = ((Field) column.getJavaMember()).getAnnotation(Lob.class) != null; if (isLob) gridFSInputFile = createGFSInputFile(gfs, entity, (Field) column.getJavaMember()); gridFSInputFile.setFilename(column.getName()); if (isUpdate && column.getName().equals(m.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; for (Attribute attr : attributes) if (!attr.isCollection() && !attr.getName().equalsIgnoreCase(m.getIdAttribute().getName())) else if (attr.isCollection())
Set<Attribute> attributes = entityType.getSingularAttributes(); Field field = (Field) attribute.getJavaMember(); String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && m.getIdAttribute().getJavaType().equals(field.getType())) else if (!attribute.isCollection() && !attribute.isAssociation() && !((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equals(columnName)) if (entity != null && !metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
@Override public String toString() { StringBuilder builder = new StringBuilder(); for (Attribute<?, ?> attribute : attributes) { builder.append(attribute.getName()).append("."); } return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf(".")); } }
public static JPAMember create(Attribute<?, ?> jpaAttribute, Object target) { Member javaMember = jpaAttribute.getJavaMember(); if (javaMember instanceof Field) return new FieldMember((Field) javaMember, target); if (javaMember instanceof Method) return new GetterSetterMember((Method) javaMember, null, target); // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_95:_20091017:_Attribute.getJavaMember.28.29_returns_null_for_a_BasicType_on_a_MappedSuperclass_because_of_an_uninitialized_accessor JPAMember rt = reverseEngineerJPAMember(jpaAttribute.getDeclaringType().getJavaType(), jpaAttribute.getName(), target); if (rt == null) throw new IllegalArgumentException("Could not find java member for: " + jpaAttribute); return rt; }
EntityType entityType = metaModel.entity(relationshipObj.getClass()); Set<Attribute> attributes = entityType.getSingularAttributes(); for (Attribute attribute : attributes) Field f = (Field) attribute.getJavaMember(); if (!f.getType().equals(entityMetadata.getEntityClazz()) && !f.getType().equals(targetNodeMetadata.getEntityClazz())) relationshipObj.getClass()); String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); if (metaModel.isEmbeddable(relMetadata.getIdAttribute().getBindableJavaType()) && ((SingularAttribute) attribute).isId()) relMetadata.getIdAttribute().getBindableJavaType()).getSingularAttributes(); for (Attribute embeddableAttribute : embeddableAttributes) embeddedColumn = embeddableAttribute.getName(); Object value = PropertyAccessorHelper .getObject(id, (Field) embeddableAttribute.getJavaMember());
private static void setFieldValue(Object entity, Object value, Attribute column) { value = PropertyAccessorHelper.fromSourceToTargetClass(column.getJavaType(), value.getClass(), value); PropertyAccessorHelper.set(entity, (Field) column.getJavaMember(), value); }
private void initPossibleSortbyColumnList(EntityManager em) { Metamodel metamodel = em.getMetamodel(); EntityType<SLASummaryBean> slaSummaryBeanEntityType = metamodel.entity(SLASummaryBean.class); Set<Attribute<SLASummaryBean,?>> slaSummaryBeanAttributes = slaSummaryBeanEntityType.getDeclaredAttributes(); possibleSortbyColumns = new ArrayList<>(); for (Attribute<SLASummaryBean,?> attribute : slaSummaryBeanAttributes) { possibleSortbyColumns.add(attribute.getName()); } }
} else { String fieldName = columnName.equals(((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName()) ? metadata.getIdAttribute().getName() : metadata.getFieldName(columnName); Attribute attribute = fieldName != null ? entityType.getAttribute(fieldName) : null; if (!attribute.isAssociation()) { entity = DSClientUtilities.assign(row, entity, metadata, dataType.getName(), entityType, columnName, null, metamodel); } else if (metamodel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) { entity = populateCompositeId(metadata, entity, columnName, row, metamodel, metadata.getIdAttribute(), metadata.getEntityClazz(), dataType);