List of usage examples for org.hibernate.cfg Configuration configure
@Deprecated public Configuration configure(org.w3c.dom.Document document) throws HibernateException
From source file:net.jforum.core.hibernate.AbstractDAOTestCase.java
License:Open Source License
@Before public void setUp() throws Exception { Configuration config = new AnnotationConfiguration(); config.configure("/hibernate-tests.cfg.xml"); sessionFactory = config.buildSessionFactory(); session = sessionFactory.openSession(); beginTransaction();//from ww w. j a va2s.co m }
From source file:net.lizalab.util.jasypt.h4.ext.connectionprovider.EncryptedConnectionProviderImplIT.java
License:Apache License
@Test public final void testC3P0ConnectionProviderImpl() { // Load up the configuration, for this test we'll use the c3p0 // specific cfg which is /hibernate.c3p0.cfg.xml. Configuration configuration = new Configuration(); configuration.configure("hibernate.c3p0.cfg.xml"); doTest(configuration);//ww w.j av a 2 s . c o m }
From source file:net.pixomania.crawler.db.HibernateUtil.java
private static SessionFactory buildSessionFactory() { try {//from w ww .j a v a 2s.c om Configuration configuration = new Configuration(); configuration.configure("net/pixomania/crawler/db/hibernate.cfg.xml"); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); return configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:nl.intercommit.weaves.hibernate.SessionFactoryConfiguration.java
License:Open Source License
public final void configure(final Configuration configuration) { configuration.configure(configFile); }
From source file:org.accretegb.modules.customswingcomponent.Utils.java
License:Apache License
static public Map<String, String> getAuthorizationStrs() { Map<String, String> map = new HashMap<String, String>(); Configuration config = new Configuration(); config.configure("pmhibernate.cfg.xml"); SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) HibernateSessionFactory.getSessionFactory(); Properties props = sessionFactoryImpl.getProperties(); String username = props.get("hibernate.connection.username").toString(); String password = props.get("hibernate.connection.password").toString(); String url = props.get("hibernate.connection.url").toString(); String server = url.split(":")[2].replace("//", ""); String port = url.split(":")[3].substring(0, url.split(":")[3].indexOf("/")); if (password.equals("")) { password = ""; }/*from w w w . j av a 2 s . com*/ map.put("username", username); map.put("password", password); map.put("url", url); map.put("server", server); map.put("port", port); return map; }
From source file:org.beangle.commons.orm.hibernate.ddl.DdlGenerator.java
License:Open Source License
public void gen(String dialect, String fileName) throws HibernateException, IOException { Configuration configuration = new OverrideConfiguration(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( DdlGenerator.class.getClassLoader()); configuration.getProperties().put(Environment.DIALECT, dialect); // config naming strategy DefaultTableNamingStrategy tableNamingStrategy = new DefaultTableNamingStrategy(); for (Resource resource : resolver.getResources("classpath*:META-INF/beangle/table.properties")) tableNamingStrategy.addConfig(resource.getURL()); RailsNamingStrategy namingStrategy = new RailsNamingStrategy(); namingStrategy.setTableNamingStrategy(tableNamingStrategy); configuration.setNamingStrategy(namingStrategy); for (Resource resource : resolver.getResources("classpath*:META-INF/hibernate.cfg.xml")) configuration.configure(resource.getURL()); SchemaExport export = new SchemaExport(configuration); export.setOutputFile(fileName);/* w ww .j a v a 2 s.c o m*/ export.execute(false, false, false, true); }
From source file:org.beangle.orm.hibernate.tool.ConfigBuilder.java
License:Open Source License
/** * build configration/* ww w .j av a2 s .c o m*/ * * @throws Exception */ @SuppressWarnings("unchecked") public static Configuration build(Configuration cfg) throws Exception { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( DdlGenerator.class.getClassLoader()); // config naming strategy DefaultTableNamingStrategy tableNamingStrategy = new DefaultTableNamingStrategy(); for (Resource resource : resolver.getResources("classpath*:META-INF/beangle/table.properties")) tableNamingStrategy.addConfig(resource.getURL()); RailsNamingStrategy namingStrategy = new RailsNamingStrategy(); namingStrategy.setTableNamingStrategy(tableNamingStrategy); cfg.setNamingStrategy(namingStrategy); for (Resource resource : resolver.getResources("classpath*:META-INF/hibernate.cfg.xml")) cfg.configure(resource.getURL()); for (Resource resource : resolver.getResources("classpath*:META-INF/beangle/persist*.properties")) { InputStream is = resource.getURL().openStream(); Properties props = new Properties(); if (null != is) props.load(is); Object module = props.remove("module"); if (null == module) continue; Class<? extends AbstractPersistModule> moduleClass = (Class<? extends AbstractPersistModule>) ClassLoaders .loadClass(module.toString()); addPersistInfo(cfg, moduleClass.newInstance().getConfig()); Enumeration<String> enumer = (Enumeration<String>) props.propertyNames(); while (enumer.hasMoreElements()) { String propertyName = enumer.nextElement(); cfg.setProperty(propertyName, props.getProperty(propertyName)); } IOs.close(is); } cfg.buildMappings(); return cfg; }
From source file:org.cast.cwm.CwmApplication.java
License:Open Source License
@Override protected void configureHibernate(Configuration c) { // We don't actually want the defaults that Databinder sets. // super.configureHibernate(ac); File configFile = configuration.getFile("cwm.hibernateConfig"); if (configFile == null) throw new RuntimeException( "Hibernate config file must be specified with cwm.hibernateConfig property."); c.configure(configFile); addCwmHibernateClasses(c);// ww w. j ava 2 s . c o m }
From source file:org.clothocad.hibernate.HibernateConnection.java
License:Open Source License
public boolean connect(URL hibernateXML, List<URL> mappings) { // Create a new configuration and configures it. Configuration config = new Configuration(); for (URL map : mappings) { config.addURL(map);// ww w.j a v a 2 s . com } try { // Attempt to create a session factory from the configuration. // As long as this session factory is active, the connection is // defined as active. config.configure(hibernateXML); fac = config.buildSessionFactory(); HibernateConnection.connection = this; return true; } catch (Throwable e) { System.err.println(e); e.printStackTrace(); fac = null; return false; } }
From source file:org.codehaus.mojo.appfuse.utility.ConfigurationUtility.java
License:Apache License
/** * This method will run some basic preparation and procssing tasks on the configuration such as loading properties * files from the file system into a properties object, loading naming strategy classes and entity resolver classes. * /*from w ww .j a va 2 s . c om*/ * @param inConfiguration * The configuration to configure. * * @throws MojoExecutionException * Thrown if the configuration properties cannot be loaded. */ protected void doConfiguration(final Configuration inConfiguration) throws MojoExecutionException { validateParameters(); if (propertyFile != null) { Properties properties = new Properties(); try { properties.load(new FileInputStream(propertyFile)); } catch (FileNotFoundException ex) { throw new MojoExecutionException(propertyFile + " not found.", ex); } catch (IOException ex) { throw new MojoExecutionException("Problem while loading " + propertyFile, ex); } inConfiguration.setProperties(properties); } if (entityResolver != null) { try { Class resolver = ReflectHelper.classForName(entityResolver, this.getClass()); Object object = resolver.newInstance(); inConfiguration.setEntityResolver((EntityResolver) object); if (LOG.isDebugEnabled()) { LOG.debug("Using " + entityResolver + " as entity resolver"); } } catch (Exception e) { throw new MojoExecutionException( "Could not create or find " + entityResolver + " class to use for entity resolvement"); } } if (namingStrategy != null) { try { Class resolver = ReflectHelper.classForName(namingStrategy, this.getClass()); Object object = resolver.newInstance(); inConfiguration.setNamingStrategy((NamingStrategy) object); if (LOG.isDebugEnabled()) { LOG.debug("Using " + namingStrategy + " as naming strategy"); } } catch (Exception e) { throw new MojoExecutionException( "Could not create or find " + namingStrategy + " class to use for naming strategy"); } } if (configurationFile != null) { inConfiguration.configure(configurationFile); } addMappings(getFiles()); }