List of usage examples for org.hibernate.engine.spi SessionFactoryImplementor getDialect
@Deprecated
default Dialect getDialect()
From source file:com.amalto.core.storage.hibernate.HibernateStorage.java
License:Open Source License
@Override public void adapt(MetadataRepository newRepository, boolean force) { if (newRepository == null) { throw new IllegalArgumentException("New data model can not be null."); //$NON-NLS-1$ }//from w w w .j ava2s.c o m MetadataRepository previousRepository = getMetadataRepository(); Compare.DiffResults diffResults = Compare.compare(previousRepository, newRepository); List<ComplexTypeMetadata> sortedTypesToDrop = findSortedTypesToDrop(diffResults, force); if (sortedTypesToDrop.size() > 0) { // Clean full text index cleanFullTextIndex(sortedTypesToDrop); // Clean update reports cleanUpdateReports(sortedTypesToDrop); // Clean impacted tables cleanImpactedTables(sortedTypesToDrop); } // Reinitialize Hibernate LOGGER.info("Completing database schema update..."); //$NON-NLS-1$ // for the liquibase if (!force) { try { SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) this .getCurrentSession().getSessionFactory(); Dialect dialect = sessionFactoryImplementor.getDialect(); Connection connection = sessionFactoryImplementor.getConnectionProvider().getConnection(); LiquibaseSchemaAdapter liquibaseChange = new LiquibaseSchemaAdapter(tableResolver, diffResults, dialect, (RDBMSDataSource) this.getDataSource()); liquibaseChange.adapt(connection); } catch (Exception e) { LOGGER.error("execute liquibase update failure", e); } } try { close(false); internalInit(); prepare(newRepository, false); LOGGER.info("Database schema update complete."); //$NON-NLS-1$ } catch (Exception e) { throw new RuntimeException("Unable to complete database schema update.", e); //$NON-NLS-1$ } }
From source file:com.blazebit.persistence.impl.hibernate.function.HibernateEntityManagerIntegrator.java
License:Apache License
private Dialect getDialect(EntityManager em) { Session s = em.unwrap(Session.class); SessionFactoryImplementor sf = (SessionFactoryImplementor) s.getSessionFactory(); return sf.getDialect(); }
From source file:com.blazebit.persistence.integration.hibernate.base.function.AbstractHibernateEntityManagerFactoryIntegrator.java
License:Apache License
protected Dialect getDialect(Session s) { SessionFactoryImplementor sf = (SessionFactoryImplementor) s.getSessionFactory(); return sf.getDialect(); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
private String[] getColumnTypeForPropertyType(EntityType<?> entityType, String attributeName, SessionFactoryImplementor sfi, Type propertyType) { if (propertyType instanceof org.hibernate.type.EntityType) { propertyType = ((org.hibernate.type.EntityType) propertyType).getIdentifierOrUniqueKeyType(sfi); }// ww w . j a va 2s . c o m long length = Column.DEFAULT_LENGTH; int precision = Column.DEFAULT_PRECISION; int scale = Column.DEFAULT_SCALE; try { Method m = Type.class.getMethod("dictatedSizes", Mapping.class); Object size = ((Object[]) m.invoke(propertyType, sfi))[0]; length = (long) size.getClass().getMethod("getLength").invoke(size); precision = (int) size.getClass().getMethod("getPrecision").invoke(size); scale = (int) size.getClass().getMethod("getScale").invoke(size); } catch (Exception ex) { LOG.fine("Could not determine the column type of the attribute: " + attributeName + " of the entity: " + entityType.getName()); } return new String[] { sfi.getDialect().getTypeName(propertyType.sqlTypes(sfi)[0], length, precision, scale) }; }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate42EntityManagerFactoryIntegrator.java
License:Apache License
@Override public JpaProviderFactory getJpaProviderFactory(final EntityManagerFactory entityManagerFactory) { return new JpaProviderFactory() { @Override/*from www .j av a 2 s . co m*/ public JpaProvider createJpaProvider(EntityManager em) { SessionFactoryImplementor factory = null; PersistenceUnitUtil persistenceUnitUtil = entityManagerFactory == null ? null : entityManagerFactory.getPersistenceUnitUtil(); if (persistenceUnitUtil == null && em != null) { persistenceUnitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil(); } if (em == null) { if (entityManagerFactory instanceof SessionFactoryImplementor) { factory = (SessionFactoryImplementor) entityManagerFactory; } else if (entityManagerFactory instanceof HibernateEntityManagerFactory) { factory = (SessionFactoryImplementor) ((HibernateEntityManagerFactory) entityManagerFactory) .getSessionFactory(); } if (entityManagerFactory instanceof HibernateEntityManagerFactory) { return new HibernateJpaProvider(persistenceUnitUtil, getDbmsName(factory.getDialect()), factory.getEntityPersisters(), factory.getCollectionPersisters(), MAJOR, MINOR, FIX, TYPE); } } return new HibernateJpaProvider(persistenceUnitUtil, getDbms(em), getEntityPersisters(em), getCollectionPersisters(em), MAJOR, MINOR, FIX, TYPE); } }; }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate43Access.java
License:Apache License
public SessionFactoryImplementor wrapSessionFactory(SessionFactoryImplementor sessionFactory, DbmsDialect dbmsDialect) {/* www . j a v a 2s .c om*/ Object dialectProxy = new Hibernate43LimitHandlingDialect(sessionFactory.getDialect(), dbmsDialect); Object sessionFactoryProxy = Proxy.newProxyInstance(sessionFactory.getClass().getClassLoader(), new Class[] { SessionFactoryImplementor.class }, new Hibernate43SessionFactoryInvocationHandler(sessionFactory, dialectProxy)); return (SessionFactoryImplementor) sessionFactoryProxy; }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate43EntityManagerFactoryIntegrator.java
License:Apache License
@Override public JpaProviderFactory getJpaProviderFactory(final EntityManagerFactory entityManagerFactory) { return new JpaProviderFactory() { @Override//from w w w .j a va 2 s. c o m public JpaProvider createJpaProvider(EntityManager em) { SessionFactoryImplementor factory = null; PersistenceUnitUtil persistenceUnitUtil = entityManagerFactory == null ? null : entityManagerFactory.getPersistenceUnitUtil(); if (persistenceUnitUtil == null && em != null) { persistenceUnitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil(); } if (em == null) { if (entityManagerFactory instanceof SessionFactoryImplementor) { factory = (SessionFactoryImplementor) entityManagerFactory; } else if (entityManagerFactory instanceof HibernateEntityManagerFactory) { factory = (SessionFactoryImplementor) ((HibernateEntityManagerFactory) entityManagerFactory) .getSessionFactory(); } if (factory == null && entityManagerFactory != null) { factory = entityManagerFactory.unwrap(SessionFactoryImplementor.class); } if (factory != null) { return new HibernateJpa21Provider(persistenceUnitUtil, getDbmsName(factory.getDialect()), factory.getEntityPersisters(), factory.getCollectionPersisters(), MAJOR, MINOR, FIX, TYPE); } } return new HibernateJpa21Provider(persistenceUnitUtil, getDbms(em), getEntityPersisters(em), getCollectionPersisters(em), MAJOR, MINOR, FIX, TYPE); } }; }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate43Integrator.java
License:Apache License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity;/*from w w w.ja v a2 s. c om*/ boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate4Access.java
License:Apache License
public SessionFactoryImplementor wrapSessionFactory(SessionFactoryImplementor sessionFactory, DbmsDialect dbmsDialect) {//from w ww .j a v a 2 s . co m Object dialectProxy = new Hibernate4LimitHandlingDialect(sessionFactory.getDialect(), dbmsDialect); Object sessionFactoryProxy = Proxy.newProxyInstance(sessionFactory.getClass().getClassLoader(), new Class[] { SessionFactoryImplementor.class }, new Hibernate4SessionFactoryInvocationHandler(sessionFactory, dialectProxy)); return (SessionFactoryImplementor) sessionFactoryProxy; }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate4Integrator.java
License:Apache License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity;/*from w w w .j a v a2s .c o m*/ boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (valuesEntity.equals(entityClass)) { registerValuesEntity = false; } if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }