Java Code Examples for org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo#addManagedClassName()

The following examples show how to use org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo#addManagedClassName() . 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
Source File: JPAPersistenceUnitPostProcessor.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Scans for *.orm.xml and adds Entites from classpath.
 *
 * @param pui
 *            the pui
 */
@Override
public void postProcessPersistenceUnitInfo( MutablePersistenceUnitInfo pui )
{
    _Log.info( "Scanning for JPA orm.xml files" );

    for ( File ormFile : getListORMFiles( ) )
    {
        String ormAbsolutePath = ormFile.getAbsolutePath( );
        _Log.info( "Found ORM file : " + ormAbsolutePath );
        pui.addMappingFileName( ormAbsolutePath.substring( ormAbsolutePath.indexOf( CLASSPATH_PATH_IDENTIFIER ) ) );
    }

    _Log.info( "Scanning for JPA entities..." );

    Set<String> entityClasses = AnnotationUtil.find( Entity.class.getName( ) );
    entityClasses.addAll( AnnotationUtil.find( Embeddable.class.getName( ) ) );
    entityClasses.addAll( AnnotationUtil.find( MappedSuperclass.class.getName( ) ) );

    for ( String strClass : entityClasses )
    {
        _Log.info( "Found entity class : " + strClass );

        if ( !pui.getManagedClassNames( ).contains( strClass ) )
        {
            pui.addManagedClassName( strClass );
        }
    }

    if ( _Log.isDebugEnabled( ) )
    {
        dumpPersistenceUnitInfo( pui );
    }
}
 
Example 2
Source File: KradEntityManagerFactoryBean.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
      * {@inheritDoc}
      */
     @Override
     public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
         pui.setExcludeUnlistedClasses(DEFAULT_EXCLUDE_UNLISTED_CLASSES);
processConverterPackages(pui);
         for (String managedClassName : getManagedClassNames()) {
             pui.addManagedClassName(managedClassName);
         }
     }
 
Example 3
Source File: KradEntityManagerFactoryBean.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
       * Determines whether the managed classes contain {@link Converter} annotations and adds them if necessary.
       *
       * @param pui the list of current list of managed classes.
       */
private void processConverterPackages(MutablePersistenceUnitInfo pui) {
	if (converterPackageNames != null) {
		for (String converterPackage : converterPackageNames) {
			// Code below lifted and modified from Spring's DefaultPersistenceUnitManager
			try {
				String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
						+ ClassUtils.convertClassNameToResourcePath(converterPackage)
						+ ENTITY_CLASS_RESOURCE_PATTERN;
				if (LOG.isInfoEnabled()) {
					LOG.info(getPersistenceUnitName() + ": Scanning for JPA @Converter annotations in: "
							+ pattern);
				}
				Resource[] resources = this.resourcePatternResolver.getResources(pattern);
				MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(
						this.resourcePatternResolver);
				for (Resource resource : resources) {
					if (!resource.isReadable()) {
						continue;
					}
					if (LOG.isDebugEnabled()) {
						LOG.debug(getPersistenceUnitName() + ": Found Matching Resource: " + resource);
					}
					MetadataReader reader = readerFactory.getMetadataReader(resource);
					String className = reader.getClassMetadata().getClassName();
					if (!pui.getManagedClassNames().contains(className)
							&& converterAnnotationTypeFilter.match(reader, readerFactory)) {
						pui.addManagedClassName(className);
						if (LOG.isDebugEnabled()) {
							LOG.debug(getPersistenceUnitName()
									+ ": Registering Converter in JPA Persistence Unit: " + className);
						}
					}
				}
			} catch (IOException ex) {
				throw new PersistenceException("Failed to scan classpath converters in package: "
						+ converterPackage, ex);
			}
		}
	}
}