Example usage for org.hibernate.cfg Configuration configure

List of usage examples for org.hibernate.cfg Configuration configure

Introduction

In this page you can find the example usage for org.hibernate.cfg Configuration configure.

Prototype

@Deprecated
public Configuration configure(org.w3c.dom.Document document) throws HibernateException 

Source Link

Usage

From source file:org.jbpm.identity.hibernate.IdentitySessionFactory.java

License:Open Source License

public static Configuration createConfiguration(String resource) {
    Configuration configuration = null;
    // create the hibernate configuration
    configuration = new Configuration();

    if (resource != null) {
        log.debug("using '" + resource + "' as hibernate configuration for jbpm");
        configuration.configure(resource);
    } else {//from w w w  .j a v  a 2 s .  c  o  m
        log.debug("using the default hibernate configuration file: hibernate.cfg.xml");
        configuration.configure();
    }
    return configuration;
}

From source file:org.jbpm.pvm.executionmode.embedded.EmbeddedExecutionModeTest.java

License:Open Source License

public void testLoanApprove() {
    Configuration configuration = new Configuration();
    configuration.configure("org/jbpm/pvm/executionmode/embedded/hibernate.cfg.xml");
    sessionFactory = configuration.buildSessionFactory();

    startTransaction();//from  www  .  j a v a2  s  .c om

    Loan loan = new Loan("john doe", 234.0);
    session.save(loan);
    assertEquals("evaluate", loan.getState());

    newTransaction();

    loan = (Loan) session.get(Loan.class, loan.getDbid());
    assertEquals("evaluate", loan.getState());
    loan.approve();
    assertEquals("archive", loan.getState());

    newTransaction();

    loan = (Loan) session.get(Loan.class, loan.getDbid());
    assertEquals("archive", loan.getState());
    loan.archiveComplete();
    assertEquals("end", loan.getState());

    commitTransaction();
}

From source file:org.jbpm.pvm.executionmode.embedded.EmbeddedExecutionModeTest.java

License:Open Source License

public void testLoanReject() {
    Configuration configuration = new Configuration();
    configuration.configure("org/jbpm/pvm/executionmode/embedded/hibernate.cfg.xml");
    sessionFactory = configuration.buildSessionFactory();

    startTransaction();//from   ww w .j  av a 2  s .c  o  m

    Loan loan = new Loan("john doe", 234.0);
    session.save(loan);
    assertEquals("evaluate", loan.getState());

    newTransaction();

    loan = (Loan) session.get(Loan.class, loan.getDbid());
    assertEquals("evaluate", loan.getState());
    loan.reject();
    assertEquals("end", loan.getState());

    newTransaction();

    loan = (Loan) session.get(Loan.class, loan.getDbid());
    assertEquals("end", loan.getState());
}

From source file:org.jcvi.ometa.hibernate.dao.StandaloneSessionAndTransactionManager.java

License:Open Source License

/**
 * Getter for session factory.  This, with no param, forces the creation of a session factory
 * on-the-spot.  It is intended for use in JUnit tests.
 *
 * @return fully-operational session factory.
 */// w  w w .  j  a  v  a 2  s .com
protected SessionFactory getSessionFactory() throws DAOException {
    if (sessionFactoryObject != null)
        return sessionFactoryObject;

    if (sessionFactoryName != null && sessionFactoryName.trim().length() > 0) {
        String message = "Attempt at creating a session factory from scratch when a container session factory /"
                + sessionFactoryName + "/ may be available.";
        logger.error(message);
        throw new DAOException(message);
    }

    try {
        Configuration cfg = new AnnotationConfiguration();

        File f = new File(hibernateCfg);
        if (f.exists()) {
            cfg = cfg.configure(f);
        } else {
            cfg = cfg.configure(hibernateCfg);
        }

        SessionFactory factory = cfg.buildSessionFactory();
        sessionFactoryObject = factory;
        logger.info("Created session factory on-the-spot");
        return factory;

    } catch (Exception ex) {
        logger.error("Failed to create a session factory. " + ex.getMessage());
        throw new DAOException(ex);

    }
}

From source file:org.jessma.dao.hbn.HibernateSessionMgr.java

License:Apache License

@SuppressWarnings("deprecation")
protected SessionFactory buildSessionFactory() {
    Configuration cfg = new Configuration();

    if (GeneralHelper.isStrNotEmpty(pattern)) {
        Set<String> packages = PackageHelper.getPackages(pattern);

        for (String pkg : packages) {
            Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() {
                @Override/*from  www  . j  a v a2 s  .c  o m*/
                public boolean accept(Class<?> clazz) {
                    if (!BeanHelper.isPublicNotAbstractClass(clazz))
                        return false;
                    if (clazz.getAnnotation(Entity.class) == null)
                        return false;

                    return true;
                }
            });

            for (Class<?> clazz : entities)
                cfg.addAnnotatedClass(clazz);
        }
    }

    return cfg.configure(configFile).buildSessionFactory();
}

From source file:org.mifos.framework.util.helpers.DatabaseSetup.java

License:Open Source License

public static Configuration getHibernateConfiguration() {
    Configuration configuration = new Configuration();
    try {/*from   ww  w .j  av a 2s .  c o m*/
        configuration.configure(ClasspathResource.getURI(FilePaths.HIBERNATECFGFILE).toURL());
    } catch (Exception e) {
        throw new HibernateStartUpException(HibernateConstants.CFGFILENOTFOUND, e);
    }
    return configuration;
}

From source file:org.n52.sos.feeder.baw.hibernate.InitSessionFactory.java

License:Open Source License

/**
 * Gets the single instance of InitSessionFactory.
 *
 * @return The SessionFactory/*from   w w  w  . ja  v  a2 s .com*/
 */
public static SessionFactory getInstance() {
    if (sessionFactory == null) {
        final Configuration cfg = new Configuration();
        cfg.configure(Strings.getString("Hibernate.configFile"));
        sessionFactory = cfg.buildSessionFactory();
    }
    return sessionFactory;
}

From source file:org.onebusaway.geocoder.impl.DatabaseCachingGeocoderImplTest.java

License:Apache License

@Before
public void setup() {
    Configuration config = new AnnotationConfiguration();
    config = config.configure("org/onebusaway/geocoder/impl/hibernate-configuration.xml");
    _sessionFactory = config.buildSessionFactory();
}

From source file:org.onebusaway.gtfs.examples.GtfsHibernateReaderExampleMain.java

License:Apache License

private static HibernateGtfsFactory createHibernateGtfsFactory(String resource) {

    Configuration config = new Configuration();

    if (resource.startsWith(KEY_CLASSPATH)) {
        resource = resource.substring(KEY_CLASSPATH.length());
        config = config.configure(resource);
    } else if (resource.startsWith(KEY_FILE)) {
        resource = resource.substring(KEY_FILE.length());
        config = config.configure(new File(resource));
    } else {/*  w  w  w  .  j a  va 2 s.  c o  m*/
        config = config.configure(new File(resource));
    }

    SessionFactory sessionFactory = config.buildSessionFactory();
    return new HibernateGtfsFactory(sessionFactory);
}

From source file:org.onebusaway.gtfs.impl.GtfsMappingTest.java

License:Apache License

@Before
public void setup() throws IOException {

    Configuration config = new Configuration();
    config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
    _sessionFactory = config.buildSessionFactory();

    _dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
    _dao.open();/* w w  w.  ja va  2  s.  co m*/

    _reader = new GtfsReader();
    _reader.setEntityStore(_dao);
}