@SuppressWarnings("unchecked") public IdMetadata(IdentifiableType<T> source) { this.type = source; this.attributes = (Set<SingularAttribute<? super T, ?>>) (source.hasSingleIdAttribute() ? Collections.singleton(source.getId(source.getIdType().getJavaType())) : source.getIdClassAttributes()); }
return Optional.ofNullable(type.getVersion(Object.class)); } catch (IllegalArgumentException o_O) { Set<SingularAttribute<? super T, ?>> attributes = type.getSingularAttributes(); Class<?> superType = type.getJavaType().getSuperclass();
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; } }
public static boolean isIdentifiable(ManagedType<?> jpaManagedType) { if (jpaManagedType instanceof IdentifiableType<?>) { IdentifiableType<?> identifiableType = (IdentifiableType<?>) jpaManagedType; if (identifiableType.hasSingleIdAttribute()) { return true; if (identifiableType.getIdType() != null) { return true; return !identifiableType.getIdClassAttributes().isEmpty(); } catch (NullPointerException ex2) { return !identifiableType.getIdClassAttributes().isEmpty(); } catch (IllegalArgumentException ex) {
try idAttrib = ((IdentifiableType) managedType).getId(IDClassEntity.class); Assert.fail(); Assert.assertEquals(2, ((IdentifiableType) managedType).getIdClassAttributes().size()); Assert.assertNotNull(idAttribute); Assert.assertTrue(((SingularAttribute) idAttribute).isId());
@Nullable private Class<?> tryExtractIdTypeWithFallbackToIdTypeLookup() { try { Type<?> idType2 = type.getIdType(); return idType2 == null ? fallbackIdTypeLookup(type) : idType2.getJavaType(); } catch (IllegalStateException e) { // see https://hibernate.onjira.com/browse/HHH-6951 return fallbackIdTypeLookup(type); } }
@Nullable private static Class<?> fallbackIdTypeLookup(IdentifiableType<?> type) { IdClass annotation = AnnotationUtils.findAnnotation(type.getJavaType(), IdClass.class); return annotation == null ? null : annotation.value(); }
if (!it.hasSingleIdAttribute()) { throw new JpaStoreException( "Entity class has more than one identifier. It must have only one identifier."); Type<?> idType = it.getIdType(); Class<?> idJavaType = idType.getJavaType();
private EntityMetamodel getDeclarerEntityMetamodel(IdentifiableType<?> ownerType) { final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); if ( persistenceType == Type.PersistenceType.ENTITY) { return context.getSessionFactory() .getEntityPersister( ownerType.getJavaType().getName() ) .getEntityMetamodel(); } else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS) { PersistentClass persistentClass = context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType ); return context.getSessionFactory() .getEntityPersister( persistentClass.getClassName() ) .getEntityMetamodel(); } else { throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType ); } }
/** * Return the ORM path from the given rule. * * @param root * The {@link Root} used to resolved the path. * @param path * The path value. Nested path is accepted. * @param <U> * The entity type referenced by the {@link Root} * @param <T> * The resolved entity type of the path value. * @return The resolved {@link Path} from the root. */ @SuppressWarnings("unchecked") protected <U, T> Path<T> getOrmPath(final Root<U> root, final String path) { PathImplementor<?> currentPath = (PathImplementor<?>) root; for (final String pathFragment : path.split(DELIMITERS)) { currentPath = getNextPath(pathFragment, (From<?, ?>) currentPath); } // Fail safe identifier access for non singular target path if (currentPath instanceof SingularAttributeJoin) { currentPath = getNextPath(((IdentifiableType<?>) currentPath.getModel()).getId(Object.class).getName(), (From<?, ?>) currentPath); } return (Path<T>) currentPath; }
if (idEntity.getSupertype() != null) IdentifiableType<?> jpaObject = idEntity.getSupertype(); String className = Type.getInternalName(entity.getJavaType()); List<String> newSubclasses = new ArrayList<>(subclassNames);
public static SingularAttribute<?, ?> getVersionAttribute(IdentifiableType<?> entityType) { if (!entityType.hasVersionAttribute()) { return null; } for (SingularAttribute<?, ?> attribute : entityType.getSingularAttributes()) { if (attribute.isVersion()) { return attribute; } } return null; }
if (((IdentifiableType<Object>) jpaManagedType).hasVersionAttribute()) { for (Iterator<String> iterator = requiredUpdatableAttributes.iterator(); iterator.hasNext(); ) { ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttributes().get(iterator.next()); try { SingularAttribute<? super Object, ?> version = ((IdentifiableType<Object>) jpaManagedType).getVersion(extendedAttribute.getElementClass()); if (extendedAttribute.getAttributePathString().equals(version.getName())) { iterator.remove();
private static Set<SingularAttribute<?, ?>> collectIdAttributes(IdentifiableType<?> entityType) { Set<SingularAttribute<?, ?>> idTypes = new TreeSet<>(ATTRIBUTE_NAME_COMPARATOR); for (SingularAttribute<?, ?> attribute : entityType.getSingularAttributes()) { if (attribute.isId()) { idTypes.add(attribute); } } return idTypes; }
public static boolean isIdentifiable(ManagedType<?> jpaManagedType) { if (jpaManagedType instanceof IdentifiableType<?>) { IdentifiableType<?> identifiableType = (IdentifiableType<?>) jpaManagedType; if (identifiableType.hasSingleIdAttribute()) { return true; if (identifiableType.getIdType() != null) { return true; return !identifiableType.getIdClassAttributes().isEmpty(); } catch (NullPointerException ex2) { return !identifiableType.getIdClassAttributes().isEmpty(); } catch (IllegalArgumentException ex) {
try idAttrib = ((IdentifiableType) managedType).getId(EmbeddableEntity.class); Assert.fail(); Assert.assertEquals(1, ((IdentifiableType) managedType).getIdClassAttributes().size()); Assert.assertNotNull(idAttribute); Assert.assertTrue(((SingularAttribute) idAttribute).isId());
@Override public Type<?> getIdType() { if (idAttribute != null && !isIdClass) { return idAttribute.getType(); } return getSupertype().getIdType(); }
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; }
@Override public boolean isBag(EntityType<?> ownerType, String attributeName) { CollectionPersister persister = null; IdentifiableType<?> type = ownerType; String typeName = getTypeName(ownerType); StringBuilder sb = new StringBuilder(typeName.length() + attributeName.length() + 1); while (persister == null && type != null) { sb.setLength(0); sb.append(getTypeName(type)); sb.append('.'); sb.append(attributeName); persister = collectionPersisters.get(sb.toString()); type = type.getSupertype(); } return persister != null && !persister.hasIndex() && !persister.isInverse() && !(getAttribute(ownerType, attributeName) instanceof SetAttribute<?, ?>); }