Search in sources :

Example 56 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project uPortal by Jasig.

the class DataSourceSchemaExport method setConfiguration.

@Override
public void setConfiguration(String persistenceUnit, HibernateConfiguration hibernateConfiguration) {
    this.configuration = hibernateConfiguration.getConfiguration();
    final SessionFactoryImplementor sessionFactory = hibernateConfiguration.getSessionFactory();
    this.dialect = sessionFactory.getDialect();
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor)

Example 57 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project spring-framework by spring-projects.

the class SessionFactoryUtils method getDataSource.

/**
	 * Determine the DataSource of the given SessionFactory.
	 * @param sessionFactory the SessionFactory to check
	 * @return the DataSource, or {@code null} if none found
	 * @see ConnectionProvider
	 */
public static DataSource getDataSource(SessionFactory sessionFactory) {
    Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties");
    if (getProperties != null) {
        Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory);
        Object dataSourceValue = props.get(Environment.DATASOURCE);
        if (dataSourceValue instanceof DataSource) {
            return (DataSource) dataSourceValue;
        }
    }
    if (sessionFactory instanceof SessionFactoryImplementor) {
        SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory;
        try {
            ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
            if (cp != null) {
                return cp.unwrap(DataSource.class);
            }
        } catch (UnknownServiceException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
            }
        }
    }
    return null;
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) UnknownServiceException(org.hibernate.service.UnknownServiceException) Method(java.lang.reflect.Method) Map(java.util.Map) DataSource(javax.sql.DataSource) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)

Example 58 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class OsgiIntegrationTest method testServiceContributorDiscovery.

@Test
public void testServiceContributorDiscovery() throws Exception {
    final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
    final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService(sr);
    assertNotNull(sfi.getServiceRegistry().getService(SomeService.class));
}
Also used : SessionFactory(org.hibernate.SessionFactory) SomeService(org.hibernate.osgi.test.client.SomeService) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 59 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class OsgiIntegrationTest method testExtensionPoints.

@Test
public void testExtensionPoints() throws Exception {
    final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
    final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService(sr);
    assertTrue(TestIntegrator.passed());
    Class impl = sfi.getServiceRegistry().getService(StrategySelector.class).selectStrategyImplementor(Calendar.class, TestStrategyRegistrationProvider.GREGORIAN);
    assertNotNull(impl);
    BasicType basicType = sfi.getTypeResolver().basic(TestTypeContributor.NAME);
    assertNotNull(basicType);
}
Also used : SessionFactory(org.hibernate.SessionFactory) BasicType(org.hibernate.type.BasicType) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) BeforeClass(org.junit.BeforeClass) PerClass(org.ops4j.pax.exam.spi.reactors.PerClass) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 60 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class SpatialRelateExpression method toSqlString.

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final SessionFactoryImplementor factory = criteriaQuery.getFactory();
    final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, this.propertyName);
    final Dialect dialect = factory.getDialect();
    if (dialect instanceof SpatialDialect) {
        final SpatialDialect seDialect = (SpatialDialect) dialect;
        return seDialect.getSpatialRelateSQL(columns[0], spatialRelation);
    } else {
        throw new IllegalStateException("Dialect must be spatially enabled dialect");
    }
}
Also used : SpatialDialect(org.hibernate.spatial.SpatialDialect) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Dialect(org.hibernate.dialect.Dialect) SpatialDialect(org.hibernate.spatial.SpatialDialect)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)129 Test (org.junit.Test)46 Configuration (org.hibernate.cfg.Configuration)27 SQLException (java.sql.SQLException)18 Type (org.hibernate.type.Type)16 EntityPersister (org.hibernate.persister.entity.EntityPersister)13 Connection (java.sql.Connection)12 HibernateException (org.hibernate.HibernateException)12 PreparedStatement (java.sql.PreparedStatement)11 Metadata (org.hibernate.boot.Metadata)11 Statement (java.sql.Statement)10 ArrayList (java.util.ArrayList)10 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)10 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)10 Serializable (java.io.Serializable)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HashMap (java.util.HashMap)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 Map (java.util.Map)6