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


Java Configuration.configure方法代码示例

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


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

示例1: getSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;
    
    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");
    
    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
 
开发者ID:arun-gupta,项目名称:lambda-rds-mysql,代码行数:26,代码来源:HibernateUtil.java

示例2: HibernateHelper

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public HibernateHelper(Logger log, String dialect, String driver_class, String url, String username, String password, long retry, Class<?>... annotatedClasses) throws EngineException {
	this.log = log;
	this.retry = retry + 1;
	
	Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
	Element elt = doc.createElement("session-factory");
	addProperty(elt, "hibernate.connection.driver_class", driver_class);
	addProperty(elt, "hibernate.connection.url", url);
	addProperty(elt, "hibernate.connection.username", username);
	addProperty(elt, "hibernate.connection.password", password);
	addProperty(elt, "hibernate.dialect", dialect);
	addProperty(elt, "hibernate.hbm2ddl.auto", "update");
	addProperty(elt, "hibernate.connection.autocommit", "true");
	addProperty(elt, "hibernate.jdbc.batch_size", "1");
	addProperty(elt, "hibernate.show_sql", "true");
	doc.appendChild(doc.createElement("hibernate-configuration")).appendChild(elt);
	
	configuration = new Configuration();
	for (Class<?> annotatedClass: annotatedClasses) {
		configuration.addAnnotatedClass(annotatedClass);
	}
	configuration.configure(doc);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:24,代码来源:HibernateHelper.java

示例3: getConfiguration

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
			);
	}
	if (configurationFile != null) {
		cfg.configure( configurationFile );
	}

	String[] files = getFiles();
	for (int i = 0; i < files.length; i++) {
		String filename = files[i];
		if ( filename.endsWith(".jar") ) {
			cfg.addJar( new File(filename) );
		}
		else {
			cfg.addFile(filename);
		}
	}
	return cfg;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SchemaExportTask.java

示例4: getConfiguration

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName( namingStrategy ).newInstance()
			);
	}
	if (configurationFile!=null) {
		cfg.configure( configurationFile );
	}

	String[] files = getFiles();
	for (int i = 0; i < files.length; i++) {
		String filename = files[i];
		if ( filename.endsWith(".jar") ) {
			cfg.addJar( new File(filename) );
		}
		else {
			cfg.addFile(filename);
		}
	}
	return cfg;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SchemaUpdateTask.java

