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