Refine search
public FieldManager(EntityConfiguration entityConfiguration, EntityManager entityManager) { this.entityConfiguration = entityConfiguration; this.entityManager = entityManager; if (entityManager != null) { Set<EntityType<?>> managedEntities = entityManager.getMetamodel().getEntities(); for (EntityType managedEntity : managedEntities) { managedEntityClasses.add(managedEntity.getJavaType()); } } }
private List<Map<String, ?>> recordsInfo() { List<Map<String, ?>> records = U.list(); for (EntityType<?> type : JPA.getEntityTypes()) { Class<?> javaType = type.getJavaType(); long count = JPA.count(javaType); String idType = type.getIdType() != null ? type.getIdType().getJavaType().getSimpleName() : ""; Object superType = type.getSupertype() != null ? type.getSupertype().getJavaType().getSimpleName() : ""; records.add(U.map("type", type.getName(), "extends", superType, "ID Type", idType, "count", count)); } return records; }
if (root.getModel().hasSingleIdAttribute()) { SingularAttribute<?, ?> id = root.getModel().getId(root.getModel().getIdType().getJavaType()); query = query.multiselect(root.get((SingularAttribute) id).alias(id.getName())); query = query.multiselect(root.getModel().getIdClassAttributes().stream()// .map(it -> (Selection<?>) root.get((SingularAttribute) it).alias(it.getName())) .collect(Collectors.toList()));
private static Class<?> idType(Class<?> entityType) { for (EntityType<?> t : JPA.getEntityTypes()) { if (t.getJavaType().equals(entityType)) { return t.getIdType() != null ? t.getIdType().getJavaType() : null; } } return null; }
/** * Returns the {@link SingularAttribute} representing the identifier of the given {@link EntityType} if it contains a * singular one. * * @param entityType must not be {@literal null}. * @return */ private static Optional<? extends SingularAttribute<?, ?>> getSingularIdAttribute(EntityType<?> entityType) { if (!entityType.hasSingleIdAttribute()) { return Optional.empty(); } return entityType.getSingularAttributes().stream() // .filter(SingularAttribute::isId) // .findFirst(); } }
private TypedQuery<Long> getCountQuery(DataFetchingEnvironment environment, Field field) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<?> root = query.from(entityType); SingularAttribute<?,?> idAttribute = entityType.getId(Object.class); query.select(cb.count(root.get(idAttribute.getName()))); List<Predicate> predicates = field.getArguments().stream() .map(it -> getPredicate(cb, root, null, environment, it)) .filter(it -> it != null) .collect(Collectors.toList()); query.where(predicates.toArray(new Predicate[predicates.size()])); return entityManager.createQuery(query); }
@Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { EntityType<?> entityType = em.getMetamodel().entity(targetType.getType()); Class<?> idType = entityType.getIdType().getJavaType(); Object id = identifierConverter.convert(source, sourceType, TypeDescriptor.valueOf(idType)); return em.find(targetType.getType(), id); } }
protected Query getCountExampleQuery() { StringBuilder sb = new StringBuilder(); sb.append("SELECT COUNT(e) FROM "); sb.append(entityType.getName()); sb.append(" e"); String exampleQueryString = sb.toString(); return em.createQuery(exampleQueryString); }
EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz()); Map<String, PropertyIndex> columns = entityMetadata.getIndexProperties(); 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(), else if (!attr.isCollection() && !((SingularAttribute) attr).isId())
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();
Set<Attribute> attributes = entityType.getSingularAttributes(); for (Attribute attribute : attributes) Field field = (Field) attribute.getJavaMember(); if (!attribute.isCollection() && !attribute.isAssociation())
protected <X>Attribute<? super X, ?> idAttribute(final Class<X> klazz) { final EntityType<X> type = em.getMetamodel().entity(klazz); final Class<?> idType = type.getIdType().getJavaType(); final Attribute<? super X, ?> attribute = type.getId(idType); return attribute; }
Set<Attribute> attributes = entityType.getSingularAttributes(); Field field = (Field) attribute.getJavaMember(); String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); if (metaModel.isEmbeddable(relationshipEntityMetadata.getIdAttribute().getBindableJavaType()) && relationshipEntityMetadata.getIdAttribute().getJavaType().equals(field.getType())) else if (!attribute.isCollection() && !attribute.isAssociation() && !field.getType().equals(topLevelEntityMetadata.getEntityClazz()) && !field.getType().equals(relation.getTargetEntity())) && !metaModel.isEmbeddable(relationshipEntityMetadata.getIdAttribute().getBindableJavaType()))
public static String getEntityName(EntityManager em, Class<?> entityClass) { return em.getMetamodel().entity(entityClass).getName(); } }
/** * Returns whether the attribute of given name and type is the single identifier attribute of the given entity. * * @param entity must not be {@literal null}. * @param name must not be {@literal null}. * @param attributeType must not be {@literal null}. * @return */ public boolean isSingleIdAttribute(Class<?> entity, String name, Class<?> attributeType) { return metamodel.getEntities().stream() // .filter(it -> entity.equals(it.getJavaType())) // .findFirst() // .flatMap(it -> getSingularIdAttribute(it)) // .filter(it -> it.getJavaType().equals(attributeType)) // .map(it -> it.getName().equals(name)) // .orElse(false); }
@Override public void run() { repService.persist(bean); if (!connected) { entity = connection().getMetamodel().entity(bean.getClass()); String idName = entity.getId(bean.getClass()).getName(); id = BeanClass.getValue(bean, idName); repService.persist(new ReplicationChange(entity.getName(), id)); } }
@SuppressWarnings("unchecked") private static String getEntityIdField(EntityManager em, Class entityClass) { String idProperty = ""; Metamodel metamodel = em.getMetamodel(); EntityType e = metamodel.entity(entityClass); Set<SingularAttribute> singularAttributes = e.getSingularAttributes(); for (SingularAttribute singularAttribute : singularAttributes) { if (singularAttribute.isId()) { idProperty = singularAttribute.getName(); break; } } return idProperty; }
Set<Attribute> attributes = entityType.getAttributes(); if (!entityMetadata.getIdAttribute().getName().equals(attrib.getName()) && !metaModel.isEmbeddable(attrib.getJavaType()) && !attrib.isAssociation()) { String tableName = ((AbstractAttribute) attrib).getTableName() != null ? ((AbstractAttribute) attrib).getTableName() : entityMetadata.getTableName();
public JpaValueEncoder(final EntityType<E> entity, final EntityManagerManager entityManagerManager, final String persistenceUnitName, final PropertyAccess propertyAccess, final TypeCoercer typeCoercer, final Logger logger) { super(); this.entity = entity; this.entityManagerManager = entityManagerManager; this.persistenceUnitName = persistenceUnitName; this.typeCoercer = typeCoercer; this.logger = logger; final Type<?> idType = this.entity.getIdType(); final SingularAttribute<? super E, ?> idAttribute = this.entity.getId(idType.getJavaType()); idPropertyName = idAttribute.getName(); propertyAdapter = propertyAccess.getAdapter(entity.getJavaType()).getPropertyAdapter( idPropertyName); }
private String getIdAttribute(Class<?> entityClass) { EntityType<?> entityType = entityManager.getMetamodel().entity(entityClass); return entityType.getDeclaredId(entityType.getIdType().getJavaType()).getName(); }