Java 类org.hibernate.metamodel.MetadataSources 实例源码

项目:lams    文件:HbmMetadataSourceProcessorImpl.java   
@Override
@SuppressWarnings( {"unchecked"})
public void prepare(MetadataSources sources) {
    final HierarchyBuilder hierarchyBuilder = new HierarchyBuilder();

    for ( JaxbRoot jaxbRoot : sources.getJaxbRootList() ) {
        if ( ! JaxbHibernateMapping.class.isInstance( jaxbRoot.getRoot() ) ) {
            continue;
        }

        final MappingDocument mappingDocument = new MappingDocument( jaxbRoot, metadata );
        processors.add( new HibernateMappingProcessor( metadata, mappingDocument ) );

        hierarchyBuilder.processMappingDocument( mappingDocument );
    }

    this.entityHierarchies = hierarchyBuilder.groupEntityHierarchies();
}
项目:db-bootstrap    文件:HibernateBootstrapProvider.java   
/**
 * Create a {@link Session} based on the provided configuration file.
 *
 * @param prefix - the prefix for using when loading properties for the session
 * @param hibernateCfg - The location of the hibernate configuration file.
 * @param classLoader - class loader to use with the session factory
 * @return {@link Session}
 * @throws Exception
 */
private Session createSession(final String prefix, final String hibernateCfg, final ClassLoader classLoader)
        throws Exception {
    SessionFactory sessionFactory = null;
    DbBootstrapLogger.ROOT_LOGGER.tracef("Using hibernate configuration file %s", hibernateCfg);

    BootstrapServiceRegistryBuilder serviceRegistryBuilder = new BootstrapServiceRegistryBuilder();
    serviceRegistryBuilder.with(classLoader)
            .with(this.getClass().getClassLoader());

    StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(serviceRegistryBuilder.build())
            .configure(hibernateCfg);

    configureSettingsFromSystemProperties(prefix, standardRegistryBuilder);
    Metadata metadata = new MetadataSources(standardRegistryBuilder.build() ).buildMetadata();

    sessionFactory = metadata.getSessionFactoryBuilder()
            .build();

    return sessionFactory.openSession();
}
项目:db-bootstrap    文件:HibernateTestUtil.java   
public static SessionFactory getSessionFactory() {
    try {
        if (sessionFactory == null) {
            BootstrapServiceRegistryBuilder serviceRegistryBuilder = new BootstrapServiceRegistryBuilder();
            serviceRegistryBuilder.with(HibernateTestUtil.class.getClassLoader());

            StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(serviceRegistryBuilder.build())
                    .configure( "META-INF/hibernate.cfg.xml" )
                    .build();
            Metadata metadata = new MetadataSources( standardRegistry ).buildMetadata();

            sessionFactory = metadata.getSessionFactoryBuilder()
                    .build();
        }
    } catch (Throwable ex) {
        throw new ExceptionInInitializerError(ex);
    }
    return sessionFactory;
}
项目:dblpImporter    文件:HibernateUtil.java   
public static synchronized void buildSessionFactory(String configFile_)
    throws HibernateException
{
    try {
        File configFile = new File(configFile_);
        // Create the SessionFactory from hibernate.cfg.xml
        Configuration config = new Configuration();
        ServiceRegistry serviceRegistry;
        MetadataSources metadataSources;

        config.configure(configFile);
        serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

        _sessionFactory = config.buildSessionFactory(serviceRegistry);
    } catch(HibernateException e) {
        throw e;
    }
}
项目:lams    文件:HbmMetadataSourceProcessorImpl.java   
@Override
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
    Binder binder = new Binder( metadata, processedEntityNames );
    for ( EntityHierarchyImpl entityHierarchy : entityHierarchies ) {
        binder.processEntityHierarchy( entityHierarchy );
    }
}
项目:lams    文件:AnnotationMetadataSourceProcessorImpl.java   
@Override
@SuppressWarnings( { "unchecked" })
public void prepare(MetadataSources sources) {
    // create a jandex index from the annotated classes
    Indexer indexer = new Indexer();
    for ( Class<?> clazz : sources.getAnnotatedClasses() ) {
        indexClass( indexer, clazz.getName().replace( '.', '/' ) + ".class" );
    }

    // add package-info from the configured packages
    for ( String packageName : sources.getAnnotatedPackages() ) {
        indexClass( indexer, packageName.replace( '.', '/' ) + "/package-info.class" );
    }

    Index index = indexer.complete();

    List<JaxbRoot<JaxbEntityMappings>> mappings = new ArrayList<JaxbRoot<JaxbEntityMappings>>();
    for ( JaxbRoot<?> root : sources.getJaxbRootList() ) {
        if ( root.getRoot() instanceof JaxbEntityMappings ) {
            mappings.add( (JaxbRoot<JaxbEntityMappings>) root );
        }
    }
    if ( !mappings.isEmpty() ) {
        index = parseAndUpdateIndex( mappings, index );
    }

    if ( index.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ) != null ) {
        // todo : this needs to move to AnnotationBindingContext
        // what happens right now is that specifying this in an orm.xml causes it to effect all orm.xmls
        metadata.setGloballyQuotedIdentifiers( true );
    }
    bindingContext = new AnnotationBindingContextImpl( metadata, index );
}
项目:lams    文件:AnnotationMetadataSourceProcessorImpl.java   
@Override
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
    assertBindingContextExists();
    // need to order our annotated entities into an order we can process
    Set<EntityHierarchy> hierarchies = EntityHierarchyBuilder.createEntityHierarchies( bindingContext );

    Binder binder = new Binder( bindingContext.getMetadataImplementor(), new ArrayList<String>() );
    for ( EntityHierarchy hierarchy : hierarchies ) {
        binder.processEntityHierarchy( hierarchy );
    }
}
项目:lams    文件:AnnotationMetadataSourceProcessorImpl.java   
@Override
public void processMappingDependentMetadata(MetadataSources sources) {
    TableBinder.bind( bindingContext );
    FetchProfileBinder.bind( bindingContext );
    QueryBinder.bind( bindingContext );
    FilterDefBinder.bind( bindingContext );
}
项目:lams    文件:HbmMetadataSourceProcessorImpl.java   
@Override
public void processIndependentMetadata(MetadataSources sources) {
    for ( HibernateMappingProcessor processor : processors ) {
        processor.processIndependentMetadata();
    }
}
项目:lams    文件:HbmMetadataSourceProcessorImpl.java   
@Override
public void processTypeDependentMetadata(MetadataSources sources) {
    for ( HibernateMappingProcessor processor : processors ) {
        processor.processTypeDependentMetadata();
    }
}
项目:lams    文件:HbmMetadataSourceProcessorImpl.java   
@Override
public void processMappingDependentMetadata(MetadataSources sources) {
    for ( HibernateMappingProcessor processor : processors ) {
        processor.processMappingDependentMetadata();
    }
}
项目:lams    文件:JaxbHelper.java   
public JaxbHelper(MetadataSources metadataSources) {
    this.metadataSources = metadataSources;
}
项目:lams    文件:MetadataBuilderImpl.java   
public MetadataBuilderImpl(MetadataSources sources) {
    this(
            sources,
            getStandardServiceRegistry( sources.getServiceRegistry() )
    );
}
项目:lams    文件:MetadataBuilderImpl.java   
public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {
    this.sources = sources;
    this.options = new OptionsImpl( serviceRegistry );
}
项目:lams    文件:MetadataImpl.java   
public MetadataImpl(MetadataSources metadataSources, Options options) {
    this.serviceRegistry =  options.getServiceRegistry();
    this.options = options;
    this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
            //new DefaultIdentifierGeneratorFactory( dialect );
    this.database = new Database( options );

    this.mappingDefaults = new MappingDefaultsImpl();

    final MetadataSourceProcessor[] metadataSourceProcessors;
    if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) {
        metadataSourceProcessors = new MetadataSourceProcessor[] {
                new HbmMetadataSourceProcessorImpl( this ),
                new AnnotationMetadataSourceProcessorImpl( this )
        };
    }
    else {
        metadataSourceProcessors = new MetadataSourceProcessor[] {
                new AnnotationMetadataSourceProcessorImpl( this ),
                new HbmMetadataSourceProcessorImpl( this )
        };
    }

    this.classLoaderService = new ValueHolder<ClassLoaderService>(
            new ValueHolder.DeferredInitializer<ClassLoaderService>() {
                @Override
                public ClassLoaderService initialize() {
                    return serviceRegistry.getService( ClassLoaderService.class );
                }
            }
    );
    this.persisterClassResolverService = new ValueHolder<PersisterClassResolver>(
            new ValueHolder.DeferredInitializer<PersisterClassResolver>() {
                @Override
                public PersisterClassResolver initialize() {
                    return serviceRegistry.getService( PersisterClassResolver.class );
                }
            }
    );


    final ArrayList<String> processedEntityNames = new ArrayList<String>();

    prepare( metadataSourceProcessors, metadataSources );
    bindIndependentMetadata( metadataSourceProcessors, metadataSources );
    bindTypeDependentMetadata( metadataSourceProcessors, metadataSources );
    bindMappingMetadata( metadataSourceProcessors, metadataSources, processedEntityNames );
    bindMappingDependentMetadata( metadataSourceProcessors, metadataSources );

    // todo : remove this by coordinated ordering of entity processing
    new AssociationResolver( this ).resolve();
    new HibernateTypeResolver( this ).resolve();
    // IdentifierGeneratorResolver.resolve() must execute after AttributeTypeResolver.resolve()
    new IdentifierGeneratorResolver( this ).resolve();
}
项目:lams    文件:MetadataImpl.java   
private void prepare(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
    for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
        metadataSourceProcessor.prepare( metadataSources );
    }
}
项目:lams    文件:MetadataImpl.java   
private void bindIndependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
    for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
        metadataSourceProcessor.processIndependentMetadata( metadataSources );
    }
}
项目:lams    文件:MetadataImpl.java   
private void bindTypeDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
    for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
        metadataSourceProcessor.processTypeDependentMetadata( metadataSources );
    }
}
项目:lams    文件:MetadataImpl.java   
private void bindMappingMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources, List<String> processedEntityNames) {
    for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
        metadataSourceProcessor.processMappingMetadata( metadataSources, processedEntityNames );
    }
}
项目:lams    文件:MetadataImpl.java   
private void bindMappingDependentMetadata(MetadataSourceProcessor[] metadataSourceProcessors, MetadataSources metadataSources) {
    for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) {
        metadataSourceProcessor.processMappingDependentMetadata( metadataSources );
    }
}
项目:lams    文件:AnnotationMetadataSourceProcessorImpl.java   
@Override
public void processIndependentMetadata(MetadataSources sources) {
    assertBindingContextExists();
    TypeDefBinder.bind( bindingContext );
}
项目:lams    文件:AnnotationMetadataSourceProcessorImpl.java   
@Override
public void processTypeDependentMetadata(MetadataSources sources) {
    assertBindingContextExists();
    IdGeneratorBinder.bind( bindingContext );
}
项目:lams    文件:MetadataSourceProcessor.java   
/**
 * Prepare for processing the given sources.
 *
 * @param sources The metadata sources.
 */
public void prepare(MetadataSources sources);
项目:lams    文件:MetadataSourceProcessor.java   
/**
 * Process the independent metadata.  These have no dependency on other types of metadata being processed.
 *
 * @param sources The metadata sources.
 *
 * @see #prepare
 */
public void processIndependentMetadata(MetadataSources sources);
项目:lams    文件:MetadataSourceProcessor.java   
/**
 * Process the parts of the metadata that depend on type information (type definitions) having been processed
 * and available.
 *
 * @param sources The metadata sources.
 *
 * @see #processIndependentMetadata
 */
public void processTypeDependentMetadata(MetadataSources sources);
项目:lams    文件:MetadataSourceProcessor.java   
/**
 * Process the mapping (entities, et al) metadata.
 *
 * @param sources The metadata sources.
 * @param processedEntityNames Collection of any already processed entity names.
 *
 * @see #processTypeDependentMetadata
 */
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames);
项目:lams    文件:MetadataSourceProcessor.java   
/**
 * Process the parts of the metadata that depend on mapping (entities, et al) information having been
 * processed and available.
 *
 * @param sources The metadata sources.
 *
 * @see #processMappingMetadata
 */
public void processMappingDependentMetadata(MetadataSources sources);