Example usage for org.hibernate.internal SessionFactoryImpl getDialect

List of usage examples for org.hibernate.internal SessionFactoryImpl getDialect

Introduction

In this page you can find the example usage for org.hibernate.internal SessionFactoryImpl getDialect.

Prototype

@Deprecated
default Dialect getDialect() 

Source Link

Document

Get the SQL dialect.

Usage

From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java

License:Apache License

private void readDetailsFromConnection(RepositoryDiag diag, final SqlRepositoryConfiguration config) {
    final List<LabeledString> details = diag.getAdditionalDetails();

    Session session = getSessionFactory().openSession();
    try {//from ww  w  .ja  v a2  s .  co m
        session.beginTransaction();
        session.doWork(new Work() {

            @Override
            public void execute(Connection connection) throws SQLException {
                details.add(new LabeledString(DETAILS_TRANSACTION_ISOLATION,
                        getTransactionIsolation(connection, config)));

                Properties info = connection.getClientInfo();
                if (info == null) {
                    return;
                }

                for (String name : info.stringPropertyNames()) {
                    details.add(new LabeledString(DETAILS_CLIENT_INFO + name, info.getProperty(name)));
                }
            }
        });
        session.getTransaction().commit();

        if (!(getSessionFactory() instanceof SessionFactoryImpl)) {
            return;
        }
        SessionFactoryImpl factory = (SessionFactoryImpl) getSessionFactory();
        // we try to override configuration which was read from sql repo configuration with
        // real configuration from session factory
        String dialect = factory.getDialect() != null ? factory.getDialect().getClass().getName() : null;
        details.add(new LabeledString(DETAILS_HIBERNATE_DIALECT, dialect));
    } catch (Throwable th) {
        //nowhere to report error (no operation result available)
        session.getTransaction().rollback();
    } finally {
        cleanupSessionAndResult(session, null);
    }
}

From source file:org.babyfish.hibernate.cfg.Configuration.java

License:Open Source License

@Override
public XSessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
    Arguments.mustBeInstanceOfValue("serviceRegistry",
            Arguments.mustNotBeNull("serviceRegistry", serviceRegistry), StandardServiceRegistryImpl.class);
    replacePersisterClassResolver((AbstractServiceRegistryImpl) serviceRegistry);

    String originalCurrentSessionContext = this.getProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS);
    this.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
    SessionFactoryImpl factory;
    try {/*from   w  w  w.  j  a v  a2  s .com*/
        pathPlanKeyVlidationSuspended = true;
        try {
            factory = (SessionFactoryImpl) super.buildSessionFactory(serviceRegistry);
        } finally {
            pathPlanKeyVlidationSuspended = false;
        }
    } finally {
        if (originalCurrentSessionContext != null) {
            this.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, originalCurrentSessionContext);
        } else {
            this.getProperties().remove(Environment.CURRENT_SESSION_CONTEXT_CLASS);
        }
    }
    if (originalCurrentSessionContext != null) {
        factory.getProperties().setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS,
                originalCurrentSessionContext);
    } else {
        factory.getProperties().remove(Environment.CURRENT_SESSION_CONTEXT_CLASS);
    }

    Dialect dialect = factory.getDialect();
    if (dialect instanceof InstallableDialect) {
        ((InstallableDialect) dialect).install(factory);
    }

    EventListenerGroup<MergeEventListener> mergeEventListenerGroup = factory.getServiceRegistry()
            .getService(EventListenerRegistry.class).getEventListenerGroup(EventType.MERGE);
    MergeEventListener mergeEventListener = new ObjectModelMergeEventListener(
            mergeEventListenerGroup.listeners());
    mergeEventListenerGroup.clear();
    mergeEventListenerGroup.appendListener(mergeEventListener);

    setQueryPlanceCache(factory, this.createQueryPlanCache(factory));

    for (ClassMetadata classMetadata : factory.getAllClassMetadata().values()) {
        if (Metadatas.getObjectModelFactoryProvider(classMetadata.getMappedClass()) != null) {
            //Validate whether JPA configuration is same with object model configuration
            HibernateMetadatas.of(classMetadata.getMappedClass()).getPersistentClass(factory);
        }
    }

    return SessionFactoryImplWrapper.wrap(factory);
}