public RootImpl(CriteriaBuilderImpl criteriaBuilder, EntityType<X> entityType, boolean allowJoins) { super( criteriaBuilder, entityType.getJavaType() ); this.entityType = entityType; this.allowJoins = allowJoins; }
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 EntityType locateNearestSubclassEntity(MappedSuperclassType mappedSuperclassType, EntityType entityTypeTop) { EntityType entityTypeNearestDeclaringType = entityTypeTop; IdentifiableType superType = entityTypeNearestDeclaringType.getSupertype(); while ( superType != mappedSuperclassType ) { if ( superType == null ) { throw new IllegalStateException( String.format( "Cannot determine nearest EntityType extending mapped superclass [%s] starting from [%s]; a supertype of [%s] is null", mappedSuperclassType.getJavaType().getName(), entityTypeTop.getJavaType().getName(), entityTypeTop.getJavaType().getName() ) ); } if ( superType.getPersistenceType() == Type.PersistenceType.ENTITY ) { entityTypeNearestDeclaringType = (EntityType) superType; } superType = superType.getSupertype(); } return entityTypeNearestDeclaringType; } }
/** * 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); }
/** * If no explicit selection was defined, we have a condition called an implicit selection if the query specified * a single {@link Root} and the java type of that {@link Root root's} model is the same as this criteria's * {@link #getResultType() result type}. * * @return True if there is an explicit selection; false otherwise. */ private boolean hasImplicitSelection() { if ( getRoots().size() != 1 ) { return false; } Root root = getRoots().iterator().next(); Class<?> javaType = root.getModel().getJavaType(); if ( javaType != null && javaType != returnType ) { return false; } // if we get here, the query defined no selection but defined a single root of the same type as the // criteria query return, so we use that as the implicit selection // // todo : should we put an implicit marker in the selection to this fact to make later processing easier? return true; }
public static void emf(EntityManagerFactory emf) { U.notNull(emf, "emf"); reset(); JPAUtil.emf = emf; for (EntityType<?> entityType : emf.getMetamodel().getEntities()) { Class<?> type = entityType.getJavaType(); entityJavaTypes.add(type); entities.add(type.getName()); } }
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; }
@SuppressWarnings("unchecked") public <E> List<E> getAllEntities() { List<E> all = U.list(); for (EntityType<?> entityType : getEntityTypes()) { all.addAll((List<E>) of(entityType.getJavaType()).all()); } return all; }
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; }
(EntityType) getPathSource().getModel() ); return entityTypeNearestDeclaringType.getJavaType().getName() + '.' + attribute.getName(); return role.insert( 0, entityType.getJavaType().getName() ).toString();
/** * Returns the name of the entity referred to by the given class name * @param className * @return if className refers to a known JPA entity, then the * name of the entity if returned. If not, null is returned */ @Override public String entityNameFromClassName(String className) { for (EntityType<?> entity: metamodel.getEntities()) { // Envers can insert entities with null Java types into the metamodel if (entity.getJavaType() == null) continue; if (entity.getJavaType().getName().equals(className)) { if (!useHibernateFullEntityNames) return entity.getName(); else return className; } } return null; }
void init() { for (EntityType<?> entity : dbf.getEntityManager().getMetamodel().getEntities()) { Class type = entity.getJavaType(); String name = type.getSimpleName(); resourceTypeClassMap.put(name, type);
@SuppressWarnings({"unchecked"}) public EntityJoin(BlazeCriteriaBuilderImpl criteriaBuilder, AbstractPath<Z> pathSource, EntityType<X> entityType, JoinType joinType) { super(criteriaBuilder, entityType.getJavaType(), pathSource, null, joinType); this.model = entityType; }
@SuppressWarnings({"unchecked"}) public EntityJoin(BlazeCriteriaBuilderImpl criteriaBuilder, AbstractPath<Z> pathSource, EntityType<X> entityType, JoinType joinType) { super(criteriaBuilder, entityType.getJavaType(), pathSource, null, joinType); this.model = entityType; }
private RootImpl(BlazeCriteriaBuilderImpl criteriaBuilder, EntityType<X> entityType, boolean joinsAllowed) { super(criteriaBuilder, entityType.getJavaType()); this.entityType = entityType; this.joinsAllowed = joinsAllowed; }
private void configureEntities() { Set<EntityType<?>> mappedEntities = this.emf.getMetamodel().getEntities(); for (EntityType<?> entity : mappedEntities) { Class<?> javaType = entity.getJavaType(); if (!isAbstract(javaType.getModifiers()) && isIdentityEntity(javaType)) { ROOT_LOGGER.debugf("Mapping entity [%s] to JPA Identity Store.", javaType.getName()); this.configurationBuilder.mappedEntity(javaType); } } }
private void configureEntities() { Set<EntityType<?>> mappedEntities = this.emf.getMetamodel().getEntities(); for (EntityType<?> entity : mappedEntities) { Class<?> javaType = entity.getJavaType(); if (!isAbstract(javaType.getModifiers()) && isIdentityEntity(javaType)) { ROOT_LOGGER.debugf("Mapping entity [%s] to JPA Identity Store.", javaType.getName()); this.configurationBuilder.mappedEntity(javaType); } } }
@SuppressWarnings("unchecked") protected LeafOngoingSetOperationCTECriteriaBuilderImpl<Y> createLeaf(BaseFinalSetOperationCTECriteriaBuilderImpl<Object, ?> finalSetOperationBuilder) { CTEBuilderListener newListener = finalSetOperationBuilder.getSubListener(); LeafOngoingSetOperationCTECriteriaBuilderImpl<Y> next = new LeafOngoingSetOperationCTECriteriaBuilderImpl<Y>(mainQuery, queryContext, cteName, (Class<Object>) cteType.getJavaType(), result, newListener, (FinalSetOperationCTECriteriaBuilderImpl<Object>) finalSetOperationBuilder); newListener.onBuilderStarted(next); return next; }
protected AbstractJoin(BlazeCriteriaBuilderImpl criteriaBuilder, AbstractJoin<Z, ? super X> original, EntityType<X> treatType) { super(criteriaBuilder, treatType.getJavaType(), original.getBasePath()); this.joinAttribute = original.getAttribute(); this.joinType = original.getJoinType(); }
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; }