当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.addPackage方法代码示例

本文整理汇总了Java中org.hibernate.cfg.Configuration.addPackage方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.addPackage方法的具体用法?Java Configuration.addPackage怎么用?Java Configuration.addPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.cfg.Configuration的用法示例。


在下文中一共展示了Configuration.addPackage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postProcessMappings

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
/**
 * Reads metadata from annotated classes and packages into the
 * AnnotationConfiguration instance.
 */
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
	if (this.annotatedClasses != null) {
		for (Class<?> annotatedClass : this.annotatedClasses) {
			config.addAnnotatedClass(annotatedClass);
		}
	}
	if (this.annotatedPackages != null) {
		for (String annotatedPackage : this.annotatedPackages) {
			config.addPackage(annotatedPackage);
		}
	}
	scanPackages(config);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AnnotationSessionFactoryBean.java

示例2: newSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }
    configuration.setProperties(properties);
    return configuration.buildSessionFactory(
            new BootstrapServiceRegistryBuilder()
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:29,代码来源:AbstractTest.java

示例3: DataManager

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public DataManager(Config config) throws ServerException {
	// Disable hibernate logging
	@SuppressWarnings("unused")
	org.jboss.logging.Logger logger = org.jboss.logging.Logger.getLogger("org.hibernate");
	java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.WARNING);

	// Disable c3p0 logging
	Properties p = new Properties(System.getProperties());
	p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
	p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");
	System.setProperties(p);

	Properties properties = new Properties();

	properties.setProperty("hibernate.show_sql", config.get("database.show_sql").getAsBoolean() ? "true" : "false");

	switch (config.get("database.provider").getAsString()) {
	case "mysql":
		properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL57Dialect");
		properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");

		properties.setProperty("hibernate.connection.CharSet", "utf8");
		properties.setProperty("hibernate.connection.characterEncoding", "utf8");
		properties.setProperty("hibernate.connection.useUnicode", "true");

		properties.setProperty("hibernate.connection.url", (new StringBuilder())
				.append("jdbc:mysql://")
				.append(config.get("database.mysql.host").getAsString())
				.append(":")
				.append(config.get("database.mysql.port").getAsShort())
				.append("/")
				.append(config.get("database.mysql.database").getAsString())
				.toString());

		properties.setProperty("hibernate.connection.username", config.get("database.mysql.user").getAsString());
		properties.setProperty("hibernate.connection.password", config.get("database.mysql.password").getAsString());
		break;
	default:
		throw new ServerException("Invalid data provider " + config.get("database.provider").getAsString());
	}

	Configuration configuration = new Configuration()
			.configure()
			.addProperties(properties);

	configuration.addPackage("royaleserver.database.entity");
	for (Class<?> clazz : (new Reflections("royaleserver.database.entity")).getTypesAnnotatedWith(Entity.class)) {
		if (!Modifier.isAbstract(clazz.getModifiers())) {
			configuration.addAnnotatedClass(clazz);
		}
	}

	sessionFactory = configuration.buildSessionFactory();
	services = new DataServices(sessionFactory);
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:56,代码来源:DataManager.java

示例4: newLegacySessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
            additionalTypes.stream().forEach(type -> {
                if (type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType) {
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:44,代码来源:AbstractTest.java

示例5: newSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type, new String[]{type.getName()});
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type, new String[]{type.getName()});
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:47,代码来源:AbstractTest.java

示例6: newLegacySessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type);
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type);
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:47,代码来源:AbstractTest.java


注:本文中的org.hibernate.cfg.Configuration.addPackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。