@Override public void processEntityHierarchies(Set<String> processedEntityNames) { final List<XClass> orderedClasses = orderAndFillHierarchy( xClasses ); Map<XClass, InheritanceState> inheritanceStatePerClass = AnnotationBinder.buildInheritanceStates( orderedClasses, rootMetadataBuildingContext ); for ( XClass clazz : orderedClasses ) { if ( processedEntityNames.contains( clazz.getName() ) ) { log.debugf( "Skipping annotated class processing of entity [%s], as it has already been processed", clazz ); continue; } AnnotationBinder.bindClass( clazz, inheritanceStatePerClass, rootMetadataBuildingContext ); processedEntityNames.add( clazz.getName() ); } }
@Override public void prepare() { // use any persistence-unit-defaults defined in orm.xml ( (JpaOrmXmlPersistenceUnitDefaultAware) rootMetadataBuildingContext.getBuildingOptions() ).apply( new JpaOrmXmlPersistenceUnitDefaults() { final Map persistenceUnitDefaults = reflectionManager.getDefaults(); @Override public String getDefaultSchemaName() { return StringHelper.nullIfEmpty( (String) persistenceUnitDefaults.get( "schema" ) ); } @Override public String getDefaultCatalogName() { return StringHelper.nullIfEmpty( (String) persistenceUnitDefaults.get( "catalog" ) ); } @Override public boolean shouldImplicitlyQuoteIdentifiers() { final Object isDelimited = persistenceUnitDefaults.get( "delimited-identifier" ); return isDelimited != null && isDelimited == Boolean.TRUE; } } ); rootMetadataBuildingContext.getMetadataCollector().getDatabase().adjustDefaultNamespace( rootMetadataBuildingContext.getBuildingOptions().getMappingDefaults().getImplicitCatalogName(), rootMetadataBuildingContext.getBuildingOptions().getMappingDefaults().getImplicitSchemaName() ); AnnotationBinder.bindDefaults( rootMetadataBuildingContext ); for ( String annotatedPackage : annotatedPackages ) { AnnotationBinder.bindPackage( annotatedPackage, rootMetadataBuildingContext ); } }
private static void bindFilterDefs(XAnnotatedElement annotatedElement, MetadataBuildingContext context) { FilterDef defAnn = annotatedElement.getAnnotation( FilterDef.class ); FilterDefs defsAnn = annotatedElement.getAnnotation( FilterDefs.class ); if ( defAnn != null ) { bindFilterDef( defAnn, context ); } if ( defsAnn != null ) { for ( FilterDef def : defsAnn.value() ) { bindFilterDef( def, context ); } } }
IdentifierGeneratorDefinition idGen = buildIdGenerator( ann, context ); context.getMetadataCollector().addIdentifierGenerator( idGen ); if ( LOG.isTraceEnabled() ) { SequenceGenerators ann = pckg.getAnnotation( SequenceGenerators.class ); for ( SequenceGenerator tableGenerator : ann.value() ) { context.getMetadataCollector().addIdentifierGenerator( buildIdGenerator( tableGenerator, context ) ); IdentifierGeneratorDefinition idGen = buildIdGenerator( ann, context ); context.getMetadataCollector().addIdentifierGenerator( idGen ); TableGenerators ann = pckg.getAnnotation( TableGenerators.class ); for ( TableGenerator tableGenerator : ann.value() ) { context.getMetadataCollector().addIdentifierGenerator( buildIdGenerator( tableGenerator, context ) ); bindGenericGenerators( pckg, context ); bindQueries( pckg, context ); bindFilterDefs( pckg, context ); bindTypeDefs( pckg, context ); bindFetchProfiles( pckg, context ); BinderHelper.bindAnyMetaDefs( pckg, context );
bindQueries( clazzToProcess, mappings ); bindTypeDefs( clazzToProcess, mappings ); bindFilterDefs( clazzToProcess, mappings ); if ( !isEntityClassType( clazzToProcess, classType ) ) { return; PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStatePerClass, mappings, inheritanceState ); bindQueries( clazzToProcess, mappings ); bindFilterDefs( clazzToProcess, mappings ); bindTypeDefs( clazzToProcess, mappings ); bindFetchProfiles( clazzToProcess, mappings ); BinderHelper.bindAnyMetaDefs( clazzToProcess, mappings ); Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns( clazzToProcess, mappings, inheritanceState, superEntity ); PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity ); Cache cacheAnn = determineCacheSettings( clazzToProcess, mappings ); bindFilters( clazzToProcess, entityBinder, mappings ); bindDiscriminatorToPersistentClass( ( RootClass ) persistentClass,
bindQueries( clazzToProcess, context ); bindTypeDefs( clazzToProcess, context ); bindFilterDefs( clazzToProcess, context ); if ( !isEntityClassType( clazzToProcess, classType ) ) { return; PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStatePerClass, PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context ); Entity entityAnn = clazzToProcess.getAnnotation( Entity.class ); org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation( bindQueries( clazzToProcess, context ); bindFilterDefs( clazzToProcess, context ); bindTypeDefs( clazzToProcess, context ); bindFetchProfiles( clazzToProcess, context ); BinderHelper.bindAnyMetaDefs( clazzToProcess, context ); Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns( clazzToProcess, context, discriminatorColumn = processSingleTableDiscriminatorProperties( clazzToProcess, context,
bindManyToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ), joinColumns, !mandatory, bindOneToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ), joinColumns, !mandatory, getFetchMode( ann.fetch() ), ignoreNotFound, onDeleteCascade, ToOneBinder.getTargetEntity( inferredData, mappings ), bindAny( getCascadeStrategy( null, hibernateCascade, false, forcePersist ), ); collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false ); collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade, false, false mappings.getReflectionManager().toXClass( void.class ) ); collectionBinder.setCascadeStrategy( getCascadeStrategy( null, hibernateCascade, false, false ) );
propertyBinder.setColumns( columns ); Property prop = propertyBinder.makePropertyValueAndBind(); setVersionInformation( property, propertyBinder ); rootClass.setVersion( prop ); NotFound notFound = property.getAnnotation( NotFound.class ); boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE ); matchIgnoreNotFoundWithFetchType(propertyHolder.getEntityName(), property.getName(), ignoreNotFound, ann.fetch()); OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class ); boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() ); property.isAnnotationPresent( Id.class ) || ( property.isAnnotationPresent( MapsId.class ) && !ignoreNotFound ); bindManyToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ), joinColumns, !mandatory, property.isAnnotationPresent( Id.class ) || ( property.isAnnotationPresent( MapsId.class ) && !ignoreNotFound ); matchIgnoreNotFoundWithFetchType(propertyHolder.getEntityName(), property.getName(), ignoreNotFound, ann.fetch()); OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class ); boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() ); bindOneToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ), joinColumns, !mandatory, getFetchMode( ann.fetch() ),
public static void bindPackage(String packageName, ExtendedMappings mappings) { XPackage pckg = null; try { pckg = mappings.getReflectionManager().packageForName( packageName ); } catch (ClassNotFoundException cnf) { log.warn( "Package not found or wo package-info.java: " + packageName ); return; } if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) { SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class ); IdGenerator idGen = buildIdGenerator( ann, mappings ); mappings.addGenerator( idGen ); log.debug( "Add sequence generator with name: " + idGen.getName() ); } if ( pckg.isAnnotationPresent( TableGenerator.class ) ) { TableGenerator ann = pckg.getAnnotation( TableGenerator.class ); IdGenerator idGen = buildIdGenerator( ann, mappings ); mappings.addGenerator( idGen ); } if ( pckg.isAnnotationPresent( GenericGenerator.class ) ) { GenericGenerator ann = pckg.getAnnotation( GenericGenerator.class ); IdGenerator idGen = buildIdGenerator( ann, mappings ); mappings.addGenerator( idGen ); } bindQueries( pckg, mappings ); bindFilterDefs( pckg, mappings ); bindTypeDefs( pckg, mappings ); }
String generatorType = generatedValue != null ? generatorType( generatedValue.strategy() ) : "assigned"; String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT; if ( isComponent ) generatorType = "assigned"; //a component must not have any generator bindOneToOne( getCascadeStrategy( ann.cascade(), hibernateCascade ), joinColumns, mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade ) ); collectionBinder.setOneToMany( true ); mappings.getReflectionManager().toXClass( manyToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade ) ); collectionBinder.setOneToMany( false ); bindJoinedTableAssociation( assocTable, mappings, entityBinder, collectionBinder, propertyHolder, inferredData, mappedBy ); bindComponent( inferredData, propertyHolder, propertyAnnotated, propertyAccessor, entityBinder, isIdentifierMapper,
bindQueries( annotatedClass, mappings ); bindFilterDefs( annotatedClass, mappings ); bindTypeDefs( annotatedClass, mappings ); if ( inheritanceState.hasSons || ! discriminatorColumn.isImplicit() ) { bindDiscriminatorToPersistentClass( (RootClass) persistentClass, discriminatorColumn, HashMap<String, IdGenerator> classGenerators = buildLocalGenerators( annotatedClass, mappings ); getElementsToProcess( clazzToProcess, inheritanceStatePerClass, propertyHolder, entityBinder, mappings );
if ( trueOneToOne || mapToPK || ! BinderHelper.isDefault( mappedBy ) ) { bindManyToOne( cascadeStrategy, joinColumns, optional, ignoreNotFound, cascadeOnDelete, targetEntity,
bindManyToOne( cascadeStrategy, joinColumns, optional, ignoreNotFound, cascadeOnDelete, targetEntity,
/** * Read package level metadata. * * @param packageName java package name * * @return the configuration object * * @throws MappingException in case there is an error in the mapping data */ public AnnotationConfiguration addPackage(String packageName) throws MappingException { log.info( "Mapping package {}", packageName ); try { AnnotationBinder.bindPackage( packageName, createExtendedMappings() ); return this; } catch ( MappingException me ) { log.error( "Could not compile the mapping annotations", me ); throw me; } }
AnnotationBinder.bindDefaults( createExtendedMappings() ); isDefaultProcessed = true;
bindQueries( clazzToProcess, mappings ); bindTypeDefs( clazzToProcess, mappings ); bindFilterDefs( clazzToProcess, mappings ); if ( !isEntityClassType( clazzToProcess, classType ) ) { return; PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStatePerClass, mappings, inheritanceState ); PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity ); Entity entityAnn = clazzToProcess.getAnnotation( Entity.class ); org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation( bindQueries( clazzToProcess, mappings ); bindFilterDefs( clazzToProcess, mappings ); bindTypeDefs( clazzToProcess, mappings ); bindFetchProfiles( clazzToProcess, mappings ); BinderHelper.bindAnyMetaDefs( clazzToProcess, mappings ); Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns( clazzToProcess, mappings, inheritanceState, superEntity ); Ejb3DiscriminatorColumn discriminatorColumn = null; if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) { discriminatorColumn = processDiscriminatorProperties( clazzToProcess, mappings, inheritanceState, entityBinder );
bindQueries( clazzToProcess, context ); bindTypeDefs( clazzToProcess, context ); bindFilterDefs( clazzToProcess, context ); if ( !isEntityClassType( clazzToProcess, classType ) ) { return; PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStatePerClass, PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context ); Entity entityAnn = clazzToProcess.getAnnotation( Entity.class ); org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation( bindQueries( clazzToProcess, context ); bindFilterDefs( clazzToProcess, context ); bindTypeDefs( clazzToProcess, context ); bindFetchProfiles( clazzToProcess, context ); BinderHelper.bindAnyMetaDefs( clazzToProcess, context ); Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns( clazzToProcess, context, discriminatorColumn = processSingleTableDiscriminatorProperties( clazzToProcess, context,
propertyBinder.setColumns( columns ); Property prop = propertyBinder.makePropertyValueAndBind(); setVersionInformation( property, propertyBinder ); rootClass.setVersion( prop ); bindManyToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ), joinColumns, !mandatory, bindOneToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ), joinColumns, !mandatory, getFetchMode( ann.fetch() ), ignoreNotFound, onDeleteCascade, ToOneBinder.getTargetEntity( inferredData, mappings ), bindAny( getCascadeStrategy( null, hibernateCascade, false, forcePersist ), ); collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false ); collectionBinder.setCascadeStrategy( getCascadeStrategy(
propertyBinder.setColumns( columns ); Property prop = propertyBinder.makePropertyValueAndBind(); setVersionInformation( property, propertyBinder ); rootClass.setVersionAttributeMapping( prop ); NotFound notFound = property.getAnnotation( NotFound.class ); boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE ); matchIgnoreNotFoundWithFetchType(propertyHolder.getEntityName(), property.getName(), ignoreNotFound, ann.fetch()); OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class ); boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() ); property.isAnnotationPresent( Id.class ) || ( property.isAnnotationPresent( MapsId.class ) && !ignoreNotFound ); bindManyToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ), joinColumns, !mandatory, property.isAnnotationPresent( Id.class ) || ( property.isAnnotationPresent( MapsId.class ) && !ignoreNotFound ); matchIgnoreNotFoundWithFetchType(propertyHolder.getEntityName(), property.getName(), ignoreNotFound, ann.fetch()); OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class ); boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() ); bindOneToOne( getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ), joinColumns, !mandatory, getFetchMode( ann.fetch() ),
public static void bindPackage(String packageName, ExtendedMappings mappings) { XPackage pckg; try { pckg = mappings.getReflectionManager().packageForName( packageName ); } catch ( ClassNotFoundException cnf ) { log.warn( "Package not found or wo package-info.java: {}", packageName ); return; } if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) { SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class ); IdGenerator idGen = buildIdGenerator( ann, mappings ); mappings.addGenerator( idGen ); log.trace( "Add sequence generator with name: {}", idGen.getName() ); } if ( pckg.isAnnotationPresent( TableGenerator.class ) ) { TableGenerator ann = pckg.getAnnotation( TableGenerator.class ); IdGenerator idGen = buildIdGenerator( ann, mappings ); mappings.addGenerator( idGen ); } bindGenericGenerators( pckg, mappings ); bindQueries( pckg, mappings ); bindFilterDefs( pckg, mappings ); bindTypeDefs( pckg, mappings ); bindFetchProfiles( pckg, mappings ); BinderHelper.bindAnyMetaDefs( pckg, mappings ); }