當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。