Java Code Examples for org.hibernate.mapping.PersistentClass#getEntityName()

The following examples show how to use org.hibernate.mapping.PersistentClass#getEntityName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void addEntityBinding(PersistentClass persistentClass) throws DuplicateMappingException {
	final String entityName = persistentClass.getEntityName();
	if ( entityBindingMap.containsKey( entityName ) ) {
		throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, entityName );
	}
	entityBindingMap.put( entityName, persistentClass );

	final AccessType accessType = AccessType.fromExternalName( persistentClass.getCacheConcurrencyStrategy() );
	if ( accessType != null ) {
		if ( persistentClass.isCached() ) {
			locateCacheRegionConfigBuilder( persistentClass.getRootClass().getCacheRegionName() ).addEntityConfig(
					persistentClass,
					accessType
			);
		}

		if ( persistentClass.hasNaturalId() && persistentClass instanceof RootClass && persistentClass.getNaturalIdCacheRegionName() != null ) {
			locateCacheRegionConfigBuilder( persistentClass.getNaturalIdCacheRegionName() ).addNaturalIdConfig(
					(RootClass) persistentClass,
					accessType
			);
		}
	}
}
 
Example 2
Source Project: mPaaS   File: HibernatePropertyParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 构造Hibernate的乐观锁
 */
private void handleVersion(Property prop, PersistentClass pclazz) {
	if (!(pclazz instanceof RootClass)) {
		throw new AnnotationException(
				"Unable to define/override @Version on a subclass: "
						+ pclazz.getEntityName());
	}
	RootClass root = (RootClass) pclazz;
	root.setVersion(prop);
	root.setDeclaredVersion(prop);
	root.setOptimisticLockStyle(OptimisticLockStyle.VERSION);
}
 
Example 3
public ClassPropertyHolder(
		PersistentClass persistentClass,
		XClass entityXClass,
		Map<String, Join> joins,
		MetadataBuildingContext context,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	super( persistentClass.getEntityName(), null, entityXClass, context );
	this.persistentClass = persistentClass;
	this.joins = joins;
	this.inheritanceStatePerClass = inheritanceStatePerClass;

	this.attributeConversionInfoMap = buildAttributeConversionInfoMap( entityXClass );
}
 
Example 4
public void popEntityWorkedOn(PersistentClass persistentClass) {
	final PersistentClass stackTop = stackOfPersistentClassesBeingProcessed.remove(
			stackOfPersistentClassesBeingProcessed.size() - 1
	);
	if ( stackTop != persistentClass ) {
		throw new AssertionFailure(
				"Inconsistent popping: "
						+ persistentClass.getEntityName() + " instead of " + stackTop.getEntityName()
		);
	}
}
 
Example 5
@SuppressWarnings("unchecked")
public EntityTypeImpl(Class javaType, AbstractIdentifiableType<? super X> superType, PersistentClass persistentClass) {
	super(
			javaType,
			persistentClass.getEntityName(),
			superType,
			persistentClass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
			persistentClass.hasIdentifierProperty(),
			persistentClass.isVersioned()
	);
	this.jpaEntityName = persistentClass.getJpaEntityName();
}
 
Example 6
public static BytecodeEnhancementMetadata from(PersistentClass persistentClass) {
	final Class mappedClass = persistentClass.getMappedClass();
	final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom( mappedClass );
	final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading
			? LazyAttributesMetadata.from( persistentClass )
			: LazyAttributesMetadata.nonEnhanced( persistentClass.getEntityName() );

	return new BytecodeEnhancementMetadataPojoImpl(
			persistentClass.getEntityName(),
			mappedClass,
			enhancedForLazyLoading,
			lazyAttributesMetadata
	);
}
 
Example 7
public DynamicMapInstantiator(PersistentClass mappingInfo) {
	this.entityName = mappingInfo.getEntityName();
	isInstanceEntityNames.add( entityName );
	if ( mappingInfo.hasSubclasses() ) {
		Iterator itr = mappingInfo.getSubclassClosureIterator();
		while ( itr.hasNext() ) {
			final PersistentClass subclassInfo = ( PersistentClass ) itr.next();
			isInstanceEntityNames.add( subclassInfo.getEntityName() );
		}
	}
}
 
Example 8
/**
 * Build a LazyFetchGroupMetadata based on the attributes defined for the
 * PersistentClass
 *
 * @param mappedEntity The entity definition
 *
 * @return The built LazyFetchGroupMetadata
 */
public static LazyAttributesMetadata from(PersistentClass mappedEntity) {
	final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>();
	final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>();

	int i = -1;
	int x = 0;
	final Iterator itr = mappedEntity.getPropertyClosureIterator();
	while ( itr.hasNext() ) {
		i++;
		final Property property = (Property) itr.next();
		if ( property.isLazy() ) {
			final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ );
			lazyAttributeDescriptorMap.put( lazyAttributeDescriptor.getName(), lazyAttributeDescriptor );

			final Set<String> attributeSet = fetchGroupToAttributesMap.computeIfAbsent(
					lazyAttributeDescriptor.getFetchGroupName(),
					k -> new LinkedHashSet<>()
			);
			attributeSet.add( lazyAttributeDescriptor.getName() );
		}
	}

	if ( lazyAttributeDescriptorMap.isEmpty() ) {
		return new LazyAttributesMetadata( mappedEntity.getEntityName() );
	}

	for ( Map.Entry<String, Set<String>> entry : fetchGroupToAttributesMap.entrySet() ) {
		entry.setValue( Collections.unmodifiableSet( entry.getValue() ) );
	}

	return new LazyAttributesMetadata(
			mappedEntity.getEntityName(),
			Collections.unmodifiableMap( lazyAttributeDescriptorMap ),
			Collections.unmodifiableMap( fetchGroupToAttributesMap )
	);
}
 
