當前位置: 首頁>>代碼示例>>Java>>正文


Java MetadataSources.buildMetadata方法代碼示例

本文整理匯總了Java中org.hibernate.boot.MetadataSources.buildMetadata方法的典型用法代碼示例。如果您正苦於以下問題:Java MetadataSources.buildMetadata方法的具體用法?Java MetadataSources.buildMetadata怎麽用?Java MetadataSources.buildMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.boot.MetadataSources的用法示例。


在下文中一共展示了MetadataSources.buildMetadata方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public void start() {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url)
            .applySetting("hibernate.dialect", config.persistence.dialect)
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            .build();

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLib,代碼行數:27,代碼來源:HibernatePersistenceProvider.java

示例2: HibernateDatabase

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public HibernateDatabase(Properties properties) throws HibernateException {

        StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(properties).build();
        MetadataSources metadataSources = new MetadataSources(registry);
        metadataSources.addAnnotatedClass(SystemInfo.class)
            .addAnnotatedClass(Project.class)
            .addAnnotatedClass(Runner.class)
            .addAnnotatedClass(Repository.class)
            .addAnnotatedClass(RepositoryType.class)
            .addAnnotatedClass(SystemUnderTest.class)
            .addAnnotatedClass(Requirement.class)
            .addAnnotatedClass(Specification.class)
            .addAnnotatedClass(Reference.class)
            .addAnnotatedClass(Execution.class);

        this.properties = properties;
        this.metadata = metadataSources.buildMetadata();

    }
 
開發者ID:testIT-LivingDoc,項目名稱:livingdoc-confluence,代碼行數:20,代碼來源:HibernateDatabase.java

示例3: buildDomainMetamodel

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public static SqmDomainMetamodel buildDomainMetamodel(Class... managedClasses) {
	final MetadataSources metadataSources = new MetadataSources();
	for ( Class managedClass : managedClasses ) {
		metadataSources.addAnnotatedClass( managedClass );
	}

	final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
	metadata.validate();

	// at this point we have access to the mapping Metadata (PersistentClass, etc)
	//		use it to build the testing DomainMetamodel/TypeConfiguration

	final ExplicitSqmDomainMetamodel domainMetamodel = new ExplicitSqmDomainMetamodel( metadata );

	populateDatabaseModel( metadata, domainMetamodel );
	populateMappingModel( metadata, domainMetamodel );

	return domainMetamodel;
}
 
開發者ID:hibernate,項目名稱:hibernate-semantic-query,代碼行數:20,代碼來源:OrmHelper.java

示例4: export

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
protected void export(Class<? extends Dialect> dialect, String app_key, MetadataSources metadata, boolean create, boolean drop) {
    Assert.notNull(dialect, "dialect is invalid [null]");
    Assert.notNull(app_key, "app_key is invalid [null]");
    Assert.notNull(metadata, "metadata is invalid [null]");

    SchemaExport schemaExport = new SchemaExport((MetadataImplementor) metadata.buildMetadata());
    schemaExport.setDelimiter(";");
    schemaExport.setFormat(true);

    if (create) {
        // Generate create script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_create.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, false, true);
    }

    if (drop) {
        // Generate drop script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_drop.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, true, false);
    }
}
 
開發者ID:bartgerard,項目名稱:ubrew_v0.1,代碼行數:22,代碼來源:SchemaExporter.java

示例5: generate

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
 * Method that actually creates the file.
 *
 * @param dbDialect to use
 */
private void generate(Dialect dialect) {

        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
        ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
        StandardServiceRegistry standardServiceRegistry = ssrb.build();

        MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
        for (Class clzz : jpaClasses) {
                metadataSources.addAnnotatedClass(clzz);
        }

        Metadata metadata = metadataSources.buildMetadata();

        SchemaExport export = new SchemaExport();

        export.setDelimiter(";");
        export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
        //export.execute(true, false, false, true);
        export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
 
開發者ID:apache,項目名稱:juddi,代碼行數:26,代碼來源:App.java

示例6: createMetadataImplementor

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public static MetadataImplementor createMetadataImplementor(String dialect, String[] hibernatePackagesToScan) {
    final MetadataSources metadata = new MetadataSources(
            new StandardServiceRegistryBuilder()
                    .applySetting("hibernate.dialect", dialect)
                    .build());

    for (String packageName : hibernatePackagesToScan) {
        for (Class clazz : HibernateMetaDataHelper.getClasses(packageName)) {
            metadata.addAnnotatedClass(clazz);
        }
    }
    return (MetadataImplementor) metadata.buildMetadata();
}
 
開發者ID:shared-vd,項目名稱:tipi-engine,代碼行數:14,代碼來源:HibernateMetaDataHelper.java

示例7: testDbSchema

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Test
public void testDbSchema() {
    MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder()
                    .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").build());

    metadata.addAnnotatedClass(ConsoleEntity.class);
    metadata.addAnnotatedClass(GameEntity.class);
    metadata.addAnnotatedClass(UserEntity.class);
    metadata.addAnnotatedClass(RoleEntity.class);
    metadata.addAnnotatedClass(LibraryEntity.class);
    metadata.addAnnotatedClass(BorrowEntity.class);

    SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata());
    export.create(Target.SCRIPT);
}
 
開發者ID:MannanM,項目名稱:corporate-game-share,代碼行數:16,代碼來源:SchemaTranslator.java

