本文整理汇总了Java中org.hibernate.internal.SessionFactoryImpl类的典型用法代码示例。如果您正苦于以下问题:Java SessionFactoryImpl类的具体用法?Java SessionFactoryImpl怎么用?Java SessionFactoryImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SessionFactoryImpl类属于org.hibernate.internal包,在下文中一共展示了SessionFactoryImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSessionFactory
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* Create a {@link SessionFactory} using the properties and mappings in this configuration. The
* {@link SessionFactory} will be immutable, so changes made to {@code this} {@link Configuration} after
* building the {@link SessionFactory} will not affect it.
*
* @param serviceRegistry The registry of services to be used in creating this session factory.
*
* @return The built {@link SessionFactory}
*
* @throws HibernateException usually indicates an invalid configuration or invalid mapping information
*/
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
LOG.debugf( "Preparing to build session factory with filters : %s", filterDefinitions );
buildTypeRegistrations( serviceRegistry );
secondPassCompile();
if ( !metadataSourceQueue.isEmpty() ) {
LOG.incompleteMappingMetadataCacheProcessing();
}
validate();
Environment.verifyProperties( properties );
Properties copy = new Properties();
copy.putAll( properties );
ConfigurationHelper.resolvePlaceHolders( copy );
Settings settings = buildSettings( copy, serviceRegistry );
return new SessionFactoryImpl(
this,
mapping,
serviceRegistry,
settings,
sessionFactoryObserver
);
}
示例2: closeHibernate
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
public static void closeHibernate() {
if (sSessionFactory!=null) {
if (sSessionFactory instanceof SessionFactoryImpl) {
ConnectionProvider cp = ((SessionFactoryImpl)sSessionFactory).getConnectionProvider();
if (cp instanceof DisposableConnectionProvider) {
try {
((DisposableConnectionProvider)cp).destroy();
} catch (Exception e) {
sLog.error("Failed to destroy connection provider: " + e.getMessage());
}
}
}
sSessionFactory.close();
sSessionFactory=null;
}
}
示例3: testQueryCacheCleanup
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
@Test
public void testQueryCacheCleanup() {
MapConfig mapConfig = getHazelcastInstance(sf).getConfig().getMapConfig("org.hibernate.cache.*");
final float baseEvictionRate = 0.2f;
final int numberOfEntities = 100;
final int defaultCleanupPeriod = 60;
final int maxSize = mapConfig.getMaxSizeConfig().getSize();
final int evictedItemCount = numberOfEntities - maxSize + (int) (maxSize * baseEvictionRate);
insertDummyEntities(numberOfEntities);
for (int i = 0; i < numberOfEntities; i++) {
executeQuery(sf, i);
}
HazelcastQueryResultsRegion queryRegion = ((HazelcastQueryResultsRegion) (((SessionFactoryImpl) sf).getQueryCache()).getRegion());
assertEquals(numberOfEntities, queryRegion.getCache().size());
sleep(defaultCleanupPeriod);
assertEquals(numberOfEntities - evictedItemCount, queryRegion.getCache().size());
}
示例4: copyCollectionPersister
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* This is a workaround for HHH-6562 (https://hibernate.atlassian.net/browse/HHH-6562)
*/
@SuppressWarnings("unchecked")
private void copyCollectionPersister(String originalKey, String copyKey,
SessionFactoryImpl sessionFactory) {
try {
Field collectionPersistersField = SessionFactoryImpl.class
.getDeclaredField("collectionPersisters");
collectionPersistersField.setAccessible(true);
Map collectionPersisters = (Map) collectionPersistersField.get(sessionFactory);
if (collectionPersisters.containsKey(originalKey)) {
Object collectionPersister = collectionPersisters.get(originalKey);
collectionPersisters.put(copyKey, collectionPersister);
}
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: build
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
@Override
public EntityManagerFactoryImpl build() {
SessionFactoryImpl sessionFactory =
((SessionFactoryImpl) (SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory = ((EntityManagerFactoryImpl) super.build()))
.getSessionFactory());
StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
serviceRegistry.getService(EntityManagerFactoryRef.class).setEntityManagerFactory(SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory);
ContextHelper.getSearchintegratorBySFI(sessionFactory).getIndexBindings().replaceAll((entityClass, entityIndexBinding) -> {
MutableEntityIndexBinding newEntityIndexBinding =
new DefaultMutableEntityIndexBinding(entityIndexBinding.getSelectionStrategy(), entityIndexBinding.getSimilarity(),
entityIndexBinding.getIndexManagers(), SdcctEntityManagerFactoryFactoryBean.this.entityIndexingInterceptor);
newEntityIndexBinding.setDocumentBuilderIndexedEntity(entityIndexBinding.getDocumentBuilder());
return newEntityIndexBinding;
});
serviceRegistry.getService(DbMetadataService.class);
return SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory;
}
示例6: provide
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* Provide a singleton instance of the hibernate session factory.
*
* @return A session factory.
*/
@Override
public SessionFactory provide() {
logger.trace("Creating hibernate session factory.");
// Build the service registry.
SessionFactory factory = new MetadataSources(serviceRegistry)
.buildMetadata()
.buildSessionFactory();
// Register our event listeners.
injectEventListeners(((SessionFactoryImpl) factory)
.getServiceRegistry());
return factory;
}
示例7: testOverrideProperties
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
@Test
public void testOverrideProperties() {
getTransactionTemplate().execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus status) {
Session session = getEntityManager().unwrap( Session.class );
SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory();
FlexyPoolHibernateConnectionProvider flexyPoolHibernateConnectionProvider =
(FlexyPoolHibernateConnectionProvider) sessionFactory.getConnectionProvider();
FlexyPoolDataSource flexyPoolDataSource = ReflectionUtils.getFieldValue(
flexyPoolHibernateConnectionProvider,
"flexyPoolDataSource"
);
assertEquals( "abcd1234", ReflectionUtils.getFieldValue( flexyPoolDataSource, "uniqueName" ));
return null;
}
});
}
开发者ID:vladmihalcea,项目名称:flexy-pool,代码行数:21,代码来源:ResourceLocalFlexyPoolHibernateConnectionProviderIntegrationTest.java
示例8: createQuery
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* 根据hql创建Hibernate Query对象
*
* @param queryOrNamedQuery hql 或者Hibernate的NamedQuery
* @param values
* 数量可变的参数,按顺序绑定.
*
* @return {@link Query}
*/
protected Query createQuery(String queryOrNamedQuery, Object... values) {
Assert.hasText(queryOrNamedQuery, "queryOrNamedQuery不能为空");
SessionFactoryImpl factory = (SessionFactoryImpl) sessionFactory;
NamedQueryDefinition nqd = factory.getNamedQuery( queryOrNamedQuery );
Query query = null;
if (nqd != null) {
query = getSession().getNamedQuery(queryOrNamedQuery);
} else {
query = getSession().createQuery(queryOrNamedQuery);
}
setQueryValues(query, values);
return query;
}
示例9: createSQLQuery
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* 根据查询SQL与参数列表创建SQLQuery对象
*
* @param queryOrNamedSQLQuery query 或者 NamedSQLQuery
* @param values 数量可变的参数,按顺序绑定.
*
* @return {@link SQLQuery}
*/
protected SQLQuery createSQLQuery( String queryOrNamedSQLQuery, Object... values) {
Assert.hasText(queryOrNamedSQLQuery, "queryOrNamedSQLQuery不能为空");
SessionFactoryImpl factory = (SessionFactoryImpl) sessionFactory;
NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryOrNamedSQLQuery );
Query query = null;
if (nsqlqd != null) {
query = getSession().getNamedQuery(queryOrNamedSQLQuery);
} else {
query = getSession().createSQLQuery(queryOrNamedSQLQuery);
}
setQueryValues(query, values);
SQLQuery sqlQuery = (SQLQuery)query;
return sqlQuery.addEntity(entityClass);
}
示例10: registerEventListener
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* Register event listener.
*
* @param sessionFactory the session factory
* @param listener the listener
* @param eventTypes the event types
*/
@SuppressWarnings("unchecked")
public static void registerEventListener(SessionFactory sessionFactory, Object listener, EventType... eventTypes) {
shouldNotBeNull(sessionFactory, "sessionFactory");
shouldNotBeNull(listener, "listener");
log.trace("sessionFactory에 event listener를 등록합니다... listener=[{}], eventTypes=[{}]",
listener, StringTool.listToString(eventTypes));
EventListenerRegistry registry =
((SessionFactoryImpl) sessionFactory)
.getServiceRegistry()
.getService(EventListenerRegistry.class);
for (EventType eventType : eventTypes) {
try {
registry.getEventListenerGroup(eventType).appendListener(listener);
} catch (Exception ignored) {}
}
}
示例11: toMementos
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
public List<ParameterMemento> toMementos(SessionFactoryImpl sessionFactory) {
final List<ParameterMemento> mementos = new ArrayList<ParameterMemento>();
for ( ParameterDefinition definition : parameterDefinitions ) {
mementos.add(definition.toMemento( sessionFactory ));
}
return mementos;
}
示例12: toMemento
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
public ParameterMemento toMemento(SessionFactoryImpl sessionFactory) {
return new ParameterMemento(
position,
name,
parameterMode,
type,
sessionFactory.getTypeResolver().heuristicType( type.getName() )
);
}
示例13: getType
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
/**
* REVISAR NIKOLAS
*/
@Override
public Type getType(Criteria subcriteria, String propertyName)
throws HibernateException {
System.out.println("Prperty name ==> "+propertyName);
BasicType _type = ((SessionFactoryImpl) sessionFactory).getTypeResolver()
.basic(rootCriteria.getMapColumns().get(propertyName).getType().getName());
/*return getPropertyMapping( getEntityName( subcriteria, propertyName ) )
.toType( getPropertyName( propertyName ) );*/
return _type;
}
示例14: checkEntityManagerFactoryConfiguration
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
public static void checkEntityManagerFactoryConfiguration(EntityManagerFactory entityManagerFactory) {
try {
SessionFactoryImpl sessionFactoryImpl = entityManagerFactory.unwrap(SessionFactoryImpl.class);
if (PostgreSQL9Dialect.class
.isInstance(sessionFactoryImpl.getServiceRegistry().getService(JdbcServices.class).getDialect())) {
//fix ClassLeftUnique and ClassRightUnique, as PostgreSQL cannot evaluate them on statement level
modifyConstraints(sessionFactoryImpl);
}
} catch (PersistenceException e) {
LogManager.getLogger()
.warn("Unsupported EntityManagerFactory found: {}", entityManagerFactory.getClass().getName());
}
}
示例15: init
import org.hibernate.internal.SessionFactoryImpl; //导入依赖的package包/类
@Override
public void init() {
boolean testing = Boolean.parseBoolean(System.getProperty("testing"));
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
configuration.setInterceptor(new HibernateInterceptor());
if (!testing) {
configuration.setProperty("hibernate.connection.username", Reference.getEnvironmentProperty("db.username"));
configuration.setProperty("hibernate.connection.password", Reference.getEnvironmentProperty("db.password"));
String url = "jdbc:mysql://" + Reference.getEnvironmentProperty("db.host") + ":" + Reference.getEnvironmentProperty("db.port") + "/devwars";
configuration.setProperty("hibernate.connection.url", url);
} else {
configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:testdb");
configuration.setProperty("hibernate.connection.username", "sa");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
}
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
EventListenerRegistry registry = ((SessionFactoryImpl) DatabaseManager.sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(postLoadEvent ->
{
HibernateInterceptor.postLoadAny(postLoadEvent.getEntity());
HibernateInterceptor.invokeMethodWithAnnotation(postLoadEvent.getEntity(), PostLoad.class);
});
}