Example 9
public DynamicMapInstantiator(PersistentClass mappingInfo) {
	this.entityName = mappingInfo.getEntityName();
	isInstanceEntityNames.add( entityName );
	if ( mappingInfo.hasSubclasses() ) {
		Iterator itr = mappingInfo.getSubclassClosureIterator();
		while ( itr.hasNext() ) {
			final PersistentClass subclassInfo = ( PersistentClass ) itr.next();
			isInstanceEntityNames.add( subclassInfo.getEntityName() );
		}
	}
}
 
Example 10
Source Project: quarkus   File: ProxyDefinitions.java    License: Apache License 2.0 4 votes vote down vote up
private static Class<?> generateProxyClass(PersistentClass persistentClass,
        Supplier<ByteBuddyProxyHelper> byteBuddyProxyHelper,
        PreGeneratedProxies preGeneratedProxies) {
    final String entityName = persistentClass.getEntityName();
    final Class mappedClass = persistentClass.getMappedClass();
    if ((mappedClass.getModifiers() & ACC_FINAL) == ACC_FINAL) {
        LOGGER.warn("Could not generate an enhanced proxy for entity '" + entityName + "' (class='"
                + mappedClass.getCanonicalName()
                + "') as it's final. Your application might perform better if we're allowed to extend it.");
        return null;
    }
    final Set<Class> proxyInterfaces = ProxyFactoryHelper.extractProxyInterfaces(persistentClass, entityName);
    PreGeneratedProxies.ProxyClassDetailsHolder preProxy = preGeneratedProxies.getProxies()
            .get(persistentClass.getClassName());
    Class<?> preGeneratedProxy = null;
    boolean match = true;
    if (preProxy != null) {
        match = proxyInterfaces.size() == preProxy.getProxyInterfaces().size();
        if (match) {
            for (Class i : proxyInterfaces) {
                if (!preProxy.getProxyInterfaces().contains(i.getName())) {
                    match = false;
                    break;
                }
            }
        }
        if (match) {
            try {
                preGeneratedProxy = Class.forName(preProxy.getClassName(), false,
                        Thread.currentThread().getContextClassLoader());
            } catch (ClassNotFoundException e) {
                //should never happen
                throw new RuntimeException("Unable to load proxy class", e);
            }
        }
    }

    if (preGeneratedProxy == null) {
        if (match) {
            LOGGER.warnf("Unable to find a build time generated proxy for entity %s",
                    persistentClass.getClassName());
        } else {
            //TODO: this should be changed to an exception after 1.4
            //really it should be an exception now
            LOGGER.errorf(
                    "Unable to use a build time generated proxy for entity %s, as the build time proxy " +
                            "interfaces %s are different to the runtime ones %s. This should not happen, please open an " +
                            "issue at https://github.com/quarkusio/quarkus/issues",
                    persistentClass.getClassName(), preProxy.getProxyInterfaces(), proxyInterfaces);
        }
        Class<?> proxyDef = byteBuddyProxyHelper.get().buildProxy(mappedClass, toArray(proxyInterfaces));
        return proxyDef;
    } else {
        return preGeneratedProxy;
    }
}
 
Example 11
private static void processIdPropertiesIfNotAlready(
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		MetadataBuildingContext context,
		PersistentClass persistentClass,
		EntityBinder entityBinder,
		PropertyHolder propertyHolder,
		HashMap<String, IdentifierGeneratorDefinition> classGenerators,
		InheritanceState.ElementsToProcess elementsToProcess,
		boolean subclassAndSingleTableStrategy,
		Set<String> idPropertiesIfIdClass) {
	Set<String> missingIdProperties = new HashSet<>( idPropertiesIfIdClass );
	for ( PropertyData propertyAnnotatedElement : elementsToProcess.getElements() ) {
		String propertyName = propertyAnnotatedElement.getPropertyName();
		if ( !idPropertiesIfIdClass.contains( propertyName ) ) {
			processElementAnnotations(
					propertyHolder,
					subclassAndSingleTableStrategy
							? Nullability.FORCED_NULL
							: Nullability.NO_CONSTRAINT,
					propertyAnnotatedElement,
					classGenerators,
					entityBinder,
					false,
					false,
					false,
					context,
					inheritanceStatePerClass
			);
		}
		else {
			missingIdProperties.remove( propertyName );
		}
	}

	if ( missingIdProperties.size() != 0 ) {
		StringBuilder missings = new StringBuilder();
		for ( String property : missingIdProperties ) {
			missings.append( property ).append( ", " );
		}
		throw new AnnotationException(
				"Unable to find properties ("
						+ missings.substring( 0, missings.length() - 2 )
						+ ") in entity annotated with @IdClass:" + persistentClass.getEntityName()
		);
	}
}
 
Example 12
public EntityNamingSourceImpl(PersistentClass entityBinding) {
	this( entityBinding.getEntityName(), entityBinding.getClassName(), entityBinding.getJpaEntityName() );
}
 
Example 13
public void addClass(PersistentClass persistentClass) throws MappingException {
	Object old = classes.put( persistentClass.getEntityName(), persistentClass );
	if ( old!=null ) {
		throw new DuplicateMappingException( "class/entity", persistentClass.getEntityName() );
	}
}
 
Example 14
protected Instantiator buildInstantiator(PersistentClass persistentClass) {
	return new MyEntityInstantiator( persistentClass.getEntityName() );
}