示例5: getConfiguration

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private Configuration getConfiguration() throws Exception {
	Configuration cfg = new Configuration();
	if (namingStrategy!=null) {
		cfg.setNamingStrategy(
				(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
			);
	}
	if (configurationFile!=null) {
		cfg.configure( configurationFile );
	}

	String[] files = getFiles();
	for (int i = 0; i < files.length; i++) {
		String filename = files[i];
		if ( filename.endsWith(".jar") ) {
			cfg.addJar( new File(filename) );
		}
		else {
			cfg.addFile(filename);
		}
	}
	return cfg;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SchemaValidatorTask.java

示例6: createSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory createSessionFactory() {
    
    SessionFactory sessionFactory = null;

    try {

        String resource;
        
        Configuration configuration = new Configuration();

        resource = "oswf-store.cfg.xml";
        logger.info("Configuring Hibernate Mapping: " + resource);
        configuration.configure(resource);
      
        // Database configuration; H2 or MySQL
        resource = "hibernate.xml";
        logger.info("Configuring Hibernate Mapping: " + resource);
        configuration.configure(resource);
        
        // Attempt to create the SessionFactory; exceptions may be thrown                
        sessionFactory =  configuration.buildSessionFactory();

    } catch (Throwable e) {
        logger.error(fatal, "Failed to create Hibernate SessionFactory: " + e.toString());
        sessionFactory = null;
    }
    
    return sessionFactory;
}
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:30,代码来源:StartupContextListener.java

示例7: SessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory() {
    try {
        HibernateConfiguration hibernateConfiguration = ConfigurationWrapper.getInstance().getHibernateConfiguration();
        Configuration configuration = new Configuration();
        initHBMs(configuration);
        configuration.configure(hibernateConfiguration.getPathToConfigurationFile());
        StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
        sessionFactory = configuration.buildSessionFactory(standardServiceRegistryBuilder.build());
    }catch (Exception excetption){

    }
}
 
开发者ID:Shiroukoji,项目名称:FH-Manager,代码行数:13,代码来源:SessionFactory.java

示例8: createConfig

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static Configuration createConfig()
{
    Configuration config = new Configuration();
    if(Settings.HIBERNATE_CONFIG_INTERNAL_PATH)
    	config.configure(Settings.HIBERNATE_CONFIG_FILE_PATH);
    else
    	config.configure(new File(Settings.HIBERNATE_CONFIG_FILE_PATH));
    registerEntityTypes(config);
    return config;
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:11,代码来源:HibernateUtil.java

示例9: configureSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static SessionFactory configureSessionFactory()
        throws HibernateException {
    Configuration configuration = new Configuration();  
    configuration.configure();  

    Properties properties = configuration.getProperties();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
        applySettings(properties).buildServiceRegistry();          
    SessionFactory sessionFactory = configuration.
        buildSessionFactory(serviceRegistry);  

    return sessionFactory;  
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:15,代码来源:App.java

示例10: main

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();

		boolean script = true;
		// If true then execute db updates, otherwise just generate and display updates
		boolean doUpdate = true;
		String propFile = null;

		for ( int i = 0; i < args.length; i++ ) {
			if ( args[i].startsWith( "--" ) ) {
				if ( args[i].equals( "--quiet" ) ) {
					script = false;
				}
				else if ( args[i].startsWith( "--properties=" ) ) {
					propFile = args[i].substring( 13 );
				}
				else if ( args[i].startsWith( "--config=" ) ) {
					cfg.configure( args[i].substring( 9 ) );
				}
				else if ( args[i].startsWith( "--text" ) ) {
					doUpdate = false;
				}
				else if ( args[i].startsWith( "--naming=" ) ) {
					cfg.setNamingStrategy(
							( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
					);
				}
			}
			else {
				cfg.addFile( args[i] );
			}

		}

		if ( propFile != null ) {
			Properties props = new Properties();
			props.putAll( cfg.getProperties() );
			props.load( new FileInputStream( propFile ) );
			cfg.setProperties( props );
		}

		StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
		try {
			new SchemaUpdate( serviceRegistry, cfg ).execute( script, doUpdate );
		}
		finally {
			serviceRegistry.destroy();
		}
	}
	catch ( Exception e ) {
           LOG.unableToRunSchemaUpdate(e);
		e.printStackTrace();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:SchemaUpdate.java

示例11: main

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
	try {
		Configuration cfg = new Configuration();

		String propFile = null;

		for ( int i = 0; i < args.length; i++ ) {
			if ( args[i].startsWith( "--" ) ) {
				if ( args[i].startsWith( "--properties=" ) ) {
					propFile = args[i].substring( 13 );
				}
				else if ( args[i].startsWith( "--config=" ) ) {
					cfg.configure( args[i].substring( 9 ) );
				}
				else if ( args[i].startsWith( "--naming=" ) ) {
					cfg.setNamingStrategy(
							( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
					);
				}
			}
			else {
				cfg.addFile( args[i] );
			}

		}

		if ( propFile != null ) {
			Properties props = new Properties();
			props.putAll( cfg.getProperties() );
			props.load( new FileInputStream( propFile ) );
			cfg.setProperties( props );
		}

		StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
		try {
			new SchemaValidator( serviceRegistry, cfg ).validate();
		}
		finally {
			serviceRegistry.destroy();
		}
	}
	catch ( Exception e ) {
           LOG.unableToRunSchemaUpdate(e);
		e.printStackTrace();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:SchemaValidator.java

示例12: createSessionFactory

import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory createSessionFactory() {

    closeSessionFactory();

    String[] resources = {"oswf-store.cfg.xml", RDBMS_CONFIGURATION};
    
    Configuration configuration = new Configuration();

    for (String resource : resources) 
        configuration.configure(resource);

    return configuration.buildSessionFactory();
}
 
开发者ID:will-gilbert,项目名称:OSWf-OSWorkflow-fork,代码行数:14,代码来源:HibernatePersistentVarsTest.java


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