示例8: get

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public DataStore get() {
    // method to force class initialization
    MetadataSources metadataSources = new MetadataSources(
            new StandardServiceRegistryBuilder()
                    .configure("hibernate.cfg.xml")
                    .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
                    .applySetting(Environment.URL, "jdbc:mysql://localhost:"
                            + System.getProperty("mysql.port", "3306")
                            + "/root?serverTimezone=UTC")
                    .applySetting(Environment.USER, "root")
                    .applySetting(Environment.PASS, "root")
                    .build());

    metadataSources.addAnnotatedClass(HibernateUser.class);

    MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata();

    // create example tables from beans
    SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true);
    schemaExport.drop(false, true);
    schemaExport.execute(false, true, false, true);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException(schemaExport.getExceptions().toString());
    }

    LATEST_HIBERNATE_STORE = new AbstractHibernateStore.Builder(metadataImplementor.buildSessionFactory())
        .withScrollEnabled(true)
        .withScrollMode(ScrollMode.FORWARD_ONLY)
        .build();

    BridgeableRedisStore hbaseStore = new BridgeableRedisStore();

    return new MultiplexManager(LATEST_HIBERNATE_STORE, hbaseStore);
}
 
開發者ID:yahoo,項目名稱:elide,代碼行數:37,代碼來源:BridgeableStoreSupplier.java

示例9: startHibernate

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
    builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:36,代碼來源:HibernateL2CacheStrategySelfTest.java

示例10: startHibernate

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = registryBuilder();

    for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    // Use the same cache for Entity and Entity2.
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    StandardServiceRegistry srvcRegistry = builder.build();

    MetadataSources metadataSources = new MetadataSources(srvcRegistry);

    for (Class entityClass : getAnnotatedClasses())
        metadataSources.addAnnotatedClass(entityClass);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
        collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() );

    return metadata.buildSessionFactory();
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:36,代碼來源:HibernateL2CacheSelfTest.java

示例11: validateSchema

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
 * Schema validation
 */
private void validateSchema() {
    try {
        StandardServiceRegistry registry = localSessionFactory.getConfiguration()
                .getStandardServiceRegistryBuilder().build();
        MetadataSources sources = new MetadataSources(registry);
        sources.addPackage("org.unitedinternet.cosmo.model.hibernate");
        Metadata metadata = sources.buildMetadata(registry);
        new SchemaValidator().validate(metadata);
        LOG.info("schema validation passed");
    } catch (HibernateException e) {
        LOG.error("error validating schema", e);
        throw e;
    }
}
 
開發者ID:1and1,項目名稱:cosmo,代碼行數:18,代碼來源:DbInitializer.java

示例12: start

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public void start() {
    // don't judge me, bukkit doesn't want to resolve those so we need to manually load them
    Class[] iDontEvenKnow = new Class[]{CoreMessageLogger_$logger.class, Log_$logger.class,
            ConnectionPoolingLogger_$logger.class, EntityManagerMessageLogger_$logger.class, ConnectionAccessLogger_$logger.class};

    boolean shouldCreateTable = config.persistence.initialTableCreation;
    if (shouldCreateTable) {
        config.persistence.initialTableCreation = false;
        configHandler.saveGlobalConfig();
    }

    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            // credentials and stuff
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url + "?useSSL=false")
            .applySetting("hibernate.dialect", config.persistence.dialect)
            // misc settings
            .applySetting("hibernate.hbm2ddl.auto", shouldCreateTable ? "create" : "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            //TODO apparently this is an anti-pattern [0], but it fixes an issue so ¯\_(ツ)_/¯
            // [0]: https://vladmihalcea.com/2016/09/05/the-hibernate-enable_lazy_load_no_trans-anti-pattern/
            .applySetting("hibernate.enable_lazy_load_no_trans", true)
            .applySetting("hibernate.connection.autocommit", true)
            // connection pool
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            //TODO figure out how to use hikari with hibernate
            //.applySetting("hibernate.connection.provider_class","com.zaxxer.hikari.hibernate.HikariConnectionProvider")
            .build();

    JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(ComponentTypeDescriptor.INSTANCE);

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections("").getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLibv2,代碼行數:48,代碼來源:HibernatePersistenceProvider.java

示例13: get

import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public DataStore get() {
    // Add additional checks to our static check mappings map.
    // NOTE: This is a bit hacky. We need to do a major overhaul on our test architecture
    TestCheckMappings.MAPPINGS.put("filterCheck", Filtered.FilterCheck.class);
    TestCheckMappings.MAPPINGS.put("filterCheck3", Filtered.FilterCheck3.class);

    // method to force class initialization
    MetadataSources metadataSources = new MetadataSources(
            new StandardServiceRegistryBuilder()
                    .configure("hibernate.cfg.xml")
                    .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
                    .applySetting(Environment.URL, "jdbc:mysql://localhost:"
                            + System.getProperty("mysql.port", "3306")
                            + "/root?serverTimezone=UTC")
                    .applySetting(Environment.USER, "root")
                    .applySetting(Environment.PASS, "root")
                    .build());

    try {
        ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class)
                .forEach(metadataSources::addAnnotatedClass);
    } catch (MappingException e) {
        throw new RuntimeException(e);
    }

    MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata();

    // create example tables from beans
    SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true);
    schemaExport.drop(false, true);
    schemaExport.execute(false, true, false, true);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException(schemaExport.getExceptions().toString());
    }

    return new AbstractHibernateStore.Builder(metadataImplementor.buildSessionFactory())
            .withScrollEnabled(true)
            .withScrollMode(ScrollMode.FORWARD_ONLY)
            .build();
}
 
開發者ID:yahoo,項目名稱:elide,代碼行數:43,代碼來源:HibernateDataStoreSupplier.java


注:本文中的org.hibernate.boot.MetadataSources.buildMetadata方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。