Java 类org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry 实例源码

项目:hibernate-json-type    文件:JsonTypeContributor.java   
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
    JsonType jtype;
    JavaTypeDescriptor jdesc;
    try {
        jtype = JsonType.INSTANCE;
        jdesc = JsonJavaTypeDescriptor.INSTANCE;
    }
    catch (Throwable t) {
        // Avoid logging system for a project so small
        System.err.println("JSON type contribution failed! Message: " + t.getMessage());
        t.printStackTrace(System.err);
        return;
    }
    JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(jdesc);
    typeContributions.contributeType(jtype);
}
项目:VoxelGamesLibv2    文件:HibernatePersistenceProvider.java   
@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();
    